From 321021c9dd494e4efdda0e4de495f49a61984c4e Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 22 May 2022 17:45:23 +0200 Subject: [PATCH] Fix issue #81 - Open a link when clicking content --- .../android/activities/ComposeActivity.java | 17 +++- .../android/client/entities/QuickLoad.java | 91 ++++++++++--------- .../app/fedilab/android/helper/Helper.java | 1 + .../android/ui/drawer/StatusAdapter.java | 1 + 4 files changed, 65 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java index e7ef67907..44b18b3b8 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -101,7 +101,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana private ScheduledStatus scheduledStatus; private String visibility; private app.fedilab.android.client.mastodon.entities.Account accountMention; - + private String statusReplyId; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -125,6 +125,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana statusReply = (Status) b.getSerializable(Helper.ARG_STATUS_REPLY); statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT); scheduledStatus = (ScheduledStatus) b.getSerializable(Helper.ARG_STATUS_SCHEDULED); + statusReplyId = b.getString(Helper.ARG_STATUS_REPLY_ID); statusMention = (Status) b.getSerializable(Helper.ARG_STATUS_MENTION); account = (Account) b.getSerializable(Helper.ARG_ACCOUNT); instance = b.getString(Helper.ARG_INSTANCE, BaseMainActivity.currentInstance); @@ -172,8 +173,18 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana Status status = new Status(); statusDraftList.add(status); - //Restore a draft with all messages - if (statusDraft != null) { + if (statusReplyId != null && statusDraft != null) {//Delete and redraft + ArrayList statusDraftListDR = new ArrayList<>(); + statusDraftListDR.add(statusDraft.statusDraftList.get(0)); + statusList.addAll(statusDraftListDR); + composeAdapter = new ComposeAdapter(statusList, 0, account, accountMention, visibility); + composeAdapter.manageDrafts = this; + LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); + binding.recyclerView.setLayoutManager(mLayoutManager); + binding.recyclerView.setAdapter(composeAdapter); + statusesVM.getContext(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusReplyId) + .observe(ComposeActivity.this, this::initializeContextView); + } else if (statusDraft != null) {//Restore a draft with all messages new Thread(() -> { if (statusDraft.statusReplyList != null) { statusDraft.statusReplyList = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statusDraft.statusReplyList); diff --git a/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java b/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java index 3829c2b2f..0dfdf2ca4 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java +++ b/app/src/main/java/app/fedilab/android/client/entities/QuickLoad.java @@ -214,54 +214,61 @@ public class QuickLoad { QuickLoad localQuickLoad = getSavedValue(account, Timeline.TimeLineEnum.LOCAL, null); QuickLoad publicQuickLoad = getSavedValue(account, Timeline.TimeLineEnum.PUBLIC, null); - for (Status status : homeQuickLoad.statuses) { - if (status.id.equals(id)) { - homeQuickLoad.statuses.remove(status); - break; + if (homeQuickLoad != null && homeQuickLoad.statuses != null) { + for (Status status : homeQuickLoad.statuses) { + if (status.id.equals(id)) { + homeQuickLoad.statuses.remove(status); + break; + } + } + ContentValues valuesHome = new ContentValues(); + valuesHome.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(homeQuickLoad.statuses)); + //Inserts token + try { + db.update(Sqlite.TABLE_QUICK_LOAD, + valuesHome, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?", + new String[]{homeQuickLoad.user_id, homeQuickLoad.instance, homeQuickLoad.slug}); + } catch (Exception e) { + e.printStackTrace(); } } - for (Status status : localQuickLoad.statuses) { - if (status.id.equals(id)) { - localQuickLoad.statuses.remove(status); - break; + if (localQuickLoad != null && localQuickLoad.statuses != null) { + for (Status status : localQuickLoad.statuses) { + if (status.id.equals(id)) { + localQuickLoad.statuses.remove(status); + break; + } + } + ContentValues valuesLocal = new ContentValues(); + valuesLocal.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(localQuickLoad.statuses)); + //Inserts token + try { + db.update(Sqlite.TABLE_QUICK_LOAD, + valuesLocal, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?", + new String[]{localQuickLoad.user_id, localQuickLoad.instance, localQuickLoad.slug}); + } catch (Exception e) { + e.printStackTrace(); } } - for (Status status : publicQuickLoad.statuses) { - if (status.id.equals(id)) { - publicQuickLoad.statuses.remove(status); - break; + if (publicQuickLoad != null && publicQuickLoad.statuses != null) { + for (Status status : publicQuickLoad.statuses) { + if (status.id.equals(id)) { + publicQuickLoad.statuses.remove(status); + break; + } + } + ContentValues valuesPublic = new ContentValues(); + valuesPublic.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(publicQuickLoad.statuses)); + //Inserts token + try { + db.update(Sqlite.TABLE_QUICK_LOAD, + valuesPublic, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?", + new String[]{publicQuickLoad.user_id, publicQuickLoad.instance, publicQuickLoad.slug}); + } catch (Exception e) { + e.printStackTrace(); } } - ContentValues valuesHome = new ContentValues(); - valuesHome.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(homeQuickLoad.statuses)); - //Inserts token - try { - db.update(Sqlite.TABLE_QUICK_LOAD, - valuesHome, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?", - new String[]{homeQuickLoad.user_id, homeQuickLoad.instance, homeQuickLoad.slug}); - } catch (Exception e) { - e.printStackTrace(); - } - ContentValues valuesLocal = new ContentValues(); - valuesLocal.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(homeQuickLoad.statuses)); - //Inserts token - try { - db.update(Sqlite.TABLE_QUICK_LOAD, - valuesLocal, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?", - new String[]{homeQuickLoad.user_id, homeQuickLoad.instance, homeQuickLoad.slug}); - } catch (Exception e) { - e.printStackTrace(); - } - ContentValues valuesPublic = new ContentValues(); - valuesPublic.put(Sqlite.COL_STATUSES, StatusDraft.mastodonStatusListToStringStorage(homeQuickLoad.statuses)); - //Inserts token - try { - db.update(Sqlite.TABLE_QUICK_LOAD, - valuesPublic, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_SLUG + "=?", - new String[]{homeQuickLoad.user_id, homeQuickLoad.instance, homeQuickLoad.slug}); - } catch (Exception e) { - e.printStackTrace(); - } + } /** diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 170882206..bb83e2289 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -188,6 +188,7 @@ public class Helper { public static final String ARG_STATUS_DRAFT_ID = "ARG_STATUS_DRAFT_ID"; public static final String ARG_STATUS_REPLY = "ARG_STATUS_REPLY"; + public static final String ARG_STATUS_REPLY_ID = "ARG_STATUS_REPLY_ID"; public static final String ARG_ACCOUNT = "ARG_ACCOUNT"; public static final String ARG_ACCOUNT_MENTION = "ARG_ACCOUNT_MENTION"; public static final String ARG_MINIFIED = "ARG_MINIFIED"; diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index f08a6b290..6b86702ad 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -1277,6 +1277,7 @@ public class StatusAdapter extends RecyclerView.Adapter statusDeleted.id = null; statusDraft.statusDraftList.add(statusDeleted); intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft); + intent.putExtra(Helper.ARG_STATUS_REPLY_ID, statusDeleted.in_reply_to_id); context.startActivity(intent); sendAction(context, Helper.ARG_STATUS_DELETED, statusToDeal, null); });