Skip to content

Commit

Permalink
[feature|fix|build] Use MaterialSharedAxis for transition animation; …
Browse files Browse the repository at this point in the history
…fix DownloadTorrentWorker.Companion#startWorker WorkInfo null pointer exception; update dependencies (#7)

* [feature|build] Use MaterialSharedAxis for transition animation; update dependencies

* [optimize|fix] Optimize fragment transition implementation; fix DownloadTorrentWorker.Companion#startWorker WorkInfo null pointer exception

---------

Co-authored-by: SkyD666 <akarinnn666@gmail.com>
  • Loading branch information
lightsummer233 and SkyD666 authored Mar 19, 2024
1 parent d09a020 commit ec14b56
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 12 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 10
versionName = "1.1-alpha04"
versionName = "1.1-alpha05"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -141,17 +141,17 @@ dependencies {

implementation("com.google.android.material:material:1.11.0")

implementation("com.google.dagger:hilt-android:2.50")
ksp("com.google.dagger:hilt-android-compiler:2.50")
implementation("com.google.dagger:hilt-android:2.51")
ksp("com.google.dagger:hilt-android-compiler:2.51")

implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.squareup.okhttp3:okhttp-coroutines-jvm:5.0.0-alpha.12")
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:retrofit:2.10.0")
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")

implementation("io.coil-kt:coil:2.5.0")
implementation("io.coil-kt:coil:2.6.0")
implementation("com.rometools:rome:2.1.0")
implementation("net.dankito.readability4j:readability4j:1.0.8")
implementation("org.libtorrent4j:libtorrent4j-android-arm64:2.1.0-31")
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/skyd/anivu/base/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.navigation.fragment.findNavController
import androidx.viewbinding.ViewBinding
import com.google.android.material.color.MaterialColors
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.transition.MaterialSharedAxis
import com.skyd.anivu.R
import com.skyd.anivu.ext.popBackStackWithLifecycle

Expand Down Expand Up @@ -70,4 +71,25 @@ abstract class BaseFragment<T : ViewBinding> : Fragment() {
}
.show()
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
transitionProvider()
}

private val defaultTransitionProvider: () -> Unit = {
enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ true)
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ false)
exitTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ false)
}

protected val nullTransitionProvider: () -> Unit = {
enterTransition = null
returnTransition = null
exitTransition = null
reenterTransition = null
}

protected open val transitionProvider: () -> Unit = defaultTransitionProvider
}
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ class DownloadTorrentWorker(context: Context, parameters: WorkerParameters) :
getWorkInfoByIdFlow(workRequest.id)
.filter { it == null || it.state.isFinished }
.onEach {
removeWorkerFromFlow(it.id.toString())
removeWorkerFromFlow(workRequest.id.toString())
}.collect {
cancel()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import androidx.preference.ListPreferenceDialogFragmentCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.google.android.material.color.MaterialColors
import com.google.android.material.transition.MaterialSharedAxis
import com.skyd.anivu.ui.component.dialog.InputDialogBuilder

abstract class MaterialPreferenceFragmentCompat : PreferenceFragmentCompat() {

// https://github.com/material-components/material-components-android/issues/2732
override fun onDisplayPreferenceDialog(preference: Preference) {
when (preference) {
Expand Down Expand Up @@ -49,4 +51,25 @@ abstract class MaterialPreferenceFragmentCompat : PreferenceFragmentCompat() {
// Fix https://github.com/material-components/material-components-android/issues/1984#issuecomment-1089710991
view.setBackgroundColor(MaterialColors.getColor(view, android.R.attr.colorBackground))
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
transitionProvider()
}

private val defaultTransitionProvider: () -> Unit = {
enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ true)
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ false)
exitTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, /* forward= */ false)
}

protected val nullTransitionProvider: () -> Unit = {
enterTransition = null
returnTransition = null
exitTransition = null
reenterTransition = null
}

protected open val transitionProvider: () -> Unit = defaultTransitionProvider
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import kotlinx.coroutines.flow.onEach

@AndroidEntryPoint
class FeedFragment : BaseFragment<FragmentFeedBinding>() {
override val transitionProvider: () -> Unit = nullTransitionProvider

private val feedViewModel by viewModels<FeedViewModel>()
private val intents = Channel<FeedIntent>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class MediaFragment : BaseFragment<FragmentMediaBinding>() {
const val HAS_PARENT_DIR_KEY = "hasParentDir"
}

override val transitionProvider: () -> Unit = nullTransitionProvider

private val viewModel by viewModels<MediaViewModel>()
private val path by lazy { arguments?.getString(PATH_KEY) ?: Const.VIDEO_DIR.path }
private val hasParentDir by lazy { arguments?.getBoolean(HAS_PARENT_DIR_KEY) ?: false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MoreFragment : BaseFragment<FragmentMoreBinding>() {
override val transitionProvider: () -> Unit = nullTransitionProvider

private val adapter = VarietyAdapter(mutableListOf())

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.3.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
id("com.google.dagger.hilt.android") version "2.50" apply false
id("com.google.devtools.ksp") version "1.9.22-1.0.17" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.22"
id("com.android.application") version "8.3.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.23" apply false
id("com.google.dagger.hilt.android") version "2.51" apply false
id("com.google.devtools.ksp") version "1.9.23-1.0.19" apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.23"
}

0 comments on commit ec14b56

Please sign in to comment.