Skip to content

Commit

Permalink
添加 Nevo 跳转与未安装提示
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenhe committed Aug 1, 2020
1 parent 605ff7a commit 6b8fee8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cc.chenhe.qqnotifyevo.preference

import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.observe
Expand Down Expand Up @@ -78,9 +78,14 @@ class MainPreferenceFr : PreferenceFragmentCompat() {
if (model.mode.value == MODE_NEVO) {
serviceWarning.setTitle(R.string.warning_nevo_service)
serviceWarning.setSummary(R.string.warning_nevo_service_summary)
serviceWarning.setOnPreferenceClickListener {
startNevoApp()
true
}
} else if (model.mode.value == MODE_LEGACY) {
serviceWarning.setTitle(R.string.warning_monitor_service)
serviceWarning.setSummary(R.string.warning_monitor_service_summary)
serviceWarning.onPreferenceChangeListener = null
}
serviceWarning.isVisible = true
}
Expand Down Expand Up @@ -112,6 +117,23 @@ class MainPreferenceFr : PreferenceFragmentCompat() {
return super.onPreferenceTreeClick(preference)
}

private fun startNevoApp() {
try {
Intent().let {
it.action = Intent.ACTION_MAIN
it.addCategory(Intent.CATEGORY_LAUNCHER)
it.setPackage("com.oasisfeng.nevo")
startActivity(it)
}
} catch (e: Exception) {
AlertDialog.Builder(requireContext())
.setTitle(R.string.tip)
.setMessage(R.string.main_nevo_not_install)
.setPositiveButton(R.string.confirm, null)
.show()
}
}

private suspend fun checkServiceRunning() {
withContext(Dispatchers.Default) {
if (model.mode.value == MODE_NEVO)
Expand All @@ -124,7 +146,7 @@ class MainPreferenceFr : PreferenceFragmentCompat() {
}

private fun donate() {
AlertDialog.Builder(context)
AlertDialog.Builder(requireContext())
.setTitle(R.string.pref_donate_message)
.setSingleChoiceItems(R.array.pref_donate_options, -1) { _, i ->
startAliPay()
Expand All @@ -133,7 +155,7 @@ class MainPreferenceFr : PreferenceFragmentCompat() {
}

private fun showInfo() {
AlertDialog.Builder(context)
AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.about_dialog_title))
.setMessage(getString(R.string.about_dialog_message))
.setNeutralButton(R.string.about_dialog_github) { _, _ ->
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@
<string name="pref_delete_log_summary">%1$d个日志 总大小%2$s</string>
<string name="pref_delete_log_dialog_message">删除所有日志?</string>

<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 主界面
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

<string name="main_nevo_not_install">Nevo(女娲石)可能未安装,请先安装或切换到传统模式。\n详情请阅读使用手册。</string>

<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ 升级提示界面
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
Expand Down

0 comments on commit 6b8fee8

Please sign in to comment.