From f366776b9aed23cdf8eb5da81dbedae855644a15 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sat, 18 Aug 2018 20:12:37 +0200 Subject: [PATCH] Allow to edit custom fields in profile --- .../mastodon/activities/TootActivity.java | 21 +++++----- .../mastodon/drawers/StatusListAdapter.java | 39 ++++++++++--------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index 797c9d166..7e503dfc8 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -192,6 +192,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount private Account account; private ArrayList splitToot; private int stepSpliToot; + private boolean removed; @Override protected void onCreate(Bundle savedInstanceState) { @@ -291,6 +292,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount sharedSubject = b.getString("sharedSubject", null); mentionAccount = b.getString("mentionAccount", null); idRedirect = b.getString("idRedirect", null); + removed = b.getBoolean("removed"); restoredScheduled = b.getBoolean("restoredScheduled", false); // ACTION_SEND route if (b.getInt("uriNumberMast", 0) == 1) { @@ -1780,6 +1782,9 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount StoredStatus draft = new StatusStoredDAO(TootActivity.this, db).getStatus(id); Status status = draft.getStatus(); //Retrieves attachments + if( removed ){ + new StatusStoredDAO(TootActivity.this, db).remove(draft.getId()); + } restored = id; attachments = status.getMedia_attachments(); int childCount = toot_picture_container.getChildCount(); @@ -1796,18 +1801,10 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount toRemove.clear(); } String content = status.getContent(); - List tmpMention = status.getMentions(); - if( tmpMention != null && tmpMention.size() > 0 ){ - for(Mention mention: tmpMention){ - String mentionString; - if( mention.getAcct().contains("@")) - mentionString = "@" + mention.getAcct().split("@")[0]; - else - mentionString = "@" + mention.getAcct(); - if( content.contains(mentionString)){ - content = content.replaceAll(mentionString,"@"+mention.getAcct()); - } - } + Pattern mentionLink = Pattern.compile("(<\\s?a\\s?href=\"https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,6})\\/(@[\\/\\w._-]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)"); + Matcher matcher = mentionLink.matcher(content); + if (matcher.find()) { + content = matcher.replaceAll("$3@$2"); } if( attachments != null && attachments.size() > 0){ toot_picture_container.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 5cf5987fd..340fda3a9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -145,7 +145,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct private List timedMute; private boolean redraft; private Status status; - + private Status toot; public StatusListAdapter(Context context, List timedMute, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List statuses){ super(); this.context = context; @@ -1532,20 +1532,28 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); if( redraft ){ if( status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")){ + toot = new Status(); + toot.setIn_reply_to_id(status.getIn_reply_to_id()); + toot.setSensitive(status.isSensitive()); + toot.setMedia_attachments(status.getMedia_attachments()); + if( status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) + toot.setSpoiler_text(status.getSpoiler_text().trim()); + toot.setContent(status.getContent()); + toot.setVisibility(status.getVisibility()); new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }else{ - String content = status.getContent(); - Spanned contentSpan; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - contentSpan = Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY); - else - //noinspection deprecation - contentSpan = Html.fromHtml(content); - status.setContent(contentSpan.toString()); - long id = new StatusStoredDAO(context, db).insertStatus(status, null); + toot = new Status(); + toot.setSensitive(status.isSensitive()); + toot.setMedia_attachments(status.getMedia_attachments()); + if( status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) + toot.setSpoiler_text(status.getSpoiler_text().trim()); + toot.setVisibility(status.getVisibility()); + toot.setContent(status.getContent()); + long id = new StatusStoredDAO(context, db).insertStatus(toot, null); Intent intentToot = new Intent(context, TootActivity.class); Bundle b = new Bundle(); b.putLong("restored", id); + b.putBoolean("removed", true); intentToot.putExtras(b); context.startActivity(intentToot); } @@ -1825,18 +1833,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if( apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0){ SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - String content = status.getContent(); - Spanned contentSpan; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - contentSpan = Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY); - else - //noinspection deprecation - contentSpan = Html.fromHtml(content); - status.setContent(contentSpan.toString()); - long id = new StatusStoredDAO(context, db).insertStatus(status, apiResponse.getStatuses().get(0)); + long id = new StatusStoredDAO(context, db).insertStatus(toot, apiResponse.getStatuses().get(0)); Intent intentToot = new Intent(context, TootActivity.class); Bundle b = new Bundle(); b.putLong("restored", id); + b.putBoolean("removed", true); intentToot.putExtras(b); context.startActivity(intentToot); }