diff --git a/app/build.gradle b/app/build.gradle index 43c822e3b..c2bc779e2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ static def releaseTime() { } def name = "legado" -def version = "0." + releaseTime() +def version = "3." + releaseTime() def gitCommits = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim()) android { diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index e08399579..94535e6d4 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -1,9 +1,14 @@ ## 更新日志 * 旧版数据导入教程: -* 先在旧版阅读2.19.xxxxxx进行备份,再在新版阅读3.0的【我的】中,点击【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 +* 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 * 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。 +**2019/12/09** +* [add]其他设置->清理缓存 +* [mod]调整深色模式配色,预适配Android10 +* [mod]启用web服务 + **2019/12/03** * from Celeter1、调试log修改 2、增加书源字符串分享(RSS未包含) 3、增加导出选中的源(包含书源、RSS、替换规则) * 一键缓存 diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index a9fbf72d4..37dd40e25 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -70,13 +70,13 @@ class App : Application() { if (isNightTheme) { ThemeStore.editTheme(this) .primaryColor( - getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_blue_grey_600)) + getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900)) ) .accentColor( getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) ) .backgroundColor( - getPrefInt("colorBackgroundNight", getCompatColor(R.color.md_grey_800)) + getPrefInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000)) ) .apply() } else { @@ -101,7 +101,6 @@ class App : Application() { initNightTheme() } - private fun initNightTheme() { val targetMode = if (isNightTheme) { AppCompatDelegate.MODE_NIGHT_YES @@ -111,7 +110,6 @@ class App : Application() { AppCompatDelegate.setDefaultNightMode(targetMode) } - /** * 创建通知ID */ diff --git a/app/src/main/java/io/legado/app/help/IntentHelp.kt b/app/src/main/java/io/legado/app/help/IntentHelp.kt index 815867694..d02e13392 100644 --- a/app/src/main/java/io/legado/app/help/IntentHelp.kt +++ b/app/src/main/java/io/legado/app/help/IntentHelp.kt @@ -21,6 +21,17 @@ object IntentHelp { } } + fun toInstallUnknown(context: Context) { + try { + val intent = Intent() + intent.action = "android.settings.MANAGE_UNKNOWN_APP_SOURCES" + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + context.startActivity(intent) + } catch (ignored: Exception) { + context.toast("无法打开设置") + } + } + inline fun servicePendingIntent(context: Context, action: String): PendingIntent? { return PendingIntent.getService( context, diff --git a/app/src/main/java/io/legado/app/help/permission/Permissions.kt b/app/src/main/java/io/legado/app/help/permission/Permissions.kt index e1c0893e3..236691f7f 100644 --- a/app/src/main/java/io/legado/app/help/permission/Permissions.kt +++ b/app/src/main/java/io/legado/app/help/permission/Permissions.kt @@ -36,10 +36,12 @@ object Permissions { const val WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE" object Group { - val CALENDAR = arrayOf(READ_CALENDAR, WRITE_CALENDAR) + val STORAGE = arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE) val CAMERA = arrayOf(Permissions.CAMERA) + val CALENDAR = arrayOf(READ_CALENDAR, WRITE_CALENDAR) + val CONTACTS = arrayOf(READ_CONTACTS, WRITE_CONTACTS, GET_ACCOUNTS) val LOCATION = arrayOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION) @@ -65,8 +67,5 @@ object Permissions { RECEIVE_WAP_PUSH, RECEIVE_MMS ) - - val STORAGE = arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE) } - } diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 012623865..60ce40004 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -34,7 +34,6 @@ class WebService : BaseService() { context.startService(intent) } } - } private var httpServer: HttpServer? = null 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 52d197a08..a926a8ae2 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 @@ -19,7 +19,7 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) when (viewModel.configType) { ConfigViewModel.TYPE_CONFIG -> { - title_bar.title = getString(R.string.setting) + title_bar.title = getString(R.string.other_setting) val fTag = "configFragment" var configFragment = supportFragmentManager.findFragmentByTag(fTag) if (configFragment == null) configFragment = ConfigFragment() 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 642a57578..a47fb4360 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 @@ -100,18 +100,14 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar .setMessage("是否确认恢复?") .setPositiveButton(R.string.ok) { _, _ -> preferenceManager.sharedPreferences.edit() + // light mode .putInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) .putInt("colorAccent", getCompatColor(R.color.md_pink_800)) .putInt("colorBackground", getCompatColor(R.color.md_grey_100)) - .putInt( - "colorPrimaryNight", - getCompatColor(R.color.md_blue_grey_600) - ) - .putInt( - "colorAccentNight", - getCompatColor(R.color.md_deep_orange_800) - ) - .putInt("colorBackgroundNight", getCompatColor(R.color.md_grey_800)) + // dark mode + .putInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900)) + .putInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) + .putInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000)) .apply() App.INSTANCE.applyTheme() recreateActivities() diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index a29c34057..1e4d34a73 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -1,9 +1,8 @@ package io.legado.app.ui.config -import android.content.Intent +import android.content.Context import android.os.Build import android.os.Bundle -import android.provider.Settings import android.text.InputType import android.view.View import androidx.preference.EditTextPreference @@ -11,6 +10,7 @@ import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.help.IntentHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup @@ -21,12 +21,22 @@ import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.LogUtils import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + fun bindPreferenceSummaryToValue(preference: Preference?) { + preference?.apply { + onPreferenceChangeListener = this@WebDavConfigFragment + onPreferenceChange( + this, + context.getPrefString(key) + ) + } + } addPreferencesFromResource(R.xml.pref_config_web_dav) findPreference("web_dav_url")?.let { it.setOnBindEditTextListener { editText -> @@ -82,47 +92,49 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference return true } - private fun bindPreferenceSummaryToValue(preference: Preference?) { - preference?.apply { - onPreferenceChangeListener = this@WebDavConfigFragment - onPreferenceChange( - this, - context.getPrefString(key) - ) - } - } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - "web_dav_backup" -> Backup.backup() - "web_dav_restore" -> WebDavHelp.showRestoreDialog(requireContext()) - "import_old" -> importOld() + "web_dav_backup" -> PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { Backup.backup() } + .request() + "web_dav_restore" -> PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + WebDavHelp.showRestoreDialog(requireContext()) + } + .request() + "import_old" -> needInstallApps { importOld() } } return super.onPreferenceTreeClick(preference) } - private fun importOld() { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { - val haveInstallPermission = context!!.packageManager.canRequestPackageInstalls() - if (haveInstallPermission) { - startImport() - } else { //没有安装外部来源应用的权限 - alert(title = "开启权限提示") { - message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启" - yesButton { - val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES) - startActivityForResult(intent, 666) - } - noButton { - } - }.show().applyTint() + private fun needInstallApps(callback: () -> Unit) { + + fun canRequestPackageInstalls() :Boolean { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { + return requireContext().packageManager.canRequestPackageInstalls() } + return true + } + if (!canRequestPackageInstalls()) { + alert(title = "开启权限提示") { + message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启" + yesButton { + IntentHelp.toInstallUnknown(requireContext()) + } + noButton { + } + }.show().applyTint() } else { - startImport() + LogUtils.d("xxx","import old") + callback() } } - private fun startImport() { + private fun importOld() { alert(title = "导入") { message = "是否导入旧版本数据" yesButton { @@ -138,5 +150,4 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference } }.show().applyTint() } - } \ No newline at end of file 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 b2747f97e..b84538aa1 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 @@ -16,6 +16,7 @@ import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH +import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.book.source.manage.BookSourceActivity @@ -23,7 +24,9 @@ import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.utils.LogUtils +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.startActivity +import io.legado.app.utils.toast import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity @@ -79,12 +82,18 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { super.onPause() } - override fun onSharedPreferenceChanged( - sharedPreferences: SharedPreferences?, - key: String? - ) { + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { "isNightTheme" -> App.INSTANCE.applyDayNight() + "webService" -> { + if (requireContext().getPrefBoolean("webService")) { + WebService.start(requireContext()) + toast("正在启动服务\n具体信息查看通知栏") + }else{ + WebService.stop(requireContext()) + toast("服务已停止") + } + } "recordLog" -> LogUtils.upLevel() "downloadPath" -> BookHelp.upDownloadPath() } diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index c51be0b80..9642814de 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -7,11 +7,8 @@ import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.content.edit -import org.jetbrains.anko.connectivityManager import org.jetbrains.anko.defaultSharedPreferences -fun Context.isOnline() = connectivityManager.activeNetworkInfo?.isConnected == true - fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4786808e..123967b0a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -202,7 +202,7 @@ 替换规则名称 选择操作 全选 - 暗色主题 + 深色模式 启动页 开始下载 取消下载 diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 607359962..e96124472 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -57,7 +57,7 @@ app:iconSpaceReserved="false">