From 16d3a60c7fe82e5da0ab87b3b628d575cc32a95d Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 30 Mar 2021 10:02:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=83=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/audio/AudioPlayActivity.kt | 28 ++--- .../app/ui/book/info/BookInfoActivity.kt | 106 ++++++++---------- .../ui/book/info/edit/BookInfoEditActivity.kt | 30 ++--- .../app/ui/book/read/ReadBookActivity.kt | 17 +-- .../source/debug/BookSourceDebugActivity.kt | 25 ++--- .../app/ui/book/toc/TocActivityResult.kt | 26 +++++ .../app/ui/filepicker/FilePickerActivity.kt | 30 ++--- .../app/ui/rss/article/RssSortActivity.kt | 58 ++++------ .../rss/source/edit/RssSourceEditActivity.kt | 25 ++--- .../io/legado/app/utils/ActivityExtensions.kt | 9 -- .../main/res/layout/activity_rss_artivles.xml | 2 +- 11 files changed, 150 insertions(+), 206 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/toc/TocActivityResult.kt diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index a210aeb99..084180ca6 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -1,7 +1,6 @@ package io.legado.app.ui.audio import android.app.Activity -import android.content.Intent import android.graphics.drawable.Drawable import android.icu.text.SimpleDateFormat import android.os.Build @@ -25,7 +24,7 @@ import io.legado.app.help.ImageLoader import io.legado.app.lib.dialogs.alert import io.legado.app.service.help.AudioPlay import io.legado.app.ui.book.changesource.ChangeSourceDialog -import io.legado.app.ui.book.toc.ChapterListActivity +import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* @@ -42,7 +41,6 @@ class AudioPlayActivity : override val viewModel: AudioPlayViewModel by viewModels() - private var requestCodeChapter = 8461 private var adjustProgress = false private val progressTimeFormat by lazy { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { @@ -51,6 +49,13 @@ class AudioPlayActivity : java.text.SimpleDateFormat("mm:ss", Locale.getDefault()) } } + private val tocActivityResult = registerForActivityResult(TocActivityResult()) { + it?.let { + if (it.first != AudioPlay.durChapterIndex) { + AudioPlay.skipTo(this, it.first) + } + } + } override fun getViewBinding(): ActivityAudioPlayBinding { return ActivityAudioPlayBinding.inflate(layoutInflater) @@ -107,9 +112,7 @@ class AudioPlayActivity : }) binding.ivChapter.setOnClickListener { AudioPlay.book?.let { - startActivityForResult(requestCodeChapter) { - putExtra("bookUrl", it.bookUrl) - } + tocActivityResult.launch(it.bookUrl) } } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { @@ -183,19 +186,6 @@ class AudioPlayActivity : } } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (resultCode == Activity.RESULT_OK) { - when (requestCode) { - requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let { - if (it != AudioPlay.durChapterIndex) { - AudioPlay.skipTo(this, it) - } - } - } - } - } - override fun observeLiveBus() { observeEvent(EventBus.MEDIA_BUTTON) { if (it) { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 4d665fc32..5d06dc899 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -1,7 +1,6 @@ package io.legado.app.ui.book.info import android.annotation.SuppressLint -import android.app.Activity import android.content.Intent import android.graphics.drawable.Drawable import android.os.Bundle @@ -9,6 +8,7 @@ import android.view.Menu import android.view.MenuItem import android.widget.CheckBox import android.widget.LinearLayout +import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import com.bumptech.glide.RequestBuilder import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions @@ -35,7 +35,7 @@ import io.legado.app.ui.book.info.edit.BookInfoEditActivity import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity -import io.legado.app.ui.book.toc.ChapterListActivity +import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.utils.* @@ -47,9 +47,37 @@ class BookInfoActivity : ChangeSourceDialog.CallBack, ChangeCoverDialog.CallBack { - private val requestCodeChapterList = 568 - private val requestCodeInfoEdit = 562 - private val requestCodeRead = 432 + private val tocActivityResult = registerForActivityResult(TocActivityResult()) { + it?.let { + viewModel.bookData.value?.let { book -> + if (book.durChapterIndex != it.first) { + book.durChapterIndex = it.first + book.durChapterPos = it.second + } + startReadActivity(book) + } + } ?: let { + if (!viewModel.inBookshelf) { + viewModel.delBook() + } + } + } + private val readBookResult = registerForActivityResult( + ActivityResultContracts.StartActivityForResult() + ) { + if (it.resultCode == RESULT_OK) { + viewModel.inBookshelf = true + upTvBookshelf() + } + } + private val infoEditResult = registerForActivityResult( + ActivityResultContracts.StartActivityForResult() + ) { + if (it.resultCode == RESULT_OK) { + viewModel.upEditBook() + } + } + override val viewModel: BookInfoViewModel by viewModels() @@ -82,11 +110,10 @@ class BookInfoActivity : R.id.menu_edit -> { if (viewModel.inBookshelf) { viewModel.bookData.value?.let { - startActivityForResult( - requestCodeInfoEdit - ) { - putExtra("bookUrl", it.bookUrl) - } + infoEditResult.launch( + Intent(this, BookInfoEditActivity::class.java) + .putExtra("bookUrl", it.bookUrl) + ) } } else { toastOnUi(R.string.after_add_bookshelf) @@ -303,11 +330,7 @@ class BookInfoActivity : return } viewModel.bookData.value?.let { - startActivityForResult( - requestCodeChapterList - ) { - putExtra("bookUrl", it.bookUrl) - } + tocActivityResult.launch(it.bookUrl) } } @@ -327,19 +350,17 @@ class BookInfoActivity : private fun startReadActivity(book: Book) { when (book.type) { - BookType.audio -> startActivityForResult( - requestCodeRead - ) { - putExtra("bookUrl", book.bookUrl) - putExtra("inBookshelf", viewModel.inBookshelf) - } - else -> startActivityForResult( - requestCodeRead - ) { - putExtra("bookUrl", book.bookUrl) - putExtra("inBookshelf", viewModel.inBookshelf) - putExtra("key", IntentDataHelp.putData(book)) - } + BookType.audio -> readBookResult.launch( + Intent(this, AudioPlayActivity::class.java) + .putExtra("bookUrl", book.bookUrl) + .putExtra("inBookshelf", viewModel.inBookshelf) + ) + else -> readBookResult.launch( + Intent(this, ReadBookActivity::class.java) + .putExtra("bookUrl", book.bookUrl) + .putExtra("inBookshelf", viewModel.inBookshelf) + .putExtra("key", IntentDataHelp.putData(book)) + ) } } @@ -381,33 +402,4 @@ class BookInfoActivity : } } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - when (requestCode) { - requestCodeInfoEdit -> - if (resultCode == Activity.RESULT_OK) { - viewModel.upEditBook() - } - requestCodeChapterList -> - if (resultCode == Activity.RESULT_OK) { - viewModel.bookData.value?.let { - data?.getIntExtra("index", it.durChapterIndex)?.let { index -> - if (it.durChapterIndex != index) { - it.durChapterIndex = index - it.durChapterPos = 0 - } - startReadActivity(it) - } - } - } else { - if (!viewModel.inBookshelf) { - viewModel.delBook() - } - } - requestCodeRead -> if (resultCode == Activity.RESULT_OK) { - viewModel.inBookshelf = true - upTvBookshelf() - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 202e62df0..366296bc8 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -1,11 +1,11 @@ package io.legado.app.ui.book.info.edit import android.app.Activity -import android.content.Intent import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.documentfile.provider.DocumentFile import io.legado.app.R @@ -22,7 +22,12 @@ class BookInfoEditActivity : VMBaseActivity(), ChangeCoverDialog.CallBack { - private val resultSelectCover = 132 + private val selectCoverResult = + registerForActivityResult(ActivityResultContracts.GetContent()) { + it?.let { uri -> + coverChangeTo(uri) + } + } override val viewModel: BookInfoEditViewModel by viewModels() @@ -60,7 +65,7 @@ class BookInfoEditActivity : } } tvSelectCover.setOnClickListener { - selectImage() + selectCoverResult.launch("image/*") } tvRefreshCover.setOnClickListener { viewModel.book?.customCoverUrl = tieCoverUrl.text?.toString() @@ -96,13 +101,6 @@ class BookInfoEditActivity : } } - private fun selectImage() { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.addCategory(Intent.CATEGORY_OPENABLE) - intent.type = "image/*" - startActivityForResult(intent, resultSelectCover) - } - override fun coverChangeTo(coverUrl: String) { viewModel.book?.customCoverUrl = coverUrl binding.tieCoverUrl.setText(coverUrl) @@ -144,16 +142,4 @@ class BookInfoEditActivity : } } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - when (requestCode) { - resultSelectCover -> { - if (resultCode == Activity.RESULT_OK) { - data?.data?.let { uri -> - coverChangeTo(uri) - } - } - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 5fbd4d55f..ab673593d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -46,7 +46,7 @@ import io.legado.app.ui.book.read.page.entities.PageDirection import io.legado.app.ui.book.read.page.provider.TextPageFactory import io.legado.app.ui.book.searchContent.SearchContentActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity -import io.legado.app.ui.book.toc.ChapterListActivity +import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.login.SourceLogin import io.legado.app.ui.replace.ReplaceRuleActivity import io.legado.app.ui.replace.edit.ReplaceEditActivity @@ -71,13 +71,10 @@ class ReadBookActivity : ReadBookBaseActivity(), ColorPickerDialogListener { private val tocActivity = - registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - it.data?.let { data -> - data.getIntExtra("index", ReadBook.durChapterIndex).let { index -> - if (index != ReadBook.durChapterIndex) { - val chapterPos = data.getIntExtra("chapterPos", 0) - viewModel.openChapter(index, chapterPos) - } + registerForActivityResult(TocActivityResult()) { + it?.let { + if (it.first != ReadBook.durChapterIndex) { + viewModel.openChapter(it.first, it.second) } } } @@ -731,9 +728,7 @@ class ReadBookActivity : ReadBookBaseActivity(), */ override fun openChapterList() { ReadBook.book?.let { - tocActivity.launch(Intent(this, ChapterListActivity::class.java).apply { - putExtra("bookUrl", it.bookUrl) - }) + tocActivity.launch(it.bookUrl) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index fb11c3cfd..76e0b81f6 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.source.debug -import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -12,10 +11,8 @@ import io.legado.app.databinding.ActivitySourceDebugBinding import io.legado.app.help.LocalConfig import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor -import io.legado.app.ui.qrcode.QrCodeActivity +import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.widget.dialog.TextDialog -import io.legado.app.utils.startActivityForResult - import io.legado.app.utils.toastOnUi import kotlinx.coroutines.launch @@ -26,7 +23,11 @@ class BookSourceDebugActivity : VMBaseActivity { - startActivityForResult(qrRequestCode) + qrCodeResult.launch(null) } R.id.menu_help -> showHelp() } @@ -108,16 +109,4 @@ class BookSourceDebugActivity : VMBaseActivity { - if (resultCode == RESULT_OK) { - data?.getStringExtra("result")?.let { - startSearch(it) - } - } - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/toc/TocActivityResult.kt b/app/src/main/java/io/legado/app/ui/book/toc/TocActivityResult.kt new file mode 100644 index 000000000..1e8f688de --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/toc/TocActivityResult.kt @@ -0,0 +1,26 @@ +package io.legado.app.ui.book.toc + +import android.app.Activity.RESULT_OK +import android.content.Context +import android.content.Intent +import androidx.activity.result.contract.ActivityResultContract + +class TocActivityResult : ActivityResultContract?>() { + + override fun createIntent(context: Context, input: String?): Intent { + return Intent(context, ChapterListActivity::class.java) + .putExtra("bookUrl", input) + } + + override fun parseResult(resultCode: Int, intent: Intent?): Pair? { + if (resultCode == RESULT_OK) { + intent?.let { + return Pair( + it.getIntExtra("index", 0), + it.getIntExtra("chapterPos", 0) + ) + } + } + return null + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt index 865bf5372..f66a6494c 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerActivity.kt @@ -1,13 +1,11 @@ package io.legado.app.ui.filepicker -import android.content.Context import android.content.Intent import android.net.Uri import android.os.Build import android.os.Bundle -import androidx.activity.result.contract.ActivityResultContract +import android.webkit.MimeTypeMap import androidx.activity.result.contract.ActivityResultContracts -import androidx.annotation.CallSuper import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.constant.Theme @@ -28,7 +26,7 @@ class FilePickerActivity : onResult(Intent().setData(it)) } - private val selectDoc = registerForActivityResult(GetContent()) { + private val selectDoc = registerForActivityResult(ActivityResultContracts.OpenDocument()) { onResult(Intent().setData(it)) } @@ -65,7 +63,7 @@ class FilePickerActivity : } else { selectDoc.launch(typesOfExtensions(allowExtensions)) } - 2 -> if (mode == FilePicker.DIRECTORY) { + 1 -> if (mode == FilePicker.DIRECTORY) { checkPermissions { FilePickerDialog.show( supportFragmentManager, @@ -117,7 +115,14 @@ class FilePickerActivity : when (it) { "*" -> types.add("*/*") "txt", "xml" -> types.add("text/*") - else -> types.add("application/$it") + else -> { + val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension("json") + if (mime == null) { + types.add("application/octet-stream") + } else { + types.add(mime) + } + } } } } @@ -129,17 +134,4 @@ class FilePickerActivity : finish() } - class GetContent : ActivityResultContract, Uri>() { - @CallSuper - override fun createIntent(context: Context, input: Array): Intent { - return Intent(Intent.ACTION_GET_CONTENT) - .addCategory(Intent.CATEGORY_OPENABLE) - .putExtra(Intent.EXTRA_MIME_TYPES, input) - .setType("*/*") - } - - override fun parseResult(resultCode: Int, intent: Intent?): Uri? { - return if (intent == null || resultCode != RESULT_OK) null else intent.data - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt index 46d3480d7..f8356ae0c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt @@ -1,38 +1,47 @@ package io.legado.app.ui.rss.article -import android.app.Activity import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentManager -import androidx.fragment.app.FragmentStatePagerAdapter +import androidx.viewpager2.adapter.FragmentStateAdapter +import com.google.android.material.tabs.TabLayoutMediator import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityRssArtivlesBinding import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.utils.gone -import io.legado.app.utils.startActivityForResult import io.legado.app.utils.visible class RssSortActivity : VMBaseActivity() { override val viewModel: RssSortViewModel by viewModels() - private val editSource = 12319 private val fragments = linkedMapOf() private lateinit var adapter: TabFragmentPageAdapter + private val upSourceResult = registerForActivityResult( + ActivityResultContracts.StartActivityForResult() + ) { + if (it.resultCode == RESULT_OK) { + viewModel.initData(intent) { + upFragments() + } + } + } override fun getViewBinding(): ActivityRssArtivlesBinding { return ActivityRssArtivlesBinding.inflate(layoutInflater) } override fun onActivityCreated(savedInstanceState: Bundle?) { - adapter = TabFragmentPageAdapter(supportFragmentManager) - binding.tabLayout.setupWithViewPager(binding.viewPager) + adapter = TabFragmentPageAdapter() binding.viewPager.adapter = adapter + TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position -> + tab.text = fragments.keys.elementAt(position) + } viewModel.titleLiveData.observe(this, { binding.titleBar.title = it }) @@ -49,9 +58,10 @@ class RssSortActivity : VMBaseActivity viewModel.rssSource?.sourceUrl?.let { - startActivityForResult(editSource) { - putExtra("data", it) - } + upSourceResult.launch( + Intent(this, RssSourceEditActivity::class.java) + .putExtra("data", it) + ) } R.id.menu_clear -> { viewModel.url?.let { @@ -79,35 +89,15 @@ class RssSortActivity : VMBaseActivity if (resultCode == Activity.RESULT_OK) { - viewModel.initData(intent) { - upFragments() - } - } - } - } - - private inner class TabFragmentPageAdapter(fm: FragmentManager) : - FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { - - override fun getItemPosition(`object`: Any): Int { - return POSITION_NONE - } + private inner class TabFragmentPageAdapter : FragmentStateAdapter(this) { - override fun getPageTitle(position: Int): CharSequence { - return fragments.keys.elementAt(position) + override fun getItemCount(): Int { + return fragments.size } - override fun getItem(position: Int): Fragment { + override fun createFragment(position: Int): Fragment { return fragments.values.elementAt(position) } - - override fun getCount(): Int { - return fragments.size - } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index c70525047..6b3f2f0de 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -1,7 +1,6 @@ package io.legado.app.ui.rss.source.edit import android.app.Activity -import android.content.Intent import android.graphics.Rect import android.os.Bundle import android.view.Gravity @@ -20,7 +19,7 @@ import io.legado.app.help.LocalConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH -import io.legado.app.ui.qrcode.QrCodeActivity +import io.legado.app.ui.qrcode.QrCodeResult import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.dialog.TextDialog @@ -34,9 +33,15 @@ class RssSourceEditActivity : private var mSoftKeyboardTool: PopupWindow? = null private var mIsSoftKeyBoardShowing = false - private val qrRequestCode = 101 private val adapter = RssSourceEditAdapter() private val sourceEntities: ArrayList = ArrayList() + private val qrCodeResult = registerForActivityResult(QrCodeResult()) { + it?.let { + viewModel.importSource(it) { source: RssSource -> + upRecyclerView(source) + } + } + } override fun getViewBinding(): ActivityRssSourceEditBinding { return ActivityRssSourceEditBinding.inflate(layoutInflater) @@ -107,7 +112,7 @@ class RssSourceEditActivity : } } R.id.menu_copy_source -> sendToClip(GSON.toJson(getRssSource())) - R.id.menu_qr_code_camera -> startActivityForResult(qrRequestCode) + R.id.menu_qr_code_camera -> qrCodeResult.launch(null) R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_share_str -> share(GSON.toJson(getRssSource())) R.id.menu_share_qr -> shareWithQr( @@ -269,16 +274,4 @@ class RssSourceEditActivity : } } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - when (requestCode) { - qrRequestCode -> if (resultCode == RESULT_OK) { - data?.getStringExtra("result")?.let { - viewModel.importSource(it) { source: RssSource -> - upRecyclerView(source) - } - } - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt index 37a46f74c..72840c097 100644 --- a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt @@ -1,20 +1,11 @@ package io.legado.app.utils import android.app.Activity -import android.content.Intent import android.os.Build import android.util.DisplayMetrics import android.view.WindowInsets import android.view.WindowMetrics - -inline fun Activity.startActivityForResult( - requestCode: Int, - configIntent: Intent.() -> Unit = {} -) { - startActivityForResult(Intent(this, A::class.java).apply(configIntent), requestCode) -} - fun Activity.getSize(): DisplayMetrics { val displayMetrics = DisplayMetrics() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { diff --git a/app/src/main/res/layout/activity_rss_artivles.xml b/app/src/main/res/layout/activity_rss_artivles.xml index 50e503a9e..981ce1b6d 100644 --- a/app/src/main/res/layout/activity_rss_artivles.xml +++ b/app/src/main/res/layout/activity_rss_artivles.xml @@ -16,7 +16,7 @@ android:layout_height="wrap_content" app:tabMode="scrollable" /> -