From 55ed6841ff15e6958653a6a288e3905f2d243c5a Mon Sep 17 00:00:00 2001 From: Levi Bard Date: Thu, 26 Oct 2023 11:21:04 +0200 Subject: [PATCH] Support "replies policy" for lists (#4072) --- .../com/keylesspalace/tusky/ListsActivity.kt | 17 ++++++++---- .../keylesspalace/tusky/entity/MastoList.kt | 17 ++++++++++-- .../tusky/network/MastodonApi.kt | 6 +++-- .../tusky/viewmodel/ListsViewModel.kt | 8 +++--- app/src/main/res/layout/dialog_list.xml | 27 +++++++++++++++++++ app/src/main/res/values/string-arrays.xml | 9 ++++++- app/src/main/res/values/strings.xml | 4 +++ 7 files changed, 74 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt b/app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt index 8467e8542..955c2bd5f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt @@ -124,7 +124,9 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector { } private fun showlistNameDialog(list: MastoList?) { - val binding = DialogListBinding.inflate(layoutInflater) + val binding = DialogListBinding.inflate(layoutInflater).apply { + replyPolicySpinner.setSelection(MastoList.ReplyPolicy.from(list?.repliesPolicy).ordinal) + } val dialog = AlertDialog.Builder(this) .setView(binding.root) .setPositiveButton( @@ -134,7 +136,12 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector { R.string.action_rename_list } ) { _, _ -> - onPickedDialogName(binding.nameText.text.toString(), list?.id, binding.exclusiveCheckbox.isChecked) + onPickedDialogName( + binding.nameText.text.toString(), + list?.id, + binding.exclusiveCheckbox.isChecked, + MastoList.ReplyPolicy.entries[binding.replyPolicySpinner.selectedItemPosition].policy + ) } .setNegativeButton(android.R.string.cancel, null) .show() @@ -288,11 +295,11 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector { } } - private fun onPickedDialogName(name: String, listId: String?, exclusive: Boolean) { + private fun onPickedDialogName(name: String, listId: String?, exclusive: Boolean, replyPolicy: String) { if (listId == null) { - viewModel.createNewList(name, exclusive) + viewModel.createNewList(name, exclusive, replyPolicy) } else { - viewModel.updateList(listId, name, exclusive) + viewModel.updateList(listId, name, exclusive, replyPolicy) } } diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/MastoList.kt b/app/src/main/java/com/keylesspalace/tusky/entity/MastoList.kt index a74337ef5..e510f4d2a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/MastoList.kt +++ b/app/src/main/java/com/keylesspalace/tusky/entity/MastoList.kt @@ -16,6 +16,8 @@ package com.keylesspalace.tusky.entity +import com.google.gson.annotations.SerializedName + /** * Created by charlag on 1/4/18. */ @@ -23,5 +25,16 @@ package com.keylesspalace.tusky.entity data class MastoList( val id: String, val title: String, - val exclusive: Boolean? -) + val exclusive: Boolean?, + @SerializedName("replies_policy") val repliesPolicy: String?, +) { + enum class ReplyPolicy(val policy: String) { + NONE("none"), + LIST("list"), + FOLLOWED("followed"); + + companion object { + fun from(policy: String?): ReplyPolicy = values().firstOrNull { it.policy == policy } ?: LIST + } + } +} diff --git a/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt b/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt index 86cb88e3d..1554aa6ac 100644 --- a/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt +++ b/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.kt @@ -599,7 +599,8 @@ interface MastodonApi { @POST("api/v1/lists") suspend fun createList( @Field("title") title: String, - @Field("exclusive") exclusive: Boolean? + @Field("exclusive") exclusive: Boolean?, + @Field("replies_policy") replyPolicy: String, ): NetworkResult @FormUrlEncoded @@ -607,7 +608,8 @@ interface MastodonApi { suspend fun updateList( @Path("listId") listId: String, @Field("title") title: String, - @Field("exclusive") exclusive: Boolean? + @Field("exclusive") exclusive: Boolean?, + @Field("replies_policy") replyPolicy: String, ): NetworkResult @DELETE("api/v1/lists/{listId}") diff --git a/app/src/main/java/com/keylesspalace/tusky/viewmodel/ListsViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/viewmodel/ListsViewModel.kt index e13328a90..0dd05dafe 100644 --- a/app/src/main/java/com/keylesspalace/tusky/viewmodel/ListsViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/viewmodel/ListsViewModel.kt @@ -84,9 +84,9 @@ internal class ListsViewModel @Inject constructor(private val api: MastodonApi) } } - fun createNewList(listName: String, exclusive: Boolean) { + fun createNewList(listName: String, exclusive: Boolean, replyPolicy: String) { viewModelScope.launch { - api.createList(listName, exclusive).fold( + api.createList(listName, exclusive, replyPolicy).fold( { list -> updateState { copy(lists = lists + list) @@ -99,9 +99,9 @@ internal class ListsViewModel @Inject constructor(private val api: MastodonApi) } } - fun updateList(listId: String, listName: String, exclusive: Boolean) { + fun updateList(listId: String, listName: String, exclusive: Boolean, replyPolicy: String) { viewModelScope.launch { - api.updateList(listId, listName, exclusive).fold( + api.updateList(listId, listName, exclusive, replyPolicy).fold( { list -> updateState { copy(lists = lists.replacedFirstWhich(list) { it.id == listId }) diff --git a/app/src/main/res/layout/dialog_list.xml b/app/src/main/res/layout/dialog_list.xml index 5a75c1bed..238fc77cf 100644 --- a/app/src/main/res/layout/dialog_list.xml +++ b/app/src/main/res/layout/dialog_list.xml @@ -34,4 +34,31 @@ android:text="@string/list_exclusive_label" /> + + + + diff --git a/app/src/main/res/values/string-arrays.xml b/app/src/main/res/values/string-arrays.xml index 4748a0cbb..59e997686 100644 --- a/app/src/main/res/values/string-arrays.xml +++ b/app/src/main/res/values/string-arrays.xml @@ -42,4 +42,11 @@ @string/filter_action_warn @string/filter_action_hide - \ No newline at end of file + + + + @string/list_reply_policy_none + @string/list_reply_policy_list + @string/list_reply_policy_followed + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a55842359..a6d2541f6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -837,4 +837,8 @@ Delete filter \'%1$s\'?" Delete Do you want to save your profile changes? + No one + Members of the list + Any followed user + Show replies to