Skip to content

Commit f2c13e1

Browse files
committed
Added reorder tip card from pinned assistants
1 parent 72ec33c commit f2c13e1

13 files changed

Lines changed: 141 additions & 0 deletions

File tree

app/src/main/java/com/wstxda/switchai/ui/adapter/AssistantSelectorAdapter.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ import androidx.recyclerview.widget.ListAdapter
66
import androidx.recyclerview.widget.RecyclerView
77
import com.wstxda.switchai.databinding.ListItemAssistantCategoryBinding
88
import com.wstxda.switchai.databinding.ListItemAssistantViewBinding
9+
import com.wstxda.switchai.databinding.ListItemReorderTipBinding
910
import com.wstxda.switchai.ui.viewholder.AssistantSelectorCategoryViewHolder
1011
import com.wstxda.switchai.ui.viewholder.AssistantSelectorItemViewHolder
12+
import com.wstxda.switchai.ui.viewholder.ReorderTipViewHolder
1113
import com.wstxda.switchai.utils.Constants
1214
import java.util.Collections
1315

1416
class AssistantSelectorAdapter(
1517
private val onAssistantClicked: (String) -> Unit,
1618
private val onPinClicked: (String) -> Unit,
19+
private val onDismissTipClicked: () -> Unit,
1720
) : ListAdapter<AssistantSelectorRecyclerView, RecyclerView.ViewHolder>(
1821
AssistantSelectorDiffCallback()
1922
) {
2023

2124
override fun getItemViewType(position: Int) = when (getItem(position)) {
2225
is AssistantSelectorRecyclerView.CategoryHeader -> Constants.VIEW_TYPE_CATEGORY_HEADER
2326
is AssistantSelectorRecyclerView.AssistantSelector -> Constants.VIEW_TYPE_ASSISTANT_ITEM
27+
is AssistantSelectorRecyclerView.ReorderTip -> Constants.VIEW_TYPE_REORDER_TIP
2428
}
2529

2630
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
@@ -38,6 +42,13 @@ class AssistantSelectorAdapter(
3842
AssistantSelectorItemViewHolder(binding)
3943
}
4044

45+
Constants.VIEW_TYPE_REORDER_TIP -> {
46+
val binding = ListItemReorderTipBinding.inflate(
47+
LayoutInflater.from(parent.context), parent, false
48+
)
49+
ReorderTipViewHolder(binding)
50+
}
51+
4152
else -> throw IllegalArgumentException("Unknown viewType $viewType")
4253
}
4354

@@ -50,6 +61,10 @@ class AssistantSelectorAdapter(
5061
is AssistantSelectorRecyclerView.AssistantSelector -> (holder as AssistantSelectorItemViewHolder).bind(
5162
item, onAssistantClicked, onPinClicked
5263
)
64+
65+
is AssistantSelectorRecyclerView.ReorderTip -> (holder as ReorderTipViewHolder).bind(
66+
onDismissTipClicked
67+
)
5368
}
5469
}
5570

app/src/main/java/com/wstxda/switchai/ui/adapter/AssistantSelectorDiffCallback.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class AssistantSelectorDiffCallback : DiffUtil.ItemCallback<AssistantSelectorRec
1010

1111
oldItem is AssistantSelectorRecyclerView.CategoryHeader && newItem is AssistantSelectorRecyclerView.CategoryHeader -> oldItem.title == newItem.title
1212

13+
oldItem is AssistantSelectorRecyclerView.ReorderTip && newItem is AssistantSelectorRecyclerView.ReorderTip -> true
14+
1315
else -> false
1416
}
1517

app/src/main/java/com/wstxda/switchai/ui/adapter/AssistantSelectorRecyclerView.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import com.wstxda.switchai.data.AssistantItem
55
sealed interface AssistantSelectorRecyclerView {
66
data class CategoryHeader(val title: String) : AssistantSelectorRecyclerView
77
data class AssistantSelector(val assistantItem: AssistantItem) : AssistantSelectorRecyclerView
8+
object ReorderTip : AssistantSelectorRecyclerView
89
}

app/src/main/java/com/wstxda/switchai/ui/component/AssistantSelectorBottomSheet.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class AssistantSelectorBottomSheet : BaseBottomSheet<FragmentAssistantDialogBind
6868
dismiss()
6969
}, onPinClicked = { assistantKey ->
7070
viewModel.togglePinAssistant(assistantKey)
71+
}, onDismissTipClicked = {
72+
viewModel.dismissReorderTip()
7173
})
7274
binding.assistantsRecyclerView.apply {
7375
layoutManager = LinearLayoutManager(context)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.wstxda.switchai.ui.viewholder
2+
3+
import androidx.recyclerview.widget.RecyclerView
4+
import com.wstxda.switchai.databinding.ListItemReorderTipBinding
5+
6+
class ReorderTipViewHolder(
7+
private val binding: ListItemReorderTipBinding
8+
) : RecyclerView.ViewHolder(binding.root) {
9+
10+
fun bind(onDismissClicked: () -> Unit) {
11+
binding.dismissButton.setOnClickListener {
12+
onDismissClicked()
13+
}
14+
}
15+
}

app/src/main/java/com/wstxda/switchai/utils/Constants.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ object Constants {
4949

5050
const val VIEW_TYPE_CATEGORY_HEADER = 0
5151
const val VIEW_TYPE_ASSISTANT_ITEM = 1
52+
const val VIEW_TYPE_REORDER_TIP = 2
5253
// Maximum number of recently used assistants
5354
const val CAT_MAX_RECENTLY_USED = 3
5455
// Category for AssistantSelectorBottomSheet
5556
const val CAT_PINNED_ASSISTANTS_KEY = "pinned_assistants"
5657
const val CAT_RECENTLY_USED_ASSISTANTS_KEY = "recently_used_assistants"
58+
// Reorder tip for pinned assistants
59+
const val REORDER_TIP_DISMISSED_KEY = "reorder_tip_dismissed"
5760

5861
// Widget Material assistant action
5962

app/src/main/java/com/wstxda/switchai/viewmodel/AssistantSelectorViewModel.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ class AssistantSelectorViewModel(application: Application) : AndroidViewModel(ap
226226

227227
if (pinnedItems.isNotEmpty()) {
228228
add(AssistantSelectorRecyclerView.CategoryHeader(context.getString(R.string.assistant_category_pin)))
229+
val tipDismissed = assistantStatePreferences.getBoolean(
230+
Constants.REORDER_TIP_DISMISSED_KEY, false
231+
)
232+
if (pinnedItems.size >= 2 && !tipDismissed) {
233+
add(AssistantSelectorRecyclerView.ReorderTip)
234+
}
229235
addAll(pinnedItems)
230236
}
231237
if (recentItems.isNotEmpty()) {
@@ -282,4 +288,19 @@ class AssistantSelectorViewModel(application: Application) : AndroidViewModel(ap
282288
super.onCleared()
283289
defaultSharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
284290
}
291+
292+
fun dismissReorderTip() {
293+
viewModelScope.launch {
294+
withContext(Dispatchers.IO) {
295+
assistantStatePreferences.edit {
296+
putBoolean(Constants.REORDER_TIP_DISMISSED_KEY, true)
297+
}
298+
}
299+
val currentItems = _assistantItems.value ?: return@launch
300+
val updatedItems =
301+
currentItems.filterNot { it is AssistantSelectorRecyclerView.ReorderTip }
302+
allAssistantItems = updatedItems
303+
_assistantItems.value = updatedItems
304+
}
305+
}
285306
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="20dp"
3+
android:height="20dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportWidth="960"
6+
android:viewportHeight="960">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M291,720L240,669L429,480L240,291L291,240L480,429L669,240L720,291L531,480L720,669L669,720L480,531L291,720Z" />
10+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:tint="?attr/colorControlNormal"
5+
android:viewportWidth="960"
6+
android:viewportHeight="960">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M480,880Q447,880 423.5,856.5Q400,833 400,800L560,800Q560,833 536.5,856.5Q513,880 480,880ZM320,760L320,680L640,680L640,760L320,760ZM330,640Q261,599 220.5,530Q180,461 180,380Q180,255 267.5,167.5Q355,80 480,80Q605,80 692.5,167.5Q780,255 780,380Q780,461 739.5,530Q699,599 630,640L330,640Z" />
10+
</vector>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:app="http://schemas.android.com/apk/res-auto"
3+
style="?attr/materialCardViewFilledStyle"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:layout_marginStart="?attr/dialogPreferredPadding"
7+
android:layout_marginEnd="?attr/dialogPreferredPadding"
8+
android:layout_marginBottom="16dp"
9+
android:clickable="false"
10+
android:focusable="false"
11+
app:cardBackgroundColor="?attr/colorTertiaryContainer"
12+
app:cardCornerRadius="16dp">
13+
14+
<androidx.constraintlayout.widget.ConstraintLayout
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"
17+
android:padding="12dp">
18+
19+
<com.google.android.material.textview.MaterialTextView
20+
android:id="@+id/tip_text_view"
21+
android:layout_width="0dp"
22+
android:layout_height="wrap_content"
23+
android:layout_marginEnd="8dp"
24+
android:drawableStart="@drawable/ic_lightbulb"
25+
android:drawablePadding="12dp"
26+
android:drawableTint="?colorTertiary"
27+
android:text="@string/assistant_tip_reorder"
28+
android:textAppearance="?attr/textAppearanceBodyMedium"
29+
android:textColor="?attr/colorOnTertiaryContainer"
30+
app:layout_constraintBottom_toBottomOf="parent"
31+
app:layout_constraintEnd_toStartOf="@id/dismiss_button"
32+
app:layout_constraintStart_toStartOf="parent"
33+
app:layout_constraintTop_toTopOf="parent" />
34+
35+
<com.google.android.material.button.MaterialButton
36+
android:id="@+id/dismiss_button"
37+
style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
38+
android:layout_width="36dp"
39+
android:layout_height="36dp"
40+
android:contentDescription="@string/assistant_tip_close"
41+
android:insetLeft="0dp"
42+
android:insetTop="0dp"
43+
android:insetRight="0dp"
44+
android:insetBottom="0dp"
45+
app:backgroundTint="?attr/colorTertiaryContainer"
46+
app:icon="@drawable/ic_close"
47+
app:iconSize="20dp"
48+
app:iconTint="?attr/colorOnTertiaryContainer"
49+
app:layout_constraintBottom_toBottomOf="parent"
50+
app:layout_constraintEnd_toEndOf="parent"
51+
app:layout_constraintTop_toTopOf="parent" />
52+
</androidx.constraintlayout.widget.ConstraintLayout>
53+
</com.google.android.material.card.MaterialCardView>

0 commit comments

Comments
 (0)