Ability to remove item from updates
This commit is contained in:
@@ -13,9 +13,9 @@ import org.koitharu.kotatsu.core.db.entity.MangaEntity
|
|||||||
entity = MangaEntity::class,
|
entity = MangaEntity::class,
|
||||||
parentColumns = ["manga_id"],
|
parentColumns = ["manga_id"],
|
||||||
childColumns = ["manga_id"],
|
childColumns = ["manga_id"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE,
|
||||||
)
|
),
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
class TrackEntity(
|
class TrackEntity(
|
||||||
@PrimaryKey(autoGenerate = false)
|
@PrimaryKey(autoGenerate = false)
|
||||||
@@ -27,4 +27,4 @@ class TrackEntity(
|
|||||||
@ColumnInfo(name = "last_check") val lastCheck: Long,
|
@ColumnInfo(name = "last_check") val lastCheck: Long,
|
||||||
@get:Deprecated(message = "Should not be used", level = DeprecationLevel.ERROR)
|
@get:Deprecated(message = "Should not be used", level = DeprecationLevel.ERROR)
|
||||||
@ColumnInfo(name = "last_notified_id") val lastNotifiedChapterId: Long
|
@ColumnInfo(name = "last_notified_id") val lastNotifiedChapterId: Long
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ abstract class TracksDao {
|
|||||||
@Query("UPDATE tracks SET chapters_new = 0")
|
@Query("UPDATE tracks SET chapters_new = 0")
|
||||||
abstract suspend fun clearCounters()
|
abstract suspend fun clearCounters()
|
||||||
|
|
||||||
|
@Query("UPDATE tracks SET chapters_new = 0 WHERE manga_id = :mangaId")
|
||||||
|
abstract suspend fun clearCounter(mangaId: Long)
|
||||||
|
|
||||||
@Query("DELETE FROM tracks WHERE manga_id = :mangaId")
|
@Query("DELETE FROM tracks WHERE manga_id = :mangaId")
|
||||||
abstract suspend fun delete(mangaId: Long)
|
abstract suspend fun delete(mangaId: Long)
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,18 @@ class TrackingRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun clearUpdates(ids: Collection<Long>) {
|
||||||
|
when {
|
||||||
|
ids.isEmpty() -> return
|
||||||
|
ids.size == 1 -> db.tracksDao.clearCounter(ids.single())
|
||||||
|
else -> db.withTransaction {
|
||||||
|
for (id in ids) {
|
||||||
|
db.tracksDao.clearCounter(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun syncWithHistory(manga: Manga, chapterId: Long) {
|
suspend fun syncWithHistory(manga: Manga, chapterId: Long) {
|
||||||
val chapters = manga.chapters ?: return
|
val chapters = manga.chapters ?: return
|
||||||
val chapterIndex = chapters.indexOfFirst { x -> x.id == chapterId }
|
val chapterIndex = chapters.indexOfFirst { x -> x.id == chapterId }
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package org.koitharu.kotatsu.tracker.ui.updates
|
package org.koitharu.kotatsu.tracker.ui.updates
|
||||||
|
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
|
||||||
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
import org.koitharu.kotatsu.list.ui.MangaListFragment
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -12,6 +17,22 @@ class UpdatesFragment : MangaListFragment() {
|
|||||||
|
|
||||||
override fun onScrolledToEnd() = Unit
|
override fun onScrolledToEnd() = Unit
|
||||||
|
|
||||||
|
override fun onCreateActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
mode.menuInflater.inflate(R.menu.mode_updates, menu)
|
||||||
|
return super.onCreateActionMode(controller, mode, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActionItemClicked(controller: ListSelectionController, mode: ActionMode, item: MenuItem): Boolean {
|
||||||
|
return when (item.itemId) {
|
||||||
|
R.id.action_remove -> {
|
||||||
|
viewModel.remove(controller.snapshot())
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> super.onActionItemClicked(controller, mode, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun newInstance() = UpdatesFragment()
|
fun newInstance() = UpdatesFragment()
|
||||||
|
|||||||
@@ -59,4 +59,10 @@ class UpdatesViewModel @Inject constructor(
|
|||||||
override fun onRefresh() = Unit
|
override fun onRefresh() = Unit
|
||||||
|
|
||||||
override fun onRetry() = Unit
|
override fun onRetry() = Unit
|
||||||
|
|
||||||
|
fun remove(ids: Set<Long>) {
|
||||||
|
launchJob(Dispatchers.Default) {
|
||||||
|
repository.clearUpdates(ids)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
app/src/main/res/menu/mode_updates.xml
Normal file
29
app/src/main/res/menu/mode_updates.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_share"
|
||||||
|
android:icon="?actionModeShareDrawable"
|
||||||
|
android:title="@string/share"
|
||||||
|
app:showAsAction="ifRoom|withText" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_remove"
|
||||||
|
android:icon="@drawable/ic_delete"
|
||||||
|
android:title="@string/delete"
|
||||||
|
app:showAsAction="ifRoom|withText" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_save"
|
||||||
|
android:icon="@drawable/ic_save"
|
||||||
|
android:title="@string/save"
|
||||||
|
app:showAsAction="ifRoom|withText" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_select_all"
|
||||||
|
android:icon="?actionModeSelectAllDrawable"
|
||||||
|
android:title="@android:string/selectAll"
|
||||||
|
app:showAsAction="ifRoom|withText" />
|
||||||
|
</menu>
|
||||||
Reference in New Issue
Block a user