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 7b9c08422..dbc2118de 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 @@ -112,7 +112,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi private TabLayout tabLayout; private TextView account_note, account_follow_request; private String userId; - private static int instanceValue = 0; private Relationship relationship; private boolean showMediaOnly, showPinned; private ImageView pp_actionBar; @@ -148,7 +147,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi } setContentView(R.layout.activity_show_account); setTitle(""); - instanceValue += 1; pins = new ArrayList<>(); Bundle b = getIntent().getExtras(); account_follow = findViewById(R.id.account_follow); @@ -673,7 +671,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi bundle.putBoolean("hideHeader",true); bundle.putBoolean("showMediaOnly",showMediaOnly); bundle.putBoolean("showPinned",showPinned); - bundle.putString("hideHeaderValue",String.valueOf(instanceValue)); displayStatusFragment.setArguments(bundle); return displayStatusFragment; case 1: @@ -681,7 +678,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWING); bundle.putString("targetedId", accountId); bundle.putBoolean("hideHeader",true); - bundle.putString("hideHeaderValue",String.valueOf(instanceValue)); displayAccountsFragment.setArguments(bundle); return displayAccountsFragment; case 2: @@ -689,7 +685,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWERS); bundle.putString("targetedId", accountId); bundle.putBoolean("hideHeader",true); - bundle.putString("hideHeaderValue",String.valueOf(instanceValue)); displayAccountsFragment.setArguments(bundle); return displayAccountsFragment; } 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 e84b5685c..15a31fc67 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 @@ -14,14 +14,12 @@ package fr.gouv.etalab.mastodon.fragments; * You should have received a copy of the GNU General Public License along with Mastalab; if not, * see . */ import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Parcelable; import android.support.v4.app.Fragment; -import android.support.v4.content.LocalBroadcastManager; import android.support.v4.view.ViewCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; @@ -66,7 +64,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou private String targetedId; private boolean swiped; private ListView lv_accounts; - private String instanceValue; boolean hideHeader; @Override @@ -83,7 +80,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou type = (RetrieveAccountsAsyncTask.Type) bundle.get("type"); targetedId = bundle.getString("targetedId", null); hideHeader = bundle.getBoolean("hideHeader", false); - instanceValue = bundle.getString("hideHeaderValue", null); if( bundle.containsKey("accounts")){ ArrayList accountsReceived = bundle.getParcelableArrayList("accounts"); assert accountsReceived != null; @@ -98,13 +94,12 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou flag_loading = true; swiped = false; - swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer); - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - lv_accounts = (ListView) rootView.findViewById(R.id.lv_accounts); + swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer); + lv_accounts = rootView.findViewById(R.id.lv_accounts); - mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader); - nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_accounts); - textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action); + mainLoader = rootView.findViewById(R.id.loader); + nextElementLoader = rootView.findViewById(R.id.loading_next_accounts); + textviewNoAction = rootView.findViewById(R.id.no_action); mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); accountsListAdapter = new AccountsListAdapter(context, type, targetedId, this.accounts); @@ -115,31 +110,11 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou if (hideHeader && Build.VERSION.SDK_INT >= 21) ViewCompat.setNestedScrollingEnabled(lv_accounts, true); lv_accounts.setOnScrollListener(new AbsListView.OnScrollListener() { - int lastFirstVisibleItem = 0; @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - if (hideHeader && Build.VERSION.SDK_INT < 21) { - if(firstVisibleItem == 0 && Helper.listIsAtTop(lv_accounts)){ - Intent intent = new Intent(Helper.HEADER_ACCOUNT+instanceValue); - intent.putExtra("hide", false); - LocalBroadcastManager.getInstance(context).sendBroadcast(intent); - }else if (view.getId() == lv_accounts.getId() && totalItemCount > visibleItemCount) { - final int currentFirstVisibleItem = lv_accounts.getFirstVisiblePosition(); - if (currentFirstVisibleItem > lastFirstVisibleItem) { - Intent intent = new Intent(Helper.HEADER_ACCOUNT + instanceValue); - intent.putExtra("hide", true); - LocalBroadcastManager.getInstance(context).sendBroadcast(intent); - } else if (currentFirstVisibleItem < lastFirstVisibleItem) { - Intent intent = new Intent(Helper.HEADER_ACCOUNT + instanceValue); - intent.putExtra("hide", false); - LocalBroadcastManager.getInstance(context).sendBroadcast(intent); - } - lastFirstVisibleItem = currentFirstVisibleItem; - } - } if (firstVisibleItem + visibleItemCount == totalItemCount) { if (!flag_loading) { flag_loading = true; 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 eba180c29..52ebed89f 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 @@ -74,8 +74,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private int behaviorWithAttachments; private boolean showMediaOnly, showPinned; private int positionSpinnerTrans; - private boolean hideHeader; - private String instanceValue; private String lastReadStatus; private Intent streamingFederatedIntent, streamingLocalIntent; @@ -86,18 +84,17 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_status, container, false); statuses = new ArrayList<>(); - + knownId = new ArrayList<>(); context = getContext(); Bundle bundle = this.getArguments(); boolean comesFromSearch = false; - hideHeader = false; + boolean hideHeader = false; showMediaOnly = false; showPinned = false; if (bundle != null) { type = (RetrieveFeedsAsyncTask.Type) bundle.get("type"); targetedId = bundle.getString("targetedId", null); tag = bundle.getString("tag", null); - instanceValue = bundle.getString("hideHeaderValue", null); hideHeader = bundle.getBoolean("hideHeader", false); showMediaOnly = bundle.getBoolean("showMediaOnly",false); showPinned = bundle.getBoolean("showPinned",false); @@ -119,15 +116,15 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); isOnWifi = Helper.isOnWIFI(context); positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); - swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer); + swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer); behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); if( type == RetrieveFeedsAsyncTask.Type.HOME) lastReadStatus = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null); - lv_status = (ListView) rootView.findViewById(R.id.lv_status); - mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader); - nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_status); - textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action); + lv_status = rootView.findViewById(R.id.lv_status); + mainLoader = rootView.findViewById(R.id.loader); + nextElementLoader = rootView.findViewById(R.id.loading_next_status); + textviewNoAction = rootView.findViewById(R.id.no_action); mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); @@ -135,11 +132,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if( !comesFromSearch){ //Hide account header when scrolling for ShowAccountActivity - if (hideHeader ) + if (hideHeader) ViewCompat.setNestedScrollingEnabled(lv_status, true); lv_status.setOnScrollListener(new AbsListView.OnScrollListener() { - int lastFirstVisibleItem = 0; @Override public void onScrollStateChanged(AbsListView view, int scrollState) {