Support "replies policy" for lists (#4072)
This commit is contained in:
parent
0f1d63e3c3
commit
55ed6841ff
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MastoList>
|
||||
|
||||
@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<MastoList>
|
||||
|
||||
@DELETE("api/v1/lists/{listId}")
|
||||
|
|
|
@ -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 })
|
||||
|
|
|
@ -34,4 +34,31 @@
|
|||
android:text="@string/list_exclusive_label"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/replyPolicyLabel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/exclusiveCheckbox"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:text="@string/list_reply_policy_label"
|
||||
/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/replyPolicySpinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/replyPolicyLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:layout_marginTop="0dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:entries="@array/list_reply_policies_display"
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
@ -42,4 +42,11 @@
|
|||
<item>@string/filter_action_warn</item>
|
||||
<item>@string/filter_action_hide</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
<!-- Order must be synchronized with MastoList.ReplyPolicy -->
|
||||
<string-array name="list_reply_policies_display">
|
||||
<item>@string/list_reply_policy_none</item>
|
||||
<item>@string/list_reply_policy_list</item>
|
||||
<item>@string/list_reply_policy_followed</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
|
@ -837,4 +837,8 @@
|
|||
<string name="dialog_delete_filter_text">Delete filter \'%1$s\'?"</string>
|
||||
<string name="dialog_delete_filter_positive_action">Delete</string>
|
||||
<string name="dialog_save_profile_changes_message">Do you want to save your profile changes?</string>
|
||||
<string name="list_reply_policy_none">No one</string>
|
||||
<string name="list_reply_policy_list">Members of the list</string>
|
||||
<string name="list_reply_policy_followed">Any followed user</string>
|
||||
<string name="list_reply_policy_label">Show replies to</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue