commit mod webServer

pull/54/head
ca1e 5 years ago
parent 4b22cbc437
commit 5083eeaa06
  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. 4
      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 name = "legado"
def version = "0." + releaseTime() def version = "3." + releaseTime()
def gitCommits = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim()) def gitCommits = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim())
android { android {

@ -1,9 +1,14 @@
## 更新日志 ## 更新日志
* 旧版数据导入教程: * 旧版数据导入教程:
* 先在旧版阅读2.19.xxxxxx进行备份,再在新版阅读3.0的【我的】中,点击【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。
* 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。 * 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。
**2019/12/09**
* [add]其他设置->清理缓存
* [mod]调整深色模式配色,预适配Android10
* [mod]启用web服务
**2019/12/03** **2019/12/03**
* from Celeter1、调试log修改 2、增加书源字符串分享(RSS未包含) 3、增加导出选中的源(包含书源、RSS、替换规则) * from Celeter1、调试log修改 2、增加书源字符串分享(RSS未包含) 3、增加导出选中的源(包含书源、RSS、替换规则)
* 一键缓存 * 一键缓存

@ -70,13 +70,13 @@ class App : Application() {
if (isNightTheme) { if (isNightTheme) {
ThemeStore.editTheme(this) ThemeStore.editTheme(this)
.primaryColor( .primaryColor(
getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_blue_grey_600)) getPrefInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900))
) )
.accentColor( .accentColor(
getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800)) getPrefInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800))
) )
.backgroundColor( .backgroundColor(
getPrefInt("colorBackgroundNight", getCompatColor(R.color.md_grey_800)) getPrefInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000))
) )
.apply() .apply()
} else { } else {
@ -101,7 +101,6 @@ class App : Application() {
initNightTheme() initNightTheme()
} }
private fun initNightTheme() { private fun initNightTheme() {
val targetMode = if (isNightTheme) { val targetMode = if (isNightTheme) {
AppCompatDelegate.MODE_NIGHT_YES AppCompatDelegate.MODE_NIGHT_YES
@ -111,7 +110,6 @@ class App : Application() {
AppCompatDelegate.setDefaultNightMode(targetMode) AppCompatDelegate.setDefaultNightMode(targetMode)
} }
/** /**
* 创建通知ID * 创建通知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? { inline fun <reified T> servicePendingIntent(context: Context, action: String): PendingIntent? {
return PendingIntent.getService( return PendingIntent.getService(
context, context,

@ -36,10 +36,12 @@ object Permissions {
const val WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE" const val WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE"
object Group { object Group {
val CALENDAR = arrayOf(READ_CALENDAR, WRITE_CALENDAR) val STORAGE = arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE)
val CAMERA = arrayOf(Permissions.CAMERA) val CAMERA = arrayOf(Permissions.CAMERA)
val CALENDAR = arrayOf(READ_CALENDAR, WRITE_CALENDAR)
val CONTACTS = arrayOf(READ_CONTACTS, WRITE_CONTACTS, GET_ACCOUNTS) val CONTACTS = arrayOf(READ_CONTACTS, WRITE_CONTACTS, GET_ACCOUNTS)
val LOCATION = arrayOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION) val LOCATION = arrayOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION)
@ -65,8 +67,5 @@ object Permissions {
RECEIVE_WAP_PUSH, RECEIVE_WAP_PUSH,
RECEIVE_MMS RECEIVE_MMS
) )
val STORAGE = arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE)
} }
} }

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

@ -19,7 +19,7 @@ class ConfigActivity : VMBaseActivity<ConfigViewModel>(R.layout.activity_config)
when (viewModel.configType) { when (viewModel.configType) {
ConfigViewModel.TYPE_CONFIG -> { ConfigViewModel.TYPE_CONFIG -> {
title_bar.title = getString(R.string.setting) title_bar.title = getString(R.string.other_setting)
val fTag = "configFragment" val fTag = "configFragment"
var configFragment = supportFragmentManager.findFragmentByTag(fTag) var configFragment = supportFragmentManager.findFragmentByTag(fTag)
if (configFragment == null) configFragment = ConfigFragment() if (configFragment == null) configFragment = ConfigFragment()

@ -100,18 +100,14 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
.setMessage("是否确认恢复?") .setMessage("是否确认恢复?")
.setPositiveButton(R.string.ok) { _, _ -> .setPositiveButton(R.string.ok) { _, _ ->
preferenceManager.sharedPreferences.edit() preferenceManager.sharedPreferences.edit()
// light mode
.putInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) .putInt("colorPrimary", getCompatColor(R.color.md_light_blue_500))
.putInt("colorAccent", getCompatColor(R.color.md_pink_800)) .putInt("colorAccent", getCompatColor(R.color.md_pink_800))
.putInt("colorBackground", getCompatColor(R.color.md_grey_100)) .putInt("colorBackground", getCompatColor(R.color.md_grey_100))
.putInt( // dark mode
"colorPrimaryNight", .putInt("colorPrimaryNight", getCompatColor(R.color.md_grey_900))
getCompatColor(R.color.md_blue_grey_600) .putInt("colorAccentNight", getCompatColor(R.color.md_deep_orange_800))
) .putInt("colorBackgroundNight", getCompatColor(R.color.md_black_1000))
.putInt(
"colorAccentNight",
getCompatColor(R.color.md_deep_orange_800)
)
.putInt("colorBackgroundNight", getCompatColor(R.color.md_grey_800))
.apply() .apply()
App.INSTANCE.applyTheme() App.INSTANCE.applyTheme()
recreateActivities() recreateActivities()

@ -1,9 +1,8 @@
package io.legado.app.ui.config package io.legado.app.ui.config
import android.content.Intent import android.content.Context
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.provider.Settings
import android.text.InputType import android.text.InputType
import android.view.View import android.view.View
import androidx.preference.EditTextPreference import androidx.preference.EditTextPreference
@ -11,6 +10,7 @@ import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.help.IntentHelp
import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.help.storage.Backup 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.dialogs.yesButton
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.LogUtils
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { 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) addPreferencesFromResource(R.xml.pref_config_web_dav)
findPreference<EditTextPreference>("web_dav_url")?.let { findPreference<EditTextPreference>("web_dav_url")?.let {
it.setOnBindEditTextListener { editText -> it.setOnBindEditTextListener { editText ->
@ -82,47 +92,49 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
return true return true
} }
private fun bindPreferenceSummaryToValue(preference: Preference?) {
preference?.apply {
onPreferenceChangeListener = this@WebDavConfigFragment
onPreferenceChange(
this,
context.getPrefString(key)
)
}
}
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
"web_dav_backup" -> Backup.backup() "web_dav_backup" -> PermissionsCompat.Builder(this)
"web_dav_restore" -> WebDavHelp.showRestoreDialog(requireContext()) .addPermissions(*Permissions.Group.STORAGE)
"import_old" -> importOld() .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) return super.onPreferenceTreeClick(preference)
} }
private fun importOld() { private fun needInstallApps(callback: () -> Unit) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
val haveInstallPermission = context!!.packageManager.canRequestPackageInstalls() fun canRequestPackageInstalls() :Boolean {
if (haveInstallPermission) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
startImport() return requireContext().packageManager.canRequestPackageInstalls()
} else { //没有安装外部来源应用的权限
alert(title = "开启权限提示") {
message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启"
yesButton {
val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
startActivityForResult(intent, 666)
}
noButton {
}
}.show().applyTint()
} }
return true
}
if (!canRequestPackageInstalls()) {
alert(title = "开启权限提示") {
message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启"
yesButton {
IntentHelp.toInstallUnknown(requireContext())
}
noButton {
}
}.show().applyTint()
} else { } else {
startImport() LogUtils.d("xxx","import old")
callback()
} }
} }
private fun startImport() { private fun importOld() {
alert(title = "导入") { alert(title = "导入") {
message = "是否导入旧版本数据" message = "是否导入旧版本数据"
yesButton { yesButton {
@ -138,5 +150,4 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference
} }
}.show().applyTint() }.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.Backup
import io.legado.app.help.storage.WebDavHelp import io.legado.app.help.storage.WebDavHelp
import io.legado.app.lib.theme.ATH 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.AboutActivity
import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.about.DonateActivity
import io.legado.app.ui.book.source.manage.BookSourceActivity 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.config.ConfigViewModel
import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity
import io.legado.app.utils.LogUtils import io.legado.app.utils.LogUtils
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.toast
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
@ -79,12 +82,18 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
super.onPause() super.onPause()
} }
override fun onSharedPreferenceChanged( override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
sharedPreferences: SharedPreferences?,
key: String?
) {
when (key) { when (key) {
"isNightTheme" -> App.INSTANCE.applyDayNight() "isNightTheme" -> App.INSTANCE.applyDayNight()
"webService" -> {
if (requireContext().getPrefBoolean("webService")) {
WebService.start(requireContext())
toast("正在启动服务\n具体信息查看通知栏")
}else{
WebService.stop(requireContext())
toast("服务已停止")
}
}
"recordLog" -> LogUtils.upLevel() "recordLog" -> LogUtils.upLevel()
"downloadPath" -> BookHelp.upDownloadPath() "downloadPath" -> BookHelp.upDownloadPath()
} }

@ -7,10 +7,8 @@ import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.edit import androidx.core.content.edit
import org.jetbrains.anko.connectivityManager
import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.defaultSharedPreferences
import java.util.function.BinaryOperator
fun Context.isOnline() = connectivityManager.activeNetworkInfo?.isConnected == true
fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = fun Context.getPrefBoolean(key: String, defValue: Boolean = false) =
defaultSharedPreferences.getBoolean(key, defValue) defaultSharedPreferences.getBoolean(key, defValue)

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

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

Loading…
Cancel
Save