From 1191140858cf3f57fbacf9b0e78c9220919d7b64 Mon Sep 17 00:00:00 2001 From: Dr-TSNG Date: Mon, 7 Jun 2021 17:26:41 +0800 Subject: [PATCH] feat: complete maps rules UI --- app/build.gradle | 4 +-- .../com/tsng/hidemyapplist/MainActivity.kt | 6 ++-- .../ui/TemplateSettingsActivity.kt | 36 +++++++++++++++++++ .../main/res/layout/activity_detection.xml | 2 +- .../res/layout/alert_customize_maps_rules.xml | 33 +++++++++++++++++ app/src/main/res/values-zh-rCN/strings.xml | 1 + .../res/values-zh-rCN/strings_detection.xml | 1 - .../res/values-zh-rCN/strings_template.xml | 8 +++-- app/src/main/res/values-zh-rTW/strings.xml | 1 + .../res/values-zh-rTW/strings_detection.xml | 3 +- .../res/values-zh-rTW/strings_template.xml | 8 +++-- app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/strings_detection.xml | 1 - app/src/main/res/values/strings_template.xml | 8 +++-- app/src/main/res/xml/template_preferences.xml | 6 ++-- updates/beta-en.html | 15 +++----- updates/beta-zh.html | 16 +++------ updates/latest_version.json | 6 +++- 18 files changed, 113 insertions(+), 43 deletions(-) create mode 100644 app/src/main/res/layout/alert_customize_maps_rules.xml diff --git a/app/build.gradle b/app/build.gradle index 005c3d34..ccd79c6b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "com.tsng.hidemyapplist" minSdkVersion 24 targetSdkVersion 30 - versionCode 44 - versionName "1.7.-0.8 Prebuild" + versionCode 45 + versionName "1.7 Beta" buildConfigField "int", "SERVICE_VERSION", "43" buildConfigField "int", "MIN_RIRU_VERSION", "15" } diff --git a/app/src/main/java/com/tsng/hidemyapplist/MainActivity.kt b/app/src/main/java/com/tsng/hidemyapplist/MainActivity.kt index 31664a04..bc1efa9c 100644 --- a/app/src/main/java/com/tsng/hidemyapplist/MainActivity.kt +++ b/app/src/main/java/com/tsng/hidemyapplist/MainActivity.kt @@ -111,16 +111,16 @@ class MainActivity : AppCompatActivity(), View.OnClickListener { try { val client = OkHttpClient() val responseData = client.newCall(Request.Builder() - .url("https://cdn.jsdelivr.net/gh/Dr-TSNG/Hide-My-Applist@master/updates/latest_version.json") + .url("https://cdn.jsdelivr.net/gh/Dr-TSNG/Hide-My-Applist@updates/updates/latest_version.json") .build()).execute().body?.string() if (responseData != null) { val json = JSONObject(responseData) var data = json["Stable"] as JSONObject - var updateLogURL = "https://cdn.jsdelivr.net/gh/Dr-TSNG/Hide-My-Applist@master/updates/stable-" + var updateLogURL = "https://cdn.jsdelivr.net/gh/Dr-TSNG/Hide-My-Applist@updates/updates/stable-" if (getSharedPreferences("Settings", MODE_PRIVATE).getBoolean("ReceiveBetaUpdate", false)) if (json["Beta"] != false) { data = json["Beta"] as JSONObject - updateLogURL = "https://cdn.jsdelivr.net/gh/Dr-TSNG/Hide-My-Applist@master/updates/beta-" + updateLogURL = "https://cdn.jsdelivr.net/gh/Dr-TSNG/Hide-My-Applist@updates/updates/beta-" } updateLogURL += if (Locale.getDefault().language.contains("zh")) "zh" else "en" updateLogURL += ".html" diff --git a/app/src/main/java/com/tsng/hidemyapplist/ui/TemplateSettingsActivity.kt b/app/src/main/java/com/tsng/hidemyapplist/ui/TemplateSettingsActivity.kt index 600b9796..557c0596 100644 --- a/app/src/main/java/com/tsng/hidemyapplist/ui/TemplateSettingsActivity.kt +++ b/app/src/main/java/com/tsng/hidemyapplist/ui/TemplateSettingsActivity.kt @@ -6,12 +6,15 @@ import android.os.Bundle import android.view.Menu import android.view.MenuInflater import android.view.MenuItem +import android.view.View +import android.widget.* import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.preference.CheckBoxPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.iterator +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.tsng.hidemyapplist.R import kotlinx.android.synthetic.main.appselect.* import kotlinx.android.synthetic.main.toolbar.* @@ -59,6 +62,39 @@ class TemplateSettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.O override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { preferenceManager.sharedPreferencesName = "tpl_" + arguments?.getString("template") setPreferencesFromResource(R.xml.template_preferences, rootKey) + preferenceScreen.findPreference("MapsRules")?.setOnPreferenceClickListener { + val rules = preferenceManager.sharedPreferences.getStringSet("MapsRules", setOf()).toMutableList() + val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, rules) + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.template_add_maps_rules) + .setView(View.inflate(requireContext(), R.layout.alert_customize_maps_rules, null).apply { + findViewById(R.id.template_lv_maps_rules).apply { + this.adapter = adapter + setOnItemLongClickListener { _, _, position, _ -> + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.template_delete_maps_rule) + .setMessage(rules[position]) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(android.R.string.ok) { _, _ -> + activity?.runOnUiThread { adapter.remove(rules[position]) } + preferenceManager.sharedPreferences.edit().putStringSet("MapsRules", rules.toSet()).apply() + }.show() + true + } + } + findViewById