Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Adds support for multiple accounts last sync time #2349

Merged
merged 1 commit into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/src/common/shared/org/mozilla/vrbrowser/browser/Accounts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class Accounts constructor(val context: Context) {
Log.d(LOGTAG, "Account syncing has finished")

isSyncing = false

services.accountManager.accountProfile()?.email?.let {
SettingsStore.getInstance(context).setFxALastSync(it, getLastSynced(context))
}

syncListeners.toMutableList().forEach {
Handler(Looper.getMainLooper()).post {
it.onIdle()
Expand Down Expand Up @@ -332,7 +337,10 @@ class Accounts constructor(val context: Context) {
}

fun lastSync(): Long {
return getLastSynced(context)
services.accountManager.accountProfile()?.email?.let {
return SettingsStore.getInstance(context).getFxALastSync(it)
}
return 0
}

fun devicesByCapability(capabilities: List<DeviceCapability>): List<Device> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import android.graphics.Color;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.telemetry.TelemetryHolder;
import org.mozilla.vrbrowser.R;
Expand All @@ -21,6 +23,8 @@
import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -81,6 +85,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean BOOKMARKS_SYNC_DEFAULT = true;
public final static boolean HISTORY_SYNC_DEFAULT = true;
public final static boolean WHATS_NEW_DISPLAYED = false;
public final static long FXA_LAST_SYNC_NEVER = 0;

// Enable telemetry by default (opt-out).
public final static boolean CRASH_REPORTING_DEFAULT = false;
Expand Down Expand Up @@ -647,5 +652,47 @@ public boolean isWhatsNewDisplayed() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_whats_new_displayed), WHATS_NEW_DISPLAYED);
}

public void setFxALastSync(@NonNull String email, long timestamp) {
String json = mPrefs.getString(
mContext.getString(R.string.settings_key_fxa_last_sync),
new JSONObject().toString());

try {
JSONObject jsonObject = new JSONObject(json);
jsonObject.put(email, timestamp);

SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(mContext.getString(R.string.settings_key_fxa_last_sync), jsonObject.toString());
editor.commit();

} catch (Exception e) {
Log.d(LOGTAG, e.getMessage());
}
}

public long getFxALastSync(@NonNull String email) {
String json = mPrefs.getString(
mContext.getString(R.string.settings_key_fxa_last_sync),
null);

try {
JSONObject jsonObject = new JSONObject(json);
Iterator<String> iterator = jsonObject.keys();
while (iterator.hasNext()) {
String key = iterator.next();
if (key.equals(email)) {
return jsonObject.getLong(key);
}
}

return FXA_LAST_SYNC_NEVER;

} catch (Exception e) {
return FXA_LAST_SYNC_NEVER;
}


}

}

Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public void onAuthenticated(@NotNull OAuthAccount oAuthAccount, @NotNull AuthTyp

@Override
public void onProfileUpdated(@NotNull Profile profile) {
post(() -> mBinding.accountEmail.setText(profile.getEmail()));
mBinding.accountEmail.setText(profile.getEmail());
mBinding.setLastSync(mAccounts.lastSync());
}

@Override
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<string name="settings_key_history_sync" translatable="false">settings_key_history_sync</string>
<string name="settings_key_whats_new_displayed" translatable="false">settings_key_whats_new_displayed</string>
<string name="settings_key_ui_hardware_acceleration" translatable="false">settings_key_ui_hardware_acceleration</string>
<string name="settings_key_fxa_last_sync" translatable="false">settings_key_fxa_last_sync</string>
<string name="environment_override_help_url" translatable="false">https://github.com/MozillaReality/FirefoxReality/wiki/Environments</string>
<string name="private_policy_url" translatable="false">https://www.mozilla.org/privacy/firefox/</string>
<string name="private_report_url" translatable="false">https://mixedreality.mozilla.org/fxr/report?src=browser-fxr&amp;label=browser-firefox-reality&amp;url=%1$s</string>
Expand Down