-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ui): reorganize preference screen
- use Navigation component to navigate to different fragments - polish some preference names and their summaries - replace some preference icons with more appropriate ones - reorder preference entries - use one Activity to navigate to all fragments
- Loading branch information
1 parent
545a392
commit be95e64
Showing
20 changed files
with
307 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/src/main/java/com/osfans/trime/ui/fragments/AboutFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.osfans.trime.ui.fragments | ||
|
||
import android.content.ClipData | ||
import android.content.ClipboardManager | ||
import android.content.Context | ||
import android.os.Bundle | ||
import android.webkit.WebView | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.get | ||
import com.blankj.utilcode.util.ToastUtils | ||
import com.osfans.trime.BuildConfig | ||
import com.osfans.trime.R | ||
import com.osfans.trime.core.Rime | ||
import com.osfans.trime.ui.main.MainViewModel | ||
import com.osfans.trime.util.AppVersionUtils.writeLibraryVersionToSummary | ||
|
||
class AboutFragment : PreferenceFragmentCompat() { | ||
private val viewModel: MainViewModel by activityViewModels() | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
setPreferencesFromResource(R.xml.about_preference, rootKey) | ||
with(preferenceScreen) { | ||
get<Preference>("about__changelog") | ||
?.writeLibraryVersionToSummary(BuildConfig.BUILD_VERSION) | ||
get<Preference>("about__buildinfo")?.apply { | ||
writeLibraryVersionToSummary(BuildConfig.BUILD_INFO) | ||
setOnPreferenceClickListener { | ||
val cbm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager | ||
val info = ClipData.newPlainText("BuildInfo", BuildConfig.BUILD_INFO) | ||
cbm.setPrimaryClip(info) | ||
ToastUtils.showLong(R.string.copy_done) | ||
true | ||
} | ||
} | ||
get<Preference>("about__librime_version") | ||
?.writeLibraryVersionToSummary(Rime.get_librime_version()) | ||
get<Preference>("about__opencc_version") | ||
?.writeLibraryVersionToSummary(Rime.get_opencc_version()) | ||
get<Preference>("pref_trime_custom_qq") | ||
?.hidden() | ||
get<Preference>("about__licensing")?.setOnPreferenceClickListener { | ||
val webView = WebView(requireContext()) | ||
webView.loadUrl("file:///android_asset/license/open_source_license.html") | ||
AlertDialog.Builder(requireContext()) | ||
.setTitle(R.string.about__licensing_title) | ||
.setView(webView) | ||
.setPositiveButton(android.R.string.ok, null) | ||
.show() | ||
true | ||
} | ||
get<Preference>("about__used_libraries")?.setOnPreferenceClickListener { | ||
val webView = WebView(requireContext()) | ||
webView.loadUrl("file:///android_asset/license/library_licenses.html") | ||
AlertDialog.Builder(requireContext()) | ||
.setTitle(R.string.about__used_library_dialog_title) | ||
.setView(webView) | ||
.setPositiveButton(android.R.string.ok, null) | ||
.show() | ||
true | ||
} | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
viewModel.setToolbarTitle(getString(R.string.pref_about)) | ||
} | ||
|
||
private fun Preference.hidden() { | ||
if (this.summary.isBlank() || this.intent.data.toString().isBlank()) { | ||
this.isVisible = false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 13 additions & 17 deletions
30
app/src/main/java/com/osfans/trime/ui/fragments/LooksFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
package com.osfans.trime.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.Menu | ||
import androidx.core.view.forEach | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.get | ||
import com.osfans.trime.R | ||
import com.osfans.trime.ui.components.ColorPickerDialog | ||
import com.osfans.trime.ui.components.ThemePickerDialog | ||
import com.osfans.trime.ui.main.MainViewModel | ||
|
||
class LooksFragment : PreferenceFragmentCompat() { | ||
private val viewModel : MainViewModel by activityViewModels() | ||
private val viewModel: MainViewModel by activityViewModels() | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
addPreferencesFromResource(R.xml.looks_preference) | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
viewModel.disableTopOptionsMenu() | ||
} | ||
|
||
override fun onPreferenceTreeClick(preference: Preference?): Boolean { | ||
return when (preference?.key) { | ||
"looks__selected_theme" -> { | ||
ThemePickerDialog(requireContext()).show() | ||
with(preferenceScreen) { | ||
get<Preference>("looks__selected_theme")?.setOnPreferenceClickListener { | ||
ThemePickerDialog(context).show() | ||
true | ||
} | ||
"looks__selected_color" -> { | ||
ColorPickerDialog(requireContext()).show() | ||
get<Preference>("looks__selected_color")?.setOnPreferenceClickListener { | ||
ColorPickerDialog(context).show() | ||
true | ||
} | ||
else -> super.onPreferenceTreeClick(preference) | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
viewModel.setToolbarTitle(getString(R.string.pref_theme_and_color)) | ||
viewModel.disableTopOptionsMenu() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.