Skip to content

Commit

Permalink
update default types selection ui to be more logical
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 26, 2023
1 parent 7fb6d25 commit 4c8a5aa
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun BottomSheetDialogFragment.setFullScreen() {
}
}

// Disable sheet swipe on content scroll to avoid accidentally closing payment sheet when scrolling items.
// Disable sheet swipe on content scroll to avoid accidentally closing the sheet when scrolling items.
fun BottomSheetDialogFragment.blockContentScroll(recyclerView: RecyclerView) {
recyclerView.addOnScrollListenerAdapter(
onScrolled = { _, _, dy ->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">الوسوم</string>
<string name="nothing_selected">لم يحدد شيء</string>
<string name="something_selected">المحدد:</string>
<string name="select_all">اختر الكل</string>
<string name="select_nothing">لا تختار شيئا</string>
<string name="no_data">لايوجد بيانات</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Etiquetes</string>
<string name="nothing_selected">Res seleccionat</string>
<string name="something_selected">Seleccionat:</string>
<string name="select_all">Seleccionar tot</string>
<string name="select_nothing">No seleccioneu res</string>
<string name="no_data">No hi ha dades</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Tags</string>
<string name="nothing_selected">Nichts ausgewählt</string>
<string name="something_selected">Ausgewählt:</string>
<string name="select_all">Wählen Sie Alle</string>
<string name="select_nothing">Nichts auswählen</string>
<string name="no_data">Keine Daten</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Etiquetas</string>
<string name="nothing_selected">Nada seleccionado</string>
<string name="something_selected">Seleccionada:</string>
<string name="select_all">Seleccionar todo</string>
<string name="select_nothing">No seleccionar nada</string>
<string name="no_data">Sin datos</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">برچسب ها</string>
<string name="nothing_selected">موردی انتخاب نشده</string>
<string name="something_selected">انتخاب شده:</string>
<string name="select_all">انتخاب همه</string>
<string name="select_nothing">چیزی را انتخاب نکنید</string>
<string name="no_data">اطلاعاتی وجود ندارد</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Étiquettes</string>
<string name="nothing_selected">Rien de sélectionné</string>
<string name="something_selected">Sélection :</string>
<string name="select_all">Tout sélectionner</string>
<string name="select_nothing">Ne rien sélectionner</string>
<string name="no_data">Pas de données</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">टैग</string>
<string name="nothing_selected">कुछ भी चयनित नहीं</string>
<string name="something_selected">चयनित:</string>
<string name="select_all">सबका चयन करें</string>
<string name="select_nothing">कुछ भी नहीं चुनें</string>
<string name="no_data">कोई डेटा नहीं</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Label</string>
<string name="nothing_selected">Tidak ada yang dipilih</string>
<string name="something_selected">Terpilih:</string>
<string name="select_all">Pilih Semua</string>
<string name="select_nothing">Pilih apa pun</string>
<string name="no_data">Tidak ada data</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Etichette</string>
<string name="nothing_selected">Niente selezionato</string>
<string name="something_selected">Selezionata:</string>
<string name="select_all">Seleziona tutto</string>
<string name="select_nothing">Non selezionare nulla</string>
<string name="no_data">Nessun dato</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">タグ</string>
<string name="nothing_selected">何も選択されていません</string>
<string name="something_selected">選択済み:</string>
<string name="select_all">すべて選択</string>
<string name="select_nothing">何も選択しない</string>
<string name="no_data">データなし</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">태그</string>
<string name="nothing_selected">아무것도 선택되어있지 않습니다</string>
<string name="something_selected">선택됨:</string>
<string name="select_all">모두 선택</string>
<string name="select_nothing">아무것도 선택하지 마세요</string>
<string name="no_data">데이터 없음</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Labels</string>
<string name="nothing_selected">Niets geselecteerd</string>
<string name="something_selected">Geselecteerd:</string>
<string name="select_all">Selecteer alles</string>
<string name="select_nothing">Selecteer niets</string>
<string name="no_data">Geen gegevens</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Tags</string>
<string name="nothing_selected">Nada selecionado</string>
<string name="something_selected">Selecionada:</string>
<string name="select_all">Selecionar tudo</string>
<string name="select_nothing">Não selecione nada</string>
<string name="no_data">Sem dados</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Теги</string>
<string name="nothing_selected">Ничего не выбрано</string>
<string name="something_selected">Выбрано:</string>
<string name="select_all">Выбрать все</string>
<string name="select_nothing">Ничего не выбирать</string>
<string name="no_data">Нет данных</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Taggar</string>
<string name="nothing_selected">Inget valt</string>
<string name="something_selected">Vald:</string>
<string name="select_all">Välj alla</string>
<string name="select_nothing">Välj ingenting</string>
<string name="no_data">Inga data</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Etiketler</string>
<string name="nothing_selected">Hiçbir şey seçilmedi</string>
<string name="something_selected">Seçildi:</string>
<string name="select_all">Hepsini seç</string>
<string name="select_nothing">Hiçbir şey seçme</string>
<string name="no_data">Veri yok</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Теги</string>
<string name="nothing_selected">Нічого не вибрано</string>
<string name="something_selected">Вибрано:</string>
<string name="select_all">Вибрати все</string>
<string name="select_nothing">Нічого не вибирайте</string>
<string name="no_data">Немає даних</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">標籤</string>
<string name="nothing_selected">未選取</string>
<string name="something_selected">已選取:</string>
<string name="select_all">全選</string>
<string name="select_nothing">不選擇任何內容</string>
<string name="no_data">沒有數據</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">标签</string>
<string name="nothing_selected">未选择任何内容</string>
<string name="something_selected">已选择:</string>
<string name="select_all">全选</string>
<string name="select_nothing">不选择任何内容</string>
<string name="no_data">没有数据</string>

<!-- Range selection -->
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="record_tag_hint_short">Tags</string>
<string name="nothing_selected">Nothing selected</string>
<string name="something_selected">Selected:</string>
<string name="select_all">Select all</string>
<string name="select_nothing">Select nothing</string>
<string name="no_data">No data</string>

<!-- Range selection -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.example.util.simpletimetracker.core.extension.observeOnce
import com.example.util.simpletimetracker.core.extension.setFullScreen
import com.example.util.simpletimetracker.core.extension.setSkipCollapsed
import com.example.util.simpletimetracker.feature_base_adapter.BaseRecyclerAdapter
import com.example.util.simpletimetracker.feature_base_adapter.divider.createDividerAdapterDelegate
import com.example.util.simpletimetracker.feature_base_adapter.info.createInfoAdapterDelegate
import com.example.util.simpletimetracker.feature_base_adapter.loader.createLoaderAdapterDelegate
import com.example.util.simpletimetracker.feature_base_adapter.recordType.createRecordTypeAdapterDelegate
import com.example.util.simpletimetracker.feature_dialogs.defaultTypesSelection.viewModel.DefaultTypesSelectionViewModel
Expand All @@ -32,6 +34,8 @@ class DefaultTypesSelectionDialogFragment : BaseBottomSheetFragment<Binding>() {
BaseRecyclerAdapter(
createRecordTypeAdapterDelegate(viewModel::onRecordTypeClick),
createLoaderAdapterDelegate(),
createDividerAdapterDelegate(),
createInfoAdapterDelegate(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import androidx.lifecycle.viewModelScope
import com.example.util.simpletimetracker.core.extension.addOrRemove
import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.mapper.RecordTypeViewDataMapper
import com.example.util.simpletimetracker.core.repo.ResourceRepo
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor
import com.example.util.simpletimetracker.domain.model.CardOrder
import com.example.util.simpletimetracker.domain.model.RecordType
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType
import com.example.util.simpletimetracker.feature_base_adapter.divider.DividerViewData
import com.example.util.simpletimetracker.feature_base_adapter.info.InfoViewData
import com.example.util.simpletimetracker.feature_base_adapter.loader.LoaderViewData
import com.example.util.simpletimetracker.feature_base_adapter.recordType.RecordTypeViewData
import com.example.util.simpletimetracker.feature_dialogs.R
import com.example.util.simpletimetracker.feature_dialogs.defaultTypesSelection.interactor.GetDefaultRecordTypesInteractor
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
Expand All @@ -25,6 +29,7 @@ class DefaultTypesSelectionViewModel @Inject constructor(
private val prefsInteractor: PrefsInteractor,
private val recordTypeViewDataMapper: RecordTypeViewDataMapper,
private val getDefaultRecordTypesInteractor: GetDefaultRecordTypesInteractor,
private val resourceRepo: ResourceRepo,
) : ViewModel() {

val types: LiveData<List<ViewHolderType>> by lazy {
Expand All @@ -37,35 +42,35 @@ class DefaultTypesSelectionViewModel @Inject constructor(
}
}
val close: LiveData<Unit> = MutableLiveData()
val saveButtonEnabled: LiveData<Boolean> = MutableLiveData(true)
val saveButtonEnabled: LiveData<Boolean> = MutableLiveData(false)

private var recordTypes: List<RecordType> = emptyList()
private var typeIdsFiltered: MutableList<Long> = mutableListOf()
private var typeIdsSelected: MutableList<Long> = mutableListOf()

fun onRecordTypeClick(item: RecordTypeViewData) {
typeIdsFiltered.addOrRemove(item.id)
typeIdsSelected.addOrRemove(item.id)
updateSaveButtonEnabled()
updateRecordTypesViewData()
}

fun onShowAllClick() {
typeIdsFiltered.clear()
typeIdsSelected.addAll(recordTypes.map { it.id })
updateSaveButtonEnabled()
updateRecordTypesViewData()
}

fun onHideAllClick() {
typeIdsFiltered.addAll(recordTypes.map { it.id })
typeIdsSelected.clear()
updateSaveButtonEnabled()
updateRecordTypesViewData()
}

fun onSaveClick() {
if (typeIdsFiltered.size == recordTypes.size) return
if (typeIdsSelected.size == 0) return

saveButtonEnabled.set(false)
viewModelScope.launch {
recordTypes.filter { it.id !in typeIdsFiltered }.forEach {
recordTypes.filter { it.id in typeIdsSelected }.forEach {
// Remove ids for correct adding in database.
recordTypeInteractor.add(it.copy(id = 0))
}
Expand All @@ -75,7 +80,7 @@ class DefaultTypesSelectionViewModel @Inject constructor(
}

private fun updateSaveButtonEnabled() {
saveButtonEnabled.set(typeIdsFiltered.size != recordTypes.size)
saveButtonEnabled.set(typeIdsSelected.size != 0)
}

private fun updateRecordTypesViewData() = viewModelScope.launch {
Expand All @@ -89,15 +94,36 @@ class DefaultTypesSelectionViewModel @Inject constructor(

if (recordTypes.isEmpty()) recordTypes = loadRecordTypes()

return recordTypes.map { recordType ->
recordTypeViewDataMapper.mapFiltered(
recordType = recordType,
fun map(type: RecordType): ViewHolderType {
return recordTypeViewDataMapper.map(
recordType = type,
numberOfCards = numberOfCards,
isDarkTheme = isDarkTheme,
isFiltered = recordType.id in typeIdsFiltered,
isChecked = null,
)
}

val selected = recordTypes
.filter { it.id in typeIdsSelected }
.map(::map)
val available = recordTypes
.filter { it.id !in typeIdsSelected }
.map(::map)

val result = mutableListOf<ViewHolderType>()

if (selected.isNotEmpty()) {
result += InfoViewData(resourceRepo.getString(R.string.something_selected))
result += selected
} else {
result += InfoViewData(resourceRepo.getString(R.string.nothing_selected))
}
if (available.isNotEmpty()) {
result += DividerViewData(0)
}
result += available

return result
}

private suspend fun loadRecordTypes(): List<RecordType> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:overScrollMode="never"
tools:listitem="@layout/item_record_type_layout" />

<androidx.constraintlayout.widget.ConstraintLayout
Expand All @@ -46,7 +47,7 @@
android:ellipsize="marquee"
android:paddingHorizontal="0dp"
android:singleLine="true"
android:text="@string/types_filter_show_all"
android:text="@string/select_all"
app:layout_constraintBottom_toTopOf="@id/btnDefaultTypesSelectionSave"
app:layout_constraintEnd_toStartOf="@id/btnDefaultTypesSelectionHideAll"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -60,7 +61,7 @@
android:ellipsize="marquee"
android:paddingHorizontal="0dp"
android:singleLine="true"
android:text="@string/types_filter_hide_all"
android:text="@string/select_nothing"
app:layout_constraintBottom_toTopOf="@id/btnDefaultTypesSelectionSave"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btnDefaultTypesSelectionShowAll" />
Expand Down

0 comments on commit 4c8a5aa

Please sign in to comment.