This commit is contained in:
kunfei
2023-01-27 19:31:21 +08:00
parent e99fa33d3a
commit 50cfeae6ba
15 changed files with 28 additions and 25 deletions

View File

@@ -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 {

View File

@@ -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)//设置缓存路径

View File

@@ -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

View File

@@ -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"

View File

@@ -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()

View File

@@ -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)

View File

@@ -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()}")

View File

@@ -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) {

View File

@@ -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)

View File

@@ -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
))

View File

@@ -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<ActivityImportBookBinding, Imp
selectFolder.launch()
}
}
AppConfig.isGooglePlay -> {
AppConst.isPlayChannel -> {
binding.tvEmptyMsg.visible()
selectFolder.launch()
}

View File

@@ -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)

View File

@@ -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))

View File

@@ -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<SelectItem<Int>> {
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<SelectItem<Int>> {
return if (AppConfig.isGooglePlay) {
return if (AppConst.isPlayChannel) {
arrayListOf(SelectItem(getString(R.string.sys_file_picker), HandleFileContract.FILE))
} else {
arrayListOf(

View File

@@ -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<PreferenceCategory>("aboutCategory")
?.removePreferenceRecursively("donate")
}