Proper fix for subscription sync retention. Eliminate double sync attempt on startup.

This commit is contained in:
Akinwale Ariwodola 2020-07-22 05:49:48 +01:00
parent b4ce544965
commit 1bb5ce72fa
3 changed files with 20 additions and 20 deletions

View file

@ -306,7 +306,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public static final String SECURE_VALUE_KEY_SAVED_PASSWORD = "io.lbry.browser.PX"; public static final String SECURE_VALUE_KEY_SAVED_PASSWORD = "io.lbry.browser.PX";
public static final String SECURE_VALUE_FIRST_RUN_PASSWORD = "firstRunPassword"; public static final String SECURE_VALUE_FIRST_RUN_PASSWORD = "firstRunPassword";
private static final String TAG = "io.lbry.browser.Main"; private static final String TAG = "LbryMain";
private NavigationMenuAdapter navMenuAdapter; private NavigationMenuAdapter navMenuAdapter;
private UrlSuggestionListAdapter urlSuggestionListAdapter; private UrlSuggestionListAdapter urlSuggestionListAdapter;
@ -1567,7 +1567,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
findViewById(R.id.global_sdk_initializing_status).setVisibility(View.GONE); findViewById(R.id.global_sdk_initializing_status).setVisibility(View.GONE);
syncWalletAndLoadPreferences();
scheduleWalletBalanceUpdate(); scheduleWalletBalanceUpdate();
scheduleWalletSyncTask(); scheduleWalletSyncTask();
fetchOwnChannels(); fetchOwnChannels();
@ -1751,7 +1750,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public void run() { public void run() {
syncWalletAndLoadPreferences(); syncWalletAndLoadPreferences();
} }
}, 0, 5, TimeUnit.MINUTES); }, 0, 2, TimeUnit.MINUTES);
walletSyncScheduled = true; walletSyncScheduled = true;
} }
} }
@ -1785,7 +1784,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
//openNavFragments.get //openNavFragments.get
MergeSubscriptionsTask mergeTask = new MergeSubscriptionsTask( MergeSubscriptionsTask mergeTask = new MergeSubscriptionsTask(
subscriptions, subscriptions,
!initialSubscriptionMergeDone(), initialSubscriptionMergeDone(),
MainActivity.this, new MergeSubscriptionsTask.MergeSubscriptionsHandler() { MainActivity.this, new MergeSubscriptionsTask.MergeSubscriptionsHandler() {
@Override @Override
public void onSuccess(List<Subscription> subscriptions, List<Subscription> diff) { public void onSuccess(List<Subscription> subscriptions, List<Subscription> diff) {
@ -1800,7 +1799,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
for (Fragment fragment : openNavFragments.values()) { for (Fragment fragment : openNavFragments.values()) {
if (fragment instanceof FollowingFragment) { if (fragment instanceof FollowingFragment) {
// reload local subscriptions // reload local subscriptions
((FollowingFragment) fragment).fetchLoadedSubscriptions(true); Lbryio.cacheResolvedSubscriptions.clear();
FollowingFragment followingFragment = (FollowingFragment) fragment;
followingFragment.fetchLoadedSubscriptions(true);
} }
} }
} }
@ -1938,7 +1939,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public void onSyncGetSuccess(WalletSync walletSync) { public void onSyncGetSuccess(WalletSync walletSync) {
Lbryio.lastWalletSync = walletSync; Lbryio.lastWalletSync = walletSync;
Lbryio.lastRemoteHash = walletSync.getHash(); Lbryio.lastRemoteHash = walletSync.getHash();
loadSharedUserState();
} }
@Override @Override

View file

@ -60,8 +60,7 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
for (Subscription sub : base) { for (Subscription sub : base) {
DatabaseHelper.createOrUpdateSubscription(sub, db); DatabaseHelper.createOrUpdateSubscription(sub, db);
} }
} } else {
localSubs = DatabaseHelper.getSubscriptions(db); localSubs = DatabaseHelper.getSubscriptions(db);
for (Subscription sub : localSubs) { for (Subscription sub : localSubs) {
if (!combined.contains(sub)) { if (!combined.contains(sub)) {
@ -69,6 +68,7 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
} }
} }
} }
}
// fetch remote subscriptions // fetch remote subscriptions
JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("subscription", "list", context)); JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("subscription", "list", context));
@ -113,7 +113,6 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
diff.add(local); diff.add(local);
} }
} }
}
for (int i = 0; i < finalRemoteSubs.size(); i++) { for (int i = 0; i < finalRemoteSubs.size(); i++) {
Subscription remote = finalRemoteSubs.get(i); Subscription remote = finalRemoteSubs.get(i);
if (!combined.contains(remote)) { if (!combined.contains(remote)) {
@ -123,6 +122,7 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
} }
} }
} }
}
} catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException | IllegalStateException | SQLiteException ex) { } catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException | IllegalStateException | SQLiteException ex) {
error = ex; error = ex;
return null; return null;

View file

@ -107,7 +107,7 @@ public class SyncGetTask extends AsyncTask<Void, Void, WalletSync> {
if (applySyncChanges) { if (applySyncChanges) {
if (applySyncSuccessful) { if (applySyncSuccessful) {
handler.onSyncApplySuccess(syncHash, syncData); handler.onSyncApplySuccess(syncHash, syncData);
} else { } else if (syncApplyError != null) {
handler.onSyncApplyError(syncApplyError); handler.onSyncApplyError(syncApplyError);
} }
} }