Some cleaning

This commit is contained in:
tom79 2020-03-07 16:53:34 +01:00
parent db49b42608
commit 57691321c0
1 changed files with 22 additions and 39 deletions

View File

@ -31,22 +31,13 @@ import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.ListPreloader;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.util.FixedPreloadSizeProvider;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import app.fedilab.android.R;
@ -78,8 +69,8 @@ import static app.fedilab.android.activities.BaseMainActivity.countNewNotificati
public class DisplayNotificationsFragment extends Fragment implements OnRetrieveNotificationsInterface, OnRetrieveMissingNotificationsInterface {
LinearLayoutManager mLayoutManager;
Type type;
private LinearLayoutManager mLayoutManager;
private Type type;
private boolean flag_loading;
private Context context;
private AsyncTask<Void, Void, Void> asyncTask;
@ -137,7 +128,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
mLayoutManager = new LinearLayoutManager(context);
lv_notifications.setLayoutManager(mLayoutManager);
lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount();
int totalItemCount = mLayoutManager.getItemCount();
@ -191,35 +182,28 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
}
}
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
flag_loading = true;
swiped = true;
if (type == Type.ALL) {
countNewNotifications = 0;
try {
((MainActivity) context).updateNotifCounter();
} catch (Exception ignored) {
}
swipeRefreshLayout.setOnRefreshListener(() -> {
flag_loading = true;
swiped = true;
if (type == Type.ALL) {
countNewNotifications = 0;
try {
((MainActivity) context).updateNotifCounter();
} catch (Exception ignored) {
}
String sinceId = null;
if (notifications != null && notifications.size() > 0)
sinceId = notifications.get(0).getId();
if (context != null)
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, type, sinceId, DisplayNotificationsFragment.this).execute();
}
String sinceId = null;
if (notifications != null && notifications.size() > 0)
sinceId = notifications.get(0).getId();
if (context != null)
asyncTask = new RetrieveMissingNotificationsAsyncTask(context, type, sinceId, DisplayNotificationsFragment.this).execute();
});
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if (context != null)
asyncTask = new RetrieveNotificationsAsyncTask(context, type, true, null, max_id, DisplayNotificationsFragment.this).execute();
else
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
if (context != null)
asyncTask = new RetrieveNotificationsAsyncTask(context, type, true, null, max_id, DisplayNotificationsFragment.this).execute();
}
new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (context != null)
asyncTask = new RetrieveNotificationsAsyncTask(context, type, true, null, max_id, DisplayNotificationsFragment.this).execute();
}, 500);
return rootView;
}
@ -305,9 +289,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
textviewNoAction.setVisibility(View.GONE);
if (swiped) {
if (previousPosition > 0) {
for (int i = 0; i < previousPosition; i++) {
this.notifications.remove(0);
}
this.notifications.subList(0, previousPosition).clear();
notificationsListAdapter.notifyItemRangeRemoved(0, previousPosition);
}
swiped = false;
@ -388,7 +370,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
}
}
public void refreshAll() {
void refreshAll() {
if (context == null)
return;
max_id = null;
@ -498,6 +480,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
if (type == Type.ALL) {
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
countNewNotifications = 0;
assert lastNotif != null;
if (this.notifications != null && this.notifications.size() > 0 && this.notifications.get(0).getId().compareTo(lastNotif) > 0) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, this.notifications.get(0).getId());