From 9d0b4847e590af22023ca286742aa7425a3635da Mon Sep 17 00:00:00 2001 From: stom79 Date: Wed, 20 Dec 2017 19:23:17 +0100 Subject: [PATCH] Fixes issue #161 - Cannot reply with different account --- .../mastodon/activities/TootActivity.java | 7 ++- .../etalab/mastodon/helper/CrossActions.java | 62 +++++++++++++------ 2 files changed, 50 insertions(+), 19 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 a9103483b..c3072915e 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 @@ -187,6 +187,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount private AlertDialog dialogTrans; private AlertDialog alertDialogEmoji; private String mentionAccount; + private String idRedirect; @Override protected void onCreate(Bundle savedInstanceState) { @@ -274,6 +275,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount sharedContentIni = b.getString("sharedContent", null); sharedSubject = b.getString("sharedSubject", null); mentionAccount = b.getString("mentionAccount", null); + idRedirect = b.getString("idRedirect", null); restoredScheduled = b.getBoolean("restoredScheduled", false); // ACTION_SEND route if (b.getInt("uriNumberMast", 0) == 1) { @@ -1506,7 +1508,10 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount if( status != null ) { Intent intent = new Intent(getApplicationContext(), ShowConversationActivity.class); Bundle b = new Bundle(); - b.putString("statusId", status.getId()); + if( idRedirect == null) + b.putString("statusId", status.getId()); + else + b.putString("statusId", idRedirect); intent.putExtras(b); startActivity(intent); finish(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java index 04b5d2f62..b43471365 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java @@ -26,6 +26,8 @@ import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.widget.RecyclerView; import android.text.Html; + +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; @@ -36,6 +38,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Mention; +import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.drawers.AccountsSearchAdapter; import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface; @@ -210,25 +213,48 @@ public class CrossActions { }); builderSingle.setAdapter(accountsSearchAdapter, new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { - Account account = accountArray[which]; - Intent intent = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - if( status.getReblog() != null ) - b.putParcelable("tootReply", status.getReblog()); - else - b.putParcelable("tootReply", status); - b.putParcelable("accountReply", account); - intent.putExtras(b); //Put your id to your next Intent - context.startActivity(intent); - if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){ - try { - //Avoid to open multi activities when replying in a conversation - ((ShowConversationActivity)context).finish(); - }catch (Exception ignored){} + public void onClick(final DialogInterface dialog, int which) { + final Account account = accountArray[which]; + + new AsyncTask() { + private List remoteStatuses; + private WeakReference contextReference = new WeakReference<>(context); + + @Override + protected Void doInBackground(Void... voids) { + API api = new API(contextReference.get(), account.getInstance(), account.getToken()); + Results search = api.search(status.getReblog()!=null?status.getReblog().getUri():status.getUri()); + if( search != null){ + remoteStatuses = search.getStatuses(); + } + return null; + } + + @Override + protected void onPostExecute(Void result) { + Intent intent = new Intent(contextReference.get(), TootActivity.class); + Bundle b = new Bundle(); + if( remoteStatuses.get(0).getReblog() != null ) { + b.putParcelable("tootReply", remoteStatuses.get(0).getReblog()); + b.putString("idRedirect", status.getReblog().getId()); + }else { + b.putParcelable("tootReply", remoteStatuses.get(0)); + b.putString("idRedirect", status.getId()); + } + b.putParcelable("accountReply", account); + intent.putExtras(b); //Put your id to your next Intent + contextReference.get().startActivity(intent); + if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){ + try { + //Avoid to open multi activities when replying in a conversation + ((ShowConversationActivity)contextReference.get()).finish(); + }catch (Exception ignored){} + + } + dialog.dismiss(); + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR ); - } - dialog.dismiss(); } }); builderSingle.show();