special behavior for API < 21
This commit is contained in:
parent
6340b853f6
commit
fcf7ce6f31
|
@ -15,7 +15,10 @@
|
||||||
package fr.gouv.etalab.mastodon.activities;
|
package fr.gouv.etalab.mastodon.activities;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
@ -29,6 +32,7 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.support.design.widget.AppBarLayout;
|
import android.support.design.widget.AppBarLayout;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
@ -37,6 +41,7 @@ import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.view.PagerAdapter;
|
import android.support.v4.view.PagerAdapter;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
|
@ -114,6 +119,9 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||||
private Relationship relationship;
|
private Relationship relationship;
|
||||||
private boolean showMediaOnly;
|
private boolean showMediaOnly;
|
||||||
private ImageView pp_actionBar;
|
private ImageView pp_actionBar;
|
||||||
|
private BroadcastReceiver hide_header;
|
||||||
|
private boolean isHiddingShowing = false;
|
||||||
|
private LinearLayout main_header_container;
|
||||||
|
|
||||||
public enum action{
|
public enum action{
|
||||||
FOLLOW,
|
FOLLOW,
|
||||||
|
@ -140,7 +148,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||||
Bundle b = getIntent().getExtras();
|
Bundle b = getIntent().getExtras();
|
||||||
account_follow = (FloatingActionButton) findViewById(R.id.account_follow);
|
account_follow = (FloatingActionButton) findViewById(R.id.account_follow);
|
||||||
account_follow_request = (TextView) findViewById(R.id.account_follow_request);
|
account_follow_request = (TextView) findViewById(R.id.account_follow_request);
|
||||||
|
main_header_container = (LinearLayout) findViewById(R.id.main_header_container);
|
||||||
account_follow.setEnabled(false);
|
account_follow.setEnabled(false);
|
||||||
if(b != null){
|
if(b != null){
|
||||||
accountId = b.getString("accountId");
|
accountId = b.getString("accountId");
|
||||||
|
@ -253,6 +261,43 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if( Build.VERSION.SDK_INT < 21) {
|
||||||
|
//Register LocalBroadcast to receive selected accounts after search
|
||||||
|
hide_header = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (!isHiddingShowing) {
|
||||||
|
isHiddingShowing = true;
|
||||||
|
ImageView account_pp = (ImageView) findViewById(R.id.account_pp);
|
||||||
|
boolean hide = intent.getBooleanExtra("hide", false);
|
||||||
|
if (hide) {
|
||||||
|
main_header_container.setVisibility(View.GONE);
|
||||||
|
if (pp_actionBar != null)
|
||||||
|
pp_actionBar.setVisibility(View.VISIBLE);
|
||||||
|
tabLayout.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
manageButtonVisibility();
|
||||||
|
tabLayout.setVisibility(View.VISIBLE);
|
||||||
|
main_header_container.setVisibility(View.VISIBLE);
|
||||||
|
if (pp_actionBar != null)
|
||||||
|
pp_actionBar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
account_pp.requestLayout();
|
||||||
|
Handler handler = new Handler();
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
isHiddingShowing = false;
|
||||||
|
}
|
||||||
|
}, 700);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(hide_header, new IntentFilter(Helper.HEADER_ACCOUNT + String.valueOf(instanceValue)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -299,6 +344,12 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy(){
|
||||||
|
super.onDestroy();
|
||||||
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(hide_header);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRetrieveAccount(Account account, Error error) {
|
public void onRetrieveAccount(Account account, Error error) {
|
||||||
if( error != null){
|
if( error != null){
|
||||||
|
|
|
@ -17,9 +17,11 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -62,6 +64,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
||||||
private boolean swiped;
|
private boolean swiped;
|
||||||
private ListView lv_accounts;
|
private ListView lv_accounts;
|
||||||
private String instanceValue;
|
private String instanceValue;
|
||||||
|
boolean hideHeader;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -70,7 +73,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
||||||
|
|
||||||
context = getContext();
|
context = getContext();
|
||||||
boolean comesFromSearch = false;
|
boolean comesFromSearch = false;
|
||||||
boolean hideHeader = false;
|
hideHeader = false;
|
||||||
Bundle bundle = this.getArguments();
|
Bundle bundle = this.getArguments();
|
||||||
accounts = new ArrayList<>();
|
accounts = new ArrayList<>();
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
|
@ -107,33 +110,48 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
||||||
|
|
||||||
if( !comesFromSearch) {
|
if( !comesFromSearch) {
|
||||||
//Hide account header when scrolling for ShowAccountActivity
|
//Hide account header when scrolling for ShowAccountActivity
|
||||||
if (hideHeader) {
|
if (hideHeader && Build.VERSION.SDK_INT >= 21)
|
||||||
ViewCompat.setNestedScrollingEnabled(lv_accounts,true);
|
ViewCompat.setNestedScrollingEnabled(lv_accounts, true);
|
||||||
}else{
|
lv_accounts.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||||
lv_accounts.setOnScrollListener(new AbsListView.OnScrollListener() {
|
int lastFirstVisibleItem = 0;
|
||||||
@Override
|
@Override
|
||||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||||
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)){
|
||||||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
Intent intent = new Intent(Helper.HEADER_ACCOUNT+instanceValue);
|
||||||
if (!flag_loading) {
|
intent.putExtra("hide", false);
|
||||||
flag_loading = true;
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
||||||
if (type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING)
|
}else if (view.getId() == lv_accounts.getId() && totalItemCount > visibleItemCount) {
|
||||||
asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
final int currentFirstVisibleItem = lv_accounts.getFirstVisiblePosition();
|
||||||
else
|
if (currentFirstVisibleItem > lastFirstVisibleItem) {
|
||||||
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
Intent intent = new Intent(Helper.HEADER_ACCOUNT + instanceValue);
|
||||||
nextElementLoader.setVisibility(View.VISIBLE);
|
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);
|
||||||
}
|
}
|
||||||
} else {
|
lastFirstVisibleItem = currentFirstVisibleItem;
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||||
}
|
if (!flag_loading) {
|
||||||
|
flag_loading = true;
|
||||||
|
if (type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING)
|
||||||
|
asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
else
|
||||||
|
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
nextElementLoader.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextElementLoader.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
|
|
|
@ -14,12 +14,15 @@ package fr.gouv.etalab.mastodon.fragments;
|
||||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -76,6 +79,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
private TextView new_data;
|
private TextView new_data;
|
||||||
private int positionSpinnerTrans;
|
private int positionSpinnerTrans;
|
||||||
private String since_id;
|
private String since_id;
|
||||||
|
private boolean hideHeader;
|
||||||
|
private String instanceValue;
|
||||||
|
|
||||||
public DisplayStatusFragment(){
|
public DisplayStatusFragment(){
|
||||||
displayStatusFragment = this;
|
displayStatusFragment = this;
|
||||||
|
@ -89,12 +94,13 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
context = getContext();
|
context = getContext();
|
||||||
Bundle bundle = this.getArguments();
|
Bundle bundle = this.getArguments();
|
||||||
boolean comesFromSearch = false;
|
boolean comesFromSearch = false;
|
||||||
boolean hideHeader = false;
|
hideHeader = false;
|
||||||
showMediaOnly = false;
|
showMediaOnly = false;
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
type = (RetrieveFeedsAsyncTask.Type) bundle.get("type");
|
type = (RetrieveFeedsAsyncTask.Type) bundle.get("type");
|
||||||
targetedId = bundle.getString("targetedId", null);
|
targetedId = bundle.getString("targetedId", null);
|
||||||
tag = bundle.getString("tag", null);
|
tag = bundle.getString("tag", null);
|
||||||
|
instanceValue = bundle.getString("hideHeaderValue", null);
|
||||||
hideHeader = bundle.getBoolean("hideHeader", false);
|
hideHeader = bundle.getBoolean("hideHeader", false);
|
||||||
showMediaOnly = bundle.getBoolean("showMediaOnly",false);
|
showMediaOnly = bundle.getBoolean("showMediaOnly",false);
|
||||||
if( bundle.containsKey("statuses")){
|
if( bundle.containsKey("statuses")){
|
||||||
|
@ -129,33 +135,53 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
if( !comesFromSearch){
|
if( !comesFromSearch){
|
||||||
|
|
||||||
//Hide account header when scrolling for ShowAccountActivity
|
//Hide account header when scrolling for ShowAccountActivity
|
||||||
if(hideHeader) {
|
if (hideHeader && Build.VERSION.SDK_INT >= 21)
|
||||||
ViewCompat.setNestedScrollingEnabled(lv_status,true);
|
ViewCompat.setNestedScrollingEnabled(lv_status, true);
|
||||||
}else{
|
|
||||||
lv_status.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
||||||
@Override
|
|
||||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
||||||
|
|
||||||
}
|
lv_status.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
int lastFirstVisibleItem = 0;
|
||||||
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
|
@Override
|
||||||
if(!flag_loading ) {
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||||
flag_loading = true;
|
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
|
||||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
|
||||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
else
|
|
||||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
||||||
|
|
||||||
nextElementLoader.setVisibility(View.VISIBLE);
|
}
|
||||||
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||||
|
if (hideHeader && Build.VERSION.SDK_INT < 21) {
|
||||||
|
if(firstVisibleItem == 0 && Helper.listIsAtTop(lv_status)){
|
||||||
|
Intent intent = new Intent(Helper.HEADER_ACCOUNT+instanceValue);
|
||||||
|
intent.putExtra("hide", false);
|
||||||
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
||||||
|
}else if (view.getId() == lv_status.getId() && totalItemCount > visibleItemCount) {
|
||||||
|
final int currentFirstVisibleItem = lv_status.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);
|
||||||
}
|
}
|
||||||
} else {
|
lastFirstVisibleItem = currentFirstVisibleItem;
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
|
||||||
}
|
if(!flag_loading ) {
|
||||||
|
flag_loading = true;
|
||||||
|
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||||
|
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||||
|
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
else
|
||||||
|
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
||||||
|
nextElementLoader.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextElementLoader.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue