mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-28 17:19:00 +03:00
Replace changelog dialog with controller, move migration logic to a separate class
This commit is contained in:
parent
a5a12f8b3a
commit
256a4197c9
4 changed files with 89 additions and 76 deletions
53
app/src/main/java/eu/kanade/tachiyomi/Migrations.kt
Normal file
53
app/src/main/java/eu/kanade/tachiyomi/Migrations.kt
Normal file
|
@ -0,0 +1,53 @@
|
|||
package eu.kanade.tachiyomi
|
||||
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.updater.UpdateCheckerJob
|
||||
import java.io.File
|
||||
|
||||
object Migrations {
|
||||
|
||||
/**
|
||||
* Performs a migration when the application is updated.
|
||||
*
|
||||
* @param preferences Preferences of the application.
|
||||
* @return true if a migration is performed, false otherwise.
|
||||
*/
|
||||
fun upgrade(preferences: PreferencesHelper): Boolean {
|
||||
val context = preferences.context
|
||||
val oldVersion = preferences.lastVersionCode().getOrDefault()
|
||||
if (oldVersion < BuildConfig.VERSION_CODE) {
|
||||
preferences.lastVersionCode().set(BuildConfig.VERSION_CODE)
|
||||
|
||||
if (oldVersion == 0) return false
|
||||
|
||||
if (oldVersion < 14) {
|
||||
// Restore jobs after upgrading to evernote's job scheduler.
|
||||
if (BuildConfig.INCLUDE_UPDATER && preferences.automaticUpdates()) {
|
||||
UpdateCheckerJob.setupTask()
|
||||
}
|
||||
LibraryUpdateJob.setupTask()
|
||||
}
|
||||
if (oldVersion < 15) {
|
||||
// Delete internal chapter cache dir.
|
||||
File(context.cacheDir, "chapter_disk_cache").deleteRecursively()
|
||||
}
|
||||
if (oldVersion < 19) {
|
||||
// Move covers to external files dir.
|
||||
val oldDir = File(context.externalCacheDir, "cover_disk_cache")
|
||||
if (oldDir.exists()) {
|
||||
val destDir = context.getExternalFilesDir("covers")
|
||||
if (destDir != null) {
|
||||
oldDir.listFiles().forEach {
|
||||
it.renameTo(File(destDir, it.name))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package eu.kanade.tachiyomi.ui.main
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.AttributeSet
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import it.gmariotti.changelibs.library.view.ChangeLogRecyclerView
|
||||
|
||||
class ChangelogDialogController : DialogController() {
|
||||
|
||||
override fun onCreateDialog(savedState: Bundle?): Dialog {
|
||||
val activity = activity!!
|
||||
val view = WhatsNewRecyclerView(activity)
|
||||
return MaterialDialog.Builder(activity)
|
||||
.title(if (BuildConfig.DEBUG) "Notices" else "Changelog")
|
||||
.customView(view, false)
|
||||
.positiveText(android.R.string.yes)
|
||||
.build()
|
||||
}
|
||||
|
||||
class WhatsNewRecyclerView(context: Context) : ChangeLogRecyclerView(context) {
|
||||
override fun initAttrs(attrs: AttributeSet?, defStyle: Int) {
|
||||
mRowLayoutId = R.layout.changelog_row_layout
|
||||
mRowHeaderLayoutId = R.layout.changelog_header_layout
|
||||
mChangeLogFileResourceId = if (BuildConfig.DEBUG) R.raw.changelog_debug else R.raw.changelog_release
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package eu.kanade.tachiyomi.ui.main
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.util.AttributeSet
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.updater.UpdateCheckerJob
|
||||
import it.gmariotti.changelibs.library.view.ChangeLogRecyclerView
|
||||
import java.io.File
|
||||
|
||||
class ChangelogDialogFragment : DialogFragment() {
|
||||
|
||||
companion object {
|
||||
fun show(context: Context, preferences: PreferencesHelper, fm: FragmentManager) {
|
||||
val oldVersion = preferences.lastVersionCode().getOrDefault()
|
||||
if (oldVersion < BuildConfig.VERSION_CODE) {
|
||||
preferences.lastVersionCode().set(BuildConfig.VERSION_CODE)
|
||||
ChangelogDialogFragment().show(fm, "changelog")
|
||||
|
||||
// TODO better upgrades management
|
||||
if (oldVersion == 0) return
|
||||
|
||||
if (oldVersion < 14) {
|
||||
// Restore jobs after upgrading to evernote's job scheduler.
|
||||
if (BuildConfig.INCLUDE_UPDATER && preferences.automaticUpdates()) {
|
||||
UpdateCheckerJob.setupTask()
|
||||
}
|
||||
LibraryUpdateJob.setupTask()
|
||||
}
|
||||
if (oldVersion < 15) {
|
||||
// Delete internal chapter cache dir.
|
||||
File(context.cacheDir, "chapter_disk_cache").deleteRecursively()
|
||||
}
|
||||
if (oldVersion < 19) {
|
||||
// Move covers to external files dir.
|
||||
val oldDir = File(context.externalCacheDir, "cover_disk_cache")
|
||||
if (oldDir.exists()) {
|
||||
val destDir = context.getExternalFilesDir("covers")
|
||||
if (destDir != null) {
|
||||
oldDir.listFiles().forEach {
|
||||
it.renameTo(File(destDir, it.name))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedState: Bundle?): Dialog {
|
||||
val view = WhatsNewRecyclerView(context)
|
||||
return MaterialDialog.Builder(activity)
|
||||
.title(if (BuildConfig.DEBUG) "Notices" else "Changelog")
|
||||
.customView(view, false)
|
||||
.positiveText(android.R.string.yes)
|
||||
.build()
|
||||
}
|
||||
|
||||
class WhatsNewRecyclerView(context: Context) : ChangeLogRecyclerView(context) {
|
||||
override fun initAttrs(attrs: AttributeSet?, defStyle: Int) {
|
||||
mRowLayoutId = R.layout.changelog_row_layout
|
||||
mRowHeaderLayoutId = R.layout.changelog_header_layout
|
||||
mChangeLogFileResourceId = if (BuildConfig.DEBUG) R.raw.changelog_debug else R.raw.changelog_release
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import android.support.v7.graphics.drawable.DrawerArrowDrawable
|
|||
import android.view.ViewGroup
|
||||
import com.bluelinelabs.conductor.*
|
||||
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
|
||||
import eu.kanade.tachiyomi.Migrations
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
|
@ -136,10 +137,11 @@ class MainActivity : BaseActivity() {
|
|||
|
||||
syncActivityViewWithController(router.backstack.lastOrNull()?.controller())
|
||||
|
||||
// TODO changelog controller
|
||||
if (savedInstanceState == null) {
|
||||
// Show changelog if needed
|
||||
ChangelogDialogFragment.show(this, preferences, supportFragmentManager)
|
||||
if (Migrations.upgrade(preferences)) {
|
||||
ChangelogDialogController().showDialog(router)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue