mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Fix issue #457 - Update list name and sync them.
This commit is contained in:
parent
cdbfb17d94
commit
ae71b2ba71
5 changed files with 96 additions and 0 deletions
|
@ -45,11 +45,13 @@ import app.fedilab.android.BaseMainActivity;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.client.entities.api.Account;
|
import app.fedilab.android.client.entities.api.Account;
|
||||||
import app.fedilab.android.client.entities.api.MastodonList;
|
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.PinnedTimeline;
|
||||||
import app.fedilab.android.client.entities.app.Timeline;
|
import app.fedilab.android.client.entities.app.Timeline;
|
||||||
import app.fedilab.android.databinding.ActivityListBinding;
|
import app.fedilab.android.databinding.ActivityListBinding;
|
||||||
import app.fedilab.android.databinding.PopupAddListBinding;
|
import app.fedilab.android.databinding.PopupAddListBinding;
|
||||||
import app.fedilab.android.databinding.PopupManageAccountsListBinding;
|
import app.fedilab.android.databinding.PopupManageAccountsListBinding;
|
||||||
|
import app.fedilab.android.exception.DBException;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.helper.ThemeHelper;
|
import app.fedilab.android.helper.ThemeHelper;
|
||||||
import app.fedilab.android.ui.drawer.AccountListAdapter;
|
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));
|
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.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||||
dialogBuilder.create().show();
|
dialogBuilder.create().show();
|
||||||
|
|
|
@ -243,6 +243,17 @@ public class PinnedTimelineHelper {
|
||||||
for (MastodonList mastodonList : mastodonLists) {
|
for (MastodonList mastodonList : mastodonLists) {
|
||||||
if (mastodonList.id.compareTo(pinnedTimeline.mastodonList.id) == 0) {
|
if (mastodonList.id.compareTo(pinnedTimeline.mastodonList.id) == 0) {
|
||||||
present = true;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
app/src/main/res/drawable/ic_baseline_edit_note_24.xml
Normal file
10
app/src/main/res/drawable/ic_baseline_edit_note_24.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="#FFFFFF"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M3,10h11v2H3V10zM3,8h11V6H3V8zM3,16h7v-2H3V16zM18.01,12.87l0.71,-0.71c0.39,-0.39 1.02,-0.39 1.41,0l0.71,0.71c0.39,0.39 0.39,1.02 0,1.41l-0.71,0.71L18.01,12.87zM17.3,13.58l-5.3,5.3V21h2.12l5.3,-5.3L17.3,13.58z" />
|
||||||
|
</vector>
|
|
@ -6,6 +6,11 @@
|
||||||
android:icon="@drawable/ic_baseline_person_add_24"
|
android:icon="@drawable/ic_baseline_person_add_24"
|
||||||
android:title="@string/action_lists_add_user"
|
android:title="@string/action_lists_add_user"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_edit"
|
||||||
|
android:icon="@drawable/ic_baseline_edit_note_24"
|
||||||
|
android:title="@string/action_lists_edit"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_delete"
|
android:id="@+id/action_delete"
|
||||||
android:icon="@drawable/ic_baseline_delete_24"
|
android:icon="@drawable/ic_baseline_delete_24"
|
||||||
|
|
|
@ -1983,4 +1983,5 @@
|
||||||
<string name="not_valid_tag_name">Tag name is not valid!</string>
|
<string name="not_valid_tag_name">Tag name is not valid!</string>
|
||||||
<string name="followed_tags">Followed tags</string>
|
<string name="followed_tags">Followed tags</string>
|
||||||
<string name="follow_tag">Follow tag</string>
|
<string name="follow_tag">Follow tag</string>
|
||||||
|
<string name="action_lists_edit">Edit list</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue