Issue #41 - Fixes potential duplicate toots

This commit is contained in:
stom79 2017-11-15 09:44:12 +01:00
parent e765c01e97
commit 843bf2641b
5 changed files with 155 additions and 211 deletions

View File

@ -30,6 +30,7 @@ import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
@ -236,7 +237,9 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
@Override
public void onTabReselected(TabLayout.Tab tab) {
Fragment fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
Fragment fragment = null;
if( mPager.getAdapter() != null)
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
switch (tab.getPosition()){
case 0:
if( displayStatusFragment != null )
@ -244,9 +247,10 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
break;
case 1:
case 2:
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
if (displayAccountsFragment != null)
if( fragment != null) {
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
displayAccountsFragment.scrollToTop();
}
break;
}
}
@ -458,6 +462,7 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
final float scale = getResources().getDisplayMetrics().density;
if(account.isLocked()){
Drawable img = ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_lock_outline);
assert img != null;
img.setBounds(0,0,(int) (20 * scale + 0.5f),(int) (20 * scale + 0.5f));
account_dn.setCompoundDrawables( img, null, null, null);
}else{
@ -738,7 +743,6 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
displayStatusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("targetedId", accountId);
bundle.putBoolean("hideHeader",true);
bundle.putBoolean("showMediaOnly",showMediaOnly);
bundle.putBoolean("showPinned",showPinned);
displayStatusFragment.setArguments(bundle);
@ -747,20 +751,19 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWING);
bundle.putString("targetedId", accountId);
bundle.putBoolean("hideHeader",true);
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
case 2:
displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWERS);
bundle.putString("targetedId", accountId);
bundle.putBoolean("hideHeader",true);
displayAccountsFragment.setArguments(bundle);
return displayAccountsFragment;
}
return null;
}
@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);

View File

@ -16,11 +16,9 @@ package fr.gouv.etalab.mastodon.fragments;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
@ -65,30 +63,19 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
private String targetedId;
private boolean swiped;
private RecyclerView lv_accounts;
boolean hideHeader;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_accounts, container, false);
context = getContext();
boolean comesFromSearch = false;
hideHeader = false;
Bundle bundle = this.getArguments();
accounts = new ArrayList<>();
if (bundle != null) {
type = (RetrieveAccountsAsyncTask.Type) bundle.get("type");
targetedId = bundle.getString("targetedId", null);
hideHeader = bundle.getBoolean("hideHeader", false);
if( bundle.containsKey("accounts")){
ArrayList<Parcelable> accountsReceived = bundle.getParcelableArrayList("accounts");
assert accountsReceived != null;
for(Parcelable account: accountsReceived){
accounts.add((Account)account);
}
comesFromSearch = true;
}
}
max_id = null;
firstLoad = true;
@ -106,64 +93,54 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
accountsListAdapter = new AccountsListAdapter(context, type, targetedId, this.accounts);
lv_accounts.setAdapter(accountsListAdapter);
if( !comesFromSearch) {
//Hide account header when scrolling for ShowAccountActivity
if (hideHeader && Build.VERSION.SDK_INT >= 21)
ViewCompat.setNestedScrollingEnabled(lv_accounts, true);
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(context);
lv_accounts.setLayoutManager(mLayoutManager);
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
if(dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
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);
final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(context);
lv_accounts.setLayoutManager(mLayoutManager);
lv_accounts.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
if(dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
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() {
@Override
public void onRefresh() {
max_id = null;
accounts = new ArrayList<>();
firstLoad = true;
flag_loading = true;
swiped = 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);
}
});
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
R.color.mastodonC3);
}
});
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
max_id = null;
accounts = new ArrayList<>();
firstLoad = true;
flag_loading = true;
swiped = 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);
}
});
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
R.color.mastodonC3);
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);
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);
}else {
accountsListAdapter.notifyDataSetChanged();
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( accounts == null || accounts.size() == 0 )
textviewNoAction.setVisibility(View.VISIBLE);
}
return rootView;
}

View File

@ -280,17 +280,21 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
if( context == null)
return;
if( notification != null){
//Update the id of the last notification retrieved
MainActivity.lastNotificationId = notification.getId();
notifications.add(0, notification);
MainActivity.countNewNotifications++;
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if( firstVisibleItem > 0)
notificationsListAdapter.notifyItemInserted(0);
else
notificationsListAdapter.notifyDataSetChanged();
if( textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
//Makes sure the notifications is not already displayed
if( notification.getId() != null && notifications.get(0)!= null
&& Long.parseLong(notification.getId()) > Long.parseLong(notifications.get(0).getId())) {
//Update the id of the last notification retrieved
MainActivity.lastNotificationId = notification.getId();
notifications.add(0, notification);
MainActivity.countNewNotifications++;
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if (firstVisibleItem > 0)
notificationsListAdapter.notifyItemInserted(0);
else
notificationsListAdapter.notifyDataSetChanged();
if (textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
}
}
}
@ -299,12 +303,9 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
@Override
public void onRetrieveMissingNotifications(List<Notification> notifications) {
if( notifications != null && notifications.size() > 0) {
ArrayList<String> knownId = new ArrayList<>();
for (Notification nt : this.notifications) {
knownId.add(nt.getId());
}
for (int i = notifications.size()-1 ; i >= 0 ; i--) {
if (!knownId.contains(notifications.get(i).getId())) {
if (this.notifications.size() == 0 ||
Long.parseLong(notifications.get(i).getId()) > Long.parseLong(this.notifications.get(0).getId())) {
MainActivity.countNewNotifications++;
this.notifications.add(0, notifications.get(i));
}

View File

@ -20,10 +20,8 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -62,7 +60,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
private StatusListAdapter statusListAdapter;
private String max_id;
private List<Status> statuses;
private ArrayList<String> knownId;
private RetrieveFeedsAsyncTask.Type type;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
@ -86,35 +83,23 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
public View onCreateView(@NonNull 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;
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);
hideHeader = bundle.getBoolean("hideHeader", false);
showMediaOnly = bundle.getBoolean("showMediaOnly",false);
showPinned = bundle.getBoolean("showPinned",false);
if( bundle.containsKey("statuses")){
ArrayList<Parcelable> statusesReceived = bundle.getParcelableArrayList("statuses");
assert statusesReceived != null;
for(Parcelable status: statusesReceived){
statuses.add((Status) status);
knownId.add(((Status) status).getId());
}
comesFromSearch = true;
}
}
max_id = null;
flag_loading = true;
firstLoad = true;
swiped = false;
assert context != null;
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
isOnWifi = Helper.isOnWIFI(context);
positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
@ -133,90 +118,78 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
lv_status.setAdapter(statusListAdapter);
mLayoutManager = new LinearLayoutManager(context);
lv_status.setLayoutManager(mLayoutManager);
if( !comesFromSearch){
//Hide account header when scrolling for ShowAccountActivity
if (hideHeader)
ViewCompat.setNestedScrollingEnabled(lv_status, true);
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
if(dy > 0){
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if(!flag_loading ) {
flag_loading = true;
if( type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, 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() {
@Override
public void onRefresh() {
max_id = null;
statuses = new ArrayList<>();
knownId = new ArrayList<>();
firstLoad = true;
flag_loading = true;
swiped = true;
MainActivity.countNewStatus = 0;
if( type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, 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);
}
});
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
R.color.mastodonC3);
if( context != null) {
if (type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, 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);
}
}else {
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
if( context != null){
if (type == RetrieveFeedsAsyncTask.Type.USER)
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
if(dy > 0){
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if(firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
if(!flag_loading ) {
flag_loading = true;
if( type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if (type == RetrieveFeedsAsyncTask.Type.TAG)
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else {
else
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
}
}, 500);
}
}
});
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
max_id = null;
statuses = new ArrayList<>();
firstLoad = true;
flag_loading = true;
swiped = true;
MainActivity.countNewStatus = 0;
if( type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, 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);
}
});
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
R.color.mastodonC2,
R.color.mastodonC3);
if( context != null) {
if (type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, 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);
}
}else {
statusListAdapter.notifyDataSetChanged();
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( statuses == null || statuses.size() == 0 )
textviewNoAction.setVisibility(View.VISIBLE);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
if( context != null){
if (type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, 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);
}
}
}
}, 500);
}
return rootView;
@ -277,7 +250,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if( statuses != null && statuses.size() > 0) {
for(Status tmpStatus: statuses){
if( !knownId.contains(tmpStatus.getId())) {
if( this.statuses.size() == 0 || Long.parseLong(tmpStatus.getId()) < Long.parseLong(this.statuses.get(this.statuses.size()-1).getId())) {
if( type == RetrieveFeedsAsyncTask.Type.HOME && firstLoad && lastReadStatus != null && Long.parseLong(tmpStatus.getId()) > Long.parseLong(lastReadStatus)){
tmpStatus.setNew(true);
MainActivity.countNewStatus++;
@ -285,7 +258,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
tmpStatus.setNew(false);
}
this.statuses.add(tmpStatus);
knownId.add(tmpStatus.getId());
}
}
@ -317,42 +289,41 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
*/
public void refresh(Status status){
//New data are available
if( type == RetrieveFeedsAsyncTask.Type.HOME) {
if (context == null)
return;
if (status != null && !knownId.contains(status.getId())) {
if (context == null)
return;
if( status.getId() != null && statuses.get(0)!= null
&& Long.parseLong(status.getId()) > Long.parseLong(statuses.get(0).getId())) {
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
//Update the id of the last toot retrieved
MainActivity.lastHomeId = status.getId();
status.setReplies(new ArrayList<Status>());
statuses.add(0,status);
knownId.add(0,status.getId());
statuses.add(0, status);
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
if( !status.getAccount().getId().equals(userId))
if (!status.getAccount().getId().equals(userId))
MainActivity.countNewStatus++;
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if( firstVisibleItem > 0)
if (firstVisibleItem > 0)
statusListAdapter.notifyItemInserted(0);
else
statusListAdapter.notifyDataSetChanged();
if (textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
}
}else if(type == RetrieveFeedsAsyncTask.Type.PUBLIC || type == RetrieveFeedsAsyncTask.Type.LOCAL){
if (context == null)
return;
if (status != null && !knownId.contains(status.getId())) {
} else if (type == RetrieveFeedsAsyncTask.Type.PUBLIC || type == RetrieveFeedsAsyncTask.Type.LOCAL) {
status.setReplies(new ArrayList<Status>());
status.setNew(false);
statuses.add(0, status);
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
if( firstVisibleItem > 0)
if (firstVisibleItem > 0)
statusListAdapter.notifyItemInserted(0);
else
statusListAdapter.notifyDataSetChanged();
knownId.add(0, status.getId());
if (textviewNoAction.getVisibility() == View.VISIBLE)
textviewNoAction.setVisibility(View.GONE);
}
}
}
@ -506,10 +477,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if( statuses != null && statuses.size() > 0) {
int inserted = 0;
for (int i = statuses.size() - 1; i >= 0; i--) {
if (!knownId.contains(statuses.get(i).getId())) {
if (this.statuses.size() == 0 ||
Long.parseLong(statuses.get(i).getId()) > Long.parseLong(this.statuses.get(0).getId())) {
if (type == RetrieveFeedsAsyncTask.Type.HOME)
statuses.get(i).setNew(true);
knownId.add(0,statuses.get(i).getId());
inserted++;
statuses.get(i).setReplies(new ArrayList<Status>());
this.statuses.add(0, statuses.get(i));

View File

@ -1,14 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources tools:ignore="PrivateResource" xmlns:tools="http://schemas.android.com/tools">
<!-- LIGHT -->
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#2196F3</color>
<!-- DARK -->
<color name="colorPrimaryD">#616161</color>
<color name="colorPrimaryDarkD">#212121</color>
<color name="colorAccentD">#4db6ac</color>
<!-- Header Profile-->
<color name="header1">#0288D1</color>