From c02fb89359d7e1bed5588598cfc55ce6c5ef8172 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Wed, 4 Dec 2024 15:21:35 +0100 Subject: [PATCH] WIP: Inject (a local) NewPlayer into the NewPipe application This is the basic setup that allows us to inject a NewPlayer instance into NewPipe. Frankenpipe, rise! --- app/build.gradle | 2 + .../java/org/schabi/newpipe/MainActivity.java | 10 +++ .../org/schabi/newpipe/NewPlayerComponent.kt | 66 +++++++++++++++++++ build.gradle | 4 ++ settings.gradle | 7 ++ 5 files changed, 89 insertions(+) create mode 100644 app/src/main/java/org/schabi/newpipe/NewPlayerComponent.kt diff --git a/app/build.gradle b/app/build.gradle index 77cbdc5a4..cf7ab2780 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -199,6 +199,8 @@ dependencies { implementation libs.teamnewpipe.newpipe.extractor implementation libs.teamnewpipe.nononsense.filepicker + implementation 'com.github.TeamNewPipe:NewPlayer' + /** Checkstyle **/ checkstyle libs.tools.checkstyle ktlint libs.tools.ktlint diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 39431537d..22e95d2c9 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -56,6 +56,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; @@ -94,11 +96,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 f3772ac87..8e570a5e8 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,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') + } +}