From 02f9f8c8ea1cc2a7afac3c5aec4ac6a66a9b2a51 Mon Sep 17 00:00:00 2001 From: sk Date: Wed, 31 May 2023 12:23:04 +0200 Subject: [PATCH] always update active account, but not others --- .../joinmastodon/android/MainActivity.java | 16 +++++---- .../api/session/AccountSessionManager.java | 34 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java index bbef4dd47..2affe7dea 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java @@ -35,15 +35,18 @@ public class MainActivity extends FragmentStackActivity{ if(AccountSessionManager.getInstance().getLoggedInAccounts().isEmpty()){ showFragmentClearingBackStack(new CustomWelcomeFragment()); }else{ - AccountSessionManager.getInstance().maybeUpdateLocalInfo(); AccountSession session; Bundle args=new Bundle(); Intent intent=getIntent(); if(intent.hasExtra("fromExternalShare")) { - AccountSessionManager.getInstance().setLastActiveAccountID(intent.getStringExtra("account")); + AccountSessionManager.getInstance() + .setLastActiveAccountID(intent.getStringExtra("account")); + AccountSessionManager.getInstance().maybeUpdateLocalInfo( + AccountSessionManager.getInstance().getLastActiveAccount()); showFragmentForExternalShare(intent.getExtras()); return; } + boolean fromNotification = intent.getBooleanExtra("fromNotification", false); boolean hasNotification = intent.hasExtra("notification"); if(fromNotification){ @@ -57,6 +60,7 @@ public class MainActivity extends FragmentStackActivity{ }else{ session=AccountSessionManager.getInstance().getLastActiveAccount(); } + AccountSessionManager.getInstance().maybeUpdateLocalInfo(session); args.putString("account", session.getID()); Fragment fragment=session.activated ? new HomeFragment() : new AccountActivationFragment(); fragment.setArguments(args); @@ -80,12 +84,12 @@ public class MainActivity extends FragmentStackActivity{ @Override protected void onNewIntent(Intent intent){ super.onNewIntent(intent); - if(intent.hasExtra("fromExternalShare")) showFragmentForExternalShare(intent.getExtras()); - else if(intent.getBooleanExtra("fromNotification", false)){ + AccountSessionManager.getInstance().maybeUpdateLocalInfo(); + if (intent.hasExtra("fromExternalShare")) showFragmentForExternalShare(intent.getExtras()); + else if (intent.getBooleanExtra("fromNotification", false)) { String accountID=intent.getStringExtra("accountID"); - AccountSession accountSession; try{ - accountSession=AccountSessionManager.getInstance().getAccount(accountID); + AccountSessionManager.getInstance().getAccount(accountID); }catch(IllegalStateException x){ return; } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java index ea91d13fc..3b68ac36e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java @@ -258,31 +258,35 @@ public class AccountSessionManager{ } public void maybeUpdateLocalInfo(){ + maybeUpdateLocalInfo(null); + } + + public void maybeUpdateLocalInfo(AccountSession activeSession){ long now=System.currentTimeMillis(); HashSet domains=new HashSet<>(); for(AccountSession session:sessions.values()){ domains.add(session.domain.toLowerCase()); -// if(now-session.infoLastUpdated>24L*3600_000L){ - updateSessionPreferences(session); - updateSessionLocalInfo(session); -// } -// if(now-session.filtersLastUpdated>3600_000L){ - updateSessionWordFilters(session); -// } + if(now-session.infoLastUpdated>24L*3600_000L || session == activeSession){ + updateSessionPreferences(session); + updateSessionLocalInfo(session); + } + if(now-session.filtersLastUpdated>3600_000L || session == activeSession){ + updateSessionWordFilters(session); + } updateSessionMarkers(session); } if(loadedInstances){ - maybeUpdateCustomEmojis(domains); + maybeUpdateCustomEmojis(domains, activeSession != null ? activeSession.domain : null); } } - private void maybeUpdateCustomEmojis(Set domains){ -// long now=System.currentTimeMillis(); + private void maybeUpdateCustomEmojis(Set domains, String activeDomain){ + long now=System.currentTimeMillis(); for(String domain:domains){ -// Long lastUpdated=instancesLastUpdated.get(domain); -// if(lastUpdated==null || now-lastUpdated>24L*3600_000L){ - updateInstanceInfo(domain); -// } + Long lastUpdated=instancesLastUpdated.get(domain); + if(lastUpdated==null || now-lastUpdated>24L*3600_000L || domain.equals(activeDomain)){ + updateInstanceInfo(domain); + } } } @@ -449,7 +453,7 @@ public class AccountSessionManager{ } if(!loadedInstances){ loadedInstances=true; - maybeUpdateCustomEmojis(domains); + maybeUpdateCustomEmojis(domains, null); } }