Some cleaning
This commit is contained in:
parent
db49b42608
commit
57691321c0
|
@ -31,22 +31,13 @@ import android.widget.RelativeLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
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 {
|
public class DisplayNotificationsFragment extends Fragment implements OnRetrieveNotificationsInterface, OnRetrieveMissingNotificationsInterface {
|
||||||
|
|
||||||
|
|
||||||
LinearLayoutManager mLayoutManager;
|
private LinearLayoutManager mLayoutManager;
|
||||||
Type type;
|
private Type type;
|
||||||
private boolean flag_loading;
|
private boolean flag_loading;
|
||||||
private Context context;
|
private Context context;
|
||||||
private AsyncTask<Void, Void, Void> asyncTask;
|
private AsyncTask<Void, Void, Void> asyncTask;
|
||||||
|
@ -137,7 +128,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
mLayoutManager = new LinearLayoutManager(context);
|
mLayoutManager = new LinearLayoutManager(context);
|
||||||
lv_notifications.setLayoutManager(mLayoutManager);
|
lv_notifications.setLayoutManager(mLayoutManager);
|
||||||
lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
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) {
|
if (dy > 0) {
|
||||||
int visibleItemCount = mLayoutManager.getChildCount();
|
int visibleItemCount = mLayoutManager.getChildCount();
|
||||||
int totalItemCount = mLayoutManager.getItemCount();
|
int totalItemCount = mLayoutManager.getItemCount();
|
||||||
|
@ -191,35 +182,28 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
swipeRefreshLayout.setOnRefreshListener(() -> {
|
||||||
@Override
|
flag_loading = true;
|
||||||
public void onRefresh() {
|
swiped = true;
|
||||||
flag_loading = true;
|
if (type == Type.ALL) {
|
||||||
swiped = true;
|
countNewNotifications = 0;
|
||||||
if (type == Type.ALL) {
|
try {
|
||||||
countNewNotifications = 0;
|
((MainActivity) context).updateNotifCounter();
|
||||||
try {
|
} catch (Exception ignored) {
|
||||||
((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)
|
if (context != null)
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, type, true, null, max_id, DisplayNotificationsFragment.this).execute();
|
asyncTask = new RetrieveNotificationsAsyncTask(context, type, true, null, max_id, DisplayNotificationsFragment.this).execute();
|
||||||
else
|
else
|
||||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
@Override
|
if (context != null)
|
||||||
public void run() {
|
asyncTask = new RetrieveNotificationsAsyncTask(context, type, true, null, max_id, DisplayNotificationsFragment.this).execute();
|
||||||
if (context != null)
|
|
||||||
asyncTask = new RetrieveNotificationsAsyncTask(context, type, true, null, max_id, DisplayNotificationsFragment.this).execute();
|
|
||||||
}
|
|
||||||
}, 500);
|
}, 500);
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
@ -305,9 +289,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
textviewNoAction.setVisibility(View.GONE);
|
textviewNoAction.setVisibility(View.GONE);
|
||||||
if (swiped) {
|
if (swiped) {
|
||||||
if (previousPosition > 0) {
|
if (previousPosition > 0) {
|
||||||
for (int i = 0; i < previousPosition; i++) {
|
this.notifications.subList(0, previousPosition).clear();
|
||||||
this.notifications.remove(0);
|
|
||||||
}
|
|
||||||
notificationsListAdapter.notifyItemRangeRemoved(0, previousPosition);
|
notificationsListAdapter.notifyItemRangeRemoved(0, previousPosition);
|
||||||
}
|
}
|
||||||
swiped = false;
|
swiped = false;
|
||||||
|
@ -388,7 +370,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshAll() {
|
void refreshAll() {
|
||||||
if (context == null)
|
if (context == null)
|
||||||
return;
|
return;
|
||||||
max_id = null;
|
max_id = null;
|
||||||
|
@ -498,6 +480,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
if (type == Type.ALL) {
|
if (type == Type.ALL) {
|
||||||
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
|
||||||
countNewNotifications = 0;
|
countNewNotifications = 0;
|
||||||
|
assert lastNotif != null;
|
||||||
if (this.notifications != null && this.notifications.size() > 0 && this.notifications.get(0).getId().compareTo(lastNotif) > 0) {
|
if (this.notifications != null && this.notifications.size() > 0 && this.notifications.get(0).getId().compareTo(lastNotif) > 0) {
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, this.notifications.get(0).getId());
|
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, this.notifications.get(0).getId());
|
||||||
|
|
Loading…
Reference in New Issue