feat: delete item from context menu (#251)
* feat: delete item from context menu * fix: follow the naming convention
This commit is contained in:
parent
813b64980d
commit
8177dfdcef
4 changed files with 81 additions and 19 deletions
|
@ -296,6 +296,52 @@ class AnilistQueries {
|
||||||
return media
|
return media
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun userMediaDetails(media: Media): Media {
|
||||||
|
val query =
|
||||||
|
"""{Media(id:${media.id}){id mediaListEntry{id status progress private repeat customLists updatedAt startedAt{year month day}completedAt{year month day}}isFavourite idMal}}"""
|
||||||
|
runBlocking {
|
||||||
|
val anilist = async {
|
||||||
|
var response = executeQuery<Query.Media>(query, force = true, show = true)
|
||||||
|
if (response != null) {
|
||||||
|
fun parse() {
|
||||||
|
val fetchedMedia = response?.data?.media ?: return
|
||||||
|
|
||||||
|
if (fetchedMedia.mediaListEntry != null) {
|
||||||
|
fetchedMedia.mediaListEntry?.apply {
|
||||||
|
media.userProgress = progress
|
||||||
|
media.isListPrivate = private ?: false
|
||||||
|
media.userListId = id
|
||||||
|
media.userStatus = status?.toString()
|
||||||
|
media.inCustomListsOf = customLists?.toMutableMap()
|
||||||
|
media.userRepeat = repeat ?: 0
|
||||||
|
media.userUpdatedAt = updatedAt?.toString()?.toLong()?.times(1000)
|
||||||
|
media.userCompletedAt = completedAt ?: FuzzyDate()
|
||||||
|
media.userStartedAt = startedAt ?: FuzzyDate()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
media.isListPrivate = false
|
||||||
|
media.userStatus = null
|
||||||
|
media.userListId = null
|
||||||
|
media.userProgress = null
|
||||||
|
media.userRepeat = 0
|
||||||
|
media.userUpdatedAt = null
|
||||||
|
media.userCompletedAt = FuzzyDate()
|
||||||
|
media.userStartedAt = FuzzyDate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.data?.media != null) parse()
|
||||||
|
else {
|
||||||
|
response = executeQuery(query, force = true, useToken = false)
|
||||||
|
if (response?.data?.media != null) parse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
awaitAll(anilist)
|
||||||
|
}
|
||||||
|
return media
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun continueMedia(type: String, planned: Boolean = false): ArrayList<Media> {
|
suspend fun continueMedia(type: String, planned: Boolean = false): ArrayList<Media> {
|
||||||
val returnArray = arrayListOf<Media>()
|
val returnArray = arrayListOf<Media>()
|
||||||
val map = mutableMapOf<Int, Media>()
|
val map = mutableMapOf<Int, Media>()
|
||||||
|
|
|
@ -254,20 +254,28 @@ class MediaListDialogFragment : BottomSheetDialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.mediaListDelete.setOnClickListener {
|
binding.mediaListDelete.setOnClickListener {
|
||||||
val id = media!!.userListId
|
var id = media!!.userListId
|
||||||
if (id != null) {
|
scope.launch {
|
||||||
scope.launch {
|
withContext(Dispatchers.IO) {
|
||||||
withContext(Dispatchers.IO) {
|
if (id != null) {
|
||||||
Anilist.mutation.deleteList(id)
|
Anilist.mutation.deleteList(id!!)
|
||||||
MAL.query.deleteList(media?.anime != null, media?.idMAL)
|
MAL.query.deleteList(media?.anime != null, media?.idMAL)
|
||||||
|
} else {
|
||||||
|
val profile = Anilist.query.userMediaDetails(media!!)
|
||||||
|
profile.userListId?.let { listId ->
|
||||||
|
id = listId
|
||||||
|
Anilist.mutation.deleteList(listId)
|
||||||
|
MAL.query.deleteList(media?.anime != null, media?.idMAL)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Refresh.all()
|
|
||||||
snackString(getString(R.string.deleted_from_list))
|
|
||||||
dismissAllowingStateLoss()
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (id != null) {
|
||||||
|
Refresh.all()
|
||||||
|
snackString(getString(R.string.deleted_from_list))
|
||||||
|
dismissAllowingStateLoss()
|
||||||
} else {
|
} else {
|
||||||
snackString(getString(R.string.no_list_id))
|
snackString(getString(R.string.no_list_id))
|
||||||
Refresh.all()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,12 +59,12 @@ class MediaListDialogSmallFragment : BottomSheetDialogFragment() {
|
||||||
binding.mediaListContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin += navBarHeight }
|
binding.mediaListContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> { bottomMargin += navBarHeight }
|
||||||
val scope = viewLifecycleOwner.lifecycleScope
|
val scope = viewLifecycleOwner.lifecycleScope
|
||||||
binding.mediaListDelete.setOnClickListener {
|
binding.mediaListDelete.setOnClickListener {
|
||||||
val id = media.userListId
|
var id = media.userListId
|
||||||
if (id != null) {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
withContext(Dispatchers.IO) {
|
||||||
withContext(Dispatchers.IO) {
|
if (id != null) {
|
||||||
try {
|
try {
|
||||||
Anilist.mutation.deleteList(id)
|
Anilist.mutation.deleteList(id!!)
|
||||||
MAL.query.deleteList(media.anime != null, media.idMAL)
|
MAL.query.deleteList(media.anime != null, media.idMAL)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
@ -72,16 +72,24 @@ class MediaListDialogSmallFragment : BottomSheetDialogFragment() {
|
||||||
}
|
}
|
||||||
return@withContext
|
return@withContext
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
val profile = Anilist.query.userMediaDetails(media)
|
||||||
|
profile.userListId?.let { listId ->
|
||||||
|
id = listId
|
||||||
|
Anilist.mutation.deleteList(listId)
|
||||||
|
MAL.query.deleteList(media.anime != null, media.idMAL)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
}
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (id != null) {
|
||||||
Refresh.all()
|
Refresh.all()
|
||||||
snackString(getString(R.string.deleted_from_list))
|
snackString(getString(R.string.deleted_from_list))
|
||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
|
} else {
|
||||||
|
snackString(getString(R.string.no_list_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
snackString(getString(R.string.no_list_id))
|
|
||||||
Refresh.all()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -434,7 +434,7 @@
|
||||||
<string name="episode_not_found">Couldn\'t find episode : %1$s</string>
|
<string name="episode_not_found">Couldn\'t find episode : %1$s</string>
|
||||||
<string name="list_updated">List Updated</string>
|
<string name="list_updated">List Updated</string>
|
||||||
<string name="deleted_from_list">Deleted from List</string>
|
<string name="deleted_from_list">Deleted from List</string>
|
||||||
<string name="no_list_id">No List ID found, reloading…</string>
|
<string name="no_list_id">No List ID found…</string>
|
||||||
<string name="checking_for_update">Checking for Update</string>
|
<string name="checking_for_update">Checking for Update</string>
|
||||||
<string name="dont_show_again">Don\'t show again for version %1$s</string>
|
<string name="dont_show_again">Don\'t show again for version %1$s</string>
|
||||||
<string name="no_update_found">No Update Found</string>
|
<string name="no_update_found">No Update Found</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue