Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea406a6f authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

fix:3040: MR feedback, improve code style.

parent a3f9a101
Loading
Loading
Loading
Loading
Loading
+20 −23
Original line number Original line Diff line number Diff line
@@ -792,41 +792,38 @@ public class NotesRepository {
     * @return true if sync is possible, otherwise false.
     * @return true if sync is possible, otherwise false.
     */
     */
    public boolean isSyncPossible() {
    public boolean isSyncPossible() {
        if (isSyncPossible) {
        if (!isSyncPossible) {
            final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
            return false;
        }

        final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
        Instant lastSync = Instant.ofEpochMilli(sharedPreferences.getLong(PREF_KEY_LAST_SYNC_ATTEMPT, 0L));
        Instant lastSync = Instant.ofEpochMilli(sharedPreferences.getLong(PREF_KEY_LAST_SYNC_ATTEMPT, 0L));
            long waitBeforeNextAttemps = sharedPreferences.getLong(PREF_KEY_WAIT_BEFORE_NEXT_SYNC, 0L);
        long waitBeforeNextAttemp = sharedPreferences.getLong(PREF_KEY_WAIT_BEFORE_NEXT_SYNC, 0L);
            boolean cooldownTimeElapsed = lastSync.plus(waitBeforeNextAttemps, ChronoUnit.MILLIS).isBefore(Instant.now());
        boolean cooldownTimeElapsed = lastSync.plus(waitBeforeNextAttemp, ChronoUnit.MILLIS).isBefore(Instant.now());
        if (!cooldownTimeElapsed) {
        if (!cooldownTimeElapsed) {
                Log.i(TAG, "Sync NOT possible, previous ServiceWasDown error was less than " + waitBeforeNextAttemps + " ms ago.");
            Log.i(TAG, "Sync NOT possible, previous ServiceWasDown error was less than " + waitBeforeNextAttemp + " ms ago.");
        }
        }
        return cooldownTimeElapsed;
        return cooldownTimeElapsed;
        } else {
            return false;
        }
    }
    }


    public void serviceWasDown(boolean down) {
    public void serviceWasDown(boolean down) {
        final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
        long now = Instant.now().toEpochMilli();
        long now = Instant.now().toEpochMilli();
        long waitBeforeNextAttempt = sharedPreferences.getLong(PREF_KEY_WAIT_BEFORE_NEXT_SYNC, 0L);
        long waitBeforeNextAttempt = sharedPreferences.getLong(PREF_KEY_WAIT_BEFORE_NEXT_SYNC, 0L);

        if (down) {
        if (down) {
            if (waitBeforeNextAttempt < MIN_DELAY_AFTER_FAILED_SYNCHRONIZATION) {
            waitBeforeNextAttempt = Math.min(
                waitBeforeNextAttempt = MIN_DELAY_AFTER_FAILED_SYNCHRONIZATION;
                    Math.max(waitBeforeNextAttempt * 2, MIN_DELAY_AFTER_FAILED_SYNCHRONIZATION),
            } else {
                    MAX_DELAY_BETWEEN_SYNCHRONIZATIONS
                waitBeforeNextAttempt = 2 * waitBeforeNextAttempt;
            );
                if (waitBeforeNextAttempt > MAX_DELAY_BETWEEN_SYNCHRONIZATIONS) {
                    waitBeforeNextAttempt = MAX_DELAY_BETWEEN_SYNCHRONIZATIONS;
                }
            }
        } else {
        } else {
            waitBeforeNextAttempt = 0L;
            waitBeforeNextAttempt = 0L;
        }
        }


        SharedPreferences.Editor editor = sharedPreferences.edit();
        sharedPreferences.edit()
        editor.putLong(PREF_KEY_LAST_SYNC_ATTEMPT, now);
                .putLong(PREF_KEY_LAST_SYNC_ATTEMPT, now)
        editor.putLong(PREF_KEY_WAIT_BEFORE_NEXT_SYNC, waitBeforeNextAttempt);
                .putLong(PREF_KEY_WAIT_BEFORE_NEXT_SYNC, waitBeforeNextAttempt)
        editor.commit();
                .apply();
    }
    }


    public boolean isNetworkConnected() {
    public boolean isNetworkConnected() {