Skip to content

Commit

Permalink
Add support for setting a list's "exclusivity" option (#3932)
Browse files Browse the repository at this point in the history
Fixes #3831
  • Loading branch information
Nik Clayton authored Aug 6, 2023
1 parent 6766509 commit 846289b
Show file tree
Hide file tree
Showing 55 changed files with 101 additions and 109 deletions.
46 changes: 23 additions & 23 deletions app/src/main/java/com/keylesspalace/tusky/ListsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.PopupMenu
import android.widget.TextView
Expand All @@ -38,10 +36,10 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import at.connyduck.sparkbutton.helpers.Utils
import com.google.android.material.color.MaterialColors
import com.google.android.material.snackbar.Snackbar
import com.keylesspalace.tusky.databinding.ActivityListsBinding
import com.keylesspalace.tusky.databinding.DialogListBinding
import com.keylesspalace.tusky.di.Injectable
import com.keylesspalace.tusky.di.ViewModelFactory
import com.keylesspalace.tusky.entity.MastoList
Expand Down Expand Up @@ -118,42 +116,44 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector {
viewModel.events.collect { event ->
when (event) {
Event.CREATE_ERROR -> showMessage(R.string.error_create_list)
Event.RENAME_ERROR -> showMessage(R.string.error_rename_list)
Event.UPDATE_ERROR -> showMessage(R.string.error_rename_list)
Event.DELETE_ERROR -> showMessage(R.string.error_delete_list)
}
}
}
}

private fun showlistNameDialog(list: MastoList?) {
val layout = FrameLayout(this)
val editText = EditText(this)
editText.setHint(R.string.hint_list_name)
layout.addView(editText)
val margin = Utils.dpToPx(this, 8)
(editText.layoutParams as ViewGroup.MarginLayoutParams)
.setMargins(margin, margin, margin, 0)

val binding = DialogListBinding.inflate(layoutInflater)
val dialog = AlertDialog.Builder(this)
.setView(layout)
.setView(binding.root)
.setPositiveButton(
if (list == null) {
R.string.action_create_list
} else {
R.string.action_rename_list
}
) { _, _ ->
onPickedDialogName(editText.text, list?.id)
onPickedDialogName(binding.nameText.text.toString(), list?.id, binding.exclusiveCheckbox.isChecked)
}
.setNegativeButton(android.R.string.cancel, null)
.show()

val positiveButton = dialog.getButton(Dialog.BUTTON_POSITIVE)
editText.doOnTextChanged { s, _, _, _ ->
positiveButton.isEnabled = s?.isNotBlank() == true
binding.nameText.let { editText ->
editText.doOnTextChanged { s, _, _, _ ->
dialog.getButton(Dialog.BUTTON_POSITIVE).isEnabled = s?.isNotBlank() == true
}
editText.setText(list?.title)
editText.text?.let { editText.setSelection(it.length) }
}

list?.let {
if (it.exclusive == null) {
binding.exclusiveCheckbox.visible(false)
} else {
binding.exclusiveCheckbox.isChecked = it.exclusive
}
}
editText.setText(list?.title)
editText.text?.let { editText.setSelection(it.length) }
}

private fun showListDeleteDialog(list: MastoList) {
Expand Down Expand Up @@ -226,7 +226,7 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector {
setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.list_edit -> openListSettings(list)
R.id.list_rename -> renameListDialog(list)
R.id.list_update -> renameListDialog(list)
R.id.list_delete -> showListDeleteDialog(list)
else -> return@setOnMenuItemClickListener false
}
Expand Down Expand Up @@ -287,11 +287,11 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector {
}
}

private fun onPickedDialogName(name: CharSequence, listId: String?) {
private fun onPickedDialogName(name: String, listId: String?, exclusive: Boolean) {
if (listId == null) {
viewModel.createNewList(name.toString())
viewModel.createNewList(name, exclusive)
} else {
viewModel.renameList(listId, name.toString())
viewModel.updateList(listId, name, exclusive)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ package com.keylesspalace.tusky.entity

data class MastoList(
val id: String,
val title: String
val title: String,
val exclusive: Boolean?
)
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,16 @@ interface MastodonApi {
@FormUrlEncoded
@POST("api/v1/lists")
suspend fun createList(
@Field("title") title: String
@Field("title") title: String,
@Field("exclusive") exclusive: Boolean?
): NetworkResult<MastoList>

@FormUrlEncoded
@PUT("api/v1/lists/{listId}")
suspend fun updateList(
@Path("listId") listId: String,
@Field("title") title: String
@Field("title") title: String,
@Field("exclusive") exclusive: Boolean?
): NetworkResult<MastoList>

@DELETE("api/v1/lists/{listId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class ListsViewModel @Inject constructor(private val api: MastodonApi)
}

enum class Event {
CREATE_ERROR, DELETE_ERROR, RENAME_ERROR
CREATE_ERROR, DELETE_ERROR, UPDATE_ERROR
}

data class State(val lists: List<MastoList>, val loadingState: LoadingState)
Expand Down Expand Up @@ -84,9 +84,9 @@ internal class ListsViewModel @Inject constructor(private val api: MastodonApi)
}
}

fun createNewList(listName: String) {
fun createNewList(listName: String, exclusive: Boolean) {
viewModelScope.launch {
api.createList(listName).fold(
api.createList(listName, exclusive).fold(
{ list ->
updateState {
copy(lists = lists + list)
Expand All @@ -99,16 +99,16 @@ internal class ListsViewModel @Inject constructor(private val api: MastodonApi)
}
}

fun renameList(listId: String, listName: String) {
fun updateList(listId: String, listName: String, exclusive: Boolean) {
viewModelScope.launch {
api.updateList(listId, listName).fold(
api.updateList(listId, listName, exclusive).fold(
{ list ->
updateState {
copy(lists = lists.replacedFirstWhich(list) { it.id == listId })
}
},
{
sendEvent(Event.RENAME_ERROR)
sendEvent(Event.UPDATE_ERROR)
}
)
}
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/res/layout/dialog_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<EditText
android:id="@+id/nameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:inputType="text"
android:hint="@string/hint_list_name"
android:importantForAutofill="no"
/>

<CheckBox
android:id="@+id/exclusiveCheckbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="0dp"
app:layout_constraintTop_toBottomOf="@id/nameText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="@string/list_exclusive_label"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/menu/list_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/list_edit"
android:title="@string/action_edit_list" />
android:title="@string/action_add_or_remove_from_list" />
<item
android:id="@+id/list_rename"
android:id="@+id/list_update"
android:title="@string/action_rename_list" />
<item
android:id="@+id/list_delete"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@
<string name="action_create_list">إنشاء قائمة</string>
<string name="action_rename_list">إعادة تسمية القائمة</string>
<string name="action_delete_list">حذف القائمة</string>
<string name="action_edit_list">تعديل القائمة</string>
<string name="hint_search_people_list">البحث عن أشخاص قصد متابعتهم</string>
<string name="action_add_to_list">إضافة الحساب إلى القائمة</string>
<string name="action_remove_from_list">إزالة الحساب مِن القائمة</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-be/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@
<string name="conversation_more_recipients">%1$s, %2$s і яшчэ %3$d</string>
<string name="action_discard">Скасаваць змены</string>
<string name="action_continue_edit">Працягнуць рэдагаванне</string>
<string name="action_edit_list">Змяніць спіс</string>
<string name="hint_search_people_list">Пошук сярод вашых падпісак</string>
<string name="add_account_name">Дадаць уліковы запіс</string>
<string name="action_remove_from_list">Выдаліць уліковы запіс са спіса</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
<string name="action_remove_from_list">Премахване на акаунт от списъка</string>
<string name="action_add_to_list">Добавяне на акаунт към списъка</string>
<string name="hint_search_people_list">Търсене на хора, които следвате</string>
<string name="action_edit_list">Редакция на списъка</string>
<string name="action_delete_list">Изтриване на списъка</string>
<string name="action_rename_list">Преименуване на списъка</string>
<string name="action_create_list">Създаване на списък</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-bn-rBD/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<string name="action_remove_from_list">তালিকা থেকে অ্যাকাউন্ট সরান</string>
<string name="action_add_to_list">তালিকায় অ্যাকাউন্ট যোগ করুন</string>
<string name="hint_search_people_list">আপনি অনুসরণ মানুষের জন্য অনুসন্ধান করুন</string>
<string name="action_edit_list">তালিকা সম্পাদনা করুন</string>
<string name="action_delete_list">তালিকা মুছে দিন</string>
<string name="action_rename_list">তালিকা পুনঃ নামকরণ কর</string>
<string name="action_create_list">একটি তালিকা তৈরি করুন</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-bn-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@
<string name="action_create_list">একটি তালিকা তৈরি করুন</string>
<string name="action_rename_list">তালিকা পুনঃ নামকরণ কর</string>
<string name="action_delete_list">তালিকা মুছে দিন</string>
<string name="action_edit_list">তালিকা সম্পাদনা করুন</string>
<string name="hint_search_people_list">আপনি অনুসরণ মানুষের জন্য অনুসন্ধান করুন</string>
<string name="action_add_to_list">তালিকায় অ্যাকাউন্ট যোগ করুন</string>
<string name="action_remove_from_list">তালিকা থেকে অ্যাকাউন্ট সরান</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@
<string name="action_create_list">Crear una llista</string>
<string name="action_rename_list">Reanomenar la llista</string>
<string name="action_delete_list">Suprimir la llista</string>
<string name="action_edit_list">Modificar la llista</string>
<string name="hint_search_people_list">Cercar persones que segueixes</string>
<string name="action_add_to_list">Afegir un compte a la llista</string>
<string name="action_remove_from_list">Suprimir un compte de la llista</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ckb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@
<string name="action_remove_from_list">لابردنی ئەژمێر لە لیستەکە</string>
<string name="action_add_to_list">زیادکردنی ئەژمێر بۆ لیستەکە</string>
<string name="hint_search_people_list">گەڕان بەدوای ئەو کەسانەی کە پەیڕەوی ان دەکەیت</string>
<string name="action_edit_list">دەستکاریکردنی لیستەکە</string>
<string name="action_delete_list">سڕینەوەی لیستەکە</string>
<string name="action_rename_list">ناونانەوەی لیستەکە</string>
<string name="action_create_list">دروستکردنی لیستێک</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@
<string name="action_create_list">Vytvořit seznam</string>
<string name="action_rename_list">Přejmenovat seznam</string>
<string name="action_delete_list">Smazat seznam</string>
<string name="action_edit_list">Upravit seznam</string>
<string name="hint_search_people_list">Hledejte mezi lidmi, které sledujete</string>
<string name="action_add_to_list">Přidat účet na seznam</string>
<string name="action_remove_from_list">Odstranit účet ze seznamu</string>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-cy/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@
<string name="post_media_attachments">Atodiadau</string>
<string name="action_create_list">Creu rhestr</string>
<string name="action_rename_list">Ailenwi\'r rhestr</string>
<string name="action_edit_list">Golygu\'r rhestr</string>
<string name="hint_search_people_list">Chwilio am bobl rydych chi\'n eu dilyn</string>
<string name="profile_badge_bot_text">Bot</string>
<string name="license_cc_by_sa_4">CC-BY-SA 4.0</string>
Expand Down Expand Up @@ -731,4 +730,4 @@
\nFersiwn: %s</string>
<string name="about_copy">Copïo fersiwn a gwybodaeth dyfais</string>
<string name="about_copied">Copïwyd fersiwn a gwybodaeth dyfais</string>
</resources>
</resources>
3 changes: 1 addition & 2 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@
<string name="action_create_list">Liste erstellen</string>
<string name="action_rename_list">Liste umbenennen</string>
<string name="action_delete_list">Liste löschen</string>
<string name="action_edit_list">Liste bearbeiten</string>
<string name="action_add_to_list">Konto zur Liste hinzufügen</string>
<string name="compose_active_account_description">Veröffentlichen als %1$s</string>
<plurals name="hint_describe_for_visually_impaired">
Expand Down Expand Up @@ -674,4 +673,4 @@
<string name="error_missing_edits">Deinem Server ist bekannt, dass dieser Beitrag bearbeitet wurde. Allerdings besitzt er keine Kopien der Änderungen, weshalb diese nicht angezeigt werden können.
\n
\nHierbei handelt es sich um <a href="https://github.com/mastodon/mastodon/issues/25398">Mastodon Issue #25398</a>.</string>
</resources>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@
<string name="action_create_list">Krei liston</string>
<string name="action_rename_list">Ŝanĝi la nomon de la listo</string>
<string name="action_delete_list">Forigi la liston</string>
<string name="action_edit_list">Redakti la liston</string>
<string name="hint_search_people_list">Serĉi homojn, kiujn vi sekvas</string>
<string name="action_add_to_list">Aldoni konton al la listo</string>
<string name="action_remove_from_list">Forigi konton el la listo</string>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@
<string name="error_rename_list">No se pudo renombrar la lista</string>
<string name="error_delete_list">No se pudo eliminar la lista</string>
<string name="action_delete_list">Eliminar la lista</string>
<string name="action_edit_list">Editar la lista</string>
<string name="hint_search_people_list">Buscar personas que sigues</string>
<string name="description_post_media">Contenido: %s</string>
<string name="description_post_cw">Aviso de contenido: %s</string>
Expand Down Expand Up @@ -689,4 +688,4 @@
<string name="notification_notification_worker">Obteniendo notificaciones…</string>
<string name="load_newest_notifications">Cargar nuevas notificaciones</string>
<string name="compose_delete_draft">¿Eliminar borrador\?</string>
</resources>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values-eu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@
<string name="action_create_list">Zerrenda sortu</string>
<string name="action_rename_list">Zerrenda berrizendatu</string>
<string name="action_delete_list">Ezabatu zerrenda</string>
<string name="action_edit_list">Editatu zerrenda</string>
<string name="hint_search_people_list">Bilatu jarraitzen dituzun pertsonak</string>
<string name="action_add_to_list">Gehitu kontua zerrendan</string>
<string name="action_remove_from_list">Kendu kontua zerrendatik</string>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@
<string name="action_create_list">ایجاد یک فهرست</string>
<string name="action_rename_list">تغییر نام فهرست</string>
<string name="action_delete_list">حذف فهرست</string>
<string name="action_edit_list">ویرایش فهرست</string>
<string name="hint_search_people_list">جست‌وجوی افرادی که پی می‌گیرید</string>
<string name="action_add_to_list">افزودن حساب به فهرست</string>
<string name="action_remove_from_list">برداشتن حساب از فهرست</string>
Expand Down Expand Up @@ -683,4 +682,4 @@
\nنگارش: %s</string>
<string name="about_copy">رونوشت از اطّلاعات افزاره و نگارش</string>
<string name="about_copied">اطّلاعات افزاره و نگارش رونوشت شد</string>
</resources>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
<string name="notification_favourite_format">%s lisäsi julkaisusi suosikkeihinsa</string>
<string name="action_open_reblogged_by">Näytä jaot</string>
<string name="action_show_reblogs">Näytä jaetut julkaisut</string>
<string name="action_edit_list">Muokkaa listaa</string>
<string name="notification_summary_large">%1$s, %2$s, %3$s ja %4$d muuta</string>
<plurals name="hint_describe_for_visually_impaired">
<item quantity="one">Kuvaa näkövammaisille
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@
<string name="action_create_list">Créer une liste</string>
<string name="action_rename_list">Renommer la liste</string>
<string name="action_delete_list">Supprimer la liste</string>
<string name="action_edit_list">Modifier la liste</string>
<string name="hint_search_people_list">Chercher des personnes que vous suivez</string>
<string name="action_add_to_list">Ajouter un compte à la liste</string>
<string name="action_remove_from_list">Supprimer un compte de la liste</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-fy/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<string name="action_set_caption">Ûnderskrift pleatse</string>
<string name="action_add_to_list">Account oan de list tafoegje</string>
<string name="hint_search_people_list">Sykje om minsken dy\'t jo folgje</string>
<string name="action_edit_list">Pas de list oan</string>
<string name="action_delete_list">Smyt de list fuort</string>
<string name="action_rename_list">Neam de list om</string>
<string name="action_create_list">Meitsje in list oan</string>
Expand Down
Loading

0 comments on commit 846289b

Please sign in to comment.