From e351cafdf3980ddd94306d3c0d26dc73de7c8c2e Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 9 Oct 2020 09:45:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B9=A6=E6=BA=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 8 +- .../java/io/legado/app/constant/EventBus.kt | 6 +- .../main/java/io/legado/app/help/AppConfig.kt | 3 - .../legado/app/service/CheckSourceService.kt | 22 ++-- .../book/source/manage/BookSourceActivity.kt | 106 +++++++----------- .../main/res/layout/activity_book_source.xml | 1 + app/src/main/res/values/pref_key_value.xml | 1 - app/src/main/res/xml/pref_config_other.xml | 7 -- 8 files changed, 53 insertions(+), 101 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8a062f2f2..476e545bc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -121,15 +121,15 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" //fireBase - implementation 'com.google.firebase:firebase-analytics-ktx:17.5.0' - implementation 'com.google.firebase:firebase-crashlytics-ktx:17.2.1' + implementation 'com.google.firebase:firebase-analytics-ktx:17.6.0' + implementation 'com.google.firebase:firebase-crashlytics-ktx:17.2.2' //androidX - implementation 'androidx.core:core-ktx:1.3.1' + implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.media:media:1.2.0' implementation 'androidx.preference:preference:1.1.1' - implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.2' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'com.google.android.material:material:1.2.1' diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 1ef2e9b44..dd00d8cee 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -20,8 +20,6 @@ object EventBus { const val WEB_SERVICE = "webService" const val UP_DOWNLOAD = "upDownload" const val SAVE_CONTENT = "saveContent" - const val CHECK_INIT = "checkInit" - const val CHECK_UP_PROGRESS = "checkProgress" - const val CHECK_UP_PROGRESS_STRING = "checkProgressTxt" - const val CHECK_DONE = "checkDone" + const val CHECK_SOURCE = "checkSource" + const val CHECK_SOURCE_DONE = "checkSourceDone" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index ac32d830a..e2538e902 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -58,9 +58,6 @@ object AppConfig { App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) } - val backgroundVerification: Boolean - get() = App.INSTANCE.getPrefBoolean(R.string.pk_background_verification, true) - val autoRefreshBook: Boolean get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index b8349df45..bf9372e7a 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -9,7 +9,6 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.IntentAction import io.legado.app.help.AppConfig -import io.legado.app.help.AppConfig.backgroundVerification import io.legado.app.help.IntentHelp import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.service.help.CheckSource @@ -45,9 +44,7 @@ class CheckSourceService : BaseService() { override fun onCreate() { super.onCreate() - if (backgroundVerification) { - updateNotification(0, getString(R.string.start)) - } + updateNotification(0, getString(R.string.start)) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -64,7 +61,7 @@ class CheckSourceService : BaseService() { super.onDestroy() tasks.clear() searchPool.close() - postEvent(EventBus.CHECK_DONE, 0) + postEvent(EventBus.CHECK_SOURCE_DONE, 0) } private fun check(ids: List) { @@ -78,7 +75,6 @@ class CheckSourceService : BaseService() { allIds.addAll(ids) processIndex = 0 threadCount = min(allIds.size, threadCount) - postEvent(EventBus.CHECK_INIT, allIds.size) updateNotification(0, getString(R.string.progress_show, "", 0, allIds.size)) for (i in 0 until threadCount) { check() @@ -113,15 +109,10 @@ class CheckSourceService : BaseService() { synchronized(this) { check() checkedIds.add(sourceUrl) - if (backgroundVerification) { - updateNotification( - checkedIds.size, - getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) - ) - } else { - postEvent(EventBus.CHECK_UP_PROGRESS, checkedIds.size) - postEvent(EventBus.CHECK_UP_PROGRESS_STRING, getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size)) - } + updateNotification( + checkedIds.size, + getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) + ) if (processIndex >= allIds.size + threadCount - 1) { stopSelf() } @@ -134,6 +125,7 @@ class CheckSourceService : BaseService() { private fun updateNotification(state: Int, msg: String) { notificationBuilder.setContentText(msg) notificationBuilder.setProgress(allIds.size, state, false) + postEvent(EventBus.CHECK_SOURCE, msg) startForeground(112202, notificationBuilder.build()) } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 1f64f0791..221d6142b 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -5,8 +5,9 @@ import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent import android.os.Bundle -import android.util.DisplayMetrics -import android.view.* +import android.view.Menu +import android.view.MenuItem +import android.view.SubMenu import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.core.content.FileProvider @@ -15,15 +16,14 @@ import androidx.lifecycle.LiveData import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager +import com.google.android.material.snackbar.Snackbar import io.legado.app.App import io.legado.app.BuildConfig import io.legado.app.R -import io.legado.app.base.BaseDialogFragment import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppPattern import io.legado.app.constant.EventBus import io.legado.app.data.entities.BookSource -import io.legado.app.help.AppConfig import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH @@ -42,9 +42,7 @@ import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* -import kotlinx.android.synthetic.main.dialog_progressbar_view.* import kotlinx.android.synthetic.main.view_search.* -import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -68,6 +66,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private var groupMenu: SubMenu? = null private var sort = 0 private var sortAscending = 0 + private var snackBar: Snackbar? = null override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() @@ -100,11 +99,20 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity val intent = Intent(Intent.ACTION_SEND) val file = FileUtils.createFileWithReplace("$filesDir/shareBookSource.json") file.writeText(json) - val fileUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileProvider", file) + val fileUri = FileProvider.getUriForFile( + this, + BuildConfig.APPLICATION_ID + ".fileProvider", + file + ) intent.type = "text/*" intent.putExtra(Intent.EXTRA_STREAM, fileUri) intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION - startActivity(Intent.createChooser(intent, getString(R.string.share_selected_source))) + startActivity( + Intent.createChooser( + intent, + getString(R.string.share_selected_source) + ) + ) } catch (e: ActivityNotFoundException) { e.printStackTrace() } @@ -196,19 +204,19 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } } bookSourceLiveDate?.observe(this, { data -> - val sourceList = when (sortAscending % 2){ + val sourceList = when (sortAscending % 2) { 0 -> when (sort) { 1 -> data.sortedBy { it.weight } 2 -> data.sortedBy { it.bookSourceName } 3 -> data.sortedBy { it.bookSourceUrl } - 4 -> data.sortedByDescending { it.lastUpdateTime} + 4 -> data.sortedByDescending { it.lastUpdateTime } else -> data } else -> when (sort) { 1 -> data.sortedByDescending { it.weight } 2 -> data.sortedByDescending { it.bookSourceName } 3 -> data.sortedByDescending { it.bookSourceUrl } - 4 -> data.sortedBy { it.lastUpdateTime} + 4 -> data.sortedBy { it.lastUpdateTime } else -> data.reversed() } } @@ -218,11 +226,11 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity upCountView() }) } - private fun sortCheck (sortId: Int){ - if (sort == sortId){ - sortAscending +=1 - } - else{ + + private fun sortCheck(sortId: Int) { + if (sort == sortId) { + sortAscending += 1 + } else { sortAscending = 0 sort = sortId } @@ -299,13 +307,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity CheckSource.keyword = it } } - if (!AppConfig.backgroundVerification) { - val bundle = Bundle() - bundle.putInt("maxProgress", adapter.getSelection().size) - CheckSourceDialog().apply { - arguments = bundle - }.show(supportFragmentManager, "CheckDialog") - } CheckSource.start(this@BookSourceActivity, adapter.getSelection()) } noButton { } @@ -396,8 +397,21 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } override fun observeLiveBus() { - observeEvent(EventBus.CHECK_DONE) { - groups.map { group-> + observeEvent(EventBus.CHECK_SOURCE) { msg -> + snackBar?.setText(msg) ?: let { + snackBar = Snackbar + .make(root_view, msg, Snackbar.LENGTH_INDEFINITE) + .setAction(R.string.cancel) { + CheckSource.stop(this) + }.apply { show() } + } + } + observeEvent(EventBus.CHECK_SOURCE_DONE) { + snackBar?.let { + it.dismiss() + snackBar = null + } + groups.map { group -> if (group.contains("失效")) { search_view.setQuery("失效", true) toast("发现有失效书源,已为您自动筛选!") @@ -501,46 +515,4 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } } - class CheckSourceDialog : BaseDialogFragment() { - override fun onStart() { - super.onStart() - val dm = DisplayMetrics() - activity?.windowManager?.defaultDisplay?.getMetrics(dm) - dialog?.window?.setLayout( - (dm.widthPixels * 0.9).toInt(), - (dm.heightPixels * 0.14).toInt() - ) - dialog?.setCancelable(false) - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return inflater.inflate(R.layout.dialog_progressbar_view, container) - } - - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { - arguments?.let { bundle -> - val maxProgress = bundle.getInt("maxProgress") - ck_progress_text.text = getString(R.string.progress_show, "", 0, maxProgress) - ck_progress.max = maxProgress - observeEvent(EventBus.CHECK_UP_PROGRESS) { progress-> - ck_progress.progress = progress - } - observeEvent(EventBus.CHECK_UP_PROGRESS_STRING) { - ck_progress_text.text = it - } - observeEvent(EventBus.CHECK_DONE) { - dismiss() - } - tv_footer_left.onClick { - CheckSource.stop(requireContext()).apply { - dismiss() - } - } - } - } - } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_book_source.xml b/app/src/main/res/layout/activity_book_source.xml index 090be7b00..470138de2 100644 --- a/app/src/main/res/layout/activity_book_source.xml +++ b/app/src/main/res/layout/activity_book_source.xml @@ -1,6 +1,7 @@ diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml index 44522ad70..ef9ddd5be 100644 --- a/app/src/main/res/values/pref_key_value.xml +++ b/app/src/main/res/values/pref_key_value.xml @@ -1,6 +1,5 @@ - background_verification auto_refresh list_screen_direction full_screen diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 0bc8ae32c..0e3930546 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -51,13 +51,6 @@ app:iconSpaceReserved="false" app:layout="@layout/view_preference_category"> - -