fixed search tab query requirement

This commit is contained in:
Mariotaku Lee 2017-10-04 14:37:12 +08:00
parent 73dc2385fb
commit bfc9282b18
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
5 changed files with 15 additions and 5 deletions

View File

@ -39,7 +39,6 @@ import android.view.*
import android.widget.*
import android.widget.AbsListView.MultiChoiceModeListener
import android.widget.AdapterView.OnItemClickListener
import com.bumptech.glide.Glide
import com.mobeta.android.dslv.SimpleDragSortCursorAdapter
import kotlinx.android.synthetic.main.dialog_custom_tab_editor.*
import kotlinx.android.synthetic.main.layout_draggable_list_with_empty_view.*
@ -372,9 +371,7 @@ class CustomTabsFragment : BaseFragment(), LoaderCallbacks<Cursor?>, MultiChoice
// Make sure immutable configuration skipped in edit mode
if (editMode && !extraConf.isMutable) return@forEach
if (!conf.applyExtraConfigurationTo(tab, extraConf)) {
val titleString = extraConf.title.createString(context)
Toast.makeText(context, getString(R.string.message_tab_field_is_required,
titleString), Toast.LENGTH_SHORT).show()
extraConf.showRequiredError()
return@setOnClickListener
}
}

View File

@ -26,6 +26,8 @@ import android.support.annotation.StringRes
import android.support.v4.app.Fragment
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import org.mariotaku.twidere.R
import org.mariotaku.twidere.annotation.CustomTabType
import org.mariotaku.twidere.annotation.TabAccountFlags
import org.mariotaku.twidere.fragment.CustomTabsFragment.TabEditorDialogFragment
@ -138,6 +140,12 @@ abstract class TabConfiguration {
open fun onAccountSelectionChanged(account: AccountDetails?) {
}
open fun showRequiredError() {
val titleString = title.createString(context)
Toast.makeText(context, context.getString(R.string.message_tab_field_is_required,
titleString), Toast.LENGTH_SHORT).show()
}
}
companion object {

View File

@ -38,6 +38,10 @@ class StringExtraConfiguration(key: String, title: StringHolder, private val def
editText.setText(def)
}
override fun showRequiredError() {
editText.error = context.getString(R.string.hint_error_field_required)
}
fun maxLines(maxLines: Int): StringExtraConfiguration {
this.maxLines = maxLines
return this

View File

@ -53,7 +53,7 @@ class SearchTabConfiguration : TabConfiguration() {
val arguments = tab.arguments as TextQueryArguments
when (extraConf.key) {
EXTRA_QUERY -> {
val query = (extraConf as StringExtraConfiguration).value ?: return false
val query = (extraConf as StringExtraConfiguration).value?.takeIf(String::isNotBlank) ?: return false
arguments.query = query
}
}

View File

@ -455,6 +455,7 @@
<string name="hint_accounts_dashboard_title">Accounts dashboard</string>
<string name="hint_conversation_name">Conversation name</string>
<string name="hint_empty_filters_subscriptions">No subscriptions</string>
<string name="hint_error_field_required">Required</string>
<string name="hint_error_message_no_content">No content</string>
<string name="hint_message_select_user">Search users</string>
<string name="hint_no_account">No account</string>