From e53fc096e6db4a3d03607334d84d19cf18b72b1d Mon Sep 17 00:00:00 2001 From: stom79 Date: Tue, 25 Sep 2018 17:59:21 +0200 Subject: [PATCH] Show conversation when clicking on a toot of a remote instance --- .../mastodon/drawers/StatusListAdapter.java | 50 +++++++++++-------- .../etalab/mastodon/helper/CrossActions.java | 37 ++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 67 insertions(+), 21 deletions(-) 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 8c2f178ae..1cd284115 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 @@ -617,35 +617,43 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } }); //Click on a conversation - if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && (getItemViewType(position) == DISPLAYED_STATUS || getItemViewType(position) == COMPACT_STATUS)) { + if( (getItemViewType(position) == DISPLAYED_STATUS || getItemViewType(position) == COMPACT_STATUS)) { holder.status_content.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(context, ShowConversationActivity.class); - Bundle b = new Bundle(); - if (status.getReblog() == null) - b.putString("statusId", status.getId()); - else - b.putString("statusId", status.getReblog().getId()); - intent.putExtras(b); - if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) - ((Activity) context).finish(); - context.startActivity(intent); + if(type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) { + Intent intent = new Intent(context, ShowConversationActivity.class); + Bundle b = new Bundle(); + if (status.getReblog() == null) + b.putString("statusId", status.getId()); + else + b.putString("statusId", status.getReblog().getId()); + intent.putExtras(b); + if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) + ((Activity) context).finish(); + context.startActivity(intent); + }else { + CrossActions.doCrossConversation(context,status); + } } }); holder.main_container.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(context, ShowConversationActivity.class); - Bundle b = new Bundle(); - if (status.getReblog() == null) - b.putString("statusId", status.getId()); - else - b.putString("statusId", status.getReblog().getId()); - intent.putExtras(b); - if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) - ((Activity) context).finish(); - context.startActivity(intent); + if(type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) { + Intent intent = new Intent(context, ShowConversationActivity.class); + Bundle b = new Bundle(); + if (status.getReblog() == null) + b.putString("statusId", status.getId()); + else + b.putString("statusId", status.getReblog().getId()); + intent.putExtras(b); + if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) + ((Activity) context).finish(); + context.startActivity(intent); + }else { + CrossActions.doCrossConversation(context,status); + } } }); } 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 c88b0e9e4..7e0451282 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 @@ -236,6 +236,43 @@ public class CrossActions { }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR ); } + public static void doCrossConversation(final Context context, Status remoteStatus){ + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + Account account = new AccountDAO(context, db).getAccountByID(userId); + + new AsyncTask() { + private WeakReference contextReference = new WeakReference<>(context); + Results response; + + @Override + protected void onPreExecute() { + Toast.makeText(contextReference.get(), R.string.retrieve_remote_conversation, Toast.LENGTH_SHORT).show(); + } + + @Override + protected Void doInBackground(Void... voids) { + API api = new API(contextReference.get(), account.getInstance(), account.getToken()); + response = api.search(remoteStatus.getUrl()); + return null; + } + @Override + protected void onPostExecute(Void result) { + if( response == null){ + return; + } + List statuses = response.getStatuses(); + if( statuses != null && statuses.size() > 0) { + Intent intent = new Intent(context, ShowConversationActivity.class); + Bundle b = new Bundle(); + b.putString("statusId", statuses.get(0).getId()); + intent.putExtras(b); + context.startActivity(intent); + } + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR ); + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa4519216..478d15af5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -621,6 +621,7 @@ Select Tone Enable time slot How To Videos + Fetching remote thread! Never