From 50cfeae6baecff194897fa3b1b99dff8eddef621 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 27 Jan 2023 19:31:21 +0800 Subject: [PATCH] =?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/build.gradle | 2 -- app/src/app/java/io/legado/app/lib/cronet/CronetHelper.kt | 6 +++--- app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt | 8 ++++---- app/src/main/java/io/legado/app/constant/AppConst.kt | 3 +++ app/src/main/java/io/legado/app/help/config/AppConfig.kt | 1 - app/src/main/java/io/legado/app/help/http/HttpHelper.kt | 2 +- app/src/main/java/io/legado/app/help/source/SourceHelp.kt | 4 ++-- app/src/main/java/io/legado/app/ui/about/UpdateDialog.kt | 4 ++-- .../legado/app/ui/association/FileAssociationActivity.kt | 3 ++- .../java/io/legado/app/ui/book/cache/CacheViewModel.kt | 2 +- .../legado/app/ui/book/import/local/ImportBookActivity.kt | 3 ++- .../java/io/legado/app/ui/config/OtherConfigFragment.kt | 3 ++- .../java/io/legado/app/ui/config/ThemeConfigFragment.kt | 2 +- .../java/io/legado/app/ui/document/HandleFileActivity.kt | 6 +++--- app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt | 4 ++-- 15 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 85cecae92..132d143b3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -49,7 +49,6 @@ android { buildConfigField "String", "Cronet_Version", "\"$CronetVersion\"" buildConfigField "String", "Cronet_Main_Version", "\"$CronetMainVersion\"" - buildConfigField "boolean", "isGoogle", "false" javaCompileOptions { annotationProcessorOptions { @@ -105,7 +104,6 @@ android { dimension "mode" applicationId "io.legado.play" manifestPlaceholders.put("APP_CHANNEL_VALUE", "google") - buildConfigField "boolean", "isGoogle", "true" } } compileOptions { diff --git a/app/src/app/java/io/legado/app/lib/cronet/CronetHelper.kt b/app/src/app/java/io/legado/app/lib/cronet/CronetHelper.kt index 922fd441e..d7f770c29 100644 --- a/app/src/app/java/io/legado/app/lib/cronet/CronetHelper.kt +++ b/app/src/app/java/io/legado/app/lib/cronet/CronetHelper.kt @@ -3,8 +3,8 @@ package io.legado.app.lib.cronet import androidx.annotation.Keep +import io.legado.app.constant.AppConst import io.legado.app.constant.AppLog -import io.legado.app.help.config.AppConfig import io.legado.app.help.http.okHttpClient import io.legado.app.utils.DebugLog import okhttp3.Headers @@ -20,11 +20,11 @@ import splitties.init.appCtx internal const val BUFFER_SIZE = 32 * 1024 val cronetEngine: ExperimentalCronetEngine? by lazy { - if (!AppConfig.isGooglePlay) { + if (!AppConst.isPlayChannel) { CronetLoader.preDownload() } val builder = ExperimentalCronetEngine.Builder(appCtx).apply { - if (!AppConfig.isGooglePlay && CronetLoader.install()) { + if (!AppConst.isPlayChannel && CronetLoader.install()) { setLibraryLoader(CronetLoader)//设置自定义so库加载 } setStoragePath(appCtx.externalCacheDir?.absolutePath)//设置缓存路径 diff --git a/app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt b/app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt index c87442491..4fa99416b 100644 --- a/app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt +++ b/app/src/app/java/io/legado/app/lib/cronet/CronetLoader.kt @@ -7,7 +7,7 @@ import android.os.Build import android.text.TextUtils import androidx.annotation.Keep import io.legado.app.BuildConfig -import io.legado.app.help.config.AppConfig +import io.legado.app.constant.AppConst import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.http.cronet.CronetLoaderInterface import io.legado.app.utils.DebugLog @@ -64,7 +64,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader(), CronetLoaderInterfac } } - if (AppConfig.isGooglePlay) { + if (AppConst.isPlayChannel) { return false } if (md5.length != 32 || !soFile.exists() || md5 != getFileMD5(soFile)) { @@ -80,7 +80,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader(), CronetLoaderInterfac * 预加载Cronet */ override fun preDownload() { - if (AppConfig.isGooglePlay) { + if (AppConst.isPlayChannel) { return } Coroutine.async { @@ -266,7 +266,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader(), CronetLoaderInterfac downloadTempFile: File, destSuccessFile: File ) { - if (download || AppConfig.isGooglePlay) { + if (download || AppConst.isPlayChannel) { return } download = true diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index 7ee3f2672..f19ad27fd 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -6,6 +6,7 @@ import android.provider.Settings import androidx.annotation.Keep import com.script.javascript.RhinoScriptEngine import io.legado.app.BuildConfig +import io.legado.app.utils.channel import splitties.init.appCtx import java.text.SimpleDateFormat @@ -14,6 +15,8 @@ object AppConst { const val APP_TAG = "Legado" + val isPlayChannel = appCtx.channel == "google" + const val channelIdDownload = "channel_download" const val channelIdReadAloud = "channel_read_aloud" const val channelIdWeb = "channel_web" diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt index fec8f47c7..5879a1b7e 100644 --- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt @@ -12,7 +12,6 @@ import splitties.init.appCtx @Suppress("MemberVisibilityCanBePrivate") object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { - const val isGooglePlay = BuildConfig.isGoogle//appCtx.channel == "google" val isCronet = appCtx.getPrefBoolean(PreferKey.cronet) val useAntiAlias = appCtx.getPrefBoolean(PreferKey.antiAlias) var userAgent: String = getPrefUserAgent() diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 7d5907c92..145ab9657 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -69,7 +69,7 @@ val okHttpClient: OkHttpClient by lazy { builder.addHeader("Cache-Control", "no-cache") chain.proceed(builder.build()) }) - if (!AppConfig.isGooglePlay && AppConfig.isCronet) { + if (!AppConst.isPlayChannel && AppConfig.isCronet) { if (Cronet.loader?.install() == true) { Cronet.interceptor?.let { builder.addInterceptor(it) diff --git a/app/src/main/java/io/legado/app/help/source/SourceHelp.kt b/app/src/main/java/io/legado/app/help/source/SourceHelp.kt index 3ca560c45..ec6af0d6f 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceHelp.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceHelp.kt @@ -2,11 +2,11 @@ package io.legado.app.help.source import android.os.Handler import android.os.Looper +import io.legado.app.constant.AppConst import io.legado.app.data.appDb import io.legado.app.data.entities.BaseSource import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.RssSource -import io.legado.app.help.config.AppConfig import io.legado.app.utils.EncoderUtils import io.legado.app.utils.NetworkUtils import io.legado.app.utils.splitNotBlank @@ -59,7 +59,7 @@ object SourceHelp { url ?: return false val baseUrl = NetworkUtils.getBaseUrl(url) baseUrl ?: return false - if (AppConfig.isGooglePlay) return false + if (AppConst.isPlayChannel) return false kotlin.runCatching { val host = baseUrl.split("//", ".") val base64Url = EncoderUtils.base64Encode("${host[host.lastIndex - 1]}.${host.last()}") diff --git a/app/src/main/java/io/legado/app/ui/about/UpdateDialog.kt b/app/src/main/java/io/legado/app/ui/about/UpdateDialog.kt index 33cfb8476..9a0cfaed6 100644 --- a/app/src/main/java/io/legado/app/ui/about/UpdateDialog.kt +++ b/app/src/main/java/io/legado/app/ui/about/UpdateDialog.kt @@ -5,9 +5,9 @@ import android.view.View import android.view.ViewGroup import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.constant.AppConst import io.legado.app.databinding.DialogUpdateBinding import io.legado.app.help.AppUpdate -import io.legado.app.help.config.AppConfig import io.legado.app.lib.theme.primaryColor import io.legado.app.model.Download import io.legado.app.utils.setLayout @@ -53,7 +53,7 @@ class UpdateDialog() : BaseDialogFragment(R.layout.dialog_update) { .build() .setMarkdown(binding.textView, updateBody) } - if (!AppConfig.isGooglePlay) { + if (!AppConst.isPlayChannel) { binding.toolBar.inflateMenu(R.menu.app_update) binding.toolBar.setOnMenuItemClickListener { when (it.itemId) { diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index f7a1a7bb4..058bd9836 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -7,6 +7,7 @@ import androidx.activity.viewModels import androidx.documentfile.provider.DocumentFile import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppConst import io.legado.app.constant.AppLog import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.help.config.AppConfig @@ -107,7 +108,7 @@ class FileAssociationActivity : intent.data?.let { data -> if (data.isContentScheme()) { viewModel.dispatchIndent(data) - } else if (!AppConfig.isGooglePlay || Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) { + } else if (!AppConst.isPlayChannel || Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) { PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 6c29153c1..e4aeab359 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -342,7 +342,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } private fun setAssets(doc: DocumentFile, book: Book, epubBook: EpubBook): String { - if (!(AppConfig.isGooglePlay || appCtx.packageName.contains( + if (!(AppConst.isPlayChannel || appCtx.packageName.contains( "debug", true )) diff --git a/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt index 882b32bb5..b1d592d88 100644 --- a/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt @@ -10,6 +10,7 @@ import androidx.appcompat.widget.PopupMenu import androidx.documentfile.provider.DocumentFile import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R +import io.legado.app.constant.AppConst import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.databinding.ActivityImportBookBinding @@ -176,7 +177,7 @@ class ImportBookActivity : BaseImportBookActivity { + AppConst.isPlayChannel -> { binding.tvEmptyMsg.visible() selectFolder.launch() } 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 72c512187..88a865f6f 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 @@ -11,6 +11,7 @@ import androidx.fragment.app.activityViewModels import androidx.preference.ListPreference import androidx.preference.Preference import io.legado.app.R +import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.databinding.DialogEditTextBinding @@ -48,7 +49,7 @@ class OtherConfigFragment : PreferenceFragment(), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { putPrefBoolean(PreferKey.processText, isProcessTextEnabled()) addPreferencesFromResource(R.xml.pref_config_other) - if (AppConfig.isGooglePlay) { + if (AppConst.isPlayChannel) { preferenceScreen.removePreferenceRecursively("Cronet") } upPreferenceSummary(PreferKey.userAgent, AppConfig.userAgent) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index d2883a131..dad7fb14f 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -59,7 +59,7 @@ class ThemeConfigFragment : PreferenceFragment(), if (Build.VERSION.SDK_INT < 26) { preferenceScreen.removePreferenceRecursively(PreferKey.launcherIcon) } - if (!AppConfig.isGooglePlay) { + if (!AppConst.isPlayChannel) { preferenceScreen.removePreferenceRecursively("welcomeStyle") } upPreferenceSummary(PreferKey.bgImage, getPrefString(PreferKey.bgImage)) diff --git a/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt index 6bbade08b..e90991c6b 100644 --- a/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt +++ b/app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt @@ -8,11 +8,11 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppConst import io.legado.app.constant.AppLog import io.legado.app.constant.Theme import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.help.IntentData -import io.legado.app.help.config.AppConfig import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.alert import io.legado.app.lib.permission.Permissions @@ -160,7 +160,7 @@ class HandleFileActivity : } private fun getDirActions(onlySys: Boolean = false): ArrayList> { - return if (onlySys || AppConfig.isGooglePlay) { + return if (onlySys || AppConst.isPlayChannel) { arrayListOf(SelectItem(getString(R.string.sys_folder_picker), HandleFileContract.DIR)) } else { arrayListOf( @@ -171,7 +171,7 @@ class HandleFileActivity : } private fun getFileActions(): ArrayList> { - return if (AppConfig.isGooglePlay) { + return if (AppConst.isPlayChannel) { arrayListOf(SelectItem(getString(R.string.sys_file_picker), HandleFileContract.FILE)) } else { arrayListOf( diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index df40f6cad..e5f3ab61c 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -8,10 +8,10 @@ import android.view.View import androidx.preference.Preference import io.legado.app.R import io.legado.app.base.BaseFragment +import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.databinding.FragmentMyConfigBinding -import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ThemeConfig import io.legado.app.lib.dialogs.selector import io.legado.app.lib.prefs.NameListPreference @@ -67,7 +67,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { putPrefBoolean(PreferKey.webService, WebService.isRun) addPreferencesFromResource(R.xml.pref_main) - if (AppConfig.isGooglePlay) { + if (AppConst.isPlayChannel) { findPreference("aboutCategory") ?.removePreferenceRecursively("donate") }