From bc4ae6bdc0249f9282efea5d1fe7ccfefd6f93b0 Mon Sep 17 00:00:00 2001 From: Jatin Matani Date: Mon, 24 Nov 2014 13:48:16 -0800 Subject: Passing account info to dictionaryFacilitator Attempt to use dictionary facilitor without invoking preference manager. Instead use account from settings only when things are being reset/changed. Discussion forked from ag/591663 Overall, the idea here is to maintain an account information inside dictionary groups. Reset the dictionary groups if account changes (the way we do for locale). Since only user history dictionary is currently affected, the check to reset user history dictionary also includes the check to verify the account. For other things remain the same. SettingsValues holds the current account (and is updated if prefs change due to change in account settings). The updated settings are then propagated to dictionary facilitator via LatinIME#loadSettings. Bug:18104749,18469539 Change-Id: I553e776e7ea125d0fb7a1fe70a4c7eb0b2277fb8 --- .../personalization/UserHistoryDictionary.java | 32 +++++++--------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java') diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java index 946835cbc..2e41027a4 100644 --- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java @@ -37,20 +37,18 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; /** - * Locally gathers stats about the words user types and various other signals like auto-correction - * cancellation or manual picks. This allows the keyboard to adapt to the typist over time. + * Locally gathers statistics about the words user types and various other signals like + * auto-correction cancellation or manual picks. This allows the keyboard to adapt to the + * typist over time. */ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase { static final String NAME = UserHistoryDictionary.class.getSimpleName(); // TODO: Make this constructor private - UserHistoryDictionary(final Context context, final Locale locale) { + UserHistoryDictionary(final Context context, final Locale locale, + @Nullable final String account) { super(context, - getUserHistoryDictName( - NAME, - locale, - null /* dictFile */, - context), + getUserHistoryDictName(NAME, locale, null /* dictFile */, account), locale, Dictionary.TYPE_USER_HISTORY, null /* dictFile */); @@ -61,24 +59,21 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas */ @UsedForTesting static String getUserHistoryDictName(final String name, final Locale locale, - @Nullable final File dictFile, final Context context) { + @Nullable final File dictFile, @Nullable final String account) { if (!ProductionFlags.ENABLE_PER_ACCOUNT_USER_HISTORY_DICTIONARY) { return getDictName(name, locale, dictFile); } - return getUserHistoryDictNamePerAccount(name, locale, dictFile, context); + return getUserHistoryDictNamePerAccount(name, locale, dictFile, account); } /** * Uses the currently signed in account to determine the dictionary name. */ private static String getUserHistoryDictNamePerAccount(final String name, final Locale locale, - @Nullable final File dictFile, final Context context) { + @Nullable final File dictFile, @Nullable final String account) { if (dictFile != null) { return dictFile.getName(); } - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - final String account = prefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, - null /* default */); String dictName = name + "." + locale.toString(); if (account != null) { dictName += "." + account; @@ -90,14 +85,7 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas @SuppressWarnings("unused") @ExternallyReferenced public static UserHistoryDictionary getDictionary(final Context context, final Locale locale, - final File dictFile, final String dictNamePrefix) { - final String account; - if (ProductionFlags.ENABLE_PER_ACCOUNT_USER_HISTORY_DICTIONARY) { - account = PreferenceManager.getDefaultSharedPreferences(context) - .getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null /* default */); - } else { - account = null; - } + final File dictFile, final String dictNamePrefix, @Nullable final String account) { return PersonalizationHelper.getUserHistoryDictionary(context, locale, account); } -- cgit v1.2.3-83-g751a