diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt index 640461978..067ae5a4b 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt @@ -1,13 +1,13 @@ package io.legado.app.ui.book.changesource +import android.content.DialogInterface import android.os.Bundle -import android.view.Menu -import android.view.MenuItem -import android.view.View -import android.view.ViewGroup +import android.view.* +import android.view.KeyEvent.ACTION_UP import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar import androidx.core.os.bundleOf +import androidx.core.view.isVisible import androidx.fragment.app.viewModels import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -35,6 +35,7 @@ import kotlinx.coroutines.launch class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_change_source), Toolbar.OnMenuItemClickListener, + DialogInterface.OnKeyListener, ChangeChapterSourceAdapter.CallBack, ChangeChapterTocAdapter.Callback { @@ -78,6 +79,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c override fun onStart() { super.onStart() setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) + dialog?.setOnKeyListener(this) } override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { @@ -325,6 +327,18 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c } } + override fun onKey(dialog: DialogInterface?, keyCode: Int, event: KeyEvent?): Boolean { + when (keyCode) { + KeyEvent.KEYCODE_BACK -> event?.let { + if (it.action == ACTION_UP && binding.clToc.isVisible) { + binding.clToc.gone() + return true + } + } + } + return false + } + interface CallBack { val oldBook: Book? fun changeTo(source: BookSource, book: Book) diff --git a/app/src/main/res/layout/dialog_chapter_change_source.xml b/app/src/main/res/layout/dialog_chapter_change_source.xml index ac448641f..45f5efe81 100644 --- a/app/src/main/res/layout/dialog_chapter_change_source.xml +++ b/app/src/main/res/layout/dialog_chapter_change_source.xml @@ -42,13 +42,23 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/tool_bar"> - + android:layout_height="wrap_content" + android:background="@color/background" + android:elevation="4dp" + app:layout_constraintTop_toTopOf="parent"> + + + + + app:layout_constraintTop_toBottomOf="@+id/fl_hide_toc" />