From 88032e11df7bdebd21e5684b943da3cc373ef389 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 3 Aug 2020 14:08:35 -0400 Subject: [PATCH] Use dialog to show what's new release info --- .../ui/browse/source/SourceController.kt | 10 ++--- .../kanade/tachiyomi/ui/main/MainActivity.kt | 42 +++---------------- .../ui/main/WhatsNewDialogController.kt | 24 +++++++++++ 3 files changed, 35 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index 4f83f5ec6..14dbae471 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt @@ -149,7 +149,7 @@ class SourceController : ) } - SourceOptionsDialog(item, items).showDialog(router) + SourceOptionsDialog(item.source.toString(), items).showDialog(router) } private fun disableSource(source: Source) { @@ -270,17 +270,17 @@ class SourceController : class SourceOptionsDialog(bundle: Bundle? = null) : DialogController(bundle) { - private lateinit var item: SourceItem + private lateinit var source: String private lateinit var items: List Unit>> - constructor(item: SourceItem, items: List Unit>>) : this() { - this.item = item + constructor(source: String, items: List Unit>>) : this() { + this.source = source this.items = items } override fun onCreateDialog(savedViewState: Bundle?): Dialog { return MaterialDialog(activity!!) - .title(text = item.source.toString()) + .title(text = source) .listItems( items = items.map { it.first }, waitForPositiveButton = false diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 4d4b8e7ba..ac70fd03b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -4,14 +4,11 @@ import android.app.Activity import android.app.SearchManager import android.content.Intent import android.os.Bundle -import android.view.Gravity import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.coordinatorlayout.widget.CoordinatorLayout -import androidx.core.net.toUri import androidx.core.view.isVisible -import androidx.core.view.updateLayoutParams import com.bluelinelabs.conductor.Conductor import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler @@ -19,12 +16,12 @@ import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction import com.google.android.material.appbar.AppBarLayout import com.google.android.material.behavior.HideBottomViewOnScrollBehavior -import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayout import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver +import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.databinding.MainActivityBinding import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.ui.base.activity.BaseActivity @@ -45,14 +42,12 @@ import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.system.toast -import eu.kanade.tachiyomi.util.view.snack import java.util.Date import java.util.concurrent.TimeUnit import kotlinx.android.synthetic.main.main_activity.appbar import kotlinx.android.synthetic.main.main_activity.tabs import kotlinx.coroutines.delay import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach import timber.log.Timber class MainActivity : BaseActivity() { @@ -155,13 +150,14 @@ class MainActivity : BaseActivity() { if (savedInstanceState == null) { // Show changelog prompt on update if (Migrations.upgrade(preferences) && !BuildConfig.DEBUG) { - showUpdateInfoSnackbar() + WhatsNewDialogController().showDialog(router) } + + WhatsNewDialogController().showDialog(router) } - setExtensionsBadge() - preferences.extensionUpdatesCount().asFlow() - .onEach { setExtensionsBadge() } + preferences.extensionUpdatesCount() + .asImmediateFlow { setExtensionsBadge() } .launchIn(scope) } @@ -382,32 +378,6 @@ class MainActivity : BaseActivity() { } } - private fun showUpdateInfoSnackbar() { - val snack = binding.rootCoordinator.snack( - getString(R.string.updated_version, BuildConfig.VERSION_NAME), - Snackbar.LENGTH_INDEFINITE - ) { - setAction(R.string.whats_new) { - val url = "https://github.com/inorichi/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}" - val intent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(intent) - } - - // Ensure the snackbar sits above the bottom nav - view.updateLayoutParams { - anchorId = binding.bottomNav.id - anchorGravity = Gravity.TOP - gravity = Gravity.TOP - } - } - - // Manually handle dismiss delay since Snackbar.LENGTH_LONG is a too short - launchIO { - delay(10000) - snack.dismiss() - } - } - companion object { // Shortcut actions const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt new file mode 100644 index 000000000..a831948d1 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt @@ -0,0 +1,24 @@ +package eu.kanade.tachiyomi.ui.main + +import android.app.Dialog +import android.content.Intent +import android.os.Bundle +import androidx.core.net.toUri +import com.afollestad.materialdialogs.MaterialDialog +import eu.kanade.tachiyomi.BuildConfig +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.ui.base.controller.DialogController + +class WhatsNewDialogController(bundle: Bundle? = null) : DialogController(bundle) { + + override fun onCreateDialog(savedViewState: Bundle?): Dialog { + return MaterialDialog(activity!!) + .title(text = activity!!.getString(R.string.updated_version, BuildConfig.VERSION_NAME)) + .positiveButton(android.R.string.ok) + .neutralButton(R.string.whats_new) { + val url = "https://github.com/inorichi/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}" + val intent = Intent(Intent.ACTION_VIEW, url.toUri()) + startActivity(intent) + } + } +}