fix: search
This commit is contained in:
@@ -55,6 +55,26 @@ class MainActivity : AppCompatActivity() {
|
||||
Snackbar.make(refresh,it,Snackbar.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
search = findViewById(R.id.search)
|
||||
shortAnnotationDuration = resources.getInteger(android.R.integer.config_shortAnimTime)
|
||||
|
||||
search.setOnEditorActionListener { content, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
viewModel.uiState.value.nowSearchText.value = content.text.toString()
|
||||
viewModel.fetchPostByRefresh()
|
||||
}
|
||||
return@setOnEditorActionListener false
|
||||
}
|
||||
|
||||
//接收来自PicActivity的快捷搜索Tag
|
||||
val stringExtra = intent.getStringExtra("searchTag")
|
||||
if (stringExtra!=null){
|
||||
viewModel.uiState.value.nowSearchText.value = stringExtra
|
||||
}
|
||||
viewModel.uiState.value.nowSearchText.observe(this){
|
||||
search.setText(it)
|
||||
}
|
||||
|
||||
// val appbar = findViewById<AppBarLayout>(R.id.appbar)
|
||||
// val nowHeight = appbar.layoutParams.height
|
||||
// appbar.layoutParams.height = (application as YandViewApplication).statusBarHeight()+nowHeight
|
||||
@@ -85,17 +105,6 @@ class MainActivity : AppCompatActivity() {
|
||||
it.setHomeAsUpIndicator(R.drawable.ic_baseline_menu_24)
|
||||
}
|
||||
|
||||
search = findViewById(R.id.search)
|
||||
shortAnnotationDuration = resources.getInteger(android.R.integer.config_shortAnimTime)
|
||||
|
||||
search.setOnEditorActionListener { _, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
viewModel.fetchNewPostBySearch(search.text.toString())
|
||||
}
|
||||
return@setOnEditorActionListener false
|
||||
}
|
||||
|
||||
|
||||
|
||||
//侧边栏
|
||||
val sp = getSharedPreferences("username", 0)
|
||||
@@ -196,7 +205,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
R.id.search_nav -> {
|
||||
if (viewModel.uiState.value.showSearchBar) {
|
||||
viewModel.fetchNewPostBySearch(search.text.toString())
|
||||
viewModel.fetchPostByRefresh()
|
||||
hideIm()
|
||||
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class MainViewModel(private val repository: PostRepository,context: Context):Vie
|
||||
|
||||
try {
|
||||
val postList = repository.fetchPostData(
|
||||
_uiState.value.nowSearchText,
|
||||
_uiState.value.nowSearchText.value,
|
||||
_uiState.value.isSafe,
|
||||
_uiState.value.nowPage
|
||||
)
|
||||
@@ -100,13 +100,6 @@ class MainViewModel(private val repository: PostRepository,context: Context):Vie
|
||||
|
||||
}
|
||||
|
||||
fun fetchNewPostBySearch(target:String){
|
||||
_uiState.update {
|
||||
it.copy(nowSearchText = target)
|
||||
}
|
||||
|
||||
fetchNewPost()
|
||||
}
|
||||
|
||||
fun fetchPostByRefresh(){
|
||||
_uiState.update {
|
||||
|
||||
@@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
data class UiState(
|
||||
var showSearchBar:Boolean = false,
|
||||
val isRefreshing:MutableLiveData<Boolean> = MutableLiveData(),
|
||||
val nowSearchText:String = "",
|
||||
var nowSearchText:MutableLiveData<String> = MutableLiveData(""),
|
||||
val nowSourceName: String? = null,
|
||||
val isSafe: Boolean = true, //安全模式
|
||||
val nowPage:Int = 1,
|
||||
|
||||
Reference in New Issue
Block a user