diff --git a/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java b/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java index a12da7040..f4cd975b0 100644 --- a/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java @@ -45,11 +45,13 @@ import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.client.entities.api.Account; import app.fedilab.android.client.entities.api.MastodonList; +import app.fedilab.android.client.entities.app.Pinned; import app.fedilab.android.client.entities.app.PinnedTimeline; import app.fedilab.android.client.entities.app.Timeline; import app.fedilab.android.databinding.ActivityListBinding; import app.fedilab.android.databinding.PopupAddListBinding; import app.fedilab.android.databinding.PopupManageAccountsListBinding; +import app.fedilab.android.exception.DBException; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.ui.drawer.AccountListAdapter; @@ -295,6 +297,73 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd popupAddListBinding.addList.setError(getString(R.string.not_valid_list_name)); } + }); + dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); + dialogBuilder.create().show(); + } else if (item.getItemId() == R.id.action_edit) { + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MastodonListActivity.this, Helper.dialogStyle()); + PopupAddListBinding popupAddListBinding = PopupAddListBinding.inflate(getLayoutInflater()); + dialogBuilder.setView(popupAddListBinding.getRoot()); + popupAddListBinding.addList.setFilters(new InputFilter[]{new InputFilter.LengthFilter(255)}); + popupAddListBinding.addList.setText(mastodonList.title); + popupAddListBinding.addList.setSelection(popupAddListBinding.addList.getText().length()); + dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> { + if (popupAddListBinding.addList.getText() != null && popupAddListBinding.addList.getText().toString().trim().length() > 0) { + timelinesVM.updateList( + BaseMainActivity.currentInstance, BaseMainActivity.currentToken, mastodonList.id, + popupAddListBinding.addList.getText().toString().trim(), null) + .observe(MastodonListActivity.this, newMastodonList -> { + if (mastodonListList != null && newMastodonList != null) { + int position = 0; + for (MastodonList mastodonList : mastodonListList) { + if (newMastodonList.id.equalsIgnoreCase(mastodonList.id)) { + ReorderVM reorderVM = new ViewModelProvider(MastodonListActivity.this).get(ReorderVM.class); + int finalPosition = position; + reorderVM.getAllPinned().observe(MastodonListActivity.this, pinned -> { + if (pinned != null) { + if (pinned.pinnedTimelines != null) { + for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) { + if (pinnedTimeline.mastodonList != null) { + if (pinnedTimeline.mastodonList.id.equalsIgnoreCase(newMastodonList.id)) { + if (!newMastodonList.title.equalsIgnoreCase(pinnedTimeline.mastodonList.title)) { + pinnedTimeline.mastodonList.title = newMastodonList.title; + setTitle(newMastodonList.title); + mastodonListList.get(finalPosition).title = newMastodonList.title; + mastodonListAdapter.notifyItemChanged(finalPosition); + new Thread(() -> { + try { + new Pinned(MastodonListActivity.this).updatePinned(pinned); + Bundle b = new Bundle(); + b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); + Intent intentBD = new Intent(Helper.BROADCAST_DATA); + intentBD.putExtras(b); + LocalBroadcastManager.getInstance(MastodonListActivity.this).sendBroadcast(intentBD); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); + } + + break; + } + } + } + } + } + }); + } + position++; + } + } else { + Toasty.error(MastodonListActivity.this, getString(R.string.toast_error), Toasty.LENGTH_LONG).show(); + } + + }); + dialog.dismiss(); + } else { + popupAddListBinding.addList.setError(getString(R.string.not_valid_list_name)); + } + }); dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); dialogBuilder.create().show(); diff --git a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java index 5d9d45b69..d42b0ae67 100644 --- a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java @@ -243,6 +243,17 @@ public class PinnedTimelineHelper { for (MastodonList mastodonList : mastodonLists) { if (mastodonList.id.compareTo(pinnedTimeline.mastodonList.id) == 0) { present = true; + if (!mastodonList.title.equalsIgnoreCase(pinnedTimeline.mastodonList.title)) { + pinnedTimeline.mastodonList.title = mastodonList.title; + Pinned finalPinned1 = pinned; + new Thread(() -> { + try { + new Pinned(activity).updatePinned(finalPinned1); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); + } break; } } diff --git a/app/src/main/res/drawable/ic_baseline_edit_note_24.xml b/app/src/main/res/drawable/ic_baseline_edit_note_24.xml new file mode 100644 index 000000000..8b13e1b95 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_edit_note_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/menu/menu_list.xml b/app/src/main/res/menu/menu_list.xml index 7291001ca..95b2b0f35 100644 --- a/app/src/main/res/menu/menu_list.xml +++ b/app/src/main/res/menu/menu_list.xml @@ -6,6 +6,11 @@ android:icon="@drawable/ic_baseline_person_add_24" android:title="@string/action_lists_add_user" app:showAsAction="ifRoom" /> + Tag name is not valid! Followed tags Follow tag + Edit list