Some improvements
This commit is contained in:
parent
ea8f497902
commit
a632618a66
|
@ -82,7 +82,7 @@ public class ContextActivity extends BaseActivity {
|
||||||
focusedStatus = null; // or other values
|
focusedStatus = null; // or other values
|
||||||
if (b != null)
|
if (b != null)
|
||||||
focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS);
|
focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS);
|
||||||
if (focusedStatus == null && currentAccount == null || currentAccount.mastodon_account == null) {
|
if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) {
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1787,10 +1787,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
holder.timer.cancel();
|
holder.timer.cancel();
|
||||||
holder.timer = null;
|
holder.timer = null;
|
||||||
}
|
}
|
||||||
if (holder.dateTimer != null) {
|
|
||||||
holder.dateTimer.cancel();
|
|
||||||
holder.dateTimer = null;
|
|
||||||
}
|
|
||||||
if (status.emojis != null && status.emojis.size() > 0) {
|
if (status.emojis != null && status.emojis.size() > 0) {
|
||||||
holder.timer = new Timer();
|
holder.timer = new Timer();
|
||||||
holder.timer.scheduleAtFixedRate(new TimerTask() {
|
holder.timer.scheduleAtFixedRate(new TimerTask() {
|
||||||
|
@ -1803,16 +1799,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
}
|
}
|
||||||
}, 100, 100);
|
}, 100, 100);
|
||||||
}
|
}
|
||||||
holder.dateTimer = new Timer();
|
|
||||||
holder.dateTimer.scheduleAtFixedRate(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
||||||
Runnable myRunnable = () -> holder.binding.dateShort.setText(Helper.dateDiff(context, status.created_at));
|
|
||||||
mainHandler.post(myRunnable);
|
|
||||||
|
|
||||||
}
|
|
||||||
}, 100, 10000);
|
|
||||||
} else if (viewHolder.getItemViewType() == STATUS_ART) {
|
} else if (viewHolder.getItemViewType() == STATUS_ART) {
|
||||||
StatusViewHolder holder = (StatusViewHolder) viewHolder;
|
StatusViewHolder holder = (StatusViewHolder) viewHolder;
|
||||||
MastodonHelper.loadPPMastodon(holder.bindingArt.artPp, status.account);
|
MastodonHelper.loadPPMastodon(holder.bindingArt.artPp, status.account);
|
||||||
|
@ -1881,9 +1867,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
if (holder instanceof StatusViewHolder && ((StatusViewHolder) holder).timer != null) {
|
if (holder instanceof StatusViewHolder && ((StatusViewHolder) holder).timer != null) {
|
||||||
((StatusViewHolder) holder).timer.cancel();
|
((StatusViewHolder) holder).timer.cancel();
|
||||||
}
|
}
|
||||||
if (holder instanceof StatusViewHolder && ((StatusViewHolder) holder).dateTimer != null) {
|
|
||||||
((StatusViewHolder) holder).dateTimer.cancel();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface FetchMoreCallBack {
|
public interface FetchMoreCallBack {
|
||||||
|
@ -1900,7 +1883,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
DrawerStatusNotificationBinding bindingNotification;
|
DrawerStatusNotificationBinding bindingNotification;
|
||||||
DrawerStatusArtBinding bindingArt;
|
DrawerStatusArtBinding bindingArt;
|
||||||
Timer timer;
|
Timer timer;
|
||||||
Timer dateTimer;
|
|
||||||
|
|
||||||
StatusViewHolder(DrawerStatusBinding itemView) {
|
StatusViewHolder(DrawerStatusBinding itemView) {
|
||||||
super(itemView.getRoot());
|
super(itemView.getRoot());
|
||||||
|
|
|
@ -456,25 +456,28 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
|
||||||
}
|
}
|
||||||
int position = 0;
|
int position = 0;
|
||||||
//We loop through messages already in the timeline
|
//We loop through messages already in the timeline
|
||||||
for (Notification notificationsAlreadyPresent : this.notificationList) {
|
if (this.notificationList != null) {
|
||||||
//We compare the date of each status and we only add status having a date greater than the another, it is inserted at this position
|
notificationAdapter.notifyItemRangeChanged(0, this.notificationList.size());
|
||||||
//Pinned messages are ignored because their date can be older
|
for (Notification notificationsAlreadyPresent : this.notificationList) {
|
||||||
if (notificationReceived.id.compareTo(notificationsAlreadyPresent.id) > 0) {
|
//We compare the date of each status and we only add status having a date greater than the another, it is inserted at this position
|
||||||
|
//Pinned messages are ignored because their date can be older
|
||||||
|
if (notificationReceived.id.compareTo(notificationsAlreadyPresent.id) > 0) {
|
||||||
|
//We add the status to a list of id - thus we know it is already in the timeline
|
||||||
|
idOfAddedNotifications.add(notificationReceived.id);
|
||||||
|
this.notificationList.add(position, notificationReceived);
|
||||||
|
notificationAdapter.notifyItemInserted(position);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
//Statuses added at the bottom, we flag them by position = -2 for not dealing with them and fetch more
|
||||||
|
if (position == this.notificationList.size()) {
|
||||||
//We add the status to a list of id - thus we know it is already in the timeline
|
//We add the status to a list of id - thus we know it is already in the timeline
|
||||||
idOfAddedNotifications.add(notificationReceived.id);
|
idOfAddedNotifications.add(notificationReceived.id);
|
||||||
this.notificationList.add(position, notificationReceived);
|
this.notificationList.add(position, notificationReceived);
|
||||||
notificationAdapter.notifyItemInserted(position);
|
notificationAdapter.notifyItemInserted(position);
|
||||||
break;
|
return NOTIFICATION__AT_THE_BOTTOM;
|
||||||
}
|
}
|
||||||
position++;
|
|
||||||
}
|
|
||||||
//Statuses added at the bottom, we flag them by position = -2 for not dealing with them and fetch more
|
|
||||||
if (position == this.notificationList.size()) {
|
|
||||||
//We add the status to a list of id - thus we know it is already in the timeline
|
|
||||||
idOfAddedNotifications.add(notificationReceived.id);
|
|
||||||
this.notificationList.add(position, notificationReceived);
|
|
||||||
notificationAdapter.notifyItemInserted(position);
|
|
||||||
return NOTIFICATION__AT_THE_BOTTOM;
|
|
||||||
}
|
}
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
|
@ -499,27 +499,31 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
return STATUS_PRESENT;
|
return STATUS_PRESENT;
|
||||||
}
|
}
|
||||||
int position = 0;
|
int position = 0;
|
||||||
//We loop through messages already in the timeline
|
if (this.statuses != null) {
|
||||||
for (Status statusAlreadyPresent : this.statuses) {
|
statusAdapter.notifyItemRangeChanged(0, this.statuses.size());
|
||||||
//We compare the date of each status and we only add status having a date greater than the another, it is inserted at this position
|
//We loop through messages already in the timeline
|
||||||
//Pinned messages are ignored because their date can be older
|
for (Status statusAlreadyPresent : this.statuses) {
|
||||||
if (statusReceived.id.compareTo(statusAlreadyPresent.id) > 0 && !statusAlreadyPresent.pinned) {
|
//We compare the date of each status and we only add status having a date greater than the another, it is inserted at this position
|
||||||
|
//Pinned messages are ignored because their date can be older
|
||||||
|
if (statusReceived.id.compareTo(statusAlreadyPresent.id) > 0 && !statusAlreadyPresent.pinned) {
|
||||||
|
//We add the status to a list of id - thus we know it is already in the timeline
|
||||||
|
idOfAddedStatuses.add(statusReceived.id);
|
||||||
|
this.statuses.add(position, statusReceived);
|
||||||
|
statusAdapter.notifyItemInserted(position);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
//Statuses added at the bottom, we flag them by position = -2 for not dealing with them and fetch more
|
||||||
|
if (position == this.statuses.size()) {
|
||||||
//We add the status to a list of id - thus we know it is already in the timeline
|
//We add the status to a list of id - thus we know it is already in the timeline
|
||||||
idOfAddedStatuses.add(statusReceived.id);
|
idOfAddedStatuses.add(statusReceived.id);
|
||||||
this.statuses.add(position, statusReceived);
|
this.statuses.add(position, statusReceived);
|
||||||
statusAdapter.notifyItemInserted(position);
|
statusAdapter.notifyItemInserted(position);
|
||||||
break;
|
return STATUS_AT_THE_BOTTOM;
|
||||||
}
|
}
|
||||||
position++;
|
|
||||||
}
|
|
||||||
//Statuses added at the bottom, we flag them by position = -2 for not dealing with them and fetch more
|
|
||||||
if (position == this.statuses.size()) {
|
|
||||||
//We add the status to a list of id - thus we know it is already in the timeline
|
|
||||||
idOfAddedStatuses.add(statusReceived.id);
|
|
||||||
this.statuses.add(position, statusReceived);
|
|
||||||
statusAdapter.notifyItemInserted(position);
|
|
||||||
return STATUS_AT_THE_BOTTOM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue