Compare commits

...

5 Commits

Author SHA1 Message Date
sk
0216e22fcc don't remove badge if loaded from cache 2023-03-21 15:25:01 +01:00
sk
5734b19d8c remove unused variable 2023-03-21 15:14:25 +01:00
sk
e58aeec097 query notifications on load posts
closes sk22#471
2023-03-21 10:22:09 +01:00
sk
58b000927a session-specific notification badge
fix sk22#470
2023-03-21 10:03:31 +01:00
sk
797642b972 fix profile fragment crash
closes sk22#469
2023-03-21 09:56:44 +01:00
9 changed files with 26 additions and 17 deletions

View File

@@ -86,7 +86,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
}
String accountID=account.getID();
PushNotification pn=AccountSessionManager.getInstance().getAccount(accountID).getPushSubscriptionManager().decryptNotification(k, p, s);
E.post(new NotificationReceivedEvent(pn.notificationId+""));
E.post(new NotificationReceivedEvent(accountID, pn.notificationId+""));
new GetNotificationByID(pn.notificationId+"")
.setCallback(new Callback<>(){
@Override

View File

@@ -128,7 +128,7 @@ public class CacheController{
});
}
public void getNotifications(String maxID, int count, boolean onlyMentions, boolean onlyPosts, boolean forceReload, Callback<PaginatedResponse<List<Notification>>> callback){
public void getNotifications(String maxID, int count, boolean onlyMentions, boolean onlyPosts, boolean forceReload, Callback<CacheablePaginatedResponse<List<Notification>>> callback){
cancelDelayedClose();
databaseThread.postRunnable(()->{
try{
@@ -156,7 +156,7 @@ public class CacheController{
result.add(ntf);
}while(cursor.moveToNext());
String _newMaxID=newMaxID;
uiHandler.post(()->callback.onSuccess(new PaginatedResponse<>(result, _newMaxID)));
uiHandler.post(()->callback.onSuccess(new CacheablePaginatedResponse<>(result, _newMaxID, true)));
return;
}
}catch(IOException x){
@@ -168,7 +168,7 @@ public class CacheController{
.setCallback(new Callback<>(){
@Override
public void onSuccess(List<Notification> result){
callback.onSuccess(new PaginatedResponse<>(result.stream().filter(ntf->{
callback.onSuccess(new CacheablePaginatedResponse<>(result.stream().filter(ntf->{
if(ntf.status!=null){
for(Filter filter:filters){
if(filter.matches(ntf.status)){
@@ -177,7 +177,7 @@ public class CacheController{
}
}
return true;
}).collect(Collectors.toList()), result.isEmpty() ? null : result.get(result.size()-1).id));
}).collect(Collectors.toList()), result.isEmpty() ? null : result.get(result.size()-1).id, false));
putNotifications(result, onlyMentions, onlyPosts, maxID==null);
}

View File

@@ -1,8 +1,9 @@
package org.joinmastodon.android.events;
public class NotificationReceivedEvent {
public String id;
public NotificationReceivedEvent(String id) {
public String account, id;
public NotificationReceivedEvent(String account, String id) {
this.account = account;
this.id = id;
}
}

View File

@@ -298,9 +298,6 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
try {
long newestId = Long.parseLong(notifications.get(0).id);
long lastSeenId = Long.parseLong(session.markers.notifications.lastReadId);
System.out.println("NEWEST: " + newestId);
System.out.println("LAST SEEN: " + lastSeenId);
setNotificationBadge(newestId > lastSeenId);
} catch (Exception ignored) {
setNotificationBadge(false);
@@ -323,7 +320,7 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
@Subscribe
public void onNotificationReceived(NotificationReceivedEvent notificationReceivedEvent) {
setNotificationBadge(true);
if (notificationReceivedEvent.account.equals(accountID)) setNotificationBadge(true);
}
@Subscribe

View File

@@ -166,6 +166,10 @@ public class HomeTimelineFragment extends StatusListFragment {
}
})
.exec(accountID);
if (parent.getParentFragment() instanceof HomeFragment homeFragment) {
homeFragment.updateNotificationBadge();
}
}
@Override

View File

@@ -15,6 +15,7 @@ import org.joinmastodon.android.events.AllNotificationsSeenEvent;
import org.joinmastodon.android.events.PollUpdatedEvent;
import org.joinmastodon.android.events.RemoveAccountPostsEvent;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.CacheablePaginatedResponse;
import org.joinmastodon.android.model.Filter;
import org.joinmastodon.android.model.Notification;
import org.joinmastodon.android.model.PaginatedResponse;
@@ -128,7 +129,7 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
.getAccount(accountID).getCacheController()
.getNotifications(offset>0 ? maxID : null, count, onlyMentions, onlyPosts, refreshing, new SimpleCallback<>(this){
@Override
public void onSuccess(PaginatedResponse<List<Notification>> result){
public void onSuccess(CacheablePaginatedResponse<List<Notification>> result){
if (getActivity() == null) return;
if(refreshing)
relationships.clear();
@@ -140,7 +141,7 @@ public class NotificationsListFragment extends BaseStatusListFragment<Notificati
loadRelationships(needRelationships);
maxID=result.maxID;
if(offset==0 && !result.items.isEmpty()){
if(offset==0 && !result.items.isEmpty() && !result.isFromCache()){
E.post(new AllNotificationsSeenEvent());
new SaveMarkers(null, result.items.get(0).id).exec(accountID);
AccountSessionManager.getInstance().getAccount(accountID).markers

View File

@@ -439,6 +439,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
toolbarTitleView.setTranslationY(titleTransY);
toolbarSubtitleView.setTranslationY(titleTransY);
}
RecyclerFragment.setRefreshLayoutColors(refreshLayout);
}
@Override

View File

@@ -4,6 +4,8 @@ import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.joinmastodon.android.R;
import org.joinmastodon.android.ui.utils.UiUtils;
@@ -25,7 +27,10 @@ public abstract class RecyclerFragment<T> extends BaseRecyclerFragment<T> {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Context ctx = getContext();
if (refreshLayout != null) setRefreshLayoutColors(refreshLayout);
}
public static void setRefreshLayoutColors(SwipeRefreshLayout l) {
List<Integer> colors = new ArrayList<>(Arrays.asList(
R.color.primary_600,
R.color.red_primary_600,
@@ -33,13 +38,13 @@ public abstract class RecyclerFragment<T> extends BaseRecyclerFragment<T> {
R.color.blue_primary_600,
R.color.purple_600
));
int primary = UiUtils.getThemeColorRes(ctx, R.attr.colorPrimary600);
int primary = UiUtils.getThemeColorRes(l.getContext(), R.attr.colorPrimary600);
if (!colors.contains(primary)) colors.add(0, primary);
int offset = colors.indexOf(primary);
int[] sorted = new int[colors.size()];
for (int i = 0; i < colors.size(); i++) {
sorted[i] = colors.get((i + offset) % colors.size());
}
refreshLayout.setColorSchemeResources(sorted);
l.setColorSchemeResources(sorted);
}
}

View File

@@ -32,7 +32,7 @@ import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
import me.grishka.appkit.utils.V;
public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{
private CharSequence text, compactText;
private CharSequence text;
@DrawableRes
private int icon;
private StatusPrivacy visibility;