fetch太慢去除历史提交记录
This commit is contained in:
commit
51c16a1efc
1294 files changed
+194322
No files matched your search
@@ -0,0 +1,106 @@
|
||||
package io.legado.app.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.KeyEvent
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.help.AppConfig
|
||||
import io.legado.app.help.LifecycleHelp
|
||||
import io.legado.app.model.AudioPlay
|
||||
import io.legado.app.model.ReadAloud
|
||||
import io.legado.app.model.ReadBook
|
||||
import io.legado.app.service.AudioPlayService
|
||||
import io.legado.app.service.BaseReadAloudService
|
||||
import io.legado.app.ui.book.audio.AudioPlayActivity
|
||||
import io.legado.app.ui.book.read.ReadBookActivity
|
||||
import io.legado.app.utils.getPrefBoolean
|
||||
import io.legado.app.utils.postEvent
|
||||
|
||||
|
||||
/**
|
||||
* Created by GKF on 2018/1/6.
|
||||
* 监听耳机键
|
||||
*/
|
||||
class MediaButtonReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (handleIntent(context, intent) && isOrderedBroadcast) {
|
||||
abortBroadcast()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun handleIntent(context: Context, intent: Intent): Boolean {
|
||||
val intentAction = intent.action
|
||||
if (Intent.ACTION_MEDIA_BUTTON == intentAction) {
|
||||
val keyEvent = intent.getParcelableExtra<KeyEvent>(Intent.EXTRA_KEY_EVENT)
|
||||
?: return false
|
||||
val keycode: Int = keyEvent.keyCode
|
||||
val action: Int = keyEvent.action
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
AppLog.put("mediaButton $action")
|
||||
when (keycode) {
|
||||
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> {
|
||||
if (context.getPrefBoolean("mediaButtonPerNext", false)) {
|
||||
ReadBook.moveToPrevChapter(true)
|
||||
} else {
|
||||
ReadAloud.prevParagraph(context)
|
||||
}
|
||||
}
|
||||
KeyEvent.KEYCODE_MEDIA_NEXT -> {
|
||||
if (context.getPrefBoolean("mediaButtonPerNext", false)) {
|
||||
ReadBook.moveToNextChapter(true)
|
||||
} else {
|
||||
ReadAloud.nextParagraph(context)
|
||||
}
|
||||
}
|
||||
else -> readAloud(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun readAloud(context: Context, isMediaKey: Boolean = true) {
|
||||
when {
|
||||
BaseReadAloudService.isRun -> {
|
||||
if (BaseReadAloudService.isPlay()) {
|
||||
ReadAloud.pause(context)
|
||||
AudioPlay.pause(context)
|
||||
} else {
|
||||
ReadAloud.resume(context)
|
||||
AudioPlay.resume(context)
|
||||
}
|
||||
}
|
||||
AudioPlayService.isRun -> {
|
||||
if (AudioPlayService.pause) {
|
||||
AudioPlay.resume(context)
|
||||
} else {
|
||||
AudioPlay.pause(context)
|
||||
}
|
||||
}
|
||||
LifecycleHelp.isExistActivity(ReadBookActivity::class.java) ->
|
||||
postEvent(EventBus.MEDIA_BUTTON, true)
|
||||
LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) ->
|
||||
postEvent(EventBus.MEDIA_BUTTON, true)
|
||||
else -> if (AppConfig.mediaButtonOnExit || LifecycleHelp.activitySize() > 0 || !isMediaKey) {
|
||||
AppLog.put("readAloud start Service")
|
||||
if (ReadBook.book != null) {
|
||||
ReadBook.readAloud()
|
||||
} else {
|
||||
appDb.bookDao.lastReadBook?.let {
|
||||
ReadBook.resetData(it)
|
||||
ReadBook.curTextChapter ?: ReadBook.loadContent(false)
|
||||
ReadBook.readAloud()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package io.legado.app.receiver
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import io.legado.app.ui.book.search.SearchActivity
|
||||
import io.legado.app.ui.main.MainActivity
|
||||
import io.legado.app.utils.startActivity
|
||||
import splitties.init.appCtx
|
||||
|
||||
class SharedReceiverActivity : AppCompatActivity() {
|
||||
|
||||
private val receivingType = "text/plain"
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
initIntent()
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun initIntent() {
|
||||
when {
|
||||
intent.action == Intent.ACTION_SEND && intent.type == receivingType -> {
|
||||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
||||
dispose(it)
|
||||
}
|
||||
}
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& intent.action == Intent.ACTION_PROCESS_TEXT
|
||||
&& intent.type == receivingType -> {
|
||||
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let {
|
||||
dispose(it)
|
||||
}
|
||||
}
|
||||
intent.getStringExtra("action") == "readAloud" -> {
|
||||
MediaButtonReceiver.readAloud(appCtx, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun dispose(text: String) {
|
||||
if (text.isBlank()) {
|
||||
return
|
||||
}
|
||||
val urls = text.split("\\s".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
val result = StringBuilder()
|
||||
for (url in urls) {
|
||||
if (url.matches("http.+".toRegex()))
|
||||
result.append("\n").append(url.trim { it <= ' ' })
|
||||
}
|
||||
if (result.length > 1) {
|
||||
startActivity<MainActivity>()
|
||||
} else {
|
||||
SearchActivity.start(this, text)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.legado.app.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.BatteryManager
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.utils.postEvent
|
||||
|
||||
|
||||
class TimeBatteryReceiver : BroadcastReceiver() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun register(context: Context): TimeBatteryReceiver {
|
||||
val receiver = TimeBatteryReceiver()
|
||||
val filter = IntentFilter()
|
||||
filter.addAction(Intent.ACTION_TIME_TICK)
|
||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED)
|
||||
context.registerReceiver(receiver, filter)
|
||||
return receiver
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
when (intent?.action) {
|
||||
Intent.ACTION_TIME_TICK -> {
|
||||
postEvent(EventBus.TIME_CHANGED, "")
|
||||
}
|
||||
Intent.ACTION_BATTERY_CHANGED -> {
|
||||
val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
|
||||
postEvent(EventBus.BATTERY_CHANGED, level)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user