Use dialog to show what's new release info

This commit is contained in:
arkon 2020-08-03 14:08:35 -04:00
parent 493c8b0943
commit 88032e11df
3 changed files with 35 additions and 41 deletions

View File

@ -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<Pair<String, () -> Unit>>
constructor(item: SourceItem, items: List<Pair<String, () -> Unit>>) : this() {
this.item = item
constructor(source: String, items: List<Pair<String, () -> 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

View File

@ -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<MainActivityBinding>() {
@ -155,13 +150,14 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
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<MainActivityBinding>() {
}
}
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<CoordinatorLayout.LayoutParams> {
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"

View File

@ -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)
}
}
}