Skip to content

Commit

Permalink
remove activitybrainslug
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Nov 4, 2024
1 parent 127ae66 commit f7709e1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 161 deletions.
147 changes: 0 additions & 147 deletions new-player/src/main/java/net/newpipe/newplayer/ActivityBrainSlug.kt

This file was deleted.

5 changes: 3 additions & 2 deletions test-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ dependencies {
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.coil.compose)
implementation(libs.okhttp.android)
implementation(libs.androidx.lifecycle.runtime.ktx)


// development impl
implementation(project(":new-player"))
implementation(libs.okhttp.android)

//jitpack test
//implementation(libs.newplayer)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.annotation.OptIn
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.coroutineScope
import androidx.lifecycle.lifecycleScope
import androidx.media3.common.util.UnstableApi
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import net.newpipe.newplayer.ActivityBrainSlug
import net.newpipe.newplayer.NewPlayer
import net.newpipe.newplayer.data.PlayMode
import net.newpipe.newplayer.uiModel.NewPlayerViewModel
import net.newpipe.newplayer.uiModel.NewPlayerViewModelImpl
import net.newpipe.newplayer.uiModel.UIModeState
import net.newpipe.newplayer.testapp.databinding.ActivityMainBinding
import net.newpipe.newplayer.ui.ContentScale
import net.newpipe.newplayer.uiModel.NewPlayerUIState
import javax.inject.Inject

@AndroidEntryPoint
Expand All @@ -54,8 +58,6 @@ class MainActivity : AppCompatActivity() {
@Inject
lateinit var newPlayer: NewPlayer

var activityBrainSlug: ActivityBrainSlug? = null

lateinit var binding: ActivityMainBinding

@OptIn(UnstableApi::class)
Expand Down Expand Up @@ -121,13 +123,28 @@ class MainActivity : AppCompatActivity() {
newPlayerViewModel.newPlayer = newPlayer
newPlayerViewModel.contentFitMode = ContentScale.FIT_INSIDE

activityBrainSlug = ActivityBrainSlug(newPlayerViewModel)
activityBrainSlug?.let {
it.embeddedPlayerView = binding.embeddedPlayer
it.addViewToHideOnFullscreen(binding.buttonsLayout as View)
it.addViewToHideOnFullscreen(binding.embeddedPlayerLayout as View)
it.fullscreenPlayerView = binding.fullscreenPlayer
it.rootView = binding.root
lifecycleScope.launch {
var oldState: NewPlayerUIState? = null
newPlayerViewModel.uiState.collect { newState ->
if (oldState?.uiMode?.fullscreen != newState.uiMode.fullscreen) {
if (newState.uiMode.fullscreen) {
removeSystemInsets()
binding.embeddedPlayer.viewModel = null
binding.fullscreenPlayer.viewModel = newPlayerViewModel
binding.buttonsLayout?.visibility = View.GONE
binding.embeddedPlayerLayout.visibility = View.GONE
binding.fullscreenPlayer.visibility = View.VISIBLE
} else {
addSystemInsets()
binding.fullscreenPlayer.viewModel = null
binding.embeddedPlayer.viewModel = newPlayerViewModel
binding.buttonsLayout?.visibility = View.VISIBLE
binding.embeddedPlayerLayout.visibility = View.VISIBLE
binding.fullscreenPlayer.visibility = View.GONE
}
}
oldState = newState
}
}

////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -141,7 +158,6 @@ class MainActivity : AppCompatActivity() {
}



/**
* This callback is necessary to fix the views screen orientation.
* Because pip is enabled, an orientation changes will not trigger a reconfiguration of the activity.
Expand Down Expand Up @@ -200,4 +216,29 @@ class MainActivity : AppCompatActivity() {
reconfigurationPending = false
}
}
}


private fun addSystemInsets() {
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(
systemBars.left,
systemBars.top,
systemBars.right,
systemBars.bottom
)
insets
}
}

private fun removeSystemInsets() {
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
v.setPadding(
0, 0, 0, 0
)
insets
}

}
}

0 comments on commit f7709e1

Please sign in to comment.