From 54e14fba60e53eb961cc730f9f1913fe7bb2b179 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 12 Jun 2019 20:17:18 +0800 Subject: [PATCH] up --- app/src/main/java/io/legado/app/App.kt | 11 ++--- .../io/legado/app/ui/about/AboutActivity.kt | 34 ++++++++++++++ .../io/legado/app/ui/about/AboutFragment.kt | 15 ++++++ app/src/main/res/layout/activity_about.xml | 46 ++++++++++++++++--- app/src/main/res/menu/about.xml | 9 ++++ app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/about.xml | 36 +++++++++++++++ 7 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/about/AboutFragment.kt create mode 100644 app/src/main/res/menu/about.xml create mode 100644 app/src/main/res/xml/about.xml diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 2e678ef21..563183807 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -4,7 +4,6 @@ import android.app.Application import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context -import android.content.pm.PackageManager import android.os.Build import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatDelegate @@ -32,16 +31,16 @@ class App : Application() { private set } - private var versionCode = 0 + var versionCode = 0 + var versionName = "" override fun onCreate() { super.onCreate() INSTANCE = this db = AppDatabase.createDatabase(INSTANCE) - versionCode = try { - packageManager.getPackageInfo(packageName, 0).versionCode - } catch (e: PackageManager.NameNotFoundException) { - 0 + packageManager.getPackageInfo(packageName, 0)?.let { + versionCode = it.versionCode + versionName = it.versionName } if (!ThemeStore.isConfigured(this, versionCode)) upThemeStore() initNightTheme() diff --git a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt index fff5b7433..9afc8ac78 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt @@ -1,10 +1,15 @@ package io.legado.app.ui.about +import android.content.Intent +import android.net.Uri import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import androidx.lifecycle.AndroidViewModel import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.utils.getViewModel +import org.jetbrains.anko.toast class AboutActivity : BaseActivity() { override val viewModel: AndroidViewModel @@ -13,7 +18,36 @@ class AboutActivity : BaseActivity() { get() = R.layout.activity_about override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) { + val fTag = "aboutFragment" + var aboutFragment = supportFragmentManager.findFragmentByTag(fTag) + if (aboutFragment == null) aboutFragment = AboutFragment() + supportFragmentManager.beginTransaction() + .replace(R.id.fl_fragment, aboutFragment, fTag) + .commit() + } + + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.about, menu) + return super.onCompatCreateOptionsMenu(menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_scoring -> { + openIntent(Intent.ACTION_VIEW, "market://details?id=$packageName") + } + } + return super.onCompatOptionsItemSelected(item) } + internal fun openIntent(intentName: String, address: String) { + try { + val intent = Intent(intentName) + intent.data = Uri.parse(address) + startActivity(intent) + } catch (e: Exception) { + toast(R.string.can_not_open) + } + + } } diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt new file mode 100644 index 000000000..8dd12fc81 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -0,0 +1,15 @@ +package io.legado.app.ui.about + +import android.os.Bundle +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +import io.legado.app.App +import io.legado.app.R + +class AboutFragment : PreferenceFragmentCompat() { + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.about) + findPreference("version")?.summary = App.INSTANCE.versionName + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index d0432e55e..65bacf179 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -1,15 +1,49 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + tools:context="io.legado.app.ui.about.AboutActivity"> + + + + + android:orientation="vertical" + android:padding="10dp"> + + + + + + + diff --git a/app/src/main/res/menu/about.xml b/app/src/main/res/menu/about.xml new file mode 100644 index 000000000..7dd8f1e86 --- /dev/null +++ b/app/src/main/res/menu/about.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6ba1a7ff..9af81ad1c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,7 +55,7 @@ 退出 还未保存,是否继续编辑 阅读样式设置 - + 版本 本地 搜索 没有网络 diff --git a/app/src/main/res/xml/about.xml b/app/src/main/res/xml/about.xml new file mode 100644 index 000000000..5065b7b96 --- /dev/null +++ b/app/src/main/res/xml/about.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + \ No newline at end of file