Skip to content

Commit

Permalink
Refine search suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
5ec1cff committed Oct 6, 2023
1 parent 742bbf7 commit f8d5e44
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class SearchFragment : BaseFragment() {
op is Operation.History && !viewModel.searchAtForum
when (op) {
is Operation.History -> {
holder.binding.icon.setImageResource(R.drawable.ic_history)
val kw = op.entry.keyword
holder.binding.title.text = kw
holder.binding.root.setOnClickListener {
Expand All @@ -291,20 +292,26 @@ class SearchFragment : BaseFragment() {
}

is Operation.RemoveHistories -> {
holder.binding.icon.setImageResource(R.drawable.ic_delete)
holder.binding.title.text = "清空历史记录"
holder.binding.root.setOnClickListener {
removeAllHistoriesDialog()
}
}

is Operation.GoToForum -> {
holder.binding.icon.setImageResource(R.drawable.ic_idea)
holder.binding.title.text = "进吧:${op.name}"
holder.binding.root.setOnClickListener {
findNavController().navigate(ThreadFragmentDirections.goToForum(op.name))
}
}

is Operation.GoToThread -> {
if (op.fromClip)
holder.binding.icon.setImageResource(R.drawable.ic_copy)
else
holder.binding.icon.setImageResource(R.drawable.ic_idea)
holder.binding.title.text =
if (op.fromClip) "打开剪切板的帖子:${op.id.tid}" else
"进帖:${op.id.tid}"
Expand All @@ -314,27 +321,32 @@ class SearchFragment : BaseFragment() {
}

is Operation.SearchForum -> {
holder.binding.icon.setImageResource(R.drawable.ic_idea)
holder.binding.icon.setImageResource(R.drawable.ic_idea)
holder.binding.title.text = "搜吧:${op.name}"
holder.binding.root.setOnClickListener {
performSearch(op.name, 0)
}
}

is Operation.SearchPosts -> {
holder.binding.icon.setImageResource(R.drawable.ic_idea)
holder.binding.title.text = "搜帖:${op.keyword}"
holder.binding.root.setOnClickListener {
performSearch(op.keyword, 1)
}
}

is Operation.SearchUsers -> {
holder.binding.icon.setImageResource(R.drawable.ic_idea)
holder.binding.title.text = "搜人:${op.keyword}"
holder.binding.root.setOnClickListener {
performSearch(op.keyword, 2)
}
}

is Operation.GoToUser -> {
holder.binding.icon.setImageResource(R.drawable.ic_idea)
holder.binding.title.text = "查看用户:${op.uidOrPortrait}"
holder.binding.root.setOnClickListener {
findNavController().navigate(MobileNavigationDirections.showProfile(op.uidOrPortrait))
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_idea.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector android:height="24dp"
android:tint="#000000"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@android:color/white"
android:pathData="M9,21c0,0.55 0.45,1 1,1h4c0.55,0 1,-0.45 1,-1v-1H9V21zM12,2C8.14,2 5,5.14 5,9c0,2.38 1.19,4.47 3,5.74V17c0,0.55 0.45,1 1,1h6c0.55,0 1,-0.45 1,-1v-2.26c1.81,-1.27 3,-3.36 3,-5.74C19,5.14 15.86,2 12,2zM14,13.7V16h-4v-2.3C8.48,12.63 7,11.53 7,9c0,-2.76 2.24,-5 5,-5s5,2.24 5,5C17,11.49 15.49,12.65 14,13.7z" />
</vector>
4 changes: 3 additions & 1 deletion app/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/search_suggestions" />
android:id="@+id/search_suggestions"
android:requiresFadingEdge="vertical"
app:fitsSystemWindowsInsets="bottom" />
</io.github.a13e300.ro_tieba.view.MySearchView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
14 changes: 13 additions & 1 deletion app/src/main/res/layout/search_suggestion_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@
android:clickable="true"
android:focusable="true">

<TextView
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_margin="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/title"
android:id="@+id/icon" />

<TextView
android:layout_marginVertical="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/icon"
app:layout_constraintEnd_toStartOf="@id/input_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:id="@+id/title" />

<Button
Expand All @@ -29,6 +40,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/title"
app:layout_constraintEnd_toEndOf="parent"
android:background="?selectableItemBackground"
app:icon="@drawable/ic_input"
android:id="@+id/input_button" />
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit f8d5e44

Please sign in to comment.