Skip to content

Commit

Permalink
Attempt fix vfsfitvnm#401
Browse files Browse the repository at this point in the history
  • Loading branch information
vfsfitvnm committed Oct 26, 2022
1 parent f4a55ff commit ed8eb7c
Show file tree
Hide file tree
Showing 64 changed files with 373 additions and 944 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ kapt {
}

dependencies {
implementation(projects.composePersist)
implementation(projects.composeRouting)
implementation(projects.composeReordering)

Expand Down
29 changes: 23 additions & 6 deletions app/src/main/kotlin/it/vfsfitvnm/vimusic/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import com.valentinilk.shimmer.LocalShimmerTheme
import com.valentinilk.shimmer.defaultShimmerTheme
import it.vfsfitvnm.compose.persist.PersistMap
import it.vfsfitvnm.compose.persist.PersistMapOwner
import it.vfsfitvnm.innertube.Innertube
import it.vfsfitvnm.innertube.models.bodies.BrowseBody
import it.vfsfitvnm.innertube.requests.playlistPage
Expand Down Expand Up @@ -99,7 +101,7 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class MainActivity : ComponentActivity() {
class MainActivity : ComponentActivity(), PersistMapOwner {
private val serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
if (service is PlayerService.Binder) {
Expand All @@ -114,20 +116,20 @@ class MainActivity : ComponentActivity() {

private var binder by mutableStateOf<PlayerService.Binder?>(null)

override lateinit var persistMap: PersistMap

override fun onStart() {
super.onStart()
bindService(intent<PlayerService>(), serviceConnection, Context.BIND_AUTO_CREATE)
}

override fun onStop() {
unbindService(serviceConnection)
super.onStop()
}

@OptIn(ExperimentalFoundationApi::class, ExperimentalAnimationApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

@Suppress("DEPRECATION", "UNCHECKED_CAST")
persistMap = lastCustomNonConfigurationInstance as? PersistMap ?: PersistMap()

WindowCompat.setDecorFitsSystemWindows(window, false)

val launchedFromNotification = intent?.extras?.getBoolean("expandPlayerBottomSheet") == true
Expand Down Expand Up @@ -451,6 +453,21 @@ class MainActivity : ComponentActivity() {
}
}

override fun onRetainCustomNonConfigurationInstance() = persistMap

override fun onStop() {
unbindService(serviceConnection)
super.onStop()
}

override fun onDestroy() {
if (!isChangingConfigurations) {
persistMap.clear()
}

super.onDestroy()
}

private fun setSystemBarAppearance(isDark: Boolean) {
with(WindowCompat.getInsetsController(window, window.decorView.rootView)) {
isAppearanceLightStatusBars = !isDark
Expand Down
31 changes: 0 additions & 31 deletions app/src/main/kotlin/it/vfsfitvnm/vimusic/savers/AlbumSaver.kt

This file was deleted.

25 changes: 0 additions & 25 deletions app/src/main/kotlin/it/vfsfitvnm/vimusic/savers/ArtistSaver.kt

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions app/src/main/kotlin/it/vfsfitvnm/vimusic/savers/InfoSaver.kt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit ed8eb7c

Please sign in to comment.