From e351cafdf3980ddd94306d3c0d26dc73de7c8c2e Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 9 Oct 2020 09:45:11 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B9=A6=E6=BA=90?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 8 +- .../java/io/legado/app/constant/EventBus.kt | 6 +- .../main/java/io/legado/app/help/AppConfig.kt | 3 - .../legado/app/service/CheckSourceService.kt | 22 ++-- .../book/source/manage/BookSourceActivity.kt | 106 +++++++----------- .../main/res/layout/activity_book_source.xml | 1 + app/src/main/res/values/pref_key_value.xml | 1 - app/src/main/res/xml/pref_config_other.xml | 7 -- 8 files changed, 53 insertions(+), 101 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8a062f2f2..476e545bc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -121,15 +121,15 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" //fireBase - implementation 'com.google.firebase:firebase-analytics-ktx:17.5.0' - implementation 'com.google.firebase:firebase-crashlytics-ktx:17.2.1' + implementation 'com.google.firebase:firebase-analytics-ktx:17.6.0' + implementation 'com.google.firebase:firebase-crashlytics-ktx:17.2.2' //androidX - implementation 'androidx.core:core-ktx:1.3.1' + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.media:media:1.2.0' implementation 'androidx.preference:preference:1.1.1' - implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.2' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'com.google.android.material:material:1.2.1' diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 1ef2e9b44..dd00d8cee 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -20,8 +20,6 @@ object EventBus { const val WEB_SERVICE = "webService" const val UP_DOWNLOAD = "upDownload" const val SAVE_CONTENT = "saveContent" - const val CHECK_INIT = "checkInit" - const val CHECK_UP_PROGRESS = "checkProgress" - const val CHECK_UP_PROGRESS_STRING = "checkProgressTxt" - const val CHECK_DONE = "checkDone" + const val CHECK_SOURCE = "checkSource" + const val CHECK_SOURCE_DONE = "checkSourceDone" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index ac32d830a..e2538e902 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -58,9 +58,6 @@ object AppConfig { App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) } - val backgroundVerification: Boolean - get() = App.INSTANCE.getPrefBoolean(R.string.pk_background_verification, true) - val autoRefreshBook: Boolean get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index b8349df45..bf9372e7a 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -9,7 +9,6 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.IntentAction import io.legado.app.help.AppConfig -import io.legado.app.help.AppConfig.backgroundVerification import io.legado.app.help.IntentHelp import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.service.help.CheckSource @@ -45,9 +44,7 @@ class CheckSourceService : BaseService() { override fun onCreate() { super.onCreate() - if (backgroundVerification) { - updateNotification(0, getString(R.string.start)) - } + updateNotification(0, getString(R.string.start)) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -64,7 +61,7 @@ class CheckSourceService : BaseService() { super.onDestroy() tasks.clear() searchPool.close() - postEvent(EventBus.CHECK_DONE, 0) + postEvent(EventBus.CHECK_SOURCE_DONE, 0) } private fun check(ids: List) { @@ -78,7 +75,6 @@ class CheckSourceService : BaseService() { allIds.addAll(ids) processIndex = 0 threadCount = min(allIds.size, threadCount) - postEvent(EventBus.CHECK_INIT, allIds.size) updateNotification(0, getString(R.string.progress_show, "", 0, allIds.size)) for (i in 0 until threadCount) { check() @@ -113,15 +109,10 @@ class CheckSourceService : BaseService() { synchronized(this) { check() checkedIds.add(sourceUrl) - if (backgroundVerification) { - updateNotification( - checkedIds.size, - getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) - ) - } else { - postEvent(EventBus.CHECK_UP_PROGRESS, checkedIds.size) - postEvent(EventBus.CHECK_UP_PROGRESS_STRING, getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size)) - } + updateNotification( + checkedIds.size, + getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) + ) if (processIndex >= allIds.size + threadCount - 1) { stopSelf() } @@ -134,6 +125,7 @@ class CheckSourceService : BaseService() { private fun updateNotification(state: Int, msg: String) { notificationBuilder.setContentText(msg) notificationBuilder.setProgress(allIds.size, state, false) + postEvent(EventBus.CHECK_SOURCE, msg) startForeground(112202, notificationBuilder.build()) } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 1f64f0791..221d6142b 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -5,8 +5,9 @@ import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent import android.os.Bundle -import android.util.DisplayMetrics -import android.view.* +import android.view.Menu +import android.view.MenuItem +import android.view.SubMenu import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.core.content.FileProvider @@ -15,15 +16,14 @@ import androidx.lifecycle.LiveData import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager +import com.google.android.material.snackbar.Snackbar import io.legado.app.App import io.legado.app.BuildConfig import io.legado.app.R -import io.legado.app.base.BaseDialogFragment import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern import io.legado.app.constant.EventBus import io.legado.app.data.entities.BookSource -import io.legado.app.help.AppConfig import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH @@ -42,9 +42,7 @@ import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* -import kotlinx.android.synthetic.main.dialog_progressbar_view.* import kotlinx.android.synthetic.main.view_search.* -import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -68,6 +66,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private var groupMenu: SubMenu? = null private var sort = 0 private var sortAscending = 0 + private var snackBar: Snackbar? = null override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() @@ -100,11 +99,20 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity val intent = Intent(Intent.ACTION_SEND) val file = FileUtils.createFileWithReplace("$filesDir/shareBookSource.json") file.writeText(json) - val fileUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileProvider", file) + val fileUri = FileProvider.getUriForFile( + this, + BuildConfig.APPLICATION_ID + ".fileProvider", + file + ) intent.type = "text/*" intent.putExtra(Intent.EXTRA_STREAM, fileUri) intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION - startActivity(Intent.createChooser(intent, getString(R.string.share_selected_source))) + startActivity( + Intent.createChooser( + intent, + getString(R.string.share_selected_source) + ) + ) } catch (e: ActivityNotFoundException) { e.printStackTrace() } @@ -196,19 +204,19 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } } bookSourceLiveDate?.observe(this, { data -> - val sourceList = when (sortAscending % 2){ + val sourceList = when (sortAscending % 2) { 0 -> when (sort) { 1 -> data.sortedBy { it.weight } 2 -> data.sortedBy { it.bookSourceName } 3 -> data.sortedBy { it.bookSourceUrl } - 4 -> data.sortedByDescending { it.lastUpdateTime} + 4 -> data.sortedByDescending { it.lastUpdateTime } else -> data } else -> when (sort) { 1 -> data.sortedByDescending { it.weight } 2 -> data.sortedByDescending { it.bookSourceName } 3 -> data.sortedByDescending { it.bookSourceUrl } - 4 -> data.sortedBy { it.lastUpdateTime} + 4 -> data.sortedBy { it.lastUpdateTime } else -> data.reversed() } } @@ -218,11 +226,11 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity upCountView() }) } - private fun sortCheck (sortId: Int){ - if (sort == sortId){ - sortAscending +=1 - } - else{ + + private fun sortCheck(sortId: Int) { + if (sort == sortId) { + sortAscending += 1 + } else { sortAscending = 0 sort = sortId } @@ -299,13 +307,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity CheckSource.keyword = it } } - if (!AppConfig.backgroundVerification) { - val bundle = Bundle() - bundle.putInt("maxProgress", adapter.getSelection().size) - CheckSourceDialog().apply { - arguments = bundle - }.show(supportFragmentManager, "CheckDialog") - } CheckSource.start(this@BookSourceActivity, adapter.getSelection()) } noButton { } @@ -396,8 +397,21 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } override fun observeLiveBus() { - observeEvent(EventBus.CHECK_DONE) { - groups.map { group-> + observeEvent(EventBus.CHECK_SOURCE) { msg -> + snackBar?.setText(msg) ?: let { + snackBar = Snackbar + .make(root_view, msg, Snackbar.LENGTH_INDEFINITE) + .setAction(R.string.cancel) { + CheckSource.stop(this) + }.apply { show() } + } + } + observeEvent(EventBus.CHECK_SOURCE_DONE) { + snackBar?.let { + it.dismiss() + snackBar = null + } + groups.map { group -> if (group.contains("失效")) { search_view.setQuery("失效", true) toast("发现有失效书源,已为您自动筛选!") @@ -501,46 +515,4 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } } - class CheckSourceDialog : BaseDialogFragment() { - override fun onStart() { - super.onStart() - val dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) - dialog?.window?.setLayout( - (dm.widthPixels * 0.9).toInt(), - (dm.heightPixels * 0.14).toInt() - ) - dialog?.setCancelable(false) - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return inflater.inflate(R.layout.dialog_progressbar_view, container) - } - - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { - arguments?.let { bundle -> - val maxProgress = bundle.getInt("maxProgress") - ck_progress_text.text = getString(R.string.progress_show, "", 0, maxProgress) - ck_progress.max = maxProgress - observeEvent(EventBus.CHECK_UP_PROGRESS) { progress-> - ck_progress.progress = progress - } - observeEvent(EventBus.CHECK_UP_PROGRESS_STRING) { - ck_progress_text.text = it - } - observeEvent(EventBus.CHECK_DONE) { - dismiss() - } - tv_footer_left.onClick { - CheckSource.stop(requireContext()).apply { - dismiss() - } - } - } - } - } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_book_source.xml b/app/src/main/res/layout/activity_book_source.xml index 090be7b00..470138de2 100644 --- a/app/src/main/res/layout/activity_book_source.xml +++ b/app/src/main/res/layout/activity_book_source.xml @@ -1,6 +1,7 @@ diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml index 44522ad70..ef9ddd5be 100644 --- a/app/src/main/res/values/pref_key_value.xml +++ b/app/src/main/res/values/pref_key_value.xml @@ -1,6 +1,5 @@ - background_verification auto_refresh list_screen_direction full_screen diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 0bc8ae32c..0e3930546 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -51,13 +51,6 @@ app:iconSpaceReserved="false" app:layout="@layout/view_preference_category"> - - Date: Fri, 9 Oct 2020 14:27:20 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/view_select_action_bar.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/view_select_action_bar.xml b/app/src/main/res/layout/view_select_action_bar.xml index 5370a932d..70d15f3db 100644 --- a/app/src/main/res/layout/view_select_action_bar.xml +++ b/app/src/main/res/layout/view_select_action_bar.xml @@ -9,7 +9,8 @@ android:paddingTop="6dp" android:paddingBottom="6dp" android:gravity="center_vertical" - android:elevation="2dp" > + android:elevation="2dp" + tools:ignore="RtlHardcoded"> + android:text="@string/select_all" /> Date: Fri, 9 Oct 2020 15:55:00 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/values/pref_key_value.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml index ef9ddd5be..a0247482b 100644 --- a/app/src/main/res/values/pref_key_value.xml +++ b/app/src/main/res/values/pref_key_value.xml @@ -20,5 +20,5 @@ https://gedoor.github.io/MyBookshelf/ https://github.com/gedoor/legado/releases/latest https://api.github.com/repos/gedoor/legado/releases/latest - https://t.me/joinchat/S_beh0a2BD_pGiHjrmGixA + https://t.me/yueduguanfang From 0cac6675cfcaf7bbaa455e71bf7dbfc34bc4f5c8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 10 Oct 2020 08:43:56 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5029682c9..92c6e5f3e 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { classpath 'com.android.tools.build:gradle:4.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.3' - classpath 'com.google.gms:google-services:4.3.3' + classpath 'com.google.gms:google-services:4.3.4' classpath 'io.fabric.tools:gradle:1.31.2' } } From 714c5e516243c2aa88ab15d3a35d31656b5522ee Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 10 Oct 2020 11:36:58 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index bb94e956f..382ef012b 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/10/10** +* 优化书源校验 + **2020/10/07** * 更新时预下载10章 * 支持更多分组 From f10a89dd2f283dcb7ad92413bb60224bb19c4546 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 10 Oct 2020 14:42:57 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/menu/read_book.xml | 67 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/app/src/main/res/menu/read_book.xml b/app/src/main/res/menu/read_book.xml index bf836519e..967221408 100644 --- a/app/src/main/res/menu/read_book.xml +++ b/app/src/main/res/menu/read_book.xml @@ -3,6 +3,12 @@ xmlns:tools="http://schemas.android.com/tools" tools:context=".ui.main.MainActivity"> + + + app:showAsAction="never" /> - - - - - - - - - - - - + + + + + + + From b856081927af50ddd78f7285bea1feef6016da92 Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Sat, 10 Oct 2020 19:01:45 -0400 Subject: [PATCH 07/12] fix language not change bug fix language not change bug --- app/src/main/java/io/legado/app/App.kt | 3 +- .../java/io/legado/app/constant/EventBus.kt | 1 + .../java/io/legado/app/help/ActivityHelp.kt | 4 + .../io/legado/app/help/storage/Restore.kt | 2 +- .../io/legado/app/ui/config/ConfigActivity.kt | 12 +++ .../app/ui/config/OtherConfigFragment.kt | 4 +- .../java/io/legado/app/utils/LanguageUtils.kt | 81 ++++++++++++++----- app/src/main/res/values/arrays.xml | 8 +- app/src/main/res/values/strings.xml | 5 +- 9 files changed, 93 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 37aea552d..64f037fa4 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -7,6 +7,7 @@ import android.content.res.Configuration import android.graphics.Color import android.os.Build import android.provider.Settings +import android.util.Log import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatDelegate import androidx.multidex.MultiDexApplication @@ -46,7 +47,7 @@ class App : MultiDexApplication() { INSTANCE = this androidId = Settings.System.getString(contentResolver, Settings.Secure.ANDROID_ID) CrashHandler(this) - LanguageUtils.setConfigurationOld(this) + LanguageUtils.setConfiguration(this) db = AppDatabase.createDatabase(INSTANCE) packageManager.getPackageInfo(packageName, 0)?.let { versionCode = it.versionCode diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index dd00d8cee..8e6c2a9e6 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -3,6 +3,7 @@ package io.legado.app.constant object EventBus { const val MEDIA_BUTTON = "mediaButton" const val RECREATE = "RECREATE" + const val REOPEN = "REOPEN" const val UP_BOOK = "upBookToc" const val ALOUD_STATE = "aloud_state" const val TTS_PROGRESS = "ttsStart" diff --git a/app/src/main/java/io/legado/app/help/ActivityHelp.kt b/app/src/main/java/io/legado/app/help/ActivityHelp.kt index b14c76670..8d07a3500 100644 --- a/app/src/main/java/io/legado/app/help/ActivityHelp.kt +++ b/app/src/main/java/io/legado/app/help/ActivityHelp.kt @@ -3,6 +3,7 @@ package io.legado.app.help import android.app.Activity import android.app.Application import android.os.Bundle +import io.legado.app.utils.LanguageUtils import java.lang.ref.WeakReference import java.util.* @@ -110,5 +111,8 @@ object ActivityHelp : Application.ActivityLifecycleCallbacks { override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { add(activity) + if (!LanguageUtils.isSameWithSetting(activity)){ + LanguageUtils.setConfiguration(activity) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 7b0e7636d..0ba5e4367 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -225,7 +225,7 @@ object Restore { if (!BuildConfig.DEBUG) { LauncherIconHelp.changeIcon(App.INSTANCE.getPrefString(PreferKey.launcherIcon)) } - LanguageUtils.setConfigurationOld(App.INSTANCE) + LanguageUtils.setConfiguration(App.INSTANCE) App.INSTANCE.applyDayNight() postEvent(EventBus.SHOW_RSS, "") postEvent(EventBus.RECREATE, "") diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt index 6d7bfcfe7..ad6c1bea2 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt @@ -1,9 +1,14 @@ package io.legado.app.ui.config +import android.content.Intent import android.os.Bundle +import android.os.Process +import android.util.Log +import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.EventBus +import io.legado.app.ui.main.MainActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.activity_config.* @@ -54,5 +59,12 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) observeEvent(EventBus.RECREATE) { recreate() } + observeEvent(EventBus.REOPEN) { + Log.d("h11128", "reopen") + val intent = Intent(App.INSTANCE, MainActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) + App.INSTANCE.startActivity(intent) + Process.killProcess(Process.myPid()) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 1230bb2b5..177731855 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -7,6 +7,7 @@ import android.content.SharedPreferences import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle +import android.util.Log import android.view.View import androidx.documentfile.provider.DocumentFile import androidx.preference.ListPreference @@ -31,6 +32,7 @@ import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.utils.* import java.io.File +import java.util.* class OtherConfigFragment : BasePreferenceFragment(), @@ -123,7 +125,7 @@ class OtherConfigFragment : BasePreferenceFragment(), PreferKey.replaceEnableDefault -> AppConfig.replaceEnableDefault = App.INSTANCE.getPrefBoolean(PreferKey.replaceEnableDefault, true) PreferKey.language -> { - LanguageUtils.setConfigurationOld(App.INSTANCE) + LanguageUtils.setConfiguration(App.INSTANCE) postEvent(EventBus.RECREATE, "") } } diff --git a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt index ae6c465a8..551e91a00 100644 --- a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt @@ -4,6 +4,8 @@ import android.content.Context import android.content.res.Configuration import android.content.res.Resources import android.os.Build +import android.os.LocaleList +import android.util.Log import io.legado.app.constant.PreferKey import java.util.* @@ -16,14 +18,14 @@ object LanguageUtils { fun setConfiguration(context: Context): Context { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { val resources: Resources = context.resources - val targetLocale: Locale = when (context.getPrefString(PreferKey.language)) { - "zh" -> Locale.CHINESE - "tw" -> Locale.TRADITIONAL_CHINESE - "en" -> Locale.ENGLISH - else -> getSystemLocale() - } + val metrics = resources.displayMetrics val configuration: Configuration = resources.configuration + //Log.d("h11128", "set language to ${context.getPrefString(PreferKey.language)}") + val targetLocale = getSetLocale(context) configuration.setLocale(targetLocale) + configuration.setLocales(LocaleList(targetLocale)) + @Suppress("DEPRECATION") + resources.updateConfiguration(configuration, metrics) context.createConfigurationContext(configuration) } else { setConfigurationOld(context) @@ -34,18 +36,12 @@ object LanguageUtils { /** * 设置语言 */ - fun setConfigurationOld(context: Context) { + private fun setConfigurationOld(context: Context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { val resources: Resources = context.resources - val targetLocale: Locale = when (context.getPrefString(PreferKey.language)) { - "zh" -> Locale.CHINESE - "tw" -> Locale.TRADITIONAL_CHINESE - "en" -> Locale.ENGLISH - else -> getSystemLocale() - } + val targetLocale = getSetLocale(context) val configuration: Configuration = resources.configuration - @Suppress("DEPRECATION") - configuration.locale = targetLocale + configuration.setLocale(targetLocale) @Suppress("DEPRECATION") resources.updateConfiguration(configuration, resources.displayMetrics) } @@ -55,13 +51,62 @@ object LanguageUtils { * 当前系统语言 */ private fun getSystemLocale(): Locale { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //7.0有多语言设置获取顶部的语言 - Resources.getSystem().configuration.locales.get(0) + val locale: Locale + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //7.0有多语言设置获取顶部的语言 + locale = Resources.getSystem().configuration.locales.get(0) + } else { + @Suppress("DEPRECATION") + locale = Resources.getSystem().configuration.locale + } + return locale + } + + /** + * 当前App语言 + */ + private fun getAppLocale(context: Context): Locale { + val locale: Locale + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + locale = context.resources.configuration.locales[0] } else { @Suppress("DEPRECATION") - Resources.getSystem().configuration.locale + locale =context.resources.configuration.locale + } + /* + Log.d("h11128", "displayName " + locale.displayName) + Log.d("h11128", "displayCountry " + locale.displayCountry) + Log.d("h11128", "displayLanguage " + locale.displayLanguage) + Log.d("h11128", "Language " + locale.language) + Log.d("h11128", "Country " + locale.country) + + */ + return locale + + } + + /** + * 当前设置语言 + */ + private fun getSetLocale(context: Context): Locale { + return when (context.getPrefString(PreferKey.language)) { + "zh" -> Locale.SIMPLIFIED_CHINESE + "tw" -> Locale.TRADITIONAL_CHINESE + "en" -> Locale.ENGLISH + else -> getSystemLocale() } } + /** + * 判断系统语言和设置语言是否相同 + */ + fun isSameWithSetting(context: Context): Boolean { + val locale = getAppLocale(context) + val language = locale.language + val country = locale.country + val pfLocale = getSetLocale(context) + val pfLanguage = pfLocale.language + val pfCountry = pfLocale.country + return language == pfLanguage && country == pfCountry + } } \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 9a0410c81..f97f537fa 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -99,10 +99,10 @@ - 跟随系统 - 简体中文 - 繁体中文 - 英文 + Auto + Simplified_Chinese + Traditional_Chinese + English \ 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 39b957bf1..9186d4e20 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ + Legado @@ -693,7 +694,7 @@ Hide footer Switch Layout Text font weight switching - + Primary Accent @@ -773,4 +774,4 @@ Sort by update time Search content - \ No newline at end of file + From e8ba0801aa9c94a029a12e8dfa65efc1d2274701 Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Sat, 10 Oct 2020 19:06:00 -0400 Subject: [PATCH 08/12] update --- app/src/main/java/io/legado/app/utils/LanguageUtils.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt index 551e91a00..cf1e5a159 100644 --- a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt @@ -41,7 +41,8 @@ object LanguageUtils { val resources: Resources = context.resources val targetLocale = getSetLocale(context) val configuration: Configuration = resources.configuration - configuration.setLocale(targetLocale) + @Suppress("DEPRECATION") + configuration.locale = targetLocale @Suppress("DEPRECATION") resources.updateConfiguration(configuration, resources.displayMetrics) } @@ -70,7 +71,7 @@ object LanguageUtils { locale = context.resources.configuration.locales[0] } else { @Suppress("DEPRECATION") - locale =context.resources.configuration.locale + locale = context.resources.configuration.locale } /* Log.d("h11128", "displayName " + locale.displayName) @@ -97,7 +98,7 @@ object LanguageUtils { } /** - * 判断系统语言和设置语言是否相同 + * 判断App语言和设置语言是否相同 */ fun isSameWithSetting(context: Context): Boolean { val locale = getAppLocale(context) From 9c5ac27abc1b7364f84683c20887aec9577e8811 Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Sat, 10 Oct 2020 19:25:10 -0400 Subject: [PATCH 09/12] change to reopen --- app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt | 2 -- .../main/java/io/legado/app/ui/config/OtherConfigFragment.kt | 2 +- app/src/main/java/io/legado/app/utils/LanguageUtils.kt | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt index ad6c1bea2..0c2525d9c 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.config import android.content.Intent import android.os.Bundle import android.os.Process -import android.util.Log import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity @@ -60,7 +59,6 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) recreate() } observeEvent(EventBus.REOPEN) { - Log.d("h11128", "reopen") val intent = Intent(App.INSTANCE, MainActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) App.INSTANCE.startActivity(intent) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 177731855..36fe3dc92 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -126,7 +126,7 @@ class OtherConfigFragment : BasePreferenceFragment(), App.INSTANCE.getPrefBoolean(PreferKey.replaceEnableDefault, true) PreferKey.language -> { LanguageUtils.setConfiguration(App.INSTANCE) - postEvent(EventBus.RECREATE, "") + postEvent(EventBus.REOPEN, "") } } } diff --git a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt index cf1e5a159..def23e1e8 100644 --- a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt @@ -5,7 +5,6 @@ import android.content.res.Configuration import android.content.res.Resources import android.os.Build import android.os.LocaleList -import android.util.Log import io.legado.app.constant.PreferKey import java.util.* From b83d2bdc71977f4e974a804fb82353da3a0ce977 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 11 Oct 2020 18:17:32 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/constant/EventBus.kt | 1 - .../java/io/legado/app/ui/config/ConfigActivity.kt | 10 ---------- .../io/legado/app/ui/config/OtherConfigFragment.kt | 13 ++++++++----- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 8e6c2a9e6..dd00d8cee 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -3,7 +3,6 @@ package io.legado.app.constant object EventBus { const val MEDIA_BUTTON = "mediaButton" const val RECREATE = "RECREATE" - const val REOPEN = "REOPEN" const val UP_BOOK = "upBookToc" const val ALOUD_STATE = "aloud_state" const val TTS_PROGRESS = "ttsStart" diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt index 0c2525d9c..6d7bfcfe7 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt @@ -1,13 +1,9 @@ package io.legado.app.ui.config -import android.content.Intent import android.os.Bundle -import android.os.Process -import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.EventBus -import io.legado.app.ui.main.MainActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.activity_config.* @@ -58,11 +54,5 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) observeEvent(EventBus.RECREATE) { recreate() } - observeEvent(EventBus.REOPEN) { - val intent = Intent(App.INSTANCE, MainActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) - App.INSTANCE.startActivity(intent) - Process.killProcess(Process.myPid()) - } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 36fe3dc92..542ae8780 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -7,7 +7,7 @@ import android.content.SharedPreferences import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle -import android.util.Log +import android.os.Process import android.view.View import androidx.documentfile.provider.DocumentFile import androidx.preference.ListPreference @@ -28,11 +28,11 @@ import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.service.WebService +import io.legado.app.ui.main.MainActivity import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.utils.* import java.io.File -import java.util.* class OtherConfigFragment : BasePreferenceFragment(), @@ -124,10 +124,13 @@ class OtherConfigFragment : BasePreferenceFragment(), ) PreferKey.replaceEnableDefault -> AppConfig.replaceEnableDefault = App.INSTANCE.getPrefBoolean(PreferKey.replaceEnableDefault, true) - PreferKey.language -> { + PreferKey.language -> listView.postDelayed({ LanguageUtils.setConfiguration(App.INSTANCE) - postEvent(EventBus.REOPEN, "") - } + val intent = Intent(App.INSTANCE, MainActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) + App.INSTANCE.startActivity(intent) + Process.killProcess(Process.myPid()) + }, 1000) } } From cc6875f53a6babdb306349912fe5cce9c8819a37 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 11 Oct 2020 18:18:47 +0800 Subject: [PATCH 11/12] update log --- app/src/main/assets/updateLog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 382ef012b..53cf3a768 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,8 +3,9 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2020/10/10** +**2020/10/11** * 优化书源校验 +* 语言切换bug修复 **2020/10/07** * 更新时预下载10章 From 9d9fbb83d544d68d6bf9b1192cd65c9b4bd66753 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 11 Oct 2020 18:19:38 +0800 Subject: [PATCH 12/12] update log --- app/src/main/assets/updateLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 53cf3a768..8d26e58ca 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,7 +5,7 @@ **2020/10/11** * 优化书源校验 -* 语言切换bug修复 +* 语言切换bug修复 by [h11128](https://github.com/h11128) **2020/10/07** * 更新时预下载10章