mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-08 15:47:43 +00:00
remove unused "account"
This commit is contained in:
parent
900dfa1b9c
commit
27a2300631
10 changed files with 37 additions and 79 deletions
|
@ -4,8 +4,6 @@ package helium314.keyboard.latin;
|
|||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.inputmethod.latin.BinaryDictionary;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -35,7 +33,7 @@ public class AppsBinaryDictionary extends ExpandableBinaryDictionary {
|
|||
}
|
||||
|
||||
public static AppsBinaryDictionary getDictionary(final Context context, final Locale locale,
|
||||
final File dictFile, final String dictNamePrefix, @Nullable final String account) {
|
||||
final File dictFile, final String dictNamePrefix) {
|
||||
return new AppsBinaryDictionary(context, locale, dictFile, dictNamePrefix + NAME);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import android.provider.ContactsContract.Contacts;
|
|||
import helium314.keyboard.latin.utils.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.inputmethod.latin.BinaryDictionary;
|
||||
|
||||
|
@ -51,7 +50,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary
|
|||
}
|
||||
|
||||
public static ContactsBinaryDictionary getDictionary(final Context context, @NonNull final Locale locale,
|
||||
final File dictFile, final String dictNamePrefix, @Nullable final String account) {
|
||||
final File dictFile, final String dictNamePrefix) {
|
||||
return new ContactsBinaryDictionary(context, locale, dictFile, dictNamePrefix + NAME);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
/**
|
||||
* Interface that facilitates interaction with different kinds of dictionaries. Provides APIs to
|
||||
* instantiate and select the correct dictionaries (based on language or account), update entries
|
||||
* instantiate and select the correct dictionaries (based on language and settings), update entries
|
||||
* and fetch suggestions. Currently AndroidSpellCheckerService and LatinIME both use
|
||||
* DictionaryFacilitator as a client for interacting with dictionaries.
|
||||
*/
|
||||
|
@ -90,12 +90,9 @@ public interface DictionaryFacilitator {
|
|||
@NonNull final List<Locale> locales,
|
||||
final boolean contacts,
|
||||
final boolean apps,
|
||||
final boolean personalization,
|
||||
@Nullable final String account
|
||||
final boolean personalization
|
||||
);
|
||||
|
||||
String getAccount();
|
||||
|
||||
void resetDictionaries(
|
||||
final Context context,
|
||||
final Locale newLocale,
|
||||
|
@ -103,7 +100,6 @@ public interface DictionaryFacilitator {
|
|||
final boolean useAppsDict,
|
||||
final boolean usePersonalizedDicts,
|
||||
final boolean forceReloadMainDictionary,
|
||||
@Nullable final String account,
|
||||
final String dictNamePrefix,
|
||||
@Nullable final DictionaryInitializationListener listener);
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ import kotlin.concurrent.Volatile
|
|||
|
||||
/**
|
||||
* Facilitates interaction with different kinds of dictionaries. Provides APIs
|
||||
* to instantiate and select the correct dictionaries (based on language or account),
|
||||
* to instantiate and select the correct dictionaries (based on language and settings),
|
||||
* update entries and fetch suggestions.
|
||||
*
|
||||
*
|
||||
|
@ -110,18 +110,11 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
return currentlyPreferredDictionaryGroup.locale
|
||||
}
|
||||
|
||||
override fun getAccount(): String? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun usesSameSettings(
|
||||
locales: List<Locale>, contacts: Boolean, apps: Boolean, personalization: Boolean, account: String?
|
||||
): Boolean {
|
||||
override fun usesSameSettings(locales: List<Locale>, contacts: Boolean, apps: Boolean, personalization: Boolean): Boolean {
|
||||
val dictGroup = dictionaryGroups[0] // settings are the same for all groups
|
||||
return contacts == dictGroup.hasDict(Dictionary.TYPE_CONTACTS, account)
|
||||
&& apps == dictGroup.hasDict(Dictionary.TYPE_APPS, account)
|
||||
&& personalization == dictGroup.hasDict(Dictionary.TYPE_USER_HISTORY, account)
|
||||
&& account == dictGroup.account
|
||||
return contacts == dictGroup.hasDict(Dictionary.TYPE_CONTACTS)
|
||||
&& apps == dictGroup.hasDict(Dictionary.TYPE_APPS)
|
||||
&& personalization == dictGroup.hasDict(Dictionary.TYPE_USER_HISTORY)
|
||||
&& locales.size == dictionaryGroups.size
|
||||
&& locales.none { findDictionaryGroupWithLocale(dictionaryGroups, it) == null }
|
||||
}
|
||||
|
@ -135,7 +128,6 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
useAppsDict: Boolean,
|
||||
usePersonalizedDicts: Boolean,
|
||||
forceReloadMainDictionary: Boolean,
|
||||
account: String?,
|
||||
dictNamePrefix: String,
|
||||
listener: DictionaryInitializationListener?
|
||||
) {
|
||||
|
@ -191,7 +183,7 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
val existingDictsToCleanup = HashMap<Locale, MutableList<String>>()
|
||||
for (dictGroup in dictionaryGroups) {
|
||||
existingDictsToCleanup[dictGroup.locale] = DictionaryFacilitator.ALL_DICTIONARY_TYPES
|
||||
.filterTo(mutableListOf()) { dictGroup.hasDict(it, account) }
|
||||
.filterTo(mutableListOf()) { dictGroup.hasDict(it) }
|
||||
}
|
||||
|
||||
// create new dictionary groups and remove dictionaries to re-use from existingDictsToCleanup
|
||||
|
@ -204,7 +196,7 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
// create new or re-use already loaded main dict
|
||||
val mainDict: Dictionary?
|
||||
if (forceReload || oldDictGroupForLocale == null
|
||||
|| !oldDictGroupForLocale.hasDict(Dictionary.TYPE_MAIN, account)
|
||||
|| !oldDictGroupForLocale.hasDict(Dictionary.TYPE_MAIN)
|
||||
) {
|
||||
mainDict = null // null main dicts will be loaded later in asyncReloadUninitializedMainDictionaries
|
||||
} else {
|
||||
|
@ -217,10 +209,10 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
for (subDictType in newSubDictTypes) {
|
||||
val subDict: ExpandableBinaryDictionary
|
||||
if (forceReload || oldDictGroupForLocale == null
|
||||
|| !oldDictGroupForLocale.hasDict(subDictType, account)
|
||||
|| !oldDictGroupForLocale.hasDict(subDictType)
|
||||
) {
|
||||
// Create a new dictionary.
|
||||
subDict = getSubDict(subDictType, context, locale, null, dictNamePrefix, account) ?: continue
|
||||
subDict = getSubDict(subDictType, context, locale, null, dictNamePrefix) ?: continue
|
||||
} else {
|
||||
// Reuse the existing dictionary.
|
||||
subDict = oldDictGroupForLocale.getSubDict(subDictType) ?: continue
|
||||
|
@ -228,7 +220,7 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
}
|
||||
subDicts[subDictType] = subDict
|
||||
}
|
||||
val newDictGroup = DictionaryGroup(locale, mainDict, account, subDicts, context)
|
||||
val newDictGroup = DictionaryGroup(locale, mainDict, subDicts, context)
|
||||
newDictionaryGroups.add(newDictGroup)
|
||||
}
|
||||
return newDictionaryGroups to existingDictsToCleanup
|
||||
|
@ -305,7 +297,7 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
val sv = Settings.getValues()
|
||||
if (sv.mAddToPersonalDictionary // require the opt-in
|
||||
&& sv.mAutoCorrectEnabled == sv.mAutoCorrectionEnabledPerUserSettings // don't add if user wants autocorrect but input field does not, see https://github.com/Helium314/HeliBoard/issues/427#issuecomment-1905438000
|
||||
&& dictionaryGroups[0].hasDict(Dictionary.TYPE_USER_HISTORY, dictionaryGroups[0].account) // require personalized suggestions
|
||||
&& dictionaryGroups[0].hasDict(Dictionary.TYPE_USER_HISTORY) // require personalized suggestions
|
||||
&& !wasAutoCapitalized // we can't be 100% sure about what the user intended to type, so better don't add it
|
||||
&& words.size == 1 // only single words
|
||||
) {
|
||||
|
@ -602,15 +594,15 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
// HACK: This threshold is being used when adding a capitalized entry in the User History dictionary.
|
||||
private const val CAPITALIZED_FORM_MAX_PROBABILITY_FOR_INSERT = 140
|
||||
|
||||
private fun getSubDict(dictType: String, context: Context, locale: Locale, dictFile: File?,
|
||||
dictNamePrefix: String, account: String?
|
||||
private fun getSubDict(
|
||||
dictType: String, context: Context, locale: Locale, dictFile: File?, dictNamePrefix: String
|
||||
): ExpandableBinaryDictionary? {
|
||||
try {
|
||||
return when (dictType) {
|
||||
Dictionary.TYPE_USER_HISTORY -> UserHistoryDictionary.getDictionary(context, locale, dictFile, dictNamePrefix, account)
|
||||
Dictionary.TYPE_USER -> UserBinaryDictionary.getDictionary(context, locale, dictFile, dictNamePrefix, account)
|
||||
Dictionary.TYPE_CONTACTS -> ContactsBinaryDictionary.getDictionary(context, locale, dictFile, dictNamePrefix, account)
|
||||
Dictionary.TYPE_APPS -> AppsBinaryDictionary.getDictionary(context, locale, dictFile, dictNamePrefix, account)
|
||||
Dictionary.TYPE_USER_HISTORY -> UserHistoryDictionary.getDictionary(context, locale, dictFile, dictNamePrefix)
|
||||
Dictionary.TYPE_USER -> UserBinaryDictionary.getDictionary(context, locale, dictFile, dictNamePrefix)
|
||||
Dictionary.TYPE_CONTACTS -> ContactsBinaryDictionary.getDictionary(context, locale, dictFile, dictNamePrefix)
|
||||
Dictionary.TYPE_APPS -> AppsBinaryDictionary.getDictionary(context, locale, dictFile, dictNamePrefix)
|
||||
else -> throw IllegalArgumentException("unknown dictionary type $dictType")
|
||||
}
|
||||
} catch (e: SecurityException) {
|
||||
|
@ -649,7 +641,6 @@ class DictionaryFacilitatorImpl : DictionaryFacilitator {
|
|||
private class DictionaryGroup(
|
||||
val locale: Locale = Locale(""),
|
||||
private var mainDict: Dictionary? = null,
|
||||
val account: String? = null, // todo: not used, simply remove
|
||||
subDicts: Map<String, ExpandableBinaryDictionary> = emptyMap(),
|
||||
context: Context? = null
|
||||
) {
|
||||
|
@ -798,16 +789,10 @@ private class DictionaryGroup(
|
|||
return subDicts[dictType]
|
||||
}
|
||||
|
||||
fun hasDict(dictType: String, forAccount: String?): Boolean {
|
||||
fun hasDict(dictType: String): Boolean {
|
||||
if (dictType == Dictionary.TYPE_MAIN) {
|
||||
return mainDict != null
|
||||
}
|
||||
if (dictType == Dictionary.TYPE_USER_HISTORY && forAccount != account) {
|
||||
// If the dictionary type is user history, & if the account doesn't match,
|
||||
// return immediately. If the account matches, continue looking it up in the
|
||||
// sub dictionary map.
|
||||
return false
|
||||
}
|
||||
return subDicts.containsKey(dictType)
|
||||
}
|
||||
|
||||
|
|
|
@ -59,10 +59,8 @@ public class DictionaryFacilitatorLruCache {
|
|||
// Nothing to do if the locale is null. This would be the case before any get() calls.
|
||||
if (mLocale != null) {
|
||||
// Note: Given that personalized dictionaries are not used here; we can pass null account.
|
||||
mDictionaryFacilitator.resetDictionaries(mContext, mLocale,
|
||||
mUseContactsDictionary, mUseAppsDictionary, false /* usePersonalizedDicts */,
|
||||
false /* forceReloadMainDictionary */, null /* account */,
|
||||
mDictionaryNamePrefix, null /* listener */);
|
||||
mDictionaryFacilitator.resetDictionaries(mContext, mLocale, mUseContactsDictionary,
|
||||
mUseAppsDictionary, false, false, mDictionaryNamePrefix, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -738,8 +738,7 @@ public class LatinIME extends InputMethodService implements
|
|||
locales,
|
||||
mSettings.getCurrent().mUseContactsDictionary,
|
||||
mSettings.getCurrent().mUseAppsDictionary,
|
||||
mSettings.getCurrent().mUsePersonalizedDicts,
|
||||
mSettings.getCurrent().mAccount
|
||||
mSettings.getCurrent().mUsePersonalizedDicts
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
@ -757,7 +756,7 @@ public class LatinIME extends InputMethodService implements
|
|||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
mDictionaryFacilitator.resetDictionaries(this, locale,
|
||||
settingsValues.mUseContactsDictionary, settingsValues.mUseAppsDictionary,
|
||||
settingsValues.mUsePersonalizedDicts, false, settingsValues.mAccount, "", this);
|
||||
settingsValues.mUsePersonalizedDicts, false, "", this);
|
||||
mInputLogic.mSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold);
|
||||
}
|
||||
|
||||
|
@ -766,12 +765,9 @@ public class LatinIME extends InputMethodService implements
|
|||
*/
|
||||
/* package private */ void resetSuggestMainDict() {
|
||||
final SettingsValues settingsValues = mSettings.getCurrent();
|
||||
mDictionaryFacilitator.resetDictionaries(this /* context */,
|
||||
mDictionaryFacilitator.getMainLocale(), settingsValues.mUseContactsDictionary,
|
||||
settingsValues.mUseAppsDictionary, settingsValues.mUsePersonalizedDicts,
|
||||
true /* forceReloadMainDictionary */,
|
||||
settingsValues.mAccount, "" /* dictNamePrefix */,
|
||||
this /* DictionaryInitializationListener */);
|
||||
mDictionaryFacilitator.resetDictionaries(this, mDictionaryFacilitator.getMainLocale(),
|
||||
settingsValues.mUseContactsDictionary, settingsValues.mUseAppsDictionary,
|
||||
settingsValues.mUsePersonalizedDicts, true, "", this);
|
||||
}
|
||||
|
||||
// used for debug
|
||||
|
|
|
@ -82,8 +82,7 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
|
|||
}
|
||||
|
||||
public static UserBinaryDictionary getDictionary(
|
||||
final Context context, final Locale locale, final File dictFile,
|
||||
final String dictNamePrefix, @Nullable final String account) {
|
||||
final Context context, final Locale locale, final File dictFile, final String dictNamePrefix) {
|
||||
return new UserBinaryDictionary(context, locale, false, dictFile, dictNamePrefix + NAME);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.content.Context;
|
|||
import helium314.keyboard.latin.utils.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import helium314.keyboard.latin.common.FileUtils;
|
||||
|
||||
|
@ -31,12 +30,8 @@ public class PersonalizationHelper {
|
|||
sLangUserHistoryDictCache = new ConcurrentHashMap<>();
|
||||
|
||||
@NonNull
|
||||
public static UserHistoryDictionary getUserHistoryDictionary(
|
||||
final Context context, final Locale locale, @Nullable final String accountName) {
|
||||
public static UserHistoryDictionary getUserHistoryDictionary(final Context context, final Locale locale) {
|
||||
String lookupStr = locale.toString();
|
||||
if (accountName != null) {
|
||||
lookupStr += "." + accountName;
|
||||
}
|
||||
synchronized (sLangUserHistoryDictCache) {
|
||||
if (sLangUserHistoryDictCache.containsKey(lookupStr)) {
|
||||
final SoftReference<UserHistoryDictionary> ref =
|
||||
|
@ -50,8 +45,7 @@ public class PersonalizationHelper {
|
|||
return dict;
|
||||
}
|
||||
}
|
||||
final UserHistoryDictionary dict = new UserHistoryDictionary(
|
||||
context, locale, accountName);
|
||||
final UserHistoryDictionary dict = new UserHistoryDictionary(context, locale);
|
||||
sLangUserHistoryDictCache.put(lookupStr, new SoftReference<>(dict));
|
||||
return dict;
|
||||
}
|
||||
|
|
|
@ -30,9 +30,8 @@ public class UserHistoryDictionary extends ExpandableBinaryDictionary {
|
|||
static final String NAME = UserHistoryDictionary.class.getSimpleName();
|
||||
|
||||
// TODO: Make this constructor private
|
||||
UserHistoryDictionary(final Context context, final Locale locale,
|
||||
@Nullable final String account) {
|
||||
super(context, getUserHistoryDictName(NAME, locale, null /* dictFile */, account), locale, Dictionary.TYPE_USER_HISTORY, null);
|
||||
UserHistoryDictionary(final Context context, final Locale locale) {
|
||||
super(context, getUserHistoryDictName(NAME, locale, null), locale, Dictionary.TYPE_USER_HISTORY, null);
|
||||
if (mLocale != null && mLocale.toString().length() > 1) {
|
||||
reloadDictionaryIfRequired();
|
||||
}
|
||||
|
@ -41,14 +40,13 @@ public class UserHistoryDictionary extends ExpandableBinaryDictionary {
|
|||
/**
|
||||
* @returns the name of the {@link UserHistoryDictionary}.
|
||||
*/
|
||||
static String getUserHistoryDictName(final String name, final Locale locale,
|
||||
@Nullable final File dictFile, @Nullable final String account) {
|
||||
static String getUserHistoryDictName(final String name, final Locale locale, @Nullable final File dictFile) {
|
||||
return getDictName(name, locale, dictFile);
|
||||
}
|
||||
|
||||
public static UserHistoryDictionary getDictionary(final Context context, final Locale locale,
|
||||
final File dictFile, final String dictNamePrefix, @Nullable final String account) {
|
||||
return PersonalizationHelper.getUserHistoryDictionary(context, locale, account);
|
||||
final File dictFile, final String dictNamePrefix) {
|
||||
return PersonalizationHelper.getUserHistoryDictionary(context, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,6 @@ import android.view.inputmethod.EditorInfo;
|
|||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.util.TypedValueCompat;
|
||||
|
||||
import helium314.keyboard.compat.ConfigurationCompatKt;
|
||||
|
@ -150,9 +149,6 @@ public class SettingsValues {
|
|||
// User-defined colors
|
||||
public final Colors mColors;
|
||||
|
||||
@Nullable
|
||||
public final String mAccount; // todo: always null, remove?
|
||||
|
||||
// creation of Colors and SpacingAndPunctuations are the slowest parts in here, but still ok
|
||||
public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
|
||||
@NonNull final InputAttributes inputAttributes) {
|
||||
|
@ -228,7 +224,6 @@ public class SettingsValues {
|
|||
mGestureFloatingPreviewDynamicEnabled = Settings.readGestureDynamicPreviewEnabled(prefs);
|
||||
mGestureFastTypingCooldown = prefs.getInt(Settings.PREF_GESTURE_FAST_TYPING_COOLDOWN, Defaults.PREF_GESTURE_FAST_TYPING_COOLDOWN);
|
||||
mGestureTrailFadeoutDuration = prefs.getInt(Settings.PREF_GESTURE_TRAIL_FADEOUT_DURATION, Defaults.PREF_GESTURE_TRAIL_FADEOUT_DURATION);
|
||||
mAccount = null; // remove? or can it be useful somewhere?
|
||||
mOverrideShowingSuggestions = mInputAttributes.mMayOverrideShowingSuggestions
|
||||
&& prefs.getBoolean(Settings.PREF_ALWAYS_SHOW_SUGGESTIONS, Defaults.PREF_ALWAYS_SHOW_SUGGESTIONS)
|
||||
&& ((inputAttributes.mInputType & InputType.TYPE_MASK_VARIATION) != InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue