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_FIRST_RUN_PASSWORD = "firstRunPassword";
private static final String TAG = "io.lbry.browser.Main";
private static final String TAG = "LbryMain";
private NavigationMenuAdapter navMenuAdapter;
private UrlSuggestionListAdapter urlSuggestionListAdapter;
@ -1567,7 +1567,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
findViewById(R.id.global_sdk_initializing_status).setVisibility(View.GONE);
syncWalletAndLoadPreferences();
scheduleWalletBalanceUpdate();
scheduleWalletSyncTask();
fetchOwnChannels();
@ -1751,7 +1750,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public void run() {
syncWalletAndLoadPreferences();
}
}, 0, 5, TimeUnit.MINUTES);
}, 0, 2, TimeUnit.MINUTES);
walletSyncScheduled = true;
}
}
@ -1785,7 +1784,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
//openNavFragments.get
MergeSubscriptionsTask mergeTask = new MergeSubscriptionsTask(
subscriptions,
!initialSubscriptionMergeDone(),
initialSubscriptionMergeDone(),
MainActivity.this, new MergeSubscriptionsTask.MergeSubscriptionsHandler() {
@Override
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()) {
if (fragment instanceof FollowingFragment) {
// 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) {
Lbryio.lastWalletSync = walletSync;
Lbryio.lastRemoteHash = walletSync.getHash();
loadSharedUserState();
}
@Override

View file

@ -60,8 +60,7 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
for (Subscription sub : base) {
DatabaseHelper.createOrUpdateSubscription(sub, db);
}
}
} else {
localSubs = DatabaseHelper.getSubscriptions(db);
for (Subscription sub : localSubs) {
if (!combined.contains(sub)) {
@ -69,6 +68,7 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
}
}
}
}
// fetch remote subscriptions
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);
}
}
}
for (int i = 0; i < finalRemoteSubs.size(); i++) {
Subscription remote = finalRemoteSubs.get(i);
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) {
error = ex;
return null;

View file

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