Skip to content

Commit

Permalink
fix: predictive back gesture support
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Sep 22, 2023
1 parent a1c00d0 commit 5c9b19b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ open class CollectionActivity : BaseChangelogDialogActivity<Preferences>() {
wallpapersFragment.applyFilter(filter, closed)
}

override fun onFinish() {
super.onFinish()
override fun finish() {
setResult(
if (favoritesModified) ViewerActivity.FAVORITES_MODIFIED_RESULT
else ViewerActivity.FAVORITES_NOT_MODIFIED_RESULT,
Intent().apply {
putExtra(ViewerActivity.FAVORITES_MODIFIED, favoritesModified)
}
)
super.finish()
}

internal fun setFavoritesModified() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.MenuItem
import android.view.Window
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment
import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback
Expand Down Expand Up @@ -49,18 +50,32 @@ abstract class FramesActivity : BaseBillingActivity<Preferences>() {
private var currentTag: String = initialFragmentTag
private var oldTag: String = initialFragmentTag

private val onBackPressedCallback = object : OnBackPressedCallback(false) {
override fun handleOnBackPressed() {
if (currentItemId != initialItemId)
bottomNavigation?.selectedItemId = initialItemId
else supportFinishAfterTransition()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
setExitSharedElementCallback(MaterialContainerTransformSharedElementCallback())

super.onCreate(savedInstanceState)
setContentView(getLayoutRes())
onBackPressedDispatcher.addCallback(onBackPressedCallback)

setSupportActionBar(toolbar)
changeFragment(initialItemId, force = true)

bottomNavigation?.selectedItemId = initialItemId
bottomNavigation?.setOnItemSelectedListener { changeFragment(it.itemId) }
bottomNavigation?.setOnItemSelectedListener {
val fragmentChanged = changeFragment(it.itemId)
if (fragmentChanged)
onBackPressedCallback.isEnabled = currentItemId != initialItemId
fragmentChanged
}

wallpapersViewModel.observeWallpapers(this, ::handleWallpapersUpdate)
wallpapersViewModel.observeCollections(this, ::handleCollectionsUpdate)
Expand All @@ -70,11 +85,6 @@ abstract class FramesActivity : BaseBillingActivity<Preferences>() {
requestNotificationsPermission()
}

override fun onSafeBackPressed() {
if (currentItemId != initialItemId) bottomNavigation?.selectedItemId = initialItemId
else super.onSafeBackPressed()
}

fun updateToolbarTitle(itemId: Int = currentItemId) {
var logoSet = false
if (shouldShowToolbarLogo(itemId)) {
Expand Down Expand Up @@ -181,6 +191,7 @@ abstract class FramesActivity : BaseBillingActivity<Preferences>() {
super.onRestoreInstanceState(savedInstanceState)
currentTag = savedInstanceState.getString(CURRENT_FRAGMENT_KEY, currentTag) ?: currentTag
changeFragment(currentItemId, true)
onBackPressedCallback.isEnabled = currentItemId != initialItemId
}

override fun internalDoSearch(filter: String, closed: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ open class MuzeiSettingsActivity : BaseThemedActivity<Preferences>() {
return super.onOptionsItemSelected(item)
}

override fun onSafeBackPressed() = doFinish()

private fun saveChanges() {
preferences.refreshMuzeiOnWiFiOnly = wifiOnlyRefreshSwitch?.isChecked ?: false
preferences.muzeiCollections = selectedCollections
Expand Down Expand Up @@ -154,7 +152,7 @@ open class MuzeiSettingsActivity : BaseThemedActivity<Preferences>() {
startService(getProviderIntent()?.apply {
putExtra("restart", true)
})
} catch (e: Exception) {
} catch (_: Exception) {
}
supportFinishAfterTransition()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,32 +196,28 @@ open class ViewerActivity : BaseWallpaperApplierActivity<Preferences>() {

override fun finish() {
imageView?.setZoom(1F)
super.finish()
}

override fun onFinish() {
super.onFinish()
setResult(
if (favoritesModified) FAVORITES_MODIFIED_RESULT
else FAVORITES_NOT_MODIFIED_RESULT,
Intent().apply {
putExtra(FAVORITES_MODIFIED, favoritesModified)
}
)
super.finish()
}

private fun dismissApplierDialog() {
try {
applierDialog?.dismiss()
} catch (e: Exception) {
} catch (_: Exception) {
}
applierDialog = null
}

private fun dismissDownloadBlockedDialog() {
try {
downloadBlockedDialog?.dismiss()
} catch (e: Exception) {
} catch (_: Exception) {
}
downloadBlockedDialog = null
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.jahir.frames.ui.activities.base
import android.os.Bundle
import androidx.annotation.IdRes
import androidx.annotation.StyleRes
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import dev.jahir.frames.R
import dev.jahir.frames.data.Preferences
Expand All @@ -18,7 +19,7 @@ import dev.jahir.frames.extensions.context.statusBarLight
import dev.jahir.frames.extensions.resources.isDark
import dev.jahir.frames.extensions.utils.postDelayed

abstract class BaseThemedActivity<out P : Preferences> : BaseFinishResultActivity() {
abstract class BaseThemedActivity<out P : Preferences> : AppCompatActivity() {

private var wasUsingAmoled: Boolean = false
private var useMaterialYou: Boolean = false
Expand Down Expand Up @@ -71,11 +72,13 @@ abstract class BaseThemedActivity<out P : Preferences> : BaseFinishResultActivit
if (preferences.usesAmoledTheme) amoledTheme() else defaultTheme()
}

@Suppress("DEPRECATION")
private fun setCustomTheme() {
setTheme(getRightTheme())
setDefaultDashboardTheme()
resolveColor(com.google.android.material.R.attr.colorPrimaryDark, color(R.color.primaryDark)).let {
resolveColor(
com.google.android.material.R.attr.colorPrimaryDark,
color(R.color.primaryDark)
).let {
statusBarColor = it
if (shouldChangeStatusBarLightStatus)
statusBarLight = !it.isDark
Expand Down Expand Up @@ -105,7 +108,7 @@ abstract class BaseThemedActivity<out P : Preferences> : BaseFinishResultActivit
transaction
.replace(fragmentContainerId, fragment, fragmentTag)
.commit()
} catch (e: Exception) {
} catch (_: Exception) {
}
}

Expand Down

0 comments on commit 5c9b19b

Please sign in to comment.