Sort newly added notifications. Add remote loading TTL.
This commit is contained in:
parent
d21cfd55ab
commit
7205acb9d6
3 changed files with 31 additions and 9 deletions
|
@ -205,8 +205,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
private static final String CHANNEL_ID_PLAYBACK = "io.lbry.browser.LBRY_PLAYBACK_CHANNEL";
|
||||
private static final int PLAYBACK_NOTIFICATION_ID = 3;
|
||||
private static final String SPECIAL_URL_PREFIX = "lbry://?";
|
||||
private static final int REMOTE_NOTIFICATION_REFRESH_TTL = 300000; // 5 minutes
|
||||
public static final String SKU_SKIP = "lbryskip";
|
||||
|
||||
private Date remoteNotifcationsLastLoaded;
|
||||
private Map<String, Class> specialRouteFragmentClassMap;
|
||||
@Getter
|
||||
private boolean inPictureInPictureMode;
|
||||
|
@ -2192,9 +2194,12 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
clearWunderbarFocus(findViewById(R.id.wunderbar));
|
||||
findViewById(R.id.notifications_container).setVisibility(View.VISIBLE);
|
||||
((ImageView) findViewById(R.id.notifications_toggle_icon)).setColorFilter(ContextCompat.getColor(this, R.color.lbryGreen));
|
||||
if (notificationListAdapter == null || notificationListAdapter.getItemCount() == 0) {
|
||||
if (remoteNotifcationsLastLoaded == null ||
|
||||
(System.currentTimeMillis() - remoteNotifcationsLastLoaded.getTime() > REMOTE_NOTIFICATION_REFRESH_TTL)) {
|
||||
loadRemoteNotifications(true);
|
||||
} else {
|
||||
}
|
||||
|
||||
if (notificationListAdapter != null) {
|
||||
markNotificationsRead();
|
||||
}
|
||||
}
|
||||
|
@ -3249,6 +3254,8 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
NotificationListTask task = new NotificationListTask(this, findViewById(R.id.notifications_progress), new NotificationListTask.ListNotificationsHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<LbryNotification> notifications) {
|
||||
remoteNotifcationsLastLoaded = new Date();
|
||||
|
||||
loadLocalNotifications();
|
||||
loadUnreadNotificationsCount();
|
||||
if (markRead && findViewById(R.id.notifications_container).getVisibility() == View.VISIBLE) {
|
||||
|
@ -3289,6 +3296,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
|
||||
if (notificationListAdapter == null) {
|
||||
notificationListAdapter = new NotificationListAdapter(notifications, MainActivity.this);
|
||||
((RecyclerView) findViewById(R.id.notifications_list)).setAdapter(notificationListAdapter);
|
||||
} else {
|
||||
notificationListAdapter.addNotifications(notifications);
|
||||
}
|
||||
|
@ -3322,8 +3330,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
hideNotifications();
|
||||
}
|
||||
});
|
||||
|
||||
((RecyclerView) findViewById(R.id.notifications_list)).setAdapter(notificationListAdapter);
|
||||
}
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.bumptech.glide.Glide;
|
|||
import com.bumptech.glide.request.RequestOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.R;
|
||||
|
@ -23,9 +24,13 @@ import io.lbry.browser.model.Claim;
|
|||
import io.lbry.browser.model.lbryinc.LbryNotification;
|
||||
import io.lbry.browser.ui.controls.SolidIconView;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
public class NotificationListAdapter extends RecyclerView.Adapter<NotificationListAdapter.ViewHolder> {
|
||||
|
||||
private static final String RULE_CREATOR_SUBSCRIBER = "creator_subscriber";
|
||||
|
@ -44,10 +49,6 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
this.items = new ArrayList<>(notifications);
|
||||
}
|
||||
|
||||
public List<LbryNotification> getItems() {
|
||||
return new ArrayList<>(items);
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
protected View layoutView;
|
||||
protected TextView titleView;
|
||||
|
@ -117,8 +118,10 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
items.add(notification);
|
||||
}
|
||||
}
|
||||
Collections.sort(items, Collections.reverseOrder(new LbryNotification()));
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotificationListAdapter.ViewHolder onCreateViewHolder(ViewGroup root, int viewType) {
|
||||
View v = LayoutInflater.from(context).inflate(R.layout.list_item_notification, root, false);
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package io.lbry.browser.model.lbryinc;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
|
||||
import io.lbry.browser.model.Claim;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LbryNotification {
|
||||
public class LbryNotification implements Comparator<LbryNotification> {
|
||||
private long id;
|
||||
private long remoteId;
|
||||
private String title;
|
||||
|
@ -21,4 +22,16 @@ public class LbryNotification {
|
|||
// only for comment notifications
|
||||
private String authorUrl;
|
||||
private Claim commentAuthor;
|
||||
|
||||
public int compare(LbryNotification a, LbryNotification b) {
|
||||
long t1 = a.getTimestamp() != null ? a.getTimestamp().getTime() : 0;
|
||||
long t2 = b.getTimestamp() != null ? b.getTimestamp().getTime() : 0;
|
||||
if (t2 > t1) {
|
||||
return 1;
|
||||
}
|
||||
if (t1 > t2) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue