close #740
This commit is contained in:
parent
407deb7fac
commit
567eae5fd2
|
@ -54,6 +54,7 @@ import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_QUERY
|
|||
import org.mariotaku.twidere.adapter.AccountsSpinnerAdapter
|
||||
import org.mariotaku.twidere.annotation.Referral
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_QUERY
|
||||
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.ACTION_NAVIGATION_BACK
|
||||
import org.mariotaku.twidere.constant.KeyboardShortcutConstants.CONTEXT_TAG_NAVIGATION
|
||||
import org.mariotaku.twidere.constant.newDocumentApiKey
|
||||
|
@ -145,6 +146,11 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
|||
}
|
||||
})
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
searchQuery.setText(intent.getStringExtra(EXTRA_QUERY))
|
||||
searchQuery.setSelection(searchQuery.length())
|
||||
}
|
||||
|
||||
supportLoaderManager.initLoader(0, null, this)
|
||||
|
||||
updateSubmitButton()
|
||||
|
@ -263,6 +269,7 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
|||
}
|
||||
SuggestionsAdapter.VIEW_TYPE_SAVED_SEARCH, SuggestionsAdapter.VIEW_TYPE_SEARCH_HISTORY -> {
|
||||
IntentUtils.openSearch(this, selectedAccountDetails?.key, item.title!!)
|
||||
setResult(RESULT_SEARCH_PERFORMED)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
@ -300,6 +307,7 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
|||
if (TextUtils.isEmpty(query)) return
|
||||
val details = selectedAccountDetails ?: return
|
||||
IntentUtils.openSearch(this, details.key, query)
|
||||
setResult(RESULT_SEARCH_PERFORMED)
|
||||
finish()
|
||||
}
|
||||
|
||||
|
@ -520,5 +528,7 @@ class QuickSearchBarActivity : BaseActivity(), OnClickListener, LoaderCallbacks<
|
|||
const val EXTRA_ZXING_SCAN_RESULT = "SCAN_RESULT"
|
||||
const val ZXING_SCAN_MODE_QR_CODE = "QR_CODE_MODE"
|
||||
const val REQUEST_SCAN_QR = 101
|
||||
|
||||
const val RESULT_SEARCH_PERFORMED = 2
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,14 +25,18 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import android.provider.SearchRecentSuggestions
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.text.TextUtils
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.widget.TextView
|
||||
import org.mariotaku.chameleon.Chameleon
|
||||
import org.mariotaku.twidere.Constants.*
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.activity.ComposeActivity
|
||||
import org.mariotaku.twidere.activity.LinkHandlerActivity
|
||||
import org.mariotaku.twidere.activity.QuickSearchBarActivity
|
||||
import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener
|
||||
import org.mariotaku.twidere.adapter.SupportTabsAdapter
|
||||
import org.mariotaku.twidere.extension.model.getAccountType
|
||||
|
@ -46,8 +50,11 @@ import org.mariotaku.twidere.model.util.AccountUtils
|
|||
import org.mariotaku.twidere.provider.RecentSearchProvider
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.SearchHistory
|
||||
import org.mariotaku.twidere.util.Analyzer
|
||||
import org.mariotaku.twidere.util.ThemeUtils
|
||||
|
||||
class SearchFragment : AbsToolbarTabPagesFragment(), RefreshScrollTopInterface, SupportFragmentCallback, SystemWindowsInsetsCallback, ControlBarOffsetListener, OnPageChangeListener, LinkHandlerActivity.HideUiOnScroll {
|
||||
class SearchFragment : AbsToolbarTabPagesFragment(), RefreshScrollTopInterface, SupportFragmentCallback,
|
||||
SystemWindowsInsetsCallback, ControlBarOffsetListener, OnPageChangeListener,
|
||||
LinkHandlerActivity.HideUiOnScroll {
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
@ -65,6 +72,37 @@ class SearchFragment : AbsToolbarTabPagesFragment(), RefreshScrollTopInterface,
|
|||
AccountUtils.findByAccountKey(am, it)
|
||||
}?.getAccountType(am)))
|
||||
}
|
||||
|
||||
val activity = this.activity
|
||||
if (activity is AppCompatActivity) {
|
||||
val actionBar = activity.supportActionBar
|
||||
val theme = Chameleon.getOverrideTheme(context, activity)
|
||||
if (actionBar != null) {
|
||||
actionBar.setCustomView(R.layout.layout_actionbar_search)
|
||||
actionBar.setDisplayShowTitleEnabled(false)
|
||||
actionBar.setDisplayShowCustomEnabled(true)
|
||||
val customView = actionBar.customView
|
||||
val editQuery = customView.findViewById(R.id.editQuery) as TextView
|
||||
editQuery.setTextColor(ThemeUtils.getColorDependent(theme.colorToolbar))
|
||||
editQuery.text = query
|
||||
customView.setOnClickListener {
|
||||
val searchIntent = Intent(context, QuickSearchBarActivity::class.java).apply {
|
||||
putExtra(EXTRA_QUERY, query)
|
||||
}
|
||||
startActivityForResult(searchIntent, REQUEST_OPEN_SEARCH)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_OPEN_SEARCH -> {
|
||||
if (resultCode == QuickSearchBarActivity.RESULT_SEARCH_PERFORMED) {
|
||||
activity?.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
|
@ -120,5 +158,8 @@ class SearchFragment : AbsToolbarTabPagesFragment(), RefreshScrollTopInterface,
|
|||
name = getString(R.string.search_type_users), icon = DrawableHolder.resource(R.drawable.ic_action_user))
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val REQUEST_OPEN_SEARCH = 101
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#60808080"/>
|
||||
<corners android:radius="4dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#30808080"/>
|
||||
<corners android:radius="4dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
|
@ -64,7 +64,9 @@
|
|||
android:background="@android:color/transparent"
|
||||
android:focusable="true"
|
||||
android:hint="@string/search_hint"
|
||||
android:inputType="text|textMultiLine">
|
||||
android:imeOptions="actionSearch"
|
||||
android:inputType="text|textImeMultiLine"
|
||||
android:maxLines="1">
|
||||
|
||||
<requestFocus/>
|
||||
</org.mariotaku.twidere.view.FixedEditText>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Twidere - Twitter client for Android
|
||||
~
|
||||
~ Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_edit_text_actionbar_search"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.mariotaku.twidere.view.FixedTextView
|
||||
android:id="@+id/editQuery"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="@dimen/element_spacing_small"
|
||||
android:layout_marginLeft="@dimen/element_spacing_normal"
|
||||
android:layout_marginRight="@dimen/element_spacing_normal"
|
||||
android:layout_marginTop="@dimen/element_spacing_small"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:minHeight="32dp"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
tools:text="Search query"/>
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue