Merge branch 'devel' into feature/mal
commit
eef449af49
@ -0,0 +1,22 @@
|
|||||||
|
package org.koitharu.kotatsu.base.ui
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.app.Application.ActivityLifecycleCallbacks
|
||||||
|
import android.os.Bundle
|
||||||
|
|
||||||
|
interface DefaultActivityLifecycleCallbacks : ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) = Unit
|
||||||
|
|
||||||
|
override fun onActivityStarted(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityResumed(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityPaused(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivityStopped(activity: Activity) = Unit
|
||||||
|
|
||||||
|
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) = Unit
|
||||||
|
|
||||||
|
override fun onActivityDestroyed(activity: Activity) = Unit
|
||||||
|
}
|
||||||
@ -1,18 +1,17 @@
|
|||||||
package org.koitharu.kotatsu.core.model
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
import org.koitharu.kotatsu.parsers.util.toTitleCase
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
fun MangaSource.getLocaleTitle(): String? {
|
fun MangaSource.getLocaleTitle(): String? {
|
||||||
val lc = Locale(locale ?: return null)
|
val lc = Locale(locale ?: return null)
|
||||||
return lc.getDisplayLanguage(lc).toTitleCase(lc)
|
return lc.getDisplayLanguage(lc).toTitleCase(lc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("FunctionName")
|
fun MangaSource(name: String): MangaSource {
|
||||||
fun MangaSource(name: String): MangaSource? {
|
|
||||||
MangaSource.values().forEach {
|
MangaSource.values().forEach {
|
||||||
if (it.name == name) return it
|
if (it.name == name) return it
|
||||||
}
|
}
|
||||||
return null
|
return MangaSource.DUMMY
|
||||||
}
|
}
|
||||||
@ -1,6 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.prefs
|
|
||||||
|
|
||||||
enum class AppSection {
|
|
||||||
|
|
||||||
LOCAL, FAVOURITES, HISTORY, FEED, SUGGESTIONS
|
|
||||||
}
|
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package org.koitharu.kotatsu.shelf.domain
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
|
import org.koitharu.kotatsu.history.domain.MangaWithHistory
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
|
||||||
|
class ShelfContent(
|
||||||
|
val history: List<MangaWithHistory>,
|
||||||
|
val favourites: Map<FavouriteCategory, List<Manga>>,
|
||||||
|
val updated: Map<Manga, Int>,
|
||||||
|
val local: List<Manga>,
|
||||||
|
) {
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as ShelfContent
|
||||||
|
|
||||||
|
if (history != other.history) return false
|
||||||
|
if (favourites != other.favourites) return false
|
||||||
|
if (updated != other.updated) return false
|
||||||
|
if (local != other.local) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = history.hashCode()
|
||||||
|
result = 31 * result + favourites.hashCode()
|
||||||
|
result = 31 * result + updated.hashCode()
|
||||||
|
result = 31 * result + local.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
package org.koitharu.kotatsu.shelf.domain
|
||||||
|
|
||||||
|
enum class ShelfSection {
|
||||||
|
|
||||||
|
HISTORY, LOCAL, UPDATED, FAVORITES;
|
||||||
|
}
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
package org.koitharu.kotatsu.shelf.ui.config
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.activity.viewModels
|
||||||
|
import androidx.core.graphics.Insets
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
|
import org.koitharu.kotatsu.databinding.ActivityShelfSettingsBinding
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class ShelfSettingsActivity :
|
||||||
|
BaseActivity<ActivityShelfSettingsBinding>(),
|
||||||
|
View.OnClickListener, ShelfSettingsListener {
|
||||||
|
|
||||||
|
private val viewModel by viewModels<ShelfSettingsViewModel>()
|
||||||
|
private lateinit var reorderHelper: ItemTouchHelper
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(ActivityShelfSettingsBinding.inflate(layoutInflater))
|
||||||
|
supportActionBar?.run {
|
||||||
|
setDisplayHomeAsUpEnabled(true)
|
||||||
|
setHomeAsUpIndicator(com.google.android.material.R.drawable.abc_ic_clear_material)
|
||||||
|
}
|
||||||
|
binding.buttonDone.setOnClickListener(this)
|
||||||
|
val settingsAdapter = ShelfSettingsAdapter(this)
|
||||||
|
with(binding.recyclerView) {
|
||||||
|
setHasFixedSize(true)
|
||||||
|
adapter = settingsAdapter
|
||||||
|
reorderHelper = ItemTouchHelper(SectionsReorderCallback()).also {
|
||||||
|
it.attachToRecyclerView(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
viewModel.content.observe(this) { settingsAdapter.items = it }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemCheckedChanged(item: ShelfSettingsItemModel, isChecked: Boolean) {
|
||||||
|
viewModel.setItemChecked(item, isChecked)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDragHandleTouch(holder: RecyclerView.ViewHolder) {
|
||||||
|
reorderHelper.startDrag(holder)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClick(v: View?) {
|
||||||
|
finishAfterTransition()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onWindowInsetsChanged(insets: Insets) {
|
||||||
|
binding.root.updatePadding(
|
||||||
|
left = insets.left,
|
||||||
|
right = insets.right,
|
||||||
|
)
|
||||||
|
binding.recyclerView.updatePadding(
|
||||||
|
bottom = insets.bottom,
|
||||||
|
)
|
||||||
|
binding.toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
|
topMargin = insets.top
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class SectionsReorderCallback : ItemTouchHelper.SimpleCallback(
|
||||||
|
ItemTouchHelper.DOWN or ItemTouchHelper.UP,
|
||||||
|
0,
|
||||||
|
) {
|
||||||
|
|
||||||
|
override fun onMove(
|
||||||
|
recyclerView: RecyclerView,
|
||||||
|
viewHolder: RecyclerView.ViewHolder,
|
||||||
|
target: RecyclerView.ViewHolder,
|
||||||
|
): Boolean = viewHolder.itemViewType == target.itemViewType && viewModel.reorderSections(
|
||||||
|
viewHolder.bindingAdapterPosition,
|
||||||
|
target.bindingAdapterPosition,
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun canDropOver(
|
||||||
|
recyclerView: RecyclerView,
|
||||||
|
current: RecyclerView.ViewHolder,
|
||||||
|
target: RecyclerView.ViewHolder,
|
||||||
|
): Boolean = current.itemViewType == target.itemViewType
|
||||||
|
|
||||||
|
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) = Unit
|
||||||
|
|
||||||
|
override fun isLongPressDragEnabled() = false
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun newIntent(context: Context) = Intent(context, ShelfSettingsActivity::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
package org.koitharu.kotatsu.shelf.ui.config
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
||||||
|
|
||||||
|
class ShelfSettingsAdapter(
|
||||||
|
listener: ShelfSettingsListener,
|
||||||
|
) : AsyncListDifferDelegationAdapter<ShelfSettingsItemModel>(DiffCallback()) {
|
||||||
|
|
||||||
|
init {
|
||||||
|
delegatesManager.addDelegate(shelfCategoryAD(listener))
|
||||||
|
.addDelegate(shelfSectionAD(listener))
|
||||||
|
}
|
||||||
|
|
||||||
|
class DiffCallback : DiffUtil.ItemCallback<ShelfSettingsItemModel>() {
|
||||||
|
|
||||||
|
override fun areItemsTheSame(oldItem: ShelfSettingsItemModel, newItem: ShelfSettingsItemModel): Boolean {
|
||||||
|
return when {
|
||||||
|
oldItem is ShelfSettingsItemModel.Section && newItem is ShelfSettingsItemModel.Section -> {
|
||||||
|
oldItem.section == newItem.section
|
||||||
|
}
|
||||||
|
|
||||||
|
oldItem is ShelfSettingsItemModel.FavouriteCategory && newItem is ShelfSettingsItemModel.FavouriteCategory -> {
|
||||||
|
oldItem.id == newItem.id
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItem: ShelfSettingsItemModel, newItem: ShelfSettingsItemModel): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getChangePayload(oldItem: ShelfSettingsItemModel, newItem: ShelfSettingsItemModel): Any? {
|
||||||
|
return if (oldItem.isChecked == newItem.isChecked) {
|
||||||
|
super.getChangePayload(oldItem, newItem)
|
||||||
|
} else Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package org.koitharu.kotatsu.shelf.ui.config
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.CompoundButton
|
||||||
|
import androidx.core.view.updatePaddingRelative
|
||||||
|
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemCategoryCheckableMultipleBinding
|
||||||
|
import org.koitharu.kotatsu.databinding.ItemShelfSectionDraggableBinding
|
||||||
|
import org.koitharu.kotatsu.shelf.domain.ShelfSection
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
fun shelfSectionAD(
|
||||||
|
listener: ShelfSettingsListener,
|
||||||
|
) =
|
||||||
|
adapterDelegateViewBinding<ShelfSettingsItemModel.Section, ShelfSettingsItemModel, ItemShelfSectionDraggableBinding>(
|
||||||
|
{ layoutInflater, parent -> ItemShelfSectionDraggableBinding.inflate(layoutInflater, parent, false) },
|
||||||
|
) {
|
||||||
|
|
||||||
|
val eventListener = object :
|
||||||
|
View.OnTouchListener,
|
||||||
|
CompoundButton.OnCheckedChangeListener {
|
||||||
|
|
||||||
|
override fun onTouch(v: View?, event: MotionEvent): Boolean {
|
||||||
|
return if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||||
|
listener.onDragHandleTouch(this@adapterDelegateViewBinding)
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
|
||||||
|
listener.onItemCheckedChanged(item, isChecked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.switchToggle.setOnCheckedChangeListener(eventListener)
|
||||||
|
binding.imageViewHandle.setOnTouchListener(eventListener)
|
||||||
|
|
||||||
|
bind {
|
||||||
|
binding.textViewTitle.setText(item.section.titleResId)
|
||||||
|
binding.switchToggle.isChecked = item.isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun shelfCategoryAD(
|
||||||
|
listener: ShelfSettingsListener,
|
||||||
|
) =
|
||||||
|
adapterDelegateViewBinding<ShelfSettingsItemModel.FavouriteCategory, ShelfSettingsItemModel, ItemCategoryCheckableMultipleBinding>(
|
||||||
|
{ layoutInflater, parent -> ItemCategoryCheckableMultipleBinding.inflate(layoutInflater, parent, false) },
|
||||||
|
) {
|
||||||
|
itemView.setOnClickListener {
|
||||||
|
listener.onItemCheckedChanged(item, !item.isChecked)
|
||||||
|
}
|
||||||
|
binding.root.updatePaddingRelative(
|
||||||
|
start = binding.root.paddingStart * 2,
|
||||||
|
end = binding.root.paddingStart,
|
||||||
|
)
|
||||||
|
|
||||||
|
bind {
|
||||||
|
binding.root.text = item.title
|
||||||
|
binding.root.isChecked = item.isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val ShelfSection.titleResId: Int
|
||||||
|
get() = when (this) {
|
||||||
|
ShelfSection.HISTORY -> R.string.history
|
||||||
|
ShelfSection.LOCAL -> R.string.local_storage
|
||||||
|
ShelfSection.UPDATED -> R.string.updated
|
||||||
|
ShelfSection.FAVORITES -> R.string.favourites
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
package org.koitharu.kotatsu.shelf.ui.config
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.list.ui.model.ListModel
|
||||||
|
import org.koitharu.kotatsu.shelf.domain.ShelfSection
|
||||||
|
|
||||||
|
sealed interface ShelfSettingsItemModel : ListModel {
|
||||||
|
|
||||||
|
val isChecked: Boolean
|
||||||
|
|
||||||
|
class Section(
|
||||||
|
val section: ShelfSection,
|
||||||
|
override val isChecked: Boolean,
|
||||||
|
) : ShelfSettingsItemModel {
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as Section
|
||||||
|
|
||||||
|
if (section != other.section) return false
|
||||||
|
if (isChecked != other.isChecked) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = section.hashCode()
|
||||||
|
result = 31 * result + isChecked.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FavouriteCategory(
|
||||||
|
val id: Long,
|
||||||
|
val title: String,
|
||||||
|
override val isChecked: Boolean,
|
||||||
|
) : ShelfSettingsItemModel {
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (javaClass != other?.javaClass) return false
|
||||||
|
|
||||||
|
other as FavouriteCategory
|
||||||
|
|
||||||
|
if (id != other.id) return false
|
||||||
|
if (title != other.title) return false
|
||||||
|
if (isChecked != other.isChecked) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = id.hashCode()
|
||||||
|
result = 31 * result + title.hashCode()
|
||||||
|
result = 31 * result + isChecked.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package org.koitharu.kotatsu.shelf.ui.config
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
interface ShelfSettingsListener {
|
||||||
|
|
||||||
|
fun onItemCheckedChanged(item: ShelfSettingsItemModel, isChecked: Boolean)
|
||||||
|
|
||||||
|
fun onDragHandleTouch(holder: RecyclerView.ViewHolder)
|
||||||
|
}
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
package org.koitharu.kotatsu.shelf.ui.config
|
||||||
|
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
||||||
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
|
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||||
|
import org.koitharu.kotatsu.shelf.domain.ShelfSection
|
||||||
|
import org.koitharu.kotatsu.utils.asFlowLiveData
|
||||||
|
import org.koitharu.kotatsu.utils.ext.move
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
class ShelfSettingsViewModel @Inject constructor(
|
||||||
|
private val favouritesRepository: FavouritesRepository,
|
||||||
|
private val settings: AppSettings,
|
||||||
|
) : BaseViewModel() {
|
||||||
|
|
||||||
|
val content = combine(
|
||||||
|
settings.observeAsFlow(AppSettings.KEY_SHELF_SECTIONS) { shelfSections },
|
||||||
|
favouritesRepository.observeCategories(),
|
||||||
|
) { sections, categories ->
|
||||||
|
buildList(sections, categories)
|
||||||
|
}.asFlowLiveData(viewModelScope.coroutineContext + Dispatchers.Default, emptyList())
|
||||||
|
|
||||||
|
private var updateJob: Job? = null
|
||||||
|
|
||||||
|
fun setItemChecked(item: ShelfSettingsItemModel, isChecked: Boolean) {
|
||||||
|
val prevJob = updateJob
|
||||||
|
updateJob = launchJob(Dispatchers.Default) {
|
||||||
|
prevJob?.join()
|
||||||
|
when (item) {
|
||||||
|
is ShelfSettingsItemModel.FavouriteCategory -> {
|
||||||
|
favouritesRepository.updateCategory(item.id, isChecked)
|
||||||
|
}
|
||||||
|
|
||||||
|
is ShelfSettingsItemModel.Section -> {
|
||||||
|
val sections = settings.shelfSections
|
||||||
|
settings.shelfSections = if (isChecked) {
|
||||||
|
sections + item.section
|
||||||
|
} else {
|
||||||
|
if (sections.size > 1) {
|
||||||
|
sections - item.section
|
||||||
|
} else {
|
||||||
|
return@launchJob
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun reorderSections(oldPos: Int, newPos: Int): Boolean {
|
||||||
|
val snapshot = content.value?.toMutableList() ?: return false
|
||||||
|
snapshot.move(oldPos, newPos)
|
||||||
|
settings.shelfSections = snapshot.sections()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildList(
|
||||||
|
sections: List<ShelfSection>,
|
||||||
|
categories: List<FavouriteCategory>
|
||||||
|
): List<ShelfSettingsItemModel> {
|
||||||
|
val result = ArrayList<ShelfSettingsItemModel>()
|
||||||
|
val sectionsList = ShelfSection.values().toMutableList()
|
||||||
|
for (section in sections) {
|
||||||
|
sectionsList.remove(section)
|
||||||
|
result.addSection(section, true, categories)
|
||||||
|
}
|
||||||
|
for (section in sectionsList) {
|
||||||
|
result.addSection(section, false, categories)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun MutableList<in ShelfSettingsItemModel>.addSection(
|
||||||
|
section: ShelfSection,
|
||||||
|
isEnabled: Boolean,
|
||||||
|
favouriteCategories: List<FavouriteCategory>,
|
||||||
|
) {
|
||||||
|
add(ShelfSettingsItemModel.Section(section, isEnabled))
|
||||||
|
if (isEnabled && section == ShelfSection.FAVORITES) {
|
||||||
|
favouriteCategories.mapTo(this) {
|
||||||
|
ShelfSettingsItemModel.FavouriteCategory(
|
||||||
|
id = it.id,
|
||||||
|
title = it.title,
|
||||||
|
isChecked = it.isVisibleInLibrary,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun List<ShelfSettingsItemModel>.sections(): List<ShelfSection> {
|
||||||
|
return mapNotNull { (it as? ShelfSettingsItemModel.Section)?.takeIf { x -> x.isChecked }?.section }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,32 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.shelf.ui.config.categories
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import com.hannesdorfmann.adapterdelegates4.AsyncListDifferDelegationAdapter
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
|
|
||||||
class ShelfCategoriesConfigAdapter(
|
|
||||||
listener: OnListItemClickListener<FavouriteCategory>,
|
|
||||||
) : AsyncListDifferDelegationAdapter<FavouriteCategory>(DiffCallback()) {
|
|
||||||
|
|
||||||
init {
|
|
||||||
delegatesManager.addDelegate(shelfCategoryAD(listener))
|
|
||||||
}
|
|
||||||
|
|
||||||
class DiffCallback : DiffUtil.ItemCallback<FavouriteCategory>() {
|
|
||||||
|
|
||||||
override fun areItemsTheSame(oldItem: FavouriteCategory, newItem: FavouriteCategory): Boolean {
|
|
||||||
return oldItem.id == newItem.id
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun areContentsTheSame(oldItem: FavouriteCategory, newItem: FavouriteCategory): Boolean {
|
|
||||||
return oldItem.isVisibleInLibrary == newItem.isVisibleInLibrary && oldItem.title == newItem.title
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getChangePayload(oldItem: FavouriteCategory, newItem: FavouriteCategory): Any? {
|
|
||||||
return if (oldItem.isVisibleInLibrary == newItem.isVisibleInLibrary) {
|
|
||||||
super.getChangePayload(oldItem, newItem)
|
|
||||||
} else Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.shelf.ui.config.categories
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.core.view.isVisible
|
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
import androidx.fragment.app.viewModels
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.base.ui.BaseBottomSheet
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.databinding.SheetBaseBinding
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
|
||||||
class ShelfCategoriesConfigSheet :
|
|
||||||
BaseBottomSheet<SheetBaseBinding>(),
|
|
||||||
OnListItemClickListener<FavouriteCategory>,
|
|
||||||
View.OnClickListener {
|
|
||||||
|
|
||||||
private val viewModel by viewModels<ShelfCategoriesConfigViewModel>()
|
|
||||||
|
|
||||||
override fun onInflateView(inflater: LayoutInflater, container: ViewGroup?): SheetBaseBinding {
|
|
||||||
return SheetBaseBinding.inflate(inflater, container, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
binding.headerBar.toolbar.setTitle(R.string.favourites_categories)
|
|
||||||
binding.buttonDone.isVisible = true
|
|
||||||
binding.buttonDone.setOnClickListener(this)
|
|
||||||
val adapter = ShelfCategoriesConfigAdapter(this)
|
|
||||||
binding.recyclerView.adapter = adapter
|
|
||||||
|
|
||||||
viewModel.content.observe(viewLifecycleOwner) { adapter.items = it }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onItemClick(item: FavouriteCategory, view: View) {
|
|
||||||
viewModel.toggleItem(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(v: View?) {
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
private const val TAG = "ShelfCategoriesConfigSheet"
|
|
||||||
|
|
||||||
fun show(fm: FragmentManager) = ShelfCategoriesConfigSheet().show(fm, TAG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.shelf.ui.config.categories
|
|
||||||
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import org.koitharu.kotatsu.base.ui.BaseViewModel
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
|
||||||
import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
|
||||||
|
|
||||||
@HiltViewModel
|
|
||||||
class ShelfCategoriesConfigViewModel @Inject constructor(
|
|
||||||
private val favouritesRepository: FavouritesRepository,
|
|
||||||
) : BaseViewModel() {
|
|
||||||
|
|
||||||
val content = favouritesRepository.observeCategories()
|
|
||||||
.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, emptyList())
|
|
||||||
|
|
||||||
private var updateJob: Job? = null
|
|
||||||
|
|
||||||
fun toggleItem(category: FavouriteCategory) {
|
|
||||||
val prevJob = updateJob
|
|
||||||
updateJob = launchJob(Dispatchers.Default) {
|
|
||||||
prevJob?.join()
|
|
||||||
favouritesRepository.updateCategory(category.id, !category.isVisibleInLibrary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.shelf.ui.config.categories
|
|
||||||
|
|
||||||
import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.AdapterDelegateClickListenerAdapter
|
|
||||||
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.databinding.ItemCategoryCheckableMultipleBinding
|
|
||||||
|
|
||||||
fun shelfCategoryAD(
|
|
||||||
listener: OnListItemClickListener<FavouriteCategory>,
|
|
||||||
) = adapterDelegateViewBinding<FavouriteCategory, FavouriteCategory, ItemCategoryCheckableMultipleBinding>(
|
|
||||||
{ layoutInflater, parent -> ItemCategoryCheckableMultipleBinding.inflate(layoutInflater, parent, false) },
|
|
||||||
) {
|
|
||||||
val eventListener = AdapterDelegateClickListenerAdapter(this, listener)
|
|
||||||
itemView.setOnClickListener(eventListener)
|
|
||||||
|
|
||||||
bind {
|
|
||||||
binding.root.text = item.title
|
|
||||||
binding.root.isChecked = item.isVisibleInLibrary
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package org.koitharu.kotatsu.utils
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.lifecycle.flowWithLifecycle
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.DefaultActivityLifecycleCallbacks
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
|
import org.koitharu.kotatsu.core.prefs.observeAsFlow
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class IncognitoModeIndicator @Inject constructor(
|
||||||
|
private val settings: AppSettings,
|
||||||
|
) : DefaultActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||||
|
if (activity !is AppCompatActivity) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
settings.observeAsFlow(
|
||||||
|
key = AppSettings.KEY_INCOGNITO_MODE,
|
||||||
|
valueProducer = { isIncognitoModeEnabled },
|
||||||
|
).flowOn(Dispatchers.IO)
|
||||||
|
.flowWithLifecycle(activity.lifecycle)
|
||||||
|
.onEach { updateStatusBar(activity, it) }
|
||||||
|
.launchIn(activity.lifecycleScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateStatusBar(activity: AppCompatActivity, isIncognitoModeEnabled: Boolean) {
|
||||||
|
activity.window.statusBarColor = if (isIncognitoModeEnabled) {
|
||||||
|
ContextCompat.getColor(activity, R.color.status_bar_incognito)
|
||||||
|
} else {
|
||||||
|
activity.getThemeColor(android.R.attr.statusBarColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.ext
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import org.koitharu.kotatsu.utils.progress.ProgressResponseBody
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
|
||||||
|
suspend fun InputStream.copyToSuspending(
|
||||||
|
out: OutputStream,
|
||||||
|
bufferSize: Int = DEFAULT_BUFFER_SIZE
|
||||||
|
): Long = withContext(Dispatchers.IO) {
|
||||||
|
val job = currentCoroutineContext()[Job]
|
||||||
|
var bytesCopied: Long = 0
|
||||||
|
val buffer = ByteArray(bufferSize)
|
||||||
|
var bytes = read(buffer)
|
||||||
|
while (bytes >= 0) {
|
||||||
|
out.write(buffer, 0, bytes)
|
||||||
|
bytesCopied += bytes
|
||||||
|
job?.ensureActive()
|
||||||
|
bytes = read(buffer)
|
||||||
|
job?.ensureActive()
|
||||||
|
}
|
||||||
|
bytesCopied
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ResponseBody.withProgress(progressState: MutableStateFlow<Float>): ResponseBody {
|
||||||
|
return ProgressResponseBody(this, progressState)
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.progress
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import okhttp3.MediaType
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import okio.Buffer
|
||||||
|
import okio.BufferedSource
|
||||||
|
import okio.ForwardingSource
|
||||||
|
import okio.Source
|
||||||
|
import okio.buffer
|
||||||
|
|
||||||
|
class ProgressResponseBody(
|
||||||
|
private val delegate: ResponseBody,
|
||||||
|
private val progressState: MutableStateFlow<Float>,
|
||||||
|
) : ResponseBody() {
|
||||||
|
|
||||||
|
private var bufferedSource: BufferedSource? = null
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
super.close()
|
||||||
|
delegate.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun contentLength(): Long = delegate.contentLength()
|
||||||
|
|
||||||
|
override fun contentType(): MediaType? = delegate.contentType()
|
||||||
|
|
||||||
|
override fun source(): BufferedSource {
|
||||||
|
return bufferedSource ?: ProgressSource(delegate.source(), contentLength(), progressState).buffer().also {
|
||||||
|
bufferedSource = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ProgressSource(
|
||||||
|
delegate: Source,
|
||||||
|
private val contentLength: Long,
|
||||||
|
private val progressState: MutableStateFlow<Float>,
|
||||||
|
) : ForwardingSource(delegate) {
|
||||||
|
|
||||||
|
private var totalBytesRead = 0L
|
||||||
|
|
||||||
|
override fun read(sink: Buffer, byteCount: Long): Long {
|
||||||
|
val bytesRead = super.read(sink, byteCount)
|
||||||
|
if (contentLength > 0) {
|
||||||
|
totalBytesRead += if (bytesRead != -1L) bytesRead else 0
|
||||||
|
progressState.value = (totalBytesRead.toDouble() / contentLength.toDouble()).toFloat()
|
||||||
|
}
|
||||||
|
return bytesRead
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,81 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:animateLayoutChanges="true"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup
|
|
||||||
android:id="@+id/checkableGroup"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="16dp"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:weightSum="3">
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/button_list"
|
|
||||||
style="@style/Widget.Kotatsu.ToggleButton"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:text="@string/list"
|
|
||||||
app:icon="@drawable/ic_list" />
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/button_list_detailed"
|
|
||||||
style="@style/Widget.Kotatsu.ToggleButton"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="12dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:text="@string/detailed_list"
|
|
||||||
app:icon="@drawable/ic_list_detailed" />
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/button_grid"
|
|
||||||
style="@style/Widget.Kotatsu.ToggleButton"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:text="@string/grid"
|
|
||||||
app:icon="@drawable/ic_grid" />
|
|
||||||
|
|
||||||
</org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView_grid_title"
|
|
||||||
style="?materialAlertDialogTitleTextStyle"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingLeft="?attr/dialogPreferredPadding"
|
|
||||||
android:paddingRight="?attr/dialogPreferredPadding"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:text="@string/grid_size"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
<com.google.android.material.slider.Slider
|
|
||||||
android:id="@+id/slider_grid"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginHorizontal="16dp"
|
|
||||||
android:stepSize="5"
|
|
||||||
android:valueFrom="50"
|
|
||||||
android:valueTo="150"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:labelBehavior="floating"
|
|
||||||
app:tickVisible="false"
|
|
||||||
tools:value="100"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
tools:navigationIcon="@drawable/abc_ic_clear_material"
|
||||||
|
tools:title="@string/settings">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_done"
|
||||||
|
style="@style/Widget.Material3.Button.UnelevatedButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
android:layout_marginHorizontal="@dimen/toolbar_button_margin"
|
||||||
|
android:text="@string/done" />
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.MaterialToolbar>
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:overScrollMode="ifContentScrolls"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@ -1,75 +1,103 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<ScrollView
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<org.koitharu.kotatsu.base.ui.widgets.BottomSheetHeaderBar
|
||||||
|
android:id="@+id/headerBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:animateLayoutChanges="true"
|
app:title="@string/options" />
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup
|
<androidx.core.widget.NestedScrollView
|
||||||
android:id="@+id/checkableGroup"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginVertical="16dp"
|
android:orientation="vertical"
|
||||||
android:layout_marginHorizontal="?attr/dialogPreferredPadding"
|
android:paddingBottom="@dimen/margin_normal">
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<TextView
|
||||||
android:id="@+id/button_list"
|
|
||||||
style="@style/Widget.Kotatsu.ToggleButton"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/list"
|
android:layout_marginHorizontal="@dimen/margin_normal"
|
||||||
app:icon="@drawable/ic_list" />
|
android:layout_marginTop="@dimen/margin_normal"
|
||||||
|
android:text="@string/list_mode"
|
||||||
|
android:textAppearance="?textAppearanceTitleSmall" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||||
android:id="@+id/button_list_detailed"
|
android:id="@+id/checkableGroup"
|
||||||
style="@style/Widget.Kotatsu.ToggleButton"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/detailed_list"
|
android:layout_marginHorizontal="@dimen/margin_normal"
|
||||||
app:icon="@drawable/ic_list_detailed" />
|
android:layout_marginTop="@dimen/margin_small"
|
||||||
|
android:baselineAligned="false"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
app:selectionRequired="true"
|
||||||
|
app:singleSelection="true">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/button_grid"
|
android:id="@+id/button_list"
|
||||||
style="@style/Widget.Kotatsu.ToggleButton"
|
style="@style/Widget.Kotatsu.ToggleButton.Vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/grid"
|
android:layout_weight="1"
|
||||||
app:icon="@drawable/ic_grid" />
|
android:text="@string/compact"
|
||||||
|
app:icon="@drawable/ic_list" />
|
||||||
|
|
||||||
</org.koitharu.kotatsu.base.ui.widgets.CheckableButtonGroup>
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/button_list_detailed"
|
||||||
|
style="@style/Widget.Kotatsu.ToggleButton.Vertical"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/details"
|
||||||
|
app:icon="@drawable/ic_list_detailed" />
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/textView_grid_title"
|
android:id="@+id/button_grid"
|
||||||
style="?materialAlertDialogTitleTextStyle"
|
style="@style/Widget.Kotatsu.ToggleButton.Vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingHorizontal="?attr/dialogPreferredPadding"
|
android:layout_weight="1"
|
||||||
android:singleLine="true"
|
android:text="@string/grid"
|
||||||
android:text="@string/grid_size"
|
app:icon="@drawable/ic_grid" />
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
<com.google.android.material.slider.Slider
|
</com.google.android.material.button.MaterialButtonToggleGroup>
|
||||||
android:id="@+id/slider_grid"
|
|
||||||
android:layout_width="match_parent"
|
<TextView
|
||||||
android:layout_height="wrap_content"
|
android:id="@+id/textView_grid_title"
|
||||||
android:layout_marginHorizontal="16dp"
|
android:layout_width="match_parent"
|
||||||
android:stepSize="5"
|
android:layout_height="wrap_content"
|
||||||
android:valueFrom="50"
|
android:layout_marginHorizontal="@dimen/margin_normal"
|
||||||
android:valueTo="150"
|
android:layout_marginTop="@dimen/margin_normal"
|
||||||
android:visibility="gone"
|
android:singleLine="true"
|
||||||
app:labelBehavior="floating"
|
android:text="@string/grid_size"
|
||||||
app:tickVisible="false"
|
android:textAppearance="?textAppearanceTitleSmall"
|
||||||
tools:value="100"
|
android:visibility="gone"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
<com.google.android.material.slider.Slider
|
||||||
|
android:id="@+id/slider_grid"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="16dp"
|
||||||
|
android:stepSize="5"
|
||||||
|
android:valueFrom="50"
|
||||||
|
android:valueTo="150"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:labelBehavior="floating"
|
||||||
|
app:tickVisible="false"
|
||||||
|
tools:value="100"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
</LinearLayout>
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?android:windowBackground"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="58dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageView_handle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingHorizontal="?listPreferredItemPaddingStart"
|
||||||
|
android:scaleType="center"
|
||||||
|
android:src="@drawable/ic_reorder_handle" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView_title"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?attr/textAppearanceBodyLarge"
|
||||||
|
tools:text="@tools:sample/lorem[15]" />
|
||||||
|
|
||||||
|
<com.google.android.material.materialswitch.MaterialSwitch
|
||||||
|
android:id="@+id/switch_toggle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingHorizontal="?listPreferredItemPaddingEnd" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<plurals name="new_chapters">
|
||||||
|
<item quantity="zero">%1$d فصل جديد</item>
|
||||||
|
<item quantity="one"></item>
|
||||||
|
<item quantity="two"></item>
|
||||||
|
<item quantity="few"></item>
|
||||||
|
<item quantity="many">%1$d فصول جديدة</item>
|
||||||
|
<item quantity="other"></item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="chapters">
|
||||||
|
<item quantity="zero"></item>
|
||||||
|
<item quantity="one">%1$d فصل</item>
|
||||||
|
<item quantity="two">%1$d فصلين</item>
|
||||||
|
<item quantity="few">%1$d بعض فصول</item>
|
||||||
|
<item quantity="many">%1$d عدة فصول</item>
|
||||||
|
<item quantity="other"></item>
|
||||||
|
</plurals>
|
||||||
|
</resources>
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="detailed_list">تفاصيل القائمة</string>
|
||||||
|
<string name="error_occurred">حدث خطأ</string>
|
||||||
|
<string name="details">تفاصيل</string>
|
||||||
|
<string name="grid">شبكة</string>
|
||||||
|
<string name="list_mode">وضع القائمة</string>
|
||||||
|
<string name="settings">إعدادات</string>
|
||||||
|
<string name="remote_sources">المصادر البعيدة</string>
|
||||||
|
<string name="close_menu">غلق قائمة</string>
|
||||||
|
<string name="open_menu">فتح قائمة</string>
|
||||||
|
<string name="chapters">فصول</string>
|
||||||
|
<string name="favourites">المفضلة</string>
|
||||||
|
<string name="network_error">تعذر الاتصال بالإنترنت</string>
|
||||||
|
<string name="loading_">جار التحميل…</string>
|
||||||
|
<string name="chapter_d_of_d">فصل %1$d في %2$d</string>
|
||||||
|
<string name="close">غلق</string>
|
||||||
|
<string name="try_again">حاول مجدداً</string>
|
||||||
|
<string name="computing_">جاري الحوسبة …</string>
|
||||||
|
<string name="local_storage">التخزين المحلي</string>
|
||||||
|
<string name="history">سجل</string>
|
||||||
|
<string name="list">قائمة</string>
|
||||||
|
<string name="clear_history">محو سجل</string>
|
||||||
|
<string name="add_to_favourites">ضع هذا في المفضلة</string>
|
||||||
|
<string name="add">أضف</string>
|
||||||
|
<string name="enter_category_name">أدخل اسم القائمة</string>
|
||||||
|
<string name="save">حفظ</string>
|
||||||
|
<string name="history_is_empty">لا سجل بعد</string>
|
||||||
|
<string name="downloads">التحميلات</string>
|
||||||
|
<string name="by_name">اسم</string>
|
||||||
|
<string name="newest">الأحدث</string>
|
||||||
|
<string name="by_rating">تقييم</string>
|
||||||
|
<string name="pages">صفحات</string>
|
||||||
|
<string name="read">اقرأ</string>
|
||||||
|
<string name="share">شارك</string>
|
||||||
|
<string name="nothing_found">لم يتم عثور على اي شيء</string>
|
||||||
|
<string name="you_have_not_favourites_yet">لا مفضلة بعد</string>
|
||||||
|
<string name="search">بحث</string>
|
||||||
|
<string name="search_manga">البحث في المانجا</string>
|
||||||
|
<string name="manga_downloading_">جاري التنزيل…</string>
|
||||||
|
<string name="create_shortcut">انشاء اختصار…</string>
|
||||||
|
<string name="theme">مظهر</string>
|
||||||
|
<string name="automatic">حسب النظام</string>
|
||||||
|
<string name="share_s">شارك %s</string>
|
||||||
|
<string name="processing_">في طور معالجة…</string>
|
||||||
|
<string name="updated">محدث</string>
|
||||||
|
<string name="filter">فلتر</string>
|
||||||
|
<string name="sort_order">ترتيب الفرز</string>
|
||||||
|
<string name="light">ضوء</string>
|
||||||
|
<string name="dark">داكن</string>
|
||||||
|
<string name="clear">أزل</string>
|
||||||
|
<string name="remove">ازالة</string>
|
||||||
|
<string name="popular">شائع</string>
|
||||||
|
<string name="add_new_category">قائمة جديدة</string>
|
||||||
|
<string name="download_complete">تم التنزيل</string>
|
||||||
|
<string name="text_clear_history_prompt">هل تريد محو سجل القراءة بالكامل بشكل دائم؟</string>
|
||||||
|
</resources>
|
||||||
@ -1,34 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<style name="Theme.Kotatsu.DialogWhenLarge">
|
|
||||||
<item name="windowFixedWidthMajor">@dimen/abc_dialog_fixed_width_major</item>
|
|
||||||
<item name="windowFixedWidthMinor">@dimen/abc_dialog_fixed_width_minor</item>
|
|
||||||
<item name="windowFixedHeightMajor">@dimen/abc_dialog_fixed_height_major</item>
|
|
||||||
<item name="windowFixedHeightMinor">@dimen/abc_dialog_fixed_height_minor</item>
|
|
||||||
<item name="android:windowElevation">@dimen/abc_floating_window_z</item>
|
|
||||||
<item name="android:colorBackground">?attr/colorBackgroundFloating</item>
|
|
||||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
|
||||||
|
|
||||||
<item name="android:windowFrame">@null</item>
|
|
||||||
<item name="android:windowTitleStyle">@style/RtlOverlay.DialogWindowTitle.AppCompat</item>
|
|
||||||
<item name="android:windowTitleBackgroundStyle">@style/Base.DialogWindowTitleBackground.AppCompat</item>
|
|
||||||
<item name="android:windowBackground">@drawable/abc_dialog_material_background</item>
|
|
||||||
<item name="android:windowIsFloating">true</item>
|
|
||||||
<item name="android:backgroundDimEnabled">true</item>
|
|
||||||
<item name="android:windowContentOverlay">@null</item>
|
|
||||||
<item name="android:windowAnimationStyle">@style/Animation.AppCompat.Dialog</item>
|
|
||||||
<item name="android:windowSoftInputMode">stateUnspecified|adjustResize</item>
|
|
||||||
|
|
||||||
<item name="windowActionBar">false</item>
|
|
||||||
<item name="windowActionModeOverlay">true</item>
|
|
||||||
|
|
||||||
<item name="listPreferredItemPaddingLeft">24dip</item>
|
|
||||||
<item name="listPreferredItemPaddingRight">24dip</item>
|
|
||||||
|
|
||||||
<item name="android:listDivider">@null</item>
|
|
||||||
|
|
||||||
<item name="android:buttonBarStyle">@style/Widget.AppCompat.ButtonBar.AlertDialog</item>
|
|
||||||
<item name="android:borderlessButtonStyle">@style/Widget.AppCompat.Button.Borderless</item>
|
|
||||||
<item name="android:windowCloseOnTouchOutside">true</item>
|
|
||||||
</style>
|
|
||||||
</resources>
|
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package org.koitharu.kotatsu.core.parser
|
||||||
|
|
||||||
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||||
|
import org.koitharu.kotatsu.parsers.MangaParser
|
||||||
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||||
|
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||||
|
import org.koitharu.kotatsu.parsers.model.Manga
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||||
|
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||||
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
|
import java.util.EnumSet
|
||||||
|
|
||||||
|
class DummyParser(override val context: MangaLoaderContext) : MangaParser(MangaSource.DUMMY) {
|
||||||
|
|
||||||
|
override val configKeyDomain: ConfigKey.Domain
|
||||||
|
get() = ConfigKey.Domain("localhost", null)
|
||||||
|
|
||||||
|
override val sortOrders: Set<SortOrder>
|
||||||
|
get() = EnumSet.allOf(SortOrder::class.java)
|
||||||
|
|
||||||
|
override suspend fun getDetails(manga: Manga): Manga = stub()
|
||||||
|
|
||||||
|
override suspend fun getList(
|
||||||
|
offset: Int,
|
||||||
|
query: String?,
|
||||||
|
tags: Set<MangaTag>?,
|
||||||
|
sortOrder: SortOrder,
|
||||||
|
): List<Manga> = stub()
|
||||||
|
|
||||||
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> = stub()
|
||||||
|
|
||||||
|
override suspend fun getTags(): Set<MangaTag> = stub()
|
||||||
|
|
||||||
|
private fun stub(): Nothing {
|
||||||
|
throw NotFoundException("Usage of Dummy parser in release build", "")
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.parser
|
|
||||||
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
|
||||||
import org.koitharu.kotatsu.parsers.MangaParser
|
|
||||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
|
||||||
import org.koitharu.kotatsu.parsers.newParser
|
|
||||||
|
|
||||||
fun MangaParser(source: MangaSource, loaderContext: MangaLoaderContext): MangaParser {
|
|
||||||
return source.newParser(loaderContext)
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue