Move manga to default category (#166)
Also removed option for how to move manga between categories, will always keep category's sorting
This commit is contained in:
parent
7325a79318
commit
3ccaf92770
@ -145,8 +145,6 @@ object PreferenceKeys {
|
||||
|
||||
const val updateOnRefresh = "update_on_refresh"
|
||||
|
||||
const val keepCatSort = "keep_cat_sort"
|
||||
|
||||
const val alwaysShowChapterTransition = "always_show_chapter_transition"
|
||||
|
||||
@Deprecated("Use the preferences of the source")
|
||||
|
@ -251,8 +251,6 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun unreadBadgeType() = rxPrefs.getInteger("unread_badge_type", 2)
|
||||
|
||||
fun keepCatSort() = rxPrefs.getInteger(Keys.keepCatSort, 0)
|
||||
|
||||
fun hideFiltersAtStart() = rxPrefs.getBoolean("hide_filters_at_start", false)
|
||||
|
||||
fun alwaysShowChapterTransition() = rxPrefs.getBoolean(Keys.alwaysShowChapterTransition, true)
|
||||
|
@ -15,12 +15,6 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
toolbar_title.text = null
|
||||
} else {
|
||||
toolbar_title.text = context.getString(resId)
|
||||
post {
|
||||
if (navigationIcon !is DrawerArrowDrawable) {
|
||||
toolbar_title.text = context.getString(resId)
|
||||
requestLayout()
|
||||
}
|
||||
}
|
||||
super.setTitle(null)
|
||||
}
|
||||
}
|
||||
@ -31,12 +25,6 @@ class CenteredToolbar@JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
toolbar_title.text = ""
|
||||
} else {
|
||||
toolbar_title.text = title
|
||||
post {
|
||||
if (navigationIcon !is DrawerArrowDrawable) {
|
||||
toolbar_title.text = title
|
||||
requestLayout()
|
||||
}
|
||||
}
|
||||
super.setTitle(null)
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ class LibraryCategoryAdapter(val libraryListener: LibraryListener) :
|
||||
val db: DatabaseHelper by injectLazy()
|
||||
return when (val item: IFlexible<*>? = getItem(position)) {
|
||||
is LibraryHeaderItem ->
|
||||
if (preferences.hideCategories().getOrDefault()) null
|
||||
if (preferences.hideCategories().getOrDefault() || item.category.id == 0) null
|
||||
else getFirstLetter(item.category.name) +
|
||||
"\u200B".repeat(max(0, item.category.order))
|
||||
is LibraryItem -> {
|
||||
|
@ -23,8 +23,6 @@ import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.checkbox.checkBoxPrompt
|
||||
import com.afollestad.materialdialogs.checkbox.isCheckPromptChecked
|
||||
import com.afollestad.materialdialogs.list.listItemsSingleChoice
|
||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||
import com.bluelinelabs.conductor.ControllerChangeType
|
||||
@ -73,7 +71,6 @@ import kotlinx.android.synthetic.main.main_activity.*
|
||||
import kotlinx.coroutines.delay
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@ -158,7 +155,7 @@ class LibraryController(
|
||||
scrollDistance = 0f
|
||||
}
|
||||
} else scrollDistance = 0f
|
||||
if (order != null && order != activeCategory) {
|
||||
if (order != null && order != activeCategory && lastItem == null) {
|
||||
preferences.lastUsedCategory().set(order)
|
||||
activeCategory = order
|
||||
setTitle()
|
||||
@ -663,10 +660,16 @@ class LibraryController(
|
||||
|
||||
override fun onItemMove(fromPosition: Int, toPosition: Int) {
|
||||
// Because padding a recycler causes it to scroll up we have to scroll it back down... wild
|
||||
if ((adapter.getItem(fromPosition) is LibraryItem && adapter.getItem(fromPosition) is LibraryItem) || adapter.getItem(
|
||||
if ((adapter.getItem(fromPosition) is LibraryItem && adapter.getItem(fromPosition) is
|
||||
LibraryItem) || adapter.getItem(
|
||||
fromPosition
|
||||
) == null
|
||||
) recycler.scrollBy(0, recycler.paddingTop)
|
||||
) {
|
||||
recycler.scrollBy(0, recycler.paddingTop)
|
||||
view?.post {
|
||||
setTitle()
|
||||
}
|
||||
}
|
||||
activity?.appbar?.y = 0f
|
||||
if (lastItemPosition == toPosition) lastItemPosition = null
|
||||
else if (lastItemPosition == null) lastItemPosition = fromPosition
|
||||
@ -676,7 +679,7 @@ class LibraryController(
|
||||
if (adapter.isSelected(fromPosition)) toggleSelection(fromPosition)
|
||||
val item = adapter.getItem(fromPosition) as? LibraryItem ?: return false
|
||||
val newHeader = adapter.getSectionHeader(toPosition) as? LibraryHeaderItem
|
||||
if (toPosition <= 1) return false
|
||||
if (toPosition < 1) return false
|
||||
return (adapter.getItem(toPosition) !is LibraryHeaderItem) && (newHeader?.category?.id == item.manga.category || !presenter.mangaIsInCategory(
|
||||
item.manga, newHeader?.category?.id
|
||||
))
|
||||
@ -687,6 +690,7 @@ class LibraryController(
|
||||
lastItemPosition = null
|
||||
return
|
||||
}
|
||||
lastItem = null
|
||||
destroyActionModeIfNeeded()
|
||||
// if nothing moved
|
||||
if (lastItemPosition == null) return
|
||||
@ -705,36 +709,9 @@ class LibraryController(
|
||||
}
|
||||
return
|
||||
}
|
||||
if (newHeader?.category?.mangaSort == null) {
|
||||
moveMangaToCategory(item.manga, newHeader?.category, mangaIds, true)
|
||||
} else {
|
||||
val keepCatSort = preferences.keepCatSort().getOrDefault()
|
||||
if (keepCatSort == 0) {
|
||||
MaterialDialog(activity!!).message(R.string.switch_to_dnd)
|
||||
.positiveButton(R.string.action_switch) {
|
||||
moveMangaToCategory(
|
||||
item.manga, newHeader.category, mangaIds, true
|
||||
if (newHeader?.category != null) moveMangaToCategory(
|
||||
item.manga, newHeader.category, mangaIds
|
||||
)
|
||||
if (it.isCheckPromptChecked()) preferences.keepCatSort().set(2)
|
||||
}.checkBoxPrompt(R.string.remember_choice) {}.negativeButton(
|
||||
text = resources?.getString(
|
||||
R.string.keep_current_sort,
|
||||
resources!!.getString(newHeader.category.sortRes()).toLowerCase(
|
||||
Locale.getDefault()
|
||||
)
|
||||
)
|
||||
) {
|
||||
moveMangaToCategory(
|
||||
item.manga, newHeader.category, mangaIds, false
|
||||
)
|
||||
if (it.isCheckPromptChecked()) preferences.keepCatSort().set(1)
|
||||
}.cancelOnTouchOutside(false).show()
|
||||
} else {
|
||||
moveMangaToCategory(
|
||||
item.manga, newHeader.category, mangaIds, keepCatSort == 2
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
lastItemPosition = null
|
||||
}
|
||||
@ -742,12 +719,11 @@ class LibraryController(
|
||||
private fun moveMangaToCategory(
|
||||
manga: LibraryManga,
|
||||
category: Category?,
|
||||
mangaIds: List<Long>,
|
||||
useDND: Boolean
|
||||
mangaIds: List<Long>
|
||||
) {
|
||||
if (category?.id == null) return
|
||||
val oldCatId = manga.category
|
||||
presenter.moveMangaToCategory(manga, category.id, mangaIds, useDND)
|
||||
presenter.moveMangaToCategory(manga, category.id, mangaIds)
|
||||
snack?.dismiss()
|
||||
snack = view?.snack(
|
||||
resources!!.getString(R.string.moved_to_category, category.name)
|
||||
@ -755,7 +731,7 @@ class LibraryController(
|
||||
anchorView = bottom_sheet
|
||||
setAction(R.string.action_undo) {
|
||||
manga.category = category.id!!
|
||||
presenter.moveMangaToCategory(manga, oldCatId, mangaIds, useDND)
|
||||
presenter.moveMangaToCategory(manga, oldCatId, mangaIds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -853,28 +853,20 @@ class LibraryPresenter(
|
||||
fun moveMangaToCategory(
|
||||
manga: LibraryManga,
|
||||
catId: Int?,
|
||||
mangaIds: List<Long>,
|
||||
useDND: Boolean
|
||||
mangaIds: List<Long>
|
||||
) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val categoryId = catId ?: return@launch
|
||||
val category = categories.find { catId == it.id } ?: return@launch
|
||||
|
||||
/*val mangaMap = currentMangaMap?.toMutableMap() ?: return@launch
|
||||
val oldCatId = item.manga.category
|
||||
val oldCatMap = mangaMap[manga.category]?.toMutableList() ?: return@launch
|
||||
val newCatMap = mangaMap[catId]?.toMutableList() ?: return@launch
|
||||
oldCatMap.remove(item)
|
||||
newCatMap.add(item)
|
||||
mangaMap[oldCatId] = oldCatMap
|
||||
mangaMap[catId] = newCatMap
|
||||
currentMangaMap = mangaMap*/
|
||||
|
||||
val oldCatId = manga.category
|
||||
manga.category = categoryId
|
||||
|
||||
val mc = ArrayList<MangaCategory>()
|
||||
val categories = db.getCategoriesForManga(manga).executeAsBlocking()
|
||||
val categories =
|
||||
if (catId == 0) emptyList()
|
||||
else
|
||||
db.getCategoriesForManga(manga).executeAsBlocking()
|
||||
.filter { it.id != oldCatId } + listOf(category)
|
||||
|
||||
for (cat in categories) {
|
||||
@ -883,8 +875,7 @@ class LibraryPresenter(
|
||||
|
||||
db.setMangaCategories(mc, listOf(manga))
|
||||
|
||||
if (useDND) {
|
||||
category.mangaSort = null
|
||||
if (category.mangaSort == null) {
|
||||
val ids = mangaIds.toMutableList()
|
||||
if (!ids.contains(manga.id!!)) ids.add(manga.id!!)
|
||||
category.mangaOrder = ids
|
||||
|
@ -29,14 +29,6 @@ class SettingsLibraryController : SettingsController() {
|
||||
titleRes = R.string.pref_category_library
|
||||
preferenceCategory {
|
||||
titleRes = R.string.pref_category_library_display
|
||||
/*
|
||||
switchPreference {
|
||||
key = Keys.libraryAsSingleList
|
||||
titleRes = R.string.pref_library_single_list
|
||||
summaryRes = R.string.pref_library_single_list_summary
|
||||
defaultValue = false
|
||||
}*/
|
||||
|
||||
switchPreference {
|
||||
key = Keys.removeArticles
|
||||
titleRes = R.string.pref_remove_articles
|
||||
@ -75,19 +67,6 @@ class SettingsLibraryController : SettingsController() {
|
||||
true
|
||||
}
|
||||
}
|
||||
intListPreference(activity) {
|
||||
titleRes = R.string.pref_keep_category_sorting
|
||||
key = Keys.keepCatSort
|
||||
|
||||
customSummary = context.getString(R.string.pref_keep_category_sorting_summary)
|
||||
entries = listOf(
|
||||
context.getString(R.string.always_ask),
|
||||
context.getString(R.string.option_keep_category_sort),
|
||||
context.getString(R.string.option_switch_to_dnd)
|
||||
)
|
||||
entryRange = 0..2
|
||||
defaultValue = 0
|
||||
}
|
||||
}
|
||||
|
||||
preferenceCategory {
|
||||
|
@ -260,14 +260,6 @@
|
||||
when updating library (overwrites local covers)</string>
|
||||
|
||||
<string name="pref_category_library_migration">Migration</string>
|
||||
<string name="pref_keep_category_sorting">Change category sorting when moving</string>
|
||||
<string name="pref_keep_category_sorting_summary">Should dragging and
|
||||
dropping an entry into a new category change the category\'s sorting to drag &
|
||||
drop?</string>
|
||||
<string name="always_ask">Always ask</string>
|
||||
<string name="option_keep_category_sort">Keep category\'s current sorting</string>
|
||||
<string name="option_switch_to_dnd">Switch to Drag & Drop</string>
|
||||
|
||||
|
||||
<!-- Extension section -->
|
||||
<string name="all_lang">All</string>
|
||||
@ -460,13 +452,11 @@
|
||||
<string name="category_is_empty">Category is empty</string>
|
||||
<string name="local_source_badge">Local</string>
|
||||
<string name="confirm_manga_deletion">Remove from library?</string>
|
||||
<string name="switch_to_dnd">Switch to Drag & Drop mode?</string>
|
||||
<string name="what_should_update">What should update?</string>
|
||||
<string name="top_category">Top category (%1$s)</string>
|
||||
<string name="first_category">First category</string>
|
||||
<string name="categories_on_manual">Categories to update when manually refreshing</string>
|
||||
<string name="categories_in_global_update">All categories in global update</string>
|
||||
<string name="keep_current_sort">Keep sorting by %1$s</string>
|
||||
<string name="confirm_category_deletion">Delete category?</string>
|
||||
<string name="confirm_category_deletion_message">Manga in this category will moved into the
|
||||
default category.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user