Unregistering scrobbler
This commit is contained in:
@@ -207,6 +207,14 @@ class DetailsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun unregisterScrobbling() {
|
||||
launchJob(Dispatchers.Default) {
|
||||
scrobbler.unregisterScrobbling(
|
||||
mangaId = delegate.mangaId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun doLoad() = launchLoadingJob(Dispatchers.Default) {
|
||||
delegate.doLoad()
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.AdapterView
|
||||
import android.widget.RatingBar
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.core.net.toUri
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import coil.ImageLoader
|
||||
@@ -31,7 +33,8 @@ class ScrobblingInfoBottomSheet :
|
||||
BaseBottomSheet<SheetScrobblingBinding>(),
|
||||
AdapterView.OnItemSelectedListener,
|
||||
RatingBar.OnRatingBarChangeListener,
|
||||
View.OnClickListener {
|
||||
View.OnClickListener,
|
||||
PopupMenu.OnMenuItemClickListener {
|
||||
|
||||
private val viewModel by sharedViewModel<DetailsViewModel>()
|
||||
private val coil by inject<ImageLoader>(mode = LazyThreadSafetyMode.NONE)
|
||||
@@ -52,6 +55,12 @@ class ScrobblingInfoBottomSheet :
|
||||
binding.buttonOpen.setOnClickListener(this)
|
||||
binding.imageViewCover.setOnClickListener(this)
|
||||
binding.textViewDescription.movementMethod = LinkMovementMethod.getInstance()
|
||||
|
||||
val popupMenu = PopupMenu(view.context, binding.buttonOpen)
|
||||
popupMenu.inflate(R.menu.opt_scrobbling)
|
||||
popupMenu.setOnMenuItemClickListener(this)
|
||||
|
||||
binding.buttonOpen.setOnClickListener { popupMenu.show() }
|
||||
}
|
||||
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
@@ -74,13 +83,6 @@ class ScrobblingInfoBottomSheet :
|
||||
|
||||
override fun onClick(v: View) {
|
||||
when (v.id) {
|
||||
R.id.button_open -> {
|
||||
val url = viewModel.scrobblingInfo.value?.externalUrl ?: return
|
||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||
startActivity(
|
||||
Intent.createChooser(intent, getString(R.string.open_in_browser))
|
||||
)
|
||||
}
|
||||
R.id.imageView_cover -> {
|
||||
val coverUrl = viewModel.scrobblingInfo.value?.coverUrl ?: return
|
||||
val options = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.width, v.height)
|
||||
@@ -116,4 +118,21 @@ class ScrobblingInfoBottomSheet :
|
||||
|
||||
fun show(fm: FragmentManager) = ScrobblingInfoBottomSheet().show(fm, TAG)
|
||||
}
|
||||
|
||||
override fun onMenuItemClick(item: MenuItem?): Boolean {
|
||||
when (item?.itemId) {
|
||||
R.id.action_browser -> {
|
||||
val url = viewModel.scrobblingInfo.value?.externalUrl ?: return false
|
||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||
startActivity(
|
||||
Intent.createChooser(intent, getString(R.string.open_in_browser))
|
||||
)
|
||||
}
|
||||
R.id.action_unregister -> {
|
||||
dismiss()
|
||||
viewModel.unregisterScrobbling()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,7 @@ abstract class ScrobblingDao {
|
||||
|
||||
@Update
|
||||
abstract suspend fun update(entity: ScrobblingEntity)
|
||||
|
||||
@Query("DELETE FROM scrobblings WHERE scrobbler = :scrobbler AND manga_id = :mangaId")
|
||||
abstract suspend fun delete(scrobbler: Int, mangaId: Long)
|
||||
}
|
||||
@@ -41,6 +41,8 @@ abstract class Scrobbler(
|
||||
.map { it?.toScrobblingInfo(mangaId) }
|
||||
}
|
||||
|
||||
abstract suspend fun unregisterScrobbling(mangaId: Long)
|
||||
|
||||
protected abstract suspend fun getMangaInfo(id: Long): ScrobblerMangaInfo
|
||||
|
||||
private suspend fun ScrobblingEntity.toScrobblingInfo(mangaId: Long): ScrobblingInfo? {
|
||||
|
||||
@@ -69,6 +69,10 @@ class ShikimoriRepository(
|
||||
return storage.user
|
||||
}
|
||||
|
||||
suspend fun unregister(mangaId: Long) {
|
||||
return db.scrobblingDao.delete(ScrobblerService.SHIKIMORI.id, mangaId)
|
||||
}
|
||||
|
||||
fun logout() {
|
||||
storage.clear()
|
||||
}
|
||||
|
||||
@@ -58,6 +58,10 @@ class ShikimoriScrobbler(
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun unregisterScrobbling(mangaId: Long) {
|
||||
repository.unregister(mangaId)
|
||||
}
|
||||
|
||||
override suspend fun getMangaInfo(id: Long): ScrobblerMangaInfo {
|
||||
return repository.getMangaInfo(id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user