Merge pull request #54 from ca1e/master

补充webserver,适配深色模式
pull/55/head
kunfei 5 years ago committed by GitHub
commit 302a561ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/build.gradle
  2. 7
      app/src/main/assets/updateLog.md
  3. 6
      app/src/main/java/io/legado/app/App.kt
  4. 11
      app/src/main/java/io/legado/app/help/IntentHelp.kt
  5. 7
      app/src/main/java/io/legado/app/help/permission/Permissions.kt
  6. 1
      app/src/main/java/io/legado/app/service/WebService.kt
  7. 2
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  8. 14
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  9. 77
      app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt
  10. 17
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  11. 3
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  12. 2
      app/src/main/res/values/strings.xml
  13. 4
      app/src/main/res/xml/pref_config_theme.xml

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

@ -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、替换规则)
* 一键缓存

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

@ -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 <reified T> servicePendingIntent(context: Context, action: String): PendingIntent? {
return PendingIntent.getService(
context,

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

@ -34,7 +34,6 @@ class WebService : BaseService() {
context.startService(intent)
}
}
}
private var httpServer: HttpServer? = null

@ -19,7 +19,7 @@ class ConfigActivity : VMBaseActivity<ConfigViewModel>(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()

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

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

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

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

@ -202,7 +202,7 @@
<string name="replace_rule_summary">替换规则名称</string>
<string name="select_action">选择操作</string>
<string name="select_all">全选</string>
<string name="dark_theme">暗色主题</string>
<string name="dark_theme">深色模式</string>
<string name="welcome">启动页</string>
<string name="download_start">开始下载</string>
<string name="download_cancel">取消下载</string>

@ -57,7 +57,7 @@
app:iconSpaceReserved="false">
<io.legado.app.lib.theme.prefs.ATEColorPreference
android:defaultValue="@color/md_blue_grey_600"
android:defaultValue="@color/md_grey_900"
android:key="colorPrimaryNight"
android:summary="夜间,主色调"
android:title="主色调"
@ -73,7 +73,7 @@
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEColorPreference
android:defaultValue="@color/md_grey_800"
android:defaultValue="@color/md_black_1000"
android:key="colorBackgroundNight"
android:summary="夜间,背景色"
android:title="背景色"

Loading…
Cancel
Save