diff --git a/app/build.gradle b/app/build.gradle index e765156da..a9716fcbb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,6 +7,7 @@ plugins { id "kotlin-android" id "kotlin-kapt" id "kotlin-parcelize" + id "com.google.dagger.hilt.android" id "checkstyle" id "org.sonarqube" version "4.0.0.2929" } @@ -208,6 +209,7 @@ dependencies { implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' // WORKAROUND: v0.24.2 can't be resolved by jitpack -> use git commit hash instead implementation 'com.github.TeamNewPipe:NewPipeExtractor:ea1a1d1375efd5936ed2609d0fa3e31d5097a835' + implementation 'com.github.TeamNewPipe:NewPlayer' implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0' /** Checkstyle **/ @@ -239,6 +241,8 @@ dependencies { implementation 'androidx.viewpager2:viewpager2:1.1.0-beta02' implementation "androidx.work:work-runtime-ktx:${androidxWorkVersion}" implementation "androidx.work:work-rxjava3:${androidxWorkVersion}" + implementation 'com.google.dagger:hilt-android:2.52' + kapt 'com.google.dagger:hilt-compiler:2.52' implementation 'com.google.android.material:material:1.11.0' /** Third-party libraries **/ diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index 9bc25d55d..b327b9445 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -33,12 +33,15 @@ import java.net.SocketException; import java.util.List; import java.util.Objects; +import dagger.hilt.android.HiltAndroidApp; import io.reactivex.rxjava3.exceptions.CompositeException; import io.reactivex.rxjava3.exceptions.MissingBackpressureException; import io.reactivex.rxjava3.exceptions.OnErrorNotImplementedException; import io.reactivex.rxjava3.exceptions.UndeliverableException; import io.reactivex.rxjava3.functions.Consumer; import io.reactivex.rxjava3.plugins.RxJavaPlugins; +import kotlinx.coroutines.CoroutineScope; +import kotlinx.coroutines.Dispatchers; /* * Copyright (C) Hans-Christoph Steiner 2016 @@ -58,6 +61,7 @@ import io.reactivex.rxjava3.plugins.RxJavaPlugins; * along with NewPipe. If not, see . */ +@HiltAndroidApp public class App extends Application { public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID; private static final String TAG = App.class.toString(); diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 175694125..6a233c792 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -58,6 +58,8 @@ import androidx.preference.PreferenceManager; import com.google.android.material.bottomsheet.BottomSheetBehavior; +import net.newpipe.newplayer.NewPlayer; + import org.schabi.newpipe.databinding.ActivityMainBinding; import org.schabi.newpipe.databinding.DrawerHeaderBinding; import org.schabi.newpipe.databinding.DrawerLayoutBinding; @@ -98,11 +100,19 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import javax.inject.Inject; + +import dagger.hilt.android.AndroidEntryPoint; + +@AndroidEntryPoint public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @SuppressWarnings("ConstantConditions") public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release"); + @Inject + NewPlayer newPlayer; + private ActivityMainBinding mainBinding; private DrawerHeaderBinding drawerHeaderBinding; private DrawerLayoutBinding drawerLayoutBinding; diff --git a/app/src/main/java/org/schabi/newpipe/NewPlayerComponent.kt b/app/src/main/java/org/schabi/newpipe/NewPlayerComponent.kt new file mode 100644 index 000000000..77dcbdc4c --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/NewPlayerComponent.kt @@ -0,0 +1,66 @@ +/* NewPlayer + * + * @author Christian Schabesberger + * + * Copyright (C) NewPipe e.V. 2024 + * + * NewPlayer is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPlayer. If not, see . + */ + +package net.newpipe.newplayer.testapp + +import android.app.Application +import android.util.Log +import androidx.core.graphics.drawable.IconCompat +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import net.newpipe.newplayer.NewPlayer +import net.newpipe.newplayer.NewPlayerImpl +import net.newpipe.newplayer.repository.CachingRepository +import net.newpipe.newplayer.repository.PlaceHolderRepository +import net.newpipe.newplayer.repository.PrefetchingRepository +import org.schabi.newpipe.App +import org.schabi.newpipe.MainActivity +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object NewPlayerComponent { + @Provides + @Singleton + fun provideNewPlayer(app: Application): NewPlayer { + val player = NewPlayerImpl( + app = app, + repository = PrefetchingRepository(CachingRepository(PlaceHolderRepository())), + notificationIcon = IconCompat.createWithResource(app, net.newpipe.newplayer.R.drawable.new_player_tiny_icon), + playerActivityClass = MainActivity::class.java, + // rescueStreamFault = … + ) + if (app is App) { + CoroutineScope(Dispatchers.IO).launch { + while (true) { + player.errorFlow.collect { e -> + Log.e("NewPlayerException", e.stackTraceToString()) + } + } + } + } + return player + } +} diff --git a/build.gradle b/build.gradle index d93abc4c0..45ac9d34b 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,10 @@ buildscript { } } +plugins { + id 'com.google.dagger.hilt.android' version '2.52' apply false +} + allprojects { repositories { google() diff --git a/settings.gradle b/settings.gradle index 0338fde6c..af60f3472 100644 --- a/settings.gradle +++ b/settings.gradle @@ -9,3 +9,10 @@ include ':app' // substitute module('com.github.TeamNewPipe:NewPipeExtractor') using project(':extractor') // } //} + + +includeBuild('../NewPlayer') { + dependencySubstitution { + substitute module('com.github.TeamNewPipe:NewPlayer') using project(':new-player') + } +}