Added information about the app to a separate activity

This commit is contained in:
Zakhar Timoshenko
2021-08-02 22:44:58 +03:00
committed by Koitharu
parent d25837b40b
commit 594c359f1c
12 changed files with 224 additions and 56 deletions

View File

@@ -87,6 +87,7 @@
<activity
android:name="org.koitharu.kotatsu.download.ui.DownloadsActivity"
android:label="@string/downloads" />
<activity android:name=".about.AboutActivity" />
<service
android:name="org.koitharu.kotatsu.download.ui.service.DownloadService"

View File

@@ -0,0 +1,45 @@
package org.koitharu.kotatsu.about
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.core.graphics.Insets
import androidx.core.view.updatePadding
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.BaseActivity
import org.koitharu.kotatsu.databinding.ActivityAboutBinding
class AboutActivity : BaseActivity<ActivityAboutBinding>() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(ActivityAboutBinding.inflate(layoutInflater))
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setTitle(R.string.about)
}
}
override fun onWindowInsetsChanged(insets: Insets) {
binding.toolbar.updatePadding(
top = insets.top,
left = insets.left,
right = insets.right
)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}
companion object {
fun newIntent(context: Context) = Intent(context, AboutActivity::class.java)
}
}

View File

@@ -0,0 +1,74 @@
package org.koitharu.kotatsu.about
import android.os.Bundle
import android.view.View
import androidx.preference.Preference
import kotlinx.coroutines.launch
import org.koitharu.kotatsu.BuildConfig
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.BasePreferenceFragment
import org.koitharu.kotatsu.browser.BrowserActivity
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.settings.AppUpdateChecker
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
class AboutFragment : BasePreferenceFragment(R.string.about) {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_about)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
findPreference<Preference>(AppSettings.KEY_APP_UPDATE_AUTO)?.run {
isVisible = AppUpdateChecker.isUpdateSupported(context)
}
findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
title = getString(R.string.app_version, BuildConfig.VERSION_NAME)
isEnabled = AppUpdateChecker.isUpdateSupported(context)
}
}
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
return when (preference?.key) {
AppSettings.KEY_APP_VERSION -> {
checkForUpdates()
true
}
AppSettings.KEY_APP_TRANSLATION -> {
startActivity(context?.let { BrowserActivity.newIntent(it, "https://hosted.weblate.org/engage/kotatsu", resources.getString(R.string.about_app_translation)) })
true
}
AppSettings.KEY_FEEDBACK_4PDA -> {
startActivity(context?.let { BrowserActivity.newIntent(it, "https://4pda.to/forum/index.php?showtopic=697669", resources.getString(R.string.about_feedback_4pda)) })
true
}
AppSettings.KEY_FEEDBACK_GITHUB -> {
startActivity(context?.let { BrowserActivity.newIntent(it, "https://github.com/nv95/Kotatsu/issues", "GitHub") })
true
}
else -> super.onPreferenceTreeClick(preference)
}
}
private fun checkForUpdates() {
viewLifecycleScope.launch {
findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
setSummary(R.string.checking_for_updates)
isSelectable = false
}
val result = AppUpdateChecker(activity ?: return@launch).checkNow()
findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
setSummary(
when (result) {
true -> R.string.check_for_updates
false -> R.string.no_update_available
null -> R.string.update_check_failed
}
)
isSelectable = true
}
}
}
}

View File

@@ -184,5 +184,10 @@ class AppSettings private constructor(private val prefs: SharedPreferences) :
const val KEY_RESTORE = "restore"
const val KEY_HISTORY_GROUPING = "history_grouping"
const val KEY_REVERSE_CHAPTERS = "reverse_chapters"
// About
const val KEY_APP_TRANSLATION = "about_app_translation"
const val KEY_FEEDBACK_4PDA = "about_feedback_4pda"
const val KEY_FEEDBACK_GITHUB = "about_feedback_github"
}
}

View File

@@ -25,6 +25,7 @@ import com.google.android.material.snackbar.Snackbar
import org.koin.android.ext.android.get
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.about.AboutActivity
import org.koitharu.kotatsu.base.ui.BaseActivity
import org.koitharu.kotatsu.core.model.Manga
import org.koitharu.kotatsu.core.model.MangaSource
@@ -195,6 +196,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>(),
startActivity(SettingsActivity.newIntent(this))
return true
}
R.id.nav_action_about -> {
startActivity(AboutActivity.newIntent(this))
}
else -> return false
}
}

View File

@@ -44,19 +44,12 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
findPreference<Preference>(AppSettings.KEY_APP_UPDATE_AUTO)?.run {
isVisible = AppUpdateChecker.isUpdateSupported(context)
}
findPreference<Preference>(AppSettings.KEY_LOCAL_STORAGE)?.run {
summary = settings.getStorageDir(context)?.getStorageName(context)
?: getString(R.string.not_available)
}
findPreference<SwitchPreference>(AppSettings.KEY_PROTECT_APP)?.isChecked =
!settings.appPassword.isNullOrEmpty()
findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
title = getString(R.string.app_version, BuildConfig.VERSION_NAME)
isEnabled = AppUpdateChecker.isUpdateSupported(context)
}
settings.subscribe(this)
}
@@ -120,10 +113,6 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
}
true
}
AppSettings.KEY_APP_VERSION -> {
checkForUpdates()
true
}
else -> super.onPreferenceTreeClick(preference)
}
}
@@ -181,24 +170,4 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
.create()
.show()
}
private fun checkForUpdates() {
viewLifecycleScope.launch {
findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
setSummary(R.string.checking_for_updates)
isSelectable = false
}
val result = AppUpdateChecker(activity ?: return@launch).checkNow()
findPreference<Preference>(AppSettings.KEY_APP_VERSION)?.run {
setSummary(
when (result) {
true -> R.string.check_for_updates
false -> R.string.no_update_available
null -> R.string.update_check_failed
}
)
isSelectable = true
}
}
}
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_about"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
style="@style/Widget.Kotatsu.AppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
style="@style/Widget.Kotatsu.Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="org.koitharu.kotatsu.about.AboutFragment"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@@ -37,5 +37,9 @@
android:id="@+id/nav_action_settings"
android:icon="@drawable/ic_settings"
android:title="@string/settings" />
<item
android:id="@+id/nav_action_about"
android:icon="@drawable/ic_info_outline"
android:title="@string/about" />
</group>
</menu>

View File

@@ -222,4 +222,9 @@
<string name="text_downloads_holder">На данный момент нет активных загрузок</string>
<string name="chapter_is_missing">Глава отсутствует</string>
<string name="chapter_is_missing_text">Эта глава отсутствует на вашем устройстве. Скачайте её или прочитайте онлайн</string>
<string name="about_app_translation_summary">Помочь с переводом приложения</string>
<string name="about_app_translation">Перевод</string>
<string name="about_author">Автор</string>
<string name="about_feedback_4pda">Тема на 4PDA</string>
<string name="about_feedback">Обратная связь</string>
</resources>

View File

@@ -225,4 +225,9 @@
<string name="text_downloads_holder">There are currently no active downloads</string>
<string name="chapter_is_missing_text">This chapter is missing on your device. Download or read it online.</string>
<string name="chapter_is_missing">Chapter is missing</string>
<string name="about_app_translation_summary">Translate this app</string>
<string name="about_app_translation">Translation</string>
<string name="about_author">Author</string>
<string name="about_feedback">Feedback</string>
<string name="about_feedback_4pda">Topic on 4PDA</string>
</resources>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<PreferenceCategory
app:iconSpaceReserved="false"
app:title="@string/app_name">
<Preference
app:iconSpaceReserved="false"
app:key="app_version"
app:persistent="false"
app:summary="@string/check_for_updates" />
<SwitchPreference
app:defaultValue="true"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false"
app:key="app_update_auto"
app:summary="@string/show_notification_app_update"
app:title="@string/application_update"
tools:isPreferenceVisible="true" />
<Preference
app:iconSpaceReserved="false"
app:key="about_app_translation"
app:summary="@string/about_app_translation_summary"
app:title="@string/about_app_translation" />
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
app:title="@string/about_feedback">
<Preference
app:iconSpaceReserved="false"
app:key="about_feedback_4pda"
app:summary="https://4pda.to/forum/index.php?showtopic=697669"
app:title="@string/about_feedback_4pda" />
<Preference
app:iconSpaceReserved="false"
app:key="about_feedback_github"
app:summary="https://github.com/nv95/Kotatsu/issues"
app:title="GitHub" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -79,30 +79,9 @@
android:title="@string/new_chapters_checking"
app:iconSpaceReserved="false" />
<PreferenceCategory
android:title="@string/about"
app:iconSpaceReserved="false">
<PreferenceScreen
android:fragment="org.koitharu.kotatsu.settings.backup.BackupSettingsFragment"
android:title="@string/backup_restore"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="app_update_auto"
android:summary="@string/show_notification_app_update"
android:title="@string/application_update"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false"
tools:isPreferenceVisible="true" />
<Preference
android:key="app_version"
android:persistent="false"
android:summary="@string/check_for_updates"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceScreen
android:fragment="org.koitharu.kotatsu.settings.backup.BackupSettingsFragment"
android:title="@string/backup_restore"
app:iconSpaceReserved="false" />
</PreferenceScreen>