Fixed scrolling up on bottom dialogs and removing stuff from AniList

This commit is contained in:
Lag 2023-02-16 01:15:30 +01:00
parent 3dd0fc6c8e
commit aacd57cb5d
4 changed files with 69 additions and 45 deletions

View file

@ -759,6 +759,11 @@ class AniListApi(index: Int) : AccountManager(index), SyncAPI {
return data != "" return data != ""
} }
/** Used to query a saved MediaItem on the list to get the id for removal */
data class MediaListItemRoot(@JsonProperty("data") val data: MediaListItem? = null)
data class MediaListItem(@JsonProperty("MediaList") val MediaList: MediaListId? = null)
data class MediaListId(@JsonProperty("id") val id: Long? = null)
private suspend fun postDataAboutId( private suspend fun postDataAboutId(
id: Int, id: Int,
type: AniListStatusType, type: AniListStatusType,
@ -766,19 +771,43 @@ class AniListApi(index: Int) : AccountManager(index), SyncAPI {
progress: Int? progress: Int?
): Boolean { ): Boolean {
val q = val q =
"""mutation (${'$'}id: Int = $id, ${'$'}status: MediaListStatus = ${ // Delete item if status type is None
aniListStatusString[maxOf( if (type == AniListStatusType.None) {
0, val userID = getKey<AniListUser>(accountId, ANILIST_USER_KEY)?.id ?: return false
type.value // Get list ID for deletion
)] val idQuery = """
}, ${if (score != null) "${'$'}scoreRaw: Int = ${score * 10}" else ""} , ${if (progress != null) "${'$'}progress: Int = $progress" else ""}) { query MediaList(${'$'}userId: Int = $userID, ${'$'}mediaId: Int = $id) {
SaveMediaListEntry (mediaId: ${'$'}id, status: ${'$'}status, scoreRaw: ${'$'}scoreRaw, progress: ${'$'}progress) { MediaList(userId: ${'$'}userId, mediaId: ${'$'}mediaId) {
id id
status }
progress }
score """
} val response = postApi(idQuery)
val listId =
tryParseJson<MediaListItemRoot>(response)?.data?.MediaList?.id ?: return false
"""
mutation(${'$'}id: Int = $listId) {
DeleteMediaListEntry(id: ${'$'}id) {
deleted
}
}
"""
} else {
"""mutation (${'$'}id: Int = $id, ${'$'}status: MediaListStatus = ${
aniListStatusString[maxOf(
0,
type.value
)]
}, ${if (score != null) "${'$'}scoreRaw: Int = ${score * 10}" else ""} , ${if (progress != null) "${'$'}progress: Int = $progress" else ""}) {
SaveMediaListEntry (mediaId: ${'$'}id, status: ${'$'}status, scoreRaw: ${'$'}scoreRaw, progress: ${'$'}progress) {
id
status
progress
score
}
}""" }"""
}
val data = postApi(q) val data = postApi(q)
return data != "" return data != ""
} }

View file

@ -322,9 +322,7 @@ class ResultFragmentPhone : ResultFragment() {
// it?.dismiss() // it?.dismiss()
//} //}
builder.setCanceledOnTouchOutside(true) builder.setCanceledOnTouchOutside(true)
builder.show() builder.show()
builder builder
} }
} }

View file

@ -176,8 +176,7 @@ class ResultFragmentTv : ResultFragment() {
loadingDialog = null loadingDialog = null
} }
loadingDialog = loadingDialog ?: context?.let { ctx -> loadingDialog = loadingDialog ?: context?.let { ctx ->
val builder = val builder = BottomSheetDialog(ctx)
BottomSheetDialog(ctx)
builder.setContentView(R.layout.bottom_loading) builder.setContentView(R.layout.bottom_loading)
builder.setOnDismissListener { builder.setOnDismissListener {
loadingDialog = null loadingDialog = null
@ -187,9 +186,7 @@ class ResultFragmentTv : ResultFragment() {
// it?.dismiss() // it?.dismiss()
//} //}
builder.setCanceledOnTouchOutside(true) builder.setCanceledOnTouchOutside(true)
builder.show() builder.show()
builder builder
} }
} }

View file

@ -1,34 +1,34 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_height="match_parent"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/text1" android:id="@+id/text1"
android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:layout_width="match_parent"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_rowWeight="1"
android:layout_marginBottom="10dp" android:layout_marginTop="20dp"
android:textStyle="bold" android:layout_marginBottom="10dp"
android:textSize="20sp" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:textColor="?attr/textColor" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:layout_width="match_parent" android:textColor="?attr/textColor"
android:layout_rowWeight="1" android:textSize="20sp"
tools:text="Test" android:textStyle="bold"
android:layout_height="wrap_content" /> tools:text="Test" />
<ListView <ListView
android:nextFocusRight="@id/cancel_btt" android:id="@+id/listview1"
android:nextFocusLeft="@id/apply_btt" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listview1" android:layout_rowWeight="1"
android:layout_marginBottom="60dp" android:layout_marginBottom="60dp"
android:paddingTop="10dp" android:nestedScrollingEnabled="true"
android:requiresFadingEdge="vertical" android:nextFocusLeft="@id/apply_btt"
tools:listitem="@layout/sort_bottom_single_choice_no_checkmark" android:nextFocusRight="@id/cancel_btt"
android:layout_width="match_parent" android:paddingTop="10dp"
android:layout_height="match_parent" android:requiresFadingEdge="vertical"
android:layout_rowWeight="1" /> tools:listitem="@layout/sort_bottom_single_choice_no_checkmark" />
</LinearLayout> </LinearLayout>