Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jul 13, 2023
1 parent ffbd744 commit 5b50ee6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.book.search.SearchScope
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
import io.legado.app.ui.file.HandleFileContract
import io.legado.app.ui.login.SourceLoginActivity
Expand Down Expand Up @@ -119,11 +121,13 @@ class BookSourceEditActivity :
setResult(Activity.RESULT_OK)
finish()
}

R.id.menu_debug_source -> viewModel.save(getSource()) { source ->
startActivity<BookSourceDebugActivity> {
putExtra("key", source.bookSourceUrl)
}
}

R.id.menu_clear_cookie -> viewModel.clearCookie(getSource().bookSourceUrl)
R.id.menu_auto_complete -> viewModel.autoComplete = !viewModel.autoComplete
R.id.menu_copy_source -> sendToClip(GSON.toJson(getSource()))
Expand All @@ -135,14 +139,22 @@ class BookSourceEditActivity :
getString(R.string.share_book_source),
ErrorCorrectionLevel.L
)

R.id.menu_help -> showHelp("ruleHelp")
R.id.menu_login -> viewModel.save(getSource()) { source ->
startActivity<SourceLoginActivity> {
putExtra("type", "bookSource")
putExtra("key", source.bookSourceUrl)
}
}

R.id.menu_set_source_variable -> setSourceVariable()
R.id.menu_search -> viewModel.save(getSource()) { source ->
startActivity<SearchActivity> {
putExtra("searchScope", SearchScope(source).toString())
}
}

}
return super.onCompatOptionsItemSelected(item)
}
Expand Down Expand Up @@ -387,20 +399,28 @@ class BookSourceEditActivity :
"bookList" -> searchRule.bookList = it.value
"name" -> searchRule.name =
viewModel.ruleComplete(it.value, searchRule.bookList)

"author" -> searchRule.author =
viewModel.ruleComplete(it.value, searchRule.bookList)

"kind" -> searchRule.kind =
viewModel.ruleComplete(it.value, searchRule.bookList)

"intro" -> searchRule.intro =
viewModel.ruleComplete(it.value, searchRule.bookList)

"updateTime" -> searchRule.updateTime =
viewModel.ruleComplete(it.value, searchRule.bookList)

"wordCount" -> searchRule.wordCount =
viewModel.ruleComplete(it.value, searchRule.bookList)

"lastChapter" -> searchRule.lastChapter =
viewModel.ruleComplete(it.value, searchRule.bookList)

"coverUrl" -> searchRule.coverUrl =
viewModel.ruleComplete(it.value, searchRule.bookList, 3)

"bookUrl" -> searchRule.bookUrl =
viewModel.ruleComplete(it.value, searchRule.bookList, 2)
}
Expand All @@ -411,20 +431,28 @@ class BookSourceEditActivity :
"bookList" -> exploreRule.bookList = it.value
"name" -> exploreRule.name =
viewModel.ruleComplete(it.value, exploreRule.bookList)

"author" -> exploreRule.author =
viewModel.ruleComplete(it.value, exploreRule.bookList)

"kind" -> exploreRule.kind =
viewModel.ruleComplete(it.value, exploreRule.bookList)

"intro" -> exploreRule.intro =
viewModel.ruleComplete(it.value, exploreRule.bookList)

"updateTime" -> exploreRule.updateTime =
viewModel.ruleComplete(it.value, exploreRule.bookList)

"wordCount" -> exploreRule.wordCount =
viewModel.ruleComplete(it.value, exploreRule.bookList)

"lastChapter" -> exploreRule.lastChapter =
viewModel.ruleComplete(it.value, exploreRule.bookList)

"coverUrl" -> exploreRule.coverUrl =
viewModel.ruleComplete(it.value, exploreRule.bookList, 3)

"bookUrl" -> exploreRule.bookUrl =
viewModel.ruleComplete(it.value, exploreRule.bookList, 2)
}
Expand All @@ -435,20 +463,28 @@ class BookSourceEditActivity :
"name" -> bookInfoRule.name = viewModel.ruleComplete(it.value, bookInfoRule.init)
"author" -> bookInfoRule.author =
viewModel.ruleComplete(it.value, bookInfoRule.init)

"kind" -> bookInfoRule.kind =
viewModel.ruleComplete(it.value, bookInfoRule.init)

"intro" -> bookInfoRule.intro =
viewModel.ruleComplete(it.value, bookInfoRule.init)

"updateTime" -> bookInfoRule.updateTime =
viewModel.ruleComplete(it.value, bookInfoRule.init)

"wordCount" -> bookInfoRule.wordCount =
viewModel.ruleComplete(it.value, bookInfoRule.init)

"lastChapter" -> bookInfoRule.lastChapter =
viewModel.ruleComplete(it.value, bookInfoRule.init)

"coverUrl" -> bookInfoRule.coverUrl =
viewModel.ruleComplete(it.value, bookInfoRule.init, 3)

"tocUrl" -> bookInfoRule.tocUrl =
viewModel.ruleComplete(it.value, bookInfoRule.init, 2)

"canReName" -> bookInfoRule.canReName = it.value
"downloadUrls" -> bookInfoRule.downloadUrls =
viewModel.ruleComplete(it.value, bookInfoRule.init)
Expand Down Expand Up @@ -493,12 +529,16 @@ class BookSourceEditActivity :
"reviewUrl" -> reviewRule.reviewUrl = it.value
"avatarRule" -> reviewRule.avatarRule =
viewModel.ruleComplete(it.value, reviewRule.reviewUrl, 3)

"contentRule" -> reviewRule.contentRule =
viewModel.ruleComplete(it.value, reviewRule.reviewUrl)

"postTimeRule" -> reviewRule.postTimeRule =
viewModel.ruleComplete(it.value, reviewRule.reviewUrl)

"reviewQuoteUrl" -> reviewRule.reviewQuoteUrl =
viewModel.ruleComplete(it.value, reviewRule.reviewUrl, 2)

"voteUpUrl" -> reviewRule.voteUpUrl = it.value
"voteDownUrl" -> reviewRule.voteDownUrl = it.value
"postReviewUrl" -> reviewRule.postReviewUrl = it.value
Expand Down Expand Up @@ -541,6 +581,7 @@ class BookSourceEditActivity :
SelectItem("插入分组", "addGroup")
)
}

else -> {
helpActions.add(
SelectItem("选择文件", "selectFile")
Expand Down Expand Up @@ -588,7 +629,8 @@ class BookSourceEditActivity :
private fun setSourceVariable() {
viewModel.save(getSource()) { source ->
launch {
val comment = source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取")
val comment =
source.getDisplayVariableComment("源变量可在js中通过source.getVariable()获取")
val variable = withContext(IO) { source.getVariable() }
showDialogFragment(
VariableDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
when (it.itemId) {
R.id.menu_edit -> callBack.editSource(source.bookSourceUrl)
R.id.menu_top -> callBack.toTop(source)
R.id.menu_search -> callBack.searchBook(source)
R.id.menu_login -> context.startActivity<SourceLoginActivity> {
putExtra("type", "bookSource")
putExtra("key", source.bookSourceUrl)
Expand All @@ -188,5 +189,6 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
fun editSource(sourceUrl: String)
fun toTop(source: BookSource)
fun deleteSource(source: BookSource)
fun searchBook(bookSource: BookSource)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.primaryColor
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.explore.ExploreShowActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.book.search.SearchScope
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.main.MainActivity
import io.legado.app.ui.main.MainFragmentInterface
Expand Down Expand Up @@ -214,6 +216,12 @@ class ExploreFragment() : VMBaseFragment<ExploreViewModel>(R.layout.fragment_exp
}
}

override fun searchBook(bookSource: BookSource) {
startActivity<SearchActivity> {
putExtra("searchScope", SearchScope(bookSource).toString())
}
}

fun compressExplore() {
if (!adapter.compressExplore()) {
if (AppConfig.isEInkMode) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/menu/explore_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
android:id="@+id/menu_login"
android:title="@string/login" />

<item
android:id="@+id/menu_search"
android:title="@string/search" />

<item
android:id="@+id/menu_refresh"
android:title="@string/refresh" />
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/menu/source_edit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="AlwaysShowAction">

<item
Expand All @@ -21,15 +21,20 @@
android:title="@string/login"
app:showAsAction="never" />

<item
android:id="@+id/menu_search"
android:title="@string/search"
app:showAsAction="never" />

<item
android:id="@+id/menu_clear_cookie"
android:title="@string/cookie"
app:showAsAction="never" />

<item
android:id="@+id/menu_auto_complete"
android:title="@string/auto_complete"
android:checkable="true"
android:title="@string/auto_complete"
app:showAsAction="never" />

<item
Expand Down

0 comments on commit 5b50ee6

Please sign in to comment.