diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.java b/app/src/main/java/com/hippo/ehviewer/Settings.java index 4c60dfa5d..8c0a52e63 100644 --- a/app/src/main/java/com/hippo/ehviewer/Settings.java +++ b/app/src/main/java/com/hippo/ehviewer/Settings.java @@ -56,6 +56,7 @@ public class Settings { EhConfig ehConfig= new EhConfig(); ehConfig.excludedLanguages = getExcludedLanguages(); ehConfig.defaultCategories = getDefaultCategories(); + ehConfig.excludedNamespaces = getExcludedTagNamespaces(); ehConfig.setDirty(); return ehConfig; } @@ -227,6 +228,19 @@ public class Settings { putInt(KEY_DEFAULT_CATEGORIES, value); } + public static final String KEY_EXCLUDED_TAG_NAMESPACES = "excluded_tag_namespaces"; + private static final int DEFAULT_EXCLUDED_TAG_NAMESPACES = 0; + + public static int getExcludedTagNamespaces() { + return getInt(KEY_EXCLUDED_TAG_NAMESPACES, DEFAULT_EXCLUDED_TAG_NAMESPACES); + } + + public static void putExcludedTagNamespaces(int value) { + sEhConfig.excludedNamespaces = value; + sEhConfig.setDirty(); + putInt(KEY_EXCLUDED_TAG_NAMESPACES, value); + } + public static final String KEY_EXCLUDED_LANGUAGES = "excluded_languages"; private static final String DEFAULT_EXCLUDED_LANGUAGES = null; diff --git a/app/src/main/java/com/hippo/ehviewer/preference/ExcludedTagNamespacesPreference.java b/app/src/main/java/com/hippo/ehviewer/preference/ExcludedTagNamespacesPreference.java new file mode 100644 index 000000000..43142bbbe --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/preference/ExcludedTagNamespacesPreference.java @@ -0,0 +1,120 @@ +/* + * Copyright 2016 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.preference; + +import android.content.Context; +import android.support.v7.app.AlertDialog; +import android.util.AttributeSet; +import android.view.View; +import android.widget.CheckBox; + +import com.hippo.ehviewer.R; +import com.hippo.ehviewer.Settings; +import com.hippo.preference.DialogPreference; +import com.hippo.yorozuya.NumberUtils; +import com.hippo.yorozuya.ViewUtils; + +public class ExcludedTagNamespacesPreference extends DialogPreference { + + private View mTableLayout; + + private static final int[] EXCLUDED_TAG_GROUP_RES_ID = { + R.id.tag_group_reclass, + R.id.tag_group_language, + R.id.tag_group_parody, + R.id.tag_group_character, + R.id.tag_group_group, + R.id.tag_group_artist, + R.id.tag_group_male, + R.id.tag_group_female, + }; + + private static final int[] EXCLUDED_TAG_GROUP_ID = { + 0x1, + 0x2, + 0x4, + 0x8, + 0x10, + 0x20, + 0x40, + 0x80 + }; + + public ExcludedTagNamespacesPreference(Context context) { + super(context); + init(); + } + + public ExcludedTagNamespacesPreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public ExcludedTagNamespacesPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + public ExcludedTagNamespacesPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(); + } + + private void init() { + setDialogLayoutResource(R.layout.preference_dialog_excluded_tag_namespaces); + } + + @Override + protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { + super.onPrepareDialogBuilder(builder); + builder.setPositiveButton(android.R.string.ok, this); + } + + @Override + protected void onDialogCreated(AlertDialog dialog) { + super.onDialogCreated(dialog); + mTableLayout = ViewUtils.$$(dialog, R.id.table_layout); + setExcludedTagNamespaces(mTableLayout, Settings.getExcludedTagNamespaces()); + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + super.onDialogClosed(positiveResult); + if (null != mTableLayout && positiveResult) { + Settings.putExcludedTagNamespaces(getExcludedTagNamespaces(mTableLayout)); + } + mTableLayout = null; + } + + private void setExcludedTagNamespaces(View view, int value) { + for (int i = 0; i < EXCLUDED_TAG_GROUP_RES_ID.length; i++) { + CheckBox cb = (CheckBox) view.findViewById(EXCLUDED_TAG_GROUP_RES_ID[i]); + cb.setChecked(NumberUtils.int2boolean(value & EXCLUDED_TAG_GROUP_ID[i])); + } + } + + private int getExcludedTagNamespaces(View view) { + int newValue = 0; + for (int i = 0; i < EXCLUDED_TAG_GROUP_RES_ID.length; i++) { + CheckBox cb = (CheckBox) view.findViewById(EXCLUDED_TAG_GROUP_RES_ID[i]); + if (cb.isChecked()) { + newValue |= EXCLUDED_TAG_GROUP_ID[i]; + } + } + return newValue; + } +} diff --git a/app/src/main/res/layout/preference_dialog_excluded_tag_namespaces.xml b/app/src/main/res/layout/preference_dialog_excluded_tag_namespaces.xml new file mode 100644 index 000000000..af1191434 --- /dev/null +++ b/app/src/main/res/layout/preference_dialog_excluded_tag_namespaces.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index f562ad16f..a710142e6 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -286,6 +286,8 @@ 缩略图 主页分类显示 默认在主页所显示的分类 + 排除标签组 + 在默认搜索中排除指定标签组 排除语言 在主页与搜索中隐藏指定语言的画廊 显示日文标题 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 8e264fb6e..da49db1a9 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -284,6 +284,10 @@ 列表模式 詳情 縮略圖 + 主頁分類顯示 + 默認在主頁所顯示的分類 + 排除標籤組 + 在默認搜索中排除指定標籤組 排除語言 在主頁與搜索中隱藏指定語言的畫廊 顯示日文標題 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 61346c911..5794e694a 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -284,6 +284,10 @@ 列表模式 詳情 縮圖 + 主頁分類顯示 + 預設在主頁所顯示的分類 + 排除標籤組 + 在預設搜尋中排除指定標籤組 排除語言 在主頁與搜尋中隱藏指定語言的畫廊 顯示日文標題 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 791a83f6d..4000d1f09 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -327,6 +327,8 @@ The categories shown as default on Homepage Excluded languages Hide galleries in certain languages from the gallery list and searches + Excluded tag namespaces + Exclude certain namespaces from a default tag search Show Japanese title Try to show Japanese title. It takes more time to get gallery list Show default title. It is usually English title diff --git a/app/src/main/res/xml/eh_settings.xml b/app/src/main/res/xml/eh_settings.xml index 89db88da9..4fe1e5a0e 100644 --- a/app/src/main/res/xml/eh_settings.xml +++ b/app/src/main/res/xml/eh_settings.xml @@ -32,6 +32,11 @@ android:title="@string/settings_eh_default_categories" android:summary="@string/settings_eh_default_categories_summary"/> + +