From 26d267d534c34c6e8198d3bfefc21eb896795758 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 27 Oct 2020 19:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/AudioPlayService.kt | 3 ++- .../io/legado/app/service/BaseReadAloudService.kt | 3 ++- .../java/io/legado/app/service/CacheBookService.kt | 3 ++- .../java/io/legado/app/service/DownloadService.kt | 3 ++- .../app/ui/book/changesource/ChangeSourceViewModel.kt | 3 ++- .../java/io/legado/app/ui/widget/text/BadgeView.kt | 11 ----------- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index 1817da185..d629f2ba8 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -12,6 +12,7 @@ import android.media.MediaPlayer import android.net.Uri import android.os.Build import android.os.Handler +import android.os.Looper import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.PlaybackStateCompat import androidx.core.app.NotificationCompat @@ -50,7 +51,7 @@ class AudioPlayService : BaseService(), var timeMinute: Int = 0 } - private val handler = Handler() + private val handler = Handler(Looper.getMainLooper()) private lateinit var audioManager: AudioManager private var mFocusRequest: AudioFocusRequest? = null private var title: String = "" diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 2fd69506e..a51a7c3dd 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -9,6 +9,7 @@ import android.graphics.BitmapFactory import android.media.AudioFocusRequest import android.media.AudioManager import android.os.Handler +import android.os.Looper import android.support.v4.media.session.MediaSessionCompat import android.support.v4.media.session.PlaybackStateCompat import androidx.annotation.CallSuper @@ -40,7 +41,7 @@ abstract class BaseReadAloudService : BaseService(), } } - internal val handler = Handler() + internal val handler = Handler(Looper.getMainLooper()) private lateinit var audioManager: AudioManager private var mFocusRequest: AudioFocusRequest? = null private var broadcastReceiver: BroadcastReceiver? = null diff --git a/app/src/main/java/io/legado/app/service/CacheBookService.kt b/app/src/main/java/io/legado/app/service/CacheBookService.kt index ed00be50e..0ef8a2ea2 100644 --- a/app/src/main/java/io/legado/app/service/CacheBookService.kt +++ b/app/src/main/java/io/legado/app/service/CacheBookService.kt @@ -2,6 +2,7 @@ package io.legado.app.service import android.content.Intent import android.os.Handler +import android.os.Looper import androidx.core.app.NotificationCompat import io.legado.app.App import io.legado.app.R @@ -32,7 +33,7 @@ class CacheBookService : BaseService() { private var searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher() private var tasks = CompositeCoroutine() - private val handler = Handler() + private val handler = Handler(Looper.getMainLooper()) private var runnable: Runnable = Runnable { upDownload() } private val bookMap = ConcurrentHashMap() private val webBookMap = ConcurrentHashMap() diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index b9f4f82fe..fd21a079b 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -8,6 +8,7 @@ import android.content.IntentFilter import android.net.Uri import android.os.Build import android.os.Handler +import android.os.Looper import androidx.core.app.NotificationCompat import androidx.core.content.FileProvider import androidx.core.os.bundleOf @@ -28,7 +29,7 @@ class DownloadService : BaseService() { private val downloads = hashMapOf() private val completeDownloads = hashSetOf() - private val handler = Handler() + private val handler = Handler(Looper.getMainLooper()) private val runnable = Runnable { checkDownloadState() } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 0cbc1e2ee..979fbc8c7 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.book.changesource import android.app.Application import android.os.Bundle import android.os.Handler +import android.os.Looper import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.R @@ -27,7 +28,7 @@ import kotlin.math.min class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { private val threadCount = AppConfig.threadCount private var searchPool: ExecutorCoroutineDispatcher? = null - val handler = Handler() + val handler = Handler(Looper.getMainLooper()) val searchStateData = MutableLiveData() val searchBooksLiveData = MutableLiveData>() var name: String = "" diff --git a/app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt b/app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt index 353fa9de4..4f26a9ad2 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt @@ -12,7 +12,6 @@ import android.view.View import android.view.ViewGroup import android.widget.FrameLayout import android.widget.FrameLayout.LayoutParams -import android.widget.TabWidget import androidx.appcompat.widget.AppCompatTextView import io.legado.app.R import io.legado.app.lib.theme.accentColor @@ -186,16 +185,6 @@ class BadgeView @JvmOverloads constructor( incrementBadgeCount(-decrement) } - /** - * Attach the BadgeView to the TabWidget - * @param target the TabWidget to attach the BadgeView - * @param tabIndex index of the tab - */ - fun setTargetView(target: TabWidget, tabIndex: Int) { - val tabView = target.getChildTabViewAt(tabIndex) - setTargetView(tabView) - } - /** * Attach the BadgeView to the target view * @param target the view to attach the BadgeView