Allow migrating extra info like viewer, chapter filters, and other stuff
This commit is contained in:
parent
1a55f4845c
commit
32748fa056
@ -4,17 +4,18 @@ import eu.kanade.tachiyomi.R
|
|||||||
|
|
||||||
object MigrationFlags {
|
object MigrationFlags {
|
||||||
|
|
||||||
const val CHAPTERS = 0b001
|
const val CHAPTERS = 0b0001
|
||||||
const val CATEGORIES = 0b010
|
const val CATEGORIES = 0b0010
|
||||||
const val TRACK = 0b100
|
const val TRACK = 0b0100
|
||||||
|
const val EXTRA = 0b1000
|
||||||
|
|
||||||
private const val CHAPTERS2 = 0x1
|
private const val CHAPTERS2 = 0x1
|
||||||
private const val CATEGORIES2 = 0x2
|
private const val CATEGORIES2 = 0x2
|
||||||
private const val TRACK2 = 0x4
|
private const val TRACK2 = 0x4
|
||||||
|
|
||||||
val titles get() = arrayOf(R.string.chapters, R.string.categories, R.string.track)
|
val titles get() = arrayOf(R.string.chapters, R.string.categories, R.string.track, R.string.log_extra)
|
||||||
|
|
||||||
val flags get() = arrayOf(CHAPTERS, CATEGORIES, TRACK)
|
val flags get() = arrayOf(CHAPTERS, CATEGORIES, TRACK, EXTRA)
|
||||||
|
|
||||||
fun hasChapters(value: Int): Boolean {
|
fun hasChapters(value: Int): Boolean {
|
||||||
return value and CHAPTERS != 0
|
return value and CHAPTERS != 0
|
||||||
@ -28,6 +29,10 @@ object MigrationFlags {
|
|||||||
return value and TRACK != 0
|
return value and TRACK != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasExtra(value: Int): Boolean {
|
||||||
|
return value and EXTRA != 0
|
||||||
|
}
|
||||||
|
|
||||||
fun getEnabledFlagsPositions(value: Int): List<Int> {
|
fun getEnabledFlagsPositions(value: Int): List<Int> {
|
||||||
return flags.mapIndexedNotNull { index, flag -> if (value and flag != 0) index else null }
|
return flags.mapIndexedNotNull { index, flag -> if (value and flag != 0) index else null }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,15 +14,9 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
|
|||||||
import com.tfcporciuncula.flow.Preference
|
import com.tfcporciuncula.flow.Preference
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.databinding.MigrationBottomSheetBinding
|
||||||
import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags
|
import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import kotlinx.android.synthetic.main.migration_bottom_sheet.*
|
|
||||||
import kotlinx.android.synthetic.main.migration_bottom_sheet.extra_search_param
|
|
||||||
import kotlinx.android.synthetic.main.migration_bottom_sheet.extra_search_param_text
|
|
||||||
import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_categories
|
|
||||||
import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_chapters
|
|
||||||
import kotlinx.android.synthetic.main.migration_bottom_sheet.mig_tracking
|
|
||||||
import kotlinx.android.synthetic.main.migration_bottom_sheet.use_smart_search
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@ -38,15 +32,12 @@ class MigrationBottomSheetDialog(activity: Activity, theme: Int, private val lis
|
|||||||
private val preferences by injectLazy<PreferencesHelper>()
|
private val preferences by injectLazy<PreferencesHelper>()
|
||||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||||
|
|
||||||
init {
|
private val binding: MigrationBottomSheetBinding = MigrationBottomSheetBinding.inflate(activity.layoutInflater)
|
||||||
// Use activity theme for this layout
|
|
||||||
val view = activity.layoutInflater.inflate(R.layout.migration_bottom_sheet, null)
|
|
||||||
// val scroll = NestedScrollView(context)
|
|
||||||
// scroll.addView(view)
|
|
||||||
|
|
||||||
setContentView(view)
|
init {
|
||||||
|
setContentView(binding.root)
|
||||||
if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
sourceGroup.orientation = LinearLayout.HORIZONTAL
|
binding.sourceGroup.orientation = LinearLayout.HORIZONTAL
|
||||||
}
|
}
|
||||||
window?.setBackgroundDrawable(null)
|
window?.setBackgroundDrawable(null)
|
||||||
}
|
}
|
||||||
@ -59,11 +50,11 @@ class MigrationBottomSheetDialog(activity: Activity, theme: Int, private val lis
|
|||||||
|
|
||||||
initPreferences()
|
initPreferences()
|
||||||
|
|
||||||
fab.clicks().onEach {
|
binding.fab.clicks().onEach {
|
||||||
preferences.skipPreMigration().set(skip_step.isChecked)
|
preferences.skipPreMigration().set(binding.skipStep.isChecked)
|
||||||
listener.startMigration(
|
listener.startMigration(
|
||||||
if (use_smart_search.isChecked && extra_search_param_text.text.isNotBlank()) {
|
if (binding.useSmartSearch.isChecked && binding.extraSearchParamText.text.isNotBlank()) {
|
||||||
extra_search_param_text.text.toString()
|
binding.extraSearchParamText.toString()
|
||||||
} else null
|
} else null
|
||||||
)
|
)
|
||||||
dismiss()
|
dismiss()
|
||||||
@ -76,23 +67,25 @@ class MigrationBottomSheetDialog(activity: Activity, theme: Int, private val lis
|
|||||||
private fun initPreferences() {
|
private fun initPreferences() {
|
||||||
val flags = preferences.migrateFlags().get()
|
val flags = preferences.migrateFlags().get()
|
||||||
|
|
||||||
mig_chapters.isChecked = MigrationFlags.hasChapters(flags)
|
binding.migChapters.isChecked = MigrationFlags.hasChapters(flags)
|
||||||
mig_categories.isChecked = MigrationFlags.hasCategories(flags)
|
binding.migCategories.isChecked = MigrationFlags.hasCategories(flags)
|
||||||
mig_tracking.isChecked = MigrationFlags.hasTracks(flags)
|
binding.migTracking.isChecked = MigrationFlags.hasTracks(flags)
|
||||||
|
binding.migExtra.isChecked = MigrationFlags.hasExtra(flags)
|
||||||
|
|
||||||
mig_chapters.setOnCheckedChangeListener { _, _ -> setFlags() }
|
binding.migChapters.setOnCheckedChangeListener { _, _ -> setFlags() }
|
||||||
mig_categories.setOnCheckedChangeListener { _, _ -> setFlags() }
|
binding.migCategories.setOnCheckedChangeListener { _, _ -> setFlags() }
|
||||||
mig_tracking.setOnCheckedChangeListener { _, _ -> setFlags() }
|
binding.migTracking.setOnCheckedChangeListener { _, _ -> setFlags() }
|
||||||
|
binding.migExtra.setOnCheckedChangeListener { buttonView, isChecked -> setFlags() }
|
||||||
|
|
||||||
use_smart_search.bindToPreference(preferences.smartMigration())
|
binding.useSmartSearch.bindToPreference(preferences.smartMigration())
|
||||||
extra_search_param_text.isVisible = false
|
binding.extraSearchParamText.isVisible = false
|
||||||
extra_search_param.setOnCheckedChangeListener { _, isChecked ->
|
binding.extraSearchParam.setOnCheckedChangeListener { _, isChecked ->
|
||||||
extra_search_param_text.isVisible = isChecked
|
binding.extraSearchParamText.isVisible = isChecked
|
||||||
}
|
}
|
||||||
sourceGroup.bindToPreference(preferences.useSourceWithMost())
|
binding.sourceGroup.bindToPreference(preferences.useSourceWithMost())
|
||||||
|
|
||||||
skip_step.isChecked = preferences.skipPreMigration().get()
|
binding.skipStep.isChecked = preferences.skipPreMigration().get()
|
||||||
skip_step.setOnCheckedChangeListener { _, isChecked ->
|
binding.skipStep.setOnCheckedChangeListener { _, isChecked ->
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
(listener as? Controller)?.activity?.toast(
|
(listener as? Controller)?.activity?.toast(
|
||||||
R.string.pre_migration_skip_toast,
|
R.string.pre_migration_skip_toast,
|
||||||
@ -104,9 +97,10 @@ class MigrationBottomSheetDialog(activity: Activity, theme: Int, private val lis
|
|||||||
|
|
||||||
private fun setFlags() {
|
private fun setFlags() {
|
||||||
var flags = 0
|
var flags = 0
|
||||||
if (mig_chapters.isChecked) flags = flags or MigrationFlags.CHAPTERS
|
if (binding.migChapters.isChecked) flags = flags or MigrationFlags.CHAPTERS
|
||||||
if (mig_categories.isChecked) flags = flags or MigrationFlags.CATEGORIES
|
if (binding.migCategories.isChecked) flags = flags or MigrationFlags.CATEGORIES
|
||||||
if (mig_tracking.isChecked) flags = flags or MigrationFlags.TRACK
|
if (binding.migTracking.isChecked) flags = flags or MigrationFlags.TRACK
|
||||||
|
if (binding.migExtra.isChecked) flags = flags or MigrationFlags.EXTRA
|
||||||
preferences.migrateFlags().set(flags)
|
preferences.migrateFlags().set(flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,7 @@ class MigrationMangaPresenter(
|
|||||||
val migrateChapters = MigrationFlags.hasChapters(flags)
|
val migrateChapters = MigrationFlags.hasChapters(flags)
|
||||||
val migrateCategories = MigrationFlags.hasCategories(flags)
|
val migrateCategories = MigrationFlags.hasCategories(flags)
|
||||||
val migrateTracks = MigrationFlags.hasTracks(flags)
|
val migrateTracks = MigrationFlags.hasTracks(flags)
|
||||||
|
val migrateExtra = MigrationFlags.hasExtra(flags)
|
||||||
|
|
||||||
db.inTransaction {
|
db.inTransaction {
|
||||||
// Update chapters read
|
// Update chapters read
|
||||||
@ -99,6 +100,17 @@ class MigrationMangaPresenter(
|
|||||||
}
|
}
|
||||||
db.insertTracks(tracks).executeAsBlocking()
|
db.insertTracks(tracks).executeAsBlocking()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (migrateExtra) {
|
||||||
|
manga.bookmarkedFilter = prevManga.bookmarkedFilter
|
||||||
|
manga.downloadedFilter = prevManga.downloadedFilter
|
||||||
|
manga.readFilter = prevManga.readFilter
|
||||||
|
manga.viewer = prevManga.viewer
|
||||||
|
manga.chapter_flags = prevManga.chapter_flags
|
||||||
|
manga.displayMode = prevManga.displayMode
|
||||||
|
manga.sorting = prevManga.sorting
|
||||||
|
}
|
||||||
|
|
||||||
// Update favorite status
|
// Update favorite status
|
||||||
if (replace) {
|
if (replace) {
|
||||||
prevManga.favorite = false
|
prevManga.favorite = false
|
||||||
@ -108,6 +120,8 @@ class MigrationMangaPresenter(
|
|||||||
} else {
|
} else {
|
||||||
manga.date_added = Date().time
|
manga.date_added = Date().time
|
||||||
}
|
}
|
||||||
|
// Set extra data
|
||||||
|
|
||||||
manga.favorite = true
|
manga.favorite = true
|
||||||
db.updateMangaFavorite(manga).executeAsBlocking()
|
db.updateMangaFavorite(manga).executeAsBlocking()
|
||||||
|
|
||||||
|
|||||||
@ -60,11 +60,22 @@
|
|||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:text="@string/track"
|
android:text="@string/track"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/mig_categories"
|
app:layout_constraintBottom_toBottomOf="@+id/mig_categories"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintHorizontal_bias="0.0"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/mig_categories"
|
app:layout_constraintStart_toEndOf="@+id/mig_categories"
|
||||||
app:layout_constraintTop_toTopOf="@+id/mig_categories" />
|
app:layout_constraintTop_toTopOf="@+id/mig_categories" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/mig_extra"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:checked="true"
|
||||||
|
android:text="@string/log_extra"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/mig_tracking"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/mig_tracking"
|
||||||
|
app:layout_constraintTop_toTopOf="@+id/mig_tracking" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/options_label"
|
android:id="@+id/options_label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user