From 4a934f2737d06165f0a3b6b4745e9a25409708eb Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Mon, 8 Jul 2024 17:45:54 +0200 Subject: [PATCH] get the hilt shit to compile --- app/build.gradle.kts | 1 + .../net/newpipe/newplayer/NewPlayerApp.kt | 27 +++++++++++++ .../net/newpipe/newplayer/PlayerFragment.kt | 5 ++- .../newpipe/newplayer/VideoPlayerComponent.kt | 40 +++++++++++++++++++ .../newplayer/model/VideoPlayerViewModel.kt | 22 ++++++++++ .../net/newpipe/newplayer/ui/VideoPlayerUI.kt | 31 ++++++++++++++ build.gradle.kts | 2 +- gradle/libs.versions.toml | 26 ++++++++++-- 8 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/net/newpipe/newplayer/NewPlayerApp.kt create mode 100644 app/src/main/java/net/newpipe/newplayer/VideoPlayerComponent.kt create mode 100644 app/src/main/java/net/newpipe/newplayer/model/VideoPlayerViewModel.kt create mode 100644 app/src/main/java/net/newpipe/newplayer/ui/VideoPlayerUI.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 881afd5..b562d0b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -24,6 +24,7 @@ plugins { alias(libs.plugins.android.application) alias(libs.plugins.jetbrains.kotlin.android) alias(libs.plugins.kotlin.kapt) + alias(libs.plugins.androidHilt) } android { diff --git a/app/src/main/java/net/newpipe/newplayer/NewPlayerApp.kt b/app/src/main/java/net/newpipe/newplayer/NewPlayerApp.kt new file mode 100644 index 0000000..5663b4b --- /dev/null +++ b/app/src/main/java/net/newpipe/newplayer/NewPlayerApp.kt @@ -0,0 +1,27 @@ +/* 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 + +import android.app.Application +import dagger.hilt.android.HiltAndroidApp + +@HiltAndroidApp +class NewPlayerApp : Application() \ No newline at end of file diff --git a/app/src/main/java/net/newpipe/newplayer/PlayerFragment.kt b/app/src/main/java/net/newpipe/newplayer/PlayerFragment.kt index e7a4fe8..9a3504e 100644 --- a/app/src/main/java/net/newpipe/newplayer/PlayerFragment.kt +++ b/app/src/main/java/net/newpipe/newplayer/PlayerFragment.kt @@ -27,9 +27,12 @@ import android.view.ViewGroup import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.fragment.app.Fragment +import dagger.hilt.android.AndroidEntryPoint import net.newpipe.newplayer.ui.VideoPlayerControllerUI +import net.newpipe.newplayer.ui.VideoPlayerUI import net.newpipe.newplayer.ui.theme.VideoPlayerTheme +@AndroidEntryPoint class PlayerFragment : Fragment() { override fun onCreateView( @@ -44,7 +47,7 @@ class PlayerFragment : Fragment() { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { VideoPlayerTheme { - VideoPlayerControllerUI() + VideoPlayerUI() } } } diff --git a/app/src/main/java/net/newpipe/newplayer/VideoPlayerComponent.kt b/app/src/main/java/net/newpipe/newplayer/VideoPlayerComponent.kt new file mode 100644 index 0000000..beaf4e8 --- /dev/null +++ b/app/src/main/java/net/newpipe/newplayer/VideoPlayerComponent.kt @@ -0,0 +1,40 @@ +/* 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 + +import android.app.Application +import androidx.media3.common.Player +import androidx.media3.exoplayer.ExoPlayer +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ViewModelComponent +import dagger.hilt.android.scopes.ViewModelScoped + +@Module +@InstallIn(ViewModelComponent::class) +object VideoPlayerComponent { + @Provides + @ViewModelScoped + fun provideVideoPlayer(app: Application) : Player { + return ExoPlayer.Builder(app).build() + } +} \ No newline at end of file diff --git a/app/src/main/java/net/newpipe/newplayer/model/VideoPlayerViewModel.kt b/app/src/main/java/net/newpipe/newplayer/model/VideoPlayerViewModel.kt new file mode 100644 index 0000000..9dab975 --- /dev/null +++ b/app/src/main/java/net/newpipe/newplayer/model/VideoPlayerViewModel.kt @@ -0,0 +1,22 @@ +package net.newpipe.newplayer.model + +import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.ViewModel +import androidx.media3.common.Player +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class VideoPlayerViewModel @Inject constructor( + private val savedStateHandle: SavedStateHandle, + val player: Player +): ViewModel() { + + init { + player.prepare() + } + + override fun onCleared() { + player.release() + } +} \ No newline at end of file diff --git a/app/src/main/java/net/newpipe/newplayer/ui/VideoPlayerUI.kt b/app/src/main/java/net/newpipe/newplayer/ui/VideoPlayerUI.kt new file mode 100644 index 0000000..4584995 --- /dev/null +++ b/app/src/main/java/net/newpipe/newplayer/ui/VideoPlayerUI.kt @@ -0,0 +1,31 @@ +/* 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.ui + +import androidx.compose.runtime.Composable +import androidx.hilt.navigation.compose.hiltViewModel +import net.newpipe.newplayer.model.VideoPlayerViewModel + +@Composable +fun VideoPlayerUI() { + val videoPlayerViewModel: VideoPlayerViewModel = hiltViewModel() + VideoPlayerControllerUI() +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 4de7fc4..ed85bf0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,10 +17,10 @@ * You should have received a copy of the GNU General Public License * along with NewPlayer. If not, see . */ - // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.jetbrains.kotlin.android) apply false alias(libs.plugins.kotlin.kapt) apply false + alias(libs.plugins.androidHilt) apply false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7226b96..221032a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,3 +1,22 @@ +# 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 . + [versions] agp = "8.5.0" kotlin = "1.9.0" @@ -9,7 +28,6 @@ appcompat = "1.7.0" material = "1.12.0" activity = "1.9.0" constraintlayout = "2.1.4" -activityCompose = "1.9.0" material3 = "1.2.1" uiTooling = "1.6.8" materialIconsExtendedAndroid = "1.7.0-beta04" @@ -17,7 +35,6 @@ media3Ui = "1.4.0-beta01" hiltAndroid = "2.51.1" hiltCompiler = "1.2.0" hiltNavigationCompose = "1.2.0" -hiltAndroidCompiler = "2.51.1" lifecycleViewmodelCompose = "2.8.3" [libraries] @@ -29,7 +46,7 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version material = { group = "com.google.android.material", name = "material", version.ref = "material" } androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" } androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" } -androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } +androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity" } androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" } androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "uiTooling" } androidx-material-icons-extended-android = { group = "androidx.compose.material", name = "material-icons-extended-android", version.ref = "materialIconsExtendedAndroid" } @@ -38,11 +55,12 @@ androidx-media3-ui = { group = "androidx.media3", name = "media3-ui", version.re hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hiltAndroid" } androidx-hilt-compiler = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "hiltCompiler" } androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNavigationCompose" } -hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hiltAndroidCompiler" } +hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hiltAndroid" } androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } +androidHilt = { id = "com.google.dagger.hilt.android", version.ref = "hiltAndroid" }