Implement remove favourite
This commit is contained in:
1 parent
f08a2444be
commit
ef475000c3
3 files changed
+42
-5
No files matched your search
@@ -343,6 +343,21 @@ public class EhDB {
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void putHistoryInfoNonRefresh(GalleryInfo info) {
|
||||
HistoryDao dao = db.historyDao();
|
||||
var i = dao.load(info.getGid());
|
||||
if (null != i) {
|
||||
HistoryInfo historyInfo;
|
||||
if (info instanceof HistoryInfo) {
|
||||
historyInfo = (HistoryInfo) info;
|
||||
} else {
|
||||
historyInfo = new HistoryInfo(info);
|
||||
historyInfo.time = i.time;
|
||||
}
|
||||
dao.update(historyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void putHistoryInfo(List<HistoryInfo> historyInfoList) {
|
||||
HistoryDao dao = db.historyDao();
|
||||
for (HistoryInfo info : historyInfoList) {
|
||||
|
||||
@@ -47,6 +47,7 @@ import androidx.paging.compose.items
|
||||
import com.hippo.ehviewer.EhDB
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene
|
||||
import com.hippo.ehviewer.ui.scene.HistoryComposeScreenFragmentBridge
|
||||
import com.hippo.ehviewer.ui.widget.GalleryListLongClickDialog
|
||||
import com.hippo.ehviewer.ui.widget.ListInfoCard
|
||||
@@ -183,9 +184,11 @@ fun HistoryScreen(hostFragment: HistoryComposeScreenFragmentBridge) {
|
||||
|
||||
if (dialogStatus == HistoryScreenDialogStatus.SELECT_ITEM) {
|
||||
selectedGalleryInfo?.let { info ->
|
||||
GalleryListLongClickDialog(info = info) {
|
||||
dialogStatus = HistoryScreenDialogStatus.NONE
|
||||
}
|
||||
GalleryListLongClickDialog(
|
||||
info = info,
|
||||
{ dialogStatus = HistoryScreenDialogStatus.NONE },
|
||||
{ hostFragment.showTip(it, BaseScene.LENGTH_LONG) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,14 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.EhDB
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
|
||||
private val downloadManager = EhApplication.downloadManager
|
||||
|
||||
@@ -55,14 +59,18 @@ private fun DialogSelectorItem(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@Composable
|
||||
fun GalleryListLongClickDialog(
|
||||
info: GalleryInfo,
|
||||
fun <T : GalleryInfo> GalleryListLongClickDialog(
|
||||
info: T,
|
||||
onDismissRequest: () -> Unit,
|
||||
showTip: (String) -> Unit
|
||||
) {
|
||||
var dialogStatus by remember { mutableStateOf(DialogStatus.PRIMARY) }
|
||||
val context = LocalContext.current
|
||||
|
||||
val removeFromFavouriteSuccess = stringResource(id = R.string.remove_from_favorite_success)
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
dialogStatus = DialogStatus.PRIMARY
|
||||
@@ -117,7 +125,18 @@ fun GalleryListLongClickDialog(
|
||||
} else {
|
||||
DialogSelectorItem(
|
||||
onClick = {
|
||||
onDismissRequest()
|
||||
dialogStatus = DialogStatus.PRIMARY
|
||||
launchIO {
|
||||
runCatching {
|
||||
EhDB.removeLocalFavorites(info.gid)
|
||||
EhEngine.addFavorites(info.gid, info.token, -1, "")
|
||||
info.favoriteSlot = -2
|
||||
info.favoriteName = null
|
||||
EhDB.putHistoryInfoNonRefresh(info)
|
||||
showTip(removeFromFavouriteSuccess)
|
||||
}
|
||||
}
|
||||
},
|
||||
icon = painterResource(id = R.drawable.v_heart_broken_x24),
|
||||
text = stringResource(id = R.string.remove_from_favourites)
|
||||
|
||||
Reference in new issue
Block a user