From 4c72a094a557dd643969278f4258be9e827b6312 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 25 Sep 2019 14:22:06 +0800 Subject: [PATCH] up --- .../legado/app/lib/dialogs/AndroidDialogs.kt | 2 +- .../lib/theme/view/ATEAutoCompleteTextView.kt | 27 +++++++------------ .../book/source/manage/BookSourceActivity.kt | 24 +++++++++++++++++ .../book/source/manage/GroupManageDialog.kt | 9 +++---- .../ui/main/bookshelf/BookshelfFragment.kt | 5 ++-- .../app/ui/replacerule/GroupManageDialog.kt | 9 +++---- ...alog_edittext.xml => dialog_edit_text.xml} | 2 +- 7 files changed, 43 insertions(+), 35 deletions(-) rename app/src/main/res/layout/{dialog_edittext.xml => dialog_edit_text.xml} (90%) diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt b/app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt index 10716da17..0d40174f4 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt @@ -57,7 +57,7 @@ fun Context.alert( titleResource: Int? = null, messageResource: Int? = null, init: (AlertBuilder.() -> Unit)? = null -): AlertBuilder { +): AlertBuilder { return AndroidAlertBuilder(this).apply { if (titleResource != null) { this.titleResource = titleResource diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt index 855d82720..92e5ce110 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt @@ -2,36 +2,31 @@ package io.legado.app.lib.theme.view import android.content.Context import android.graphics.Rect -import android.os.Build import android.util.AttributeSet -import android.view.KeyEvent import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter import androidx.appcompat.widget.AppCompatAutoCompleteTextView import io.legado.app.R -import io.legado.app.lib.theme.Selector -import io.legado.app.lib.theme.ThemeStore +import io.legado.app.lib.theme.ATH import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_1line_text_and_del.view.* import org.jetbrains.anko.sdk27.listeners.onClick -class ATEAutoCompleteTextView(context: Context, attrs: AttributeSet) : - AppCompatAutoCompleteTextView(context, attrs) { +class ATEAutoCompleteTextView : AppCompatAutoCompleteTextView { + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) var delCallBack: DelCallBack? = null var showDel: Boolean = false init { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - backgroundTintList = Selector.colorBuild() - .setFocusedColor(ThemeStore.accentColor(context)) - .setDefaultColor(ThemeStore.textColorPrimary(context)) - .create() - } + ATH.applyAccentTint(this) } override fun enoughToFilter(): Boolean { @@ -41,11 +36,7 @@ class ATEAutoCompleteTextView(context: Context, attrs: AttributeSet) : override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) { super.onFocusChanged(focused, direction, previouslyFocusedRect) - performFiltering() - } - - fun performFiltering() { - performFiltering(text, KeyEvent.KEYCODE_UNKNOWN) + showDropDown() } fun setFilterValues(values: List, showDel: Boolean = false) { @@ -70,7 +61,7 @@ class ATEAutoCompleteTextView(context: Context, attrs: AttributeSet) : getItem(position)?.let { remove(it) delCallBack?.delete(it) - performFiltering() + showDropDown() } } return view 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 32510192b..0e75a00f0 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 @@ -19,14 +19,21 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.BookSource import io.legado.app.help.ItemTouchCallback import io.legado.app.help.storage.Restore +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.cancelButton +import io.legado.app.lib.dialogs.customView +import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor +import io.legado.app.lib.theme.view.ATEAutoCompleteTextView import io.legado.app.service.CheckSourceService import io.legado.app.ui.book.source.edit.SourceEditActivity import io.legado.app.ui.qrcode.QrCodeActivity +import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel import io.legado.app.utils.splitNotBlank import kotlinx.android.synthetic.main.activity_book_source.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity @@ -84,6 +91,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_check_book_source -> startService(Pair("data", adapter.getSelectionIds())) + R.id.menu_import_book_source_onLine -> showImportDialog() } if (item.groupId == R.id.source_group) { search_view.setQuery(item.title, true) @@ -153,6 +161,22 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } } + private fun showImportDialog() { + alert(titleResource = R.string.import_book_source_on_line) { + var editText: ATEAutoCompleteTextView? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view + } + } + okButton { + editText?.text + } + cancelButton() + }.show().applyTint() + } + + override fun onQueryTextChange(newText: String?): Boolean { newText?.let { initLiveDataBookSource(it) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index bf44c56a5..1cdcccd45 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -23,12 +23,11 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.lib.theme.ATH import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.requestInputMethod import io.legado.app.utils.splitNotBlank -import kotlinx.android.synthetic.main.dialog_edittext.view.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_book_group.view.tv_group import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -91,9 +90,8 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { alert(title = getString(R.string.add_group)) { var editText: EditText? = null customView { - layoutInflater.inflate(R.layout.dialog_edittext, null).apply { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - ATH.applyAccentTint(this) hint = "分组名称" } } @@ -114,9 +112,8 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { alert(title = getString(R.string.group_edit)) { var editText: EditText? = null customView { - layoutInflater.inflate(R.layout.dialog_edittext, null).apply { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - ATH.applyAccentTint(this) hint = "分组名称" setText(group) } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 8e8a581a0..60bccd39f 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -27,7 +27,7 @@ import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.bookshelf.BookshelfActivity import io.legado.app.utils.* -import kotlinx.android.synthetic.main.dialog_edittext.view.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity @@ -135,9 +135,8 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b alert(title = "新建分组") { var editText: EditText? = null customView { - layoutInflater.inflate(R.layout.dialog_edittext, null).apply { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - ATH.applyAccentTint(this) hint = "分组名称" } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt index e653947f8..49fb8c3e6 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt @@ -23,12 +23,11 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.lib.theme.ATH import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.requestInputMethod import io.legado.app.utils.splitNotBlank -import kotlinx.android.synthetic.main.dialog_edittext.view.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_book_group.view.tv_group import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -91,9 +90,8 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { alert(title = getString(R.string.add_group)) { var editText: EditText? = null customView { - layoutInflater.inflate(R.layout.dialog_edittext, null).apply { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - ATH.applyAccentTint(this) hint = "分组名称" } } @@ -114,9 +112,8 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { alert(title = getString(R.string.group_edit)) { var editText: EditText? = null customView { - layoutInflater.inflate(R.layout.dialog_edittext, null).apply { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - ATH.applyAccentTint(this) hint = "分组名称" setText(group) } diff --git a/app/src/main/res/layout/dialog_edittext.xml b/app/src/main/res/layout/dialog_edit_text.xml similarity index 90% rename from app/src/main/res/layout/dialog_edittext.xml rename to app/src/main/res/layout/dialog_edit_text.xml index 04dd314d0..2cf3da5dd 100644 --- a/app/src/main/res/layout/dialog_edittext.xml +++ b/app/src/main/res/layout/dialog_edit_text.xml @@ -7,7 +7,7 @@ android:layout_marginBottom="48dp" android:overScrollMode="ifContentScrolls"> -