mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-27 09:44:55 +03:00
Use dialog to show what's new release info
This commit is contained in:
parent
493c8b0943
commit
88032e11df
3 changed files with 35 additions and 41 deletions
|
@ -149,7 +149,7 @@ class SourceController :
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceOptionsDialog(item, items).showDialog(router)
|
SourceOptionsDialog(item.source.toString(), items).showDialog(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun disableSource(source: Source) {
|
private fun disableSource(source: Source) {
|
||||||
|
@ -270,17 +270,17 @@ class SourceController :
|
||||||
|
|
||||||
class SourceOptionsDialog(bundle: Bundle? = null) : DialogController(bundle) {
|
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>>
|
private lateinit var items: List<Pair<String, () -> Unit>>
|
||||||
|
|
||||||
constructor(item: SourceItem, items: List<Pair<String, () -> Unit>>) : this() {
|
constructor(source: String, items: List<Pair<String, () -> Unit>>) : this() {
|
||||||
this.item = item
|
this.source = source
|
||||||
this.items = items
|
this.items = items
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
|
||||||
return MaterialDialog(activity!!)
|
return MaterialDialog(activity!!)
|
||||||
.title(text = item.source.toString())
|
.title(text = source)
|
||||||
.listItems(
|
.listItems(
|
||||||
items = items.map { it.first },
|
items = items.map { it.first },
|
||||||
waitForPositiveButton = false
|
waitForPositiveButton = false
|
||||||
|
|
|
@ -4,14 +4,11 @@ import android.app.Activity
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Gravity
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.net.toUri
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
|
||||||
import com.bluelinelabs.conductor.Conductor
|
import com.bluelinelabs.conductor.Conductor
|
||||||
import com.bluelinelabs.conductor.Controller
|
import com.bluelinelabs.conductor.Controller
|
||||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||||
|
@ -19,12 +16,12 @@ import com.bluelinelabs.conductor.Router
|
||||||
import com.bluelinelabs.conductor.RouterTransaction
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
|
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import com.google.android.material.tabs.TabLayout
|
import com.google.android.material.tabs.TabLayout
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.Migrations
|
import eu.kanade.tachiyomi.Migrations
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
|
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||||
import eu.kanade.tachiyomi.databinding.MainActivityBinding
|
import eu.kanade.tachiyomi.databinding.MainActivityBinding
|
||||||
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
|
import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi
|
||||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
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.launchIO
|
||||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.view.snack
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlinx.android.synthetic.main.main_activity.appbar
|
import kotlinx.android.synthetic.main.main_activity.appbar
|
||||||
import kotlinx.android.synthetic.main.main_activity.tabs
|
import kotlinx.android.synthetic.main.main_activity.tabs
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class MainActivity : BaseActivity<MainActivityBinding>() {
|
class MainActivity : BaseActivity<MainActivityBinding>() {
|
||||||
|
@ -155,13 +150,14 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
// Show changelog prompt on update
|
// Show changelog prompt on update
|
||||||
if (Migrations.upgrade(preferences) && !BuildConfig.DEBUG) {
|
if (Migrations.upgrade(preferences) && !BuildConfig.DEBUG) {
|
||||||
showUpdateInfoSnackbar()
|
WhatsNewDialogController().showDialog(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WhatsNewDialogController().showDialog(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
setExtensionsBadge()
|
preferences.extensionUpdatesCount()
|
||||||
preferences.extensionUpdatesCount().asFlow()
|
.asImmediateFlow { setExtensionsBadge() }
|
||||||
.onEach { setExtensionsBadge() }
|
|
||||||
.launchIn(scope)
|
.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 {
|
companion object {
|
||||||
// Shortcut actions
|
// Shortcut actions
|
||||||
const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"
|
const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue