Better way to handle tag translation flag
This commit is contained in:
1 parent
5242d825c2
commit
2bab97c829
3 files changed
+4
-12
No files matched your search
@@ -24,7 +24,6 @@ import androidx.core.util.Pair;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.HashCodeUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
@@ -63,7 +62,6 @@ public class EhTagDatabase {
|
||||
// TODO more lock for different language
|
||||
private static final Lock lock = new ReentrantLock();
|
||||
private static volatile EhTagDatabase instance;
|
||||
private static boolean translate;
|
||||
|
||||
static {
|
||||
NAMESPACE_TO_PREFIX.put("artist", "a:");
|
||||
@@ -104,7 +102,6 @@ public class EhTagDatabase {
|
||||
} else {
|
||||
tagList = null;
|
||||
}
|
||||
translate = Settings.getShowTagTranslations();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -112,10 +109,6 @@ public class EhTagDatabase {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void setTranslate(boolean value) {
|
||||
translate = value;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String namespaceToPrefix(String namespace) {
|
||||
return NAMESPACE_TO_PREFIX.get(namespace);
|
||||
@@ -298,7 +291,7 @@ public class EhTagDatabase {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Pair<String, String>> suggest(String keyword) {
|
||||
public ArrayList<Pair<String, String>> suggest(String keyword, boolean translate) {
|
||||
ArrayList<Pair<String, String>> searchHints = new ArrayList<>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
var tmp = tagList.get(i);
|
||||
|
||||
@@ -76,9 +76,6 @@ class EhFragment : BasePreferenceFragment() {
|
||||
} else if (Settings.KEY_SHOW_TAG_TRANSLATIONS == key) {
|
||||
if (java.lang.Boolean.TRUE == newValue) {
|
||||
EhTagDatabase.update(requireActivity())
|
||||
EhTagDatabase.setTranslate(true)
|
||||
} else {
|
||||
EhTagDatabase.setTranslate(false)
|
||||
}
|
||||
} else if (Settings.KEY_BLACK_DARK_THEME == key) {
|
||||
if (requireActivity().resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_YES > 0) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.google.android.material.search.SearchView
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import com.hippo.app.BaseDialogBuilder
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhTagDatabase
|
||||
import com.hippo.ehviewer.widget.SearchDatabase
|
||||
import com.hippo.scene.StageActivity
|
||||
@@ -288,7 +289,8 @@ abstract class SearchBarScene : ToolbarScene() {
|
||||
val s = text.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
if (s.isNotEmpty()) {
|
||||
val keyword = s[s.size - 1]
|
||||
val searchHints = ehTagDatabase.suggest(keyword)
|
||||
val translate = Settings.getShowTagTranslations() && EhTagDatabase.isTranslatable(context)
|
||||
val searchHints = ehTagDatabase.suggest(keyword, translate)
|
||||
|
||||
for (searchHint in searchHints) {
|
||||
suggestions.add(TagSuggestion(searchHint.first, searchHint.second))
|
||||
|
||||
Reference in new issue
Block a user