From 1b28c06be074f5fea777e5d5be6322b54c3003ab Mon Sep 17 00:00:00 2001 From: tom79 Date: Thu, 20 Jul 2017 15:00:43 +0200 Subject: [PATCH] Avoid to reopen same account details when consulting an account... --- .../mastodon/activities/HashTagActivity.java | 2 +- .../activities/ShowAccountActivity.java | 18 +++++++----- .../activities/ShowConversationActivity.java | 2 +- .../mastodon/drawers/AccountsListAdapter.java | 19 ++++++++---- .../mastodon/drawers/StatusListAdapter.java | 29 ++++++++++++------- .../fragments/DisplayAccountsFragment.java | 5 ++-- .../fragments/DisplayStatusFragment.java | 4 +-- 7 files changed, 47 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java index 91c67352f..3f94d6c48 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java @@ -101,7 +101,7 @@ public class HashTagActivity extends AppCompatActivity implements OnRetrieveFeed textviewNoAction = (RelativeLayout) findViewById(R.id.no_action); mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); - statusListAdapter = new StatusListAdapter(HashTagActivity.this, RetrieveFeedsAsyncTask.Type.TAG, isOnWifi, behaviorWithAttachments, this.statuses); + statusListAdapter = new StatusListAdapter(HashTagActivity.this, RetrieveFeedsAsyncTask.Type.TAG, null, isOnWifi, behaviorWithAttachments, this.statuses); lv_status.setAdapter(statusListAdapter); setTitle(String.format("#%s", tag)); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java index a87c71afd..ca354dd89 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java @@ -115,16 +115,9 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi } setContentView(R.layout.activity_show_account); instanceValue += 1; - imageLoader = ImageLoader.getInstance(); - statuses = new ArrayList<>(); - boolean isOnWifi = Helper.isOnWIFI(getApplicationContext()); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - statusListAdapter = new StatusListAdapter(getApplicationContext(), RetrieveFeedsAsyncTask.Type.USER, isOnWifi, behaviorWithAttachments, this.statuses); - options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false) - .cacheOnDisk(true).resetViewBeforeLoading(true).build(); + Bundle b = getIntent().getExtras(); account_follow = (Button) findViewById(R.id.account_follow); account_follow.setEnabled(false); - Bundle b = getIntent().getExtras(); if(b != null){ accountId = b.getString("accountId"); new RetrieveRelationshipAsyncTask(getApplicationContext(), accountId,ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -136,6 +129,15 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi }else{ Toast.makeText(this,R.string.toast_error_loading_account,Toast.LENGTH_LONG).show(); } + imageLoader = ImageLoader.getInstance(); + statuses = new ArrayList<>(); + boolean isOnWifi = Helper.isOnWIFI(getApplicationContext()); + int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); + statusListAdapter = new StatusListAdapter(getApplicationContext(), RetrieveFeedsAsyncTask.Type.USER, accountId, isOnWifi, behaviorWithAttachments, this.statuses); + options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false) + .cacheOnDisk(true).resetViewBeforeLoading(true).build(); + + if( getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java index a2fd56393..9aa4a4390 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java @@ -180,7 +180,7 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet } } RelativeLayout loader = (RelativeLayout) findViewById(R.id.loader); - StatusListAdapter statusListAdapter = new StatusListAdapter(ShowConversationActivity.this, RetrieveFeedsAsyncTask.Type.CONTEXT, isOnWifi, behaviorWithAttachments, statuses); + StatusListAdapter statusListAdapter = new StatusListAdapter(ShowConversationActivity.this, RetrieveFeedsAsyncTask.Type.CONTEXT, null, isOnWifi, behaviorWithAttachments, statuses); lv_status.setAdapter(statusListAdapter); statusListAdapter.notifyDataSetChanged(); loader.setVisibility(View.GONE); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsListAdapter.java index 62cb433c1..241344ed1 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsListAdapter.java @@ -25,6 +25,7 @@ import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.text.Html; import android.text.util.Linkify; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -65,8 +66,9 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte private RetrieveAccountsAsyncTask.Type action; private Context context; private AccountsListAdapter accountsListAdapter; + private String targetedId; - public AccountsListAdapter(Context context, RetrieveAccountsAsyncTask.Type action, List accounts){ + public AccountsListAdapter(Context context, RetrieveAccountsAsyncTask.Type action, String targetedId, List accounts){ this.context = context; this.accounts = accounts; layoutInflater = LayoutInflater.from(context); @@ -75,6 +77,7 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte .cacheOnDisk(true).resetViewBeforeLoading(true).build(); this.action = action; this.accountsListAdapter = this; + this.targetedId = targetedId; } @@ -174,11 +177,15 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte holder.account_pp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putString("accountId", account.getId()); - intent.putExtras(b); - context.startActivity(intent); + //Avoid to reopen details about the current account + if( targetedId == null || !targetedId.equals(account.getId())){ + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putString("accountId", account.getId()); + intent.putExtras(b); + context.startActivity(intent); + } + } }); return convertView; 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 c3a4b66c8..a8375cd80 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 @@ -94,8 +94,9 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf private final int FAVOURITE = 2; private ViewHolder holder; private RetrieveFeedsAsyncTask.Type type; + private String targetedId; - public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, boolean isOnWifi, int behaviorWithAttachments, List statuses){ + public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, List statuses){ this.context = context; this.statuses = statuses; this.isOnWifi = isOnWifi; @@ -106,6 +107,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf .cacheOnDisk(true).resetViewBeforeLoading(true).build(); statusListAdapter = this; this.type = type; + this.targetedId = targetedId; } @@ -505,22 +507,27 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf holder.status_account_profile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putString("accountId", status.getAccount().getId()); - intent.putExtras(b); - context.startActivity(intent); + + if( targetedId == null || !targetedId.equals(status.getAccount().getId())){ + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putString("accountId", status.getAccount().getId()); + intent.putExtras(b); + context.startActivity(intent); + } } }); holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putString("accountId", status.getReblog().getAccount().getId()); - intent.putExtras(b); - context.startActivity(intent); + if( targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())){ + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putString("accountId", status.getReblog().getAccount().getId()); + intent.putExtras(b); + context.startActivity(intent); + } } }); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java index 2b662835f..650b7bd0b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java @@ -22,7 +22,6 @@ import android.os.Parcelable; import android.support.v4.app.Fragment; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.widget.SwipeRefreshLayout; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -103,7 +102,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action); mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); - accountsListAdapter = new AccountsListAdapter(context, type, this.accounts); + accountsListAdapter = new AccountsListAdapter(context, type, targetedId, this.accounts); lv_accounts.setAdapter(accountsListAdapter); if( !comesFromSearch) { @@ -257,7 +256,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou textviewNoAction.setVisibility(View.GONE); max_id = apiResponse.getMax_id(); if( swiped ){ - accountsListAdapter = new AccountsListAdapter(context, type, this.accounts); + accountsListAdapter = new AccountsListAdapter(context, type,targetedId, this.accounts); lv_accounts.setAdapter(accountsListAdapter); swiped = false; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index d26a28ffe..ff6308215 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -112,7 +112,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action); mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); - statusListAdapter = new StatusListAdapter(context, type, isOnWifi, behaviorWithAttachments, this.statuses); + statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, this.statuses); lv_status.setAdapter(statusListAdapter); if( !comesFromSearch){ @@ -279,7 +279,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn else textviewNoAction.setVisibility(View.GONE); if( swiped ){ - statusListAdapter = new StatusListAdapter(context, type, isOnWifi, behaviorWithAttachments, this.statuses); + statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, this.statuses); lv_status.setAdapter(statusListAdapter); swiped = false; }