Skip to content

Commit

Permalink
Ability to remove item from updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Koitharu committed Jun 21, 2023
1 parent 1394678 commit 745b349
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import org.koitharu.kotatsu.core.db.entity.MangaEntity
entity = MangaEntity::class,
parentColumns = ["manga_id"],
childColumns = ["manga_id"],
onDelete = ForeignKey.CASCADE
)
]
onDelete = ForeignKey.CASCADE,
),
],
)
class TrackEntity(
@PrimaryKey(autoGenerate = false)
Expand All @@ -27,4 +27,4 @@ class TrackEntity(
@ColumnInfo(name = "last_check") val lastCheck: Long,
@get:Deprecated(message = "Should not be used", level = DeprecationLevel.ERROR)
@ColumnInfo(name = "last_notified_id") val lastNotifiedChapterId: Long
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ abstract class TracksDao {
@Query("UPDATE tracks SET chapters_new = 0")
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")
abstract suspend fun delete(mangaId: Long)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
val chapters = manga.chapters ?: return
val chapterIndex = chapters.indexOfFirst { x -> x.id == chapterId }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
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 dagger.hilt.android.AndroidEntryPoint
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.ui.list.ListSelectionController
import org.koitharu.kotatsu.list.ui.MangaListFragment

@AndroidEntryPoint
Expand All @@ -12,6 +17,22 @@ class UpdatesFragment : MangaListFragment() {

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 {

fun newInstance() = UpdatesFragment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ class UpdatesViewModel @Inject constructor(
override fun onRefresh() = Unit

override fun onRetry() = Unit

fun remove(ids: Set<Long>) {
launchJob(Dispatchers.Default) {
repository.clearUpdates(ids)
}
}
}
29 changes: 29 additions & 0 deletions app/src/main/res/menu/mode_updates.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 745b349

Please sign in to comment.