mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-04 08:08:55 +01:00 
			
		
		
		
	Replace changelog dialog with controller, move migration logic to a separate class
This commit is contained in:
		@@ -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)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user