Add option to show favourite category on shelf
This commit is contained in:
@@ -23,8 +23,8 @@ abstract class FavouriteCategoriesDao {
|
|||||||
|
|
||||||
suspend fun delete(id: Long) = setDeletedAt(id, System.currentTimeMillis())
|
suspend fun delete(id: Long) = setDeletedAt(id, System.currentTimeMillis())
|
||||||
|
|
||||||
@Query("UPDATE favourite_categories SET title = :title, `order` = :order, `track` = :tracker WHERE category_id = :id")
|
@Query("UPDATE favourite_categories SET title = :title, `order` = :order, `track` = :tracker, `show_in_lib` = :onShelf WHERE category_id = :id")
|
||||||
abstract suspend fun update(id: Long, title: String, order: String, tracker: Boolean)
|
abstract suspend fun update(id: Long, title: String, order: String, tracker: Boolean, onShelf: Boolean)
|
||||||
|
|
||||||
@Query("UPDATE favourite_categories SET `order` = :order WHERE category_id = :id")
|
@Query("UPDATE favourite_categories SET `order` = :order WHERE category_id = :id")
|
||||||
abstract suspend fun updateOrder(id: Long, order: String)
|
abstract suspend fun updateOrder(id: Long, order: String)
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
package org.koitharu.kotatsu.favourites.domain
|
package org.koitharu.kotatsu.favourites.domain
|
||||||
|
|
||||||
import androidx.room.withTransaction
|
import androidx.room.withTransaction
|
||||||
import javax.inject.Inject
|
import kotlinx.coroutines.flow.Flow
|
||||||
import javax.inject.Singleton
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
import org.koitharu.kotatsu.base.domain.ReversibleHandle
|
||||||
import org.koitharu.kotatsu.core.db.MangaDatabase
|
import org.koitharu.kotatsu.core.db.MangaDatabase
|
||||||
import org.koitharu.kotatsu.core.db.entity.*
|
import org.koitharu.kotatsu.core.db.entity.SortOrder
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toEntities
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toEntity
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toManga
|
||||||
|
import org.koitharu.kotatsu.core.db.entity.toMangaTags
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
||||||
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
||||||
@@ -15,6 +21,8 @@ import org.koitharu.kotatsu.parsers.model.Manga
|
|||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.tracker.work.TrackerNotificationChannels
|
import org.koitharu.kotatsu.tracker.work.TrackerNotificationChannels
|
||||||
import org.koitharu.kotatsu.utils.ext.mapItems
|
import org.koitharu.kotatsu.utils.ext.mapItems
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class FavouritesRepository @Inject constructor(
|
class FavouritesRepository @Inject constructor(
|
||||||
@@ -83,7 +91,12 @@ class FavouritesRepository @Inject constructor(
|
|||||||
return db.favouriteCategoriesDao.find(id.toInt()).toFavouriteCategory()
|
return db.favouriteCategoriesDao.find(id.toInt()).toFavouriteCategory()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun createCategory(title: String, sortOrder: SortOrder, isTrackerEnabled: Boolean): FavouriteCategory {
|
suspend fun createCategory(
|
||||||
|
title: String,
|
||||||
|
sortOrder: SortOrder,
|
||||||
|
isTrackerEnabled: Boolean,
|
||||||
|
isVisibleOnShelf: Boolean,
|
||||||
|
): FavouriteCategory {
|
||||||
val entity = FavouriteCategoryEntity(
|
val entity = FavouriteCategoryEntity(
|
||||||
title = title,
|
title = title,
|
||||||
createdAt = System.currentTimeMillis(),
|
createdAt = System.currentTimeMillis(),
|
||||||
@@ -92,7 +105,7 @@ class FavouritesRepository @Inject constructor(
|
|||||||
order = sortOrder.name,
|
order = sortOrder.name,
|
||||||
track = isTrackerEnabled,
|
track = isTrackerEnabled,
|
||||||
deletedAt = 0L,
|
deletedAt = 0L,
|
||||||
isVisibleInLibrary = true,
|
isVisibleInLibrary = isVisibleOnShelf,
|
||||||
)
|
)
|
||||||
val id = db.favouriteCategoriesDao.insert(entity)
|
val id = db.favouriteCategoriesDao.insert(entity)
|
||||||
val category = entity.toFavouriteCategory(id)
|
val category = entity.toFavouriteCategory(id)
|
||||||
@@ -100,8 +113,14 @@ class FavouritesRepository @Inject constructor(
|
|||||||
return category
|
return category
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateCategory(id: Long, title: String, sortOrder: SortOrder, isTrackerEnabled: Boolean) {
|
suspend fun updateCategory(
|
||||||
db.favouriteCategoriesDao.update(id, title, sortOrder.name, isTrackerEnabled)
|
id: Long,
|
||||||
|
title: String,
|
||||||
|
sortOrder: SortOrder,
|
||||||
|
isTrackerEnabled: Boolean,
|
||||||
|
isVisibleOnShelf: Boolean,
|
||||||
|
) {
|
||||||
|
db.favouriteCategoriesDao.update(id, title, sortOrder.name, isTrackerEnabled, isVisibleOnShelf)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateCategory(id: Long, isVisibleInLibrary: Boolean) {
|
suspend fun updateCategory(id: Long, isVisibleInLibrary: Boolean) {
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ class FavouritesCategoryEditActivity :
|
|||||||
title = binding.editName.text?.toString()?.trim().orEmpty(),
|
title = binding.editName.text?.toString()?.trim().orEmpty(),
|
||||||
sortOrder = getSelectedSortOrder(),
|
sortOrder = getSelectedSortOrder(),
|
||||||
isTrackerEnabled = binding.switchTracker.isChecked,
|
isTrackerEnabled = binding.switchTracker.isChecked,
|
||||||
|
isVisibleOnShelf = binding.switchShelf.isChecked,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,6 +113,9 @@ class FavouritesCategoryEditActivity :
|
|||||||
val sortText = getString((category?.order ?: SortOrder.NEWEST).titleRes)
|
val sortText = getString((category?.order ?: SortOrder.NEWEST).titleRes)
|
||||||
binding.editSort.setText(sortText, false)
|
binding.editSort.setText(sortText, false)
|
||||||
binding.switchTracker.isChecked = category?.isTrackingEnabled ?: true
|
binding.switchTracker.isChecked = category?.isTrackingEnabled ?: true
|
||||||
|
binding.switchTracker.jumpDrawablesToCurrentState()
|
||||||
|
binding.switchShelf.isChecked = category?.isVisibleInLibrary ?: true
|
||||||
|
binding.switchShelf.jumpDrawablesToCurrentState()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onError(e: Throwable) {
|
private fun onError(e: Throwable) {
|
||||||
@@ -123,6 +127,7 @@ class FavouritesCategoryEditActivity :
|
|||||||
binding.editSort.isEnabled = !isLoading
|
binding.editSort.isEnabled = !isLoading
|
||||||
binding.editName.isEnabled = !isLoading
|
binding.editName.isEnabled = !isLoading
|
||||||
binding.switchTracker.isEnabled = !isLoading
|
binding.switchTracker.isEnabled = !isLoading
|
||||||
|
binding.switchShelf.isEnabled = !isLoading
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
binding.textViewError.isVisible = false
|
binding.textViewError.isVisible = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,13 +48,14 @@ class FavouritesCategoryEditViewModel @Inject constructor(
|
|||||||
title: String,
|
title: String,
|
||||||
sortOrder: SortOrder,
|
sortOrder: SortOrder,
|
||||||
isTrackerEnabled: Boolean,
|
isTrackerEnabled: Boolean,
|
||||||
|
isVisibleOnShelf: Boolean,
|
||||||
) {
|
) {
|
||||||
launchLoadingJob(Dispatchers.Default) {
|
launchLoadingJob(Dispatchers.Default) {
|
||||||
check(title.isNotEmpty())
|
check(title.isNotEmpty())
|
||||||
if (categoryId == NO_ID) {
|
if (categoryId == NO_ID) {
|
||||||
repository.createCategory(title, sortOrder, isTrackerEnabled)
|
repository.createCategory(title, sortOrder, isTrackerEnabled, isVisibleOnShelf)
|
||||||
} else {
|
} else {
|
||||||
repository.updateCategory(categoryId, title, sortOrder, isTrackerEnabled)
|
repository.updateCategory(categoryId, title, sortOrder, isTrackerEnabled, isVisibleOnShelf)
|
||||||
}
|
}
|
||||||
onSaved.postCall(Unit)
|
onSaved.postCall(Unit)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import org.koitharu.kotatsu.base.ui.BaseActivity
|
import org.koitharu.kotatsu.base.ui.BaseActivity
|
||||||
import org.koitharu.kotatsu.databinding.ActivityShelfSettingsBinding
|
import org.koitharu.kotatsu.databinding.ActivityShelfSettingsBinding
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ShelfSettingsActivity :
|
class ShelfSettingsActivity :
|
||||||
@@ -28,7 +29,7 @@ class ShelfSettingsActivity :
|
|||||||
setContentView(ActivityShelfSettingsBinding.inflate(layoutInflater))
|
setContentView(ActivityShelfSettingsBinding.inflate(layoutInflater))
|
||||||
supportActionBar?.run {
|
supportActionBar?.run {
|
||||||
setDisplayHomeAsUpEnabled(true)
|
setDisplayHomeAsUpEnabled(true)
|
||||||
setHomeAsUpIndicator(com.google.android.material.R.drawable.abc_ic_clear_material)
|
setHomeAsUpIndicator(materialR.drawable.abc_ic_clear_material)
|
||||||
}
|
}
|
||||||
binding.buttonDone.setOnClickListener(this)
|
binding.buttonDone.setOnClickListener(this)
|
||||||
val settingsAdapter = ShelfSettingsAdapter(this)
|
val settingsAdapter = ShelfSettingsAdapter(this)
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ fun shelfSectionAD(
|
|||||||
bind {
|
bind {
|
||||||
binding.textViewTitle.setText(item.section.titleResId)
|
binding.textViewTitle.setText(item.section.titleResId)
|
||||||
binding.switchToggle.isChecked = item.isChecked
|
binding.switchToggle.isChecked = item.isChecked
|
||||||
|
binding.switchToggle.jumpDrawablesToCurrentState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +64,7 @@ fun shelfCategoryAD(
|
|||||||
bind {
|
bind {
|
||||||
binding.root.text = item.title
|
binding.root.text = item.title
|
||||||
binding.root.isChecked = item.isChecked
|
binding.root.isChecked = item.isChecked
|
||||||
|
binding.root.jumpDrawablesToCurrentState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,14 @@
|
|||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
<com.google.android.material.materialswitch.MaterialSwitch
|
||||||
|
android:id="@+id/switch_shelf"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/show_on_shelf"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView_error"
|
android:id="@+id/textView_error"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -432,4 +432,5 @@
|
|||||||
<string name="folder_with_images_import_description">You can select a directory with archives or images. Each archive (or subdirectory) will be recognized as a chapter.</string>
|
<string name="folder_with_images_import_description">You can select a directory with archives or images. Each archive (or subdirectory) will be recognized as a chapter.</string>
|
||||||
<string name="speed">Speed</string>
|
<string name="speed">Speed</string>
|
||||||
<string name="restore_backup_description">Import a previously created backup of user data</string>
|
<string name="restore_backup_description">Import a previously created backup of user data</string>
|
||||||
|
<string name="show_on_shelf">Show on the Shelf</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user