mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-03-15 02:40:18 +01:00
Created grid span count slider in dialog
This commit is contained in:
parent
2e889f2093
commit
24cc3f5344
@ -31,6 +31,8 @@ import com.simplemobiletools.dialer.extensions.areMultipleSIMsAvailable
|
||||
import com.simplemobiletools.dialer.extensions.callContactWithSim
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.extensions.startContactDetailsIntent
|
||||
import com.simplemobiletools.dialer.helpers.GRID_MAX_SPAN_COUNT
|
||||
import com.simplemobiletools.dialer.helpers.GRID_MIN_SPAN_COUNT
|
||||
import com.simplemobiletools.dialer.interfaces.RefreshItemsListener
|
||||
import java.util.*
|
||||
|
||||
@ -349,7 +351,7 @@ class ContactsAdapter(
|
||||
val layoutManager = recyclerView.layoutManager
|
||||
if (layoutManager is GridLayoutManager) {
|
||||
val currentSpanCount = layoutManager.spanCount
|
||||
val newSpanCount = (currentSpanCount - 1).coerceIn(MIN_COLUMNS, MAX_COLUMNS)
|
||||
val newSpanCount = (currentSpanCount - 1).coerceIn(GRID_MIN_SPAN_COUNT, GRID_MAX_SPAN_COUNT)
|
||||
layoutManager.spanCount = newSpanCount
|
||||
recyclerView.requestLayout()
|
||||
onSpanCountListener(newSpanCount)
|
||||
@ -360,17 +362,11 @@ class ContactsAdapter(
|
||||
val layoutManager = recyclerView.layoutManager
|
||||
if (layoutManager is GridLayoutManager) {
|
||||
val currentSpanCount = layoutManager.spanCount
|
||||
val newSpanCount = (currentSpanCount + 1).coerceIn(MIN_COLUMNS, MAX_COLUMNS)
|
||||
val newSpanCount = (currentSpanCount + 1).coerceIn(GRID_MIN_SPAN_COUNT, GRID_MAX_SPAN_COUNT)
|
||||
layoutManager.spanCount = newSpanCount
|
||||
recyclerView.requestLayout()
|
||||
onSpanCountListener(newSpanCount)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val MIN_COLUMNS = 2
|
||||
private const val MAX_COLUMNS = 6
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,15 +2,19 @@ package com.simplemobiletools.dialer.dialogs
|
||||
|
||||
import android.view.View
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.getAlertDialogBuilder
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
|
||||
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
|
||||
import com.simplemobiletools.dialer.R
|
||||
import com.simplemobiletools.dialer.extensions.config
|
||||
import com.simplemobiletools.dialer.helpers.GRID_MAX_SPAN_COUNT
|
||||
import com.simplemobiletools.dialer.helpers.GRID_MIN_SPAN_COUNT
|
||||
import kotlinx.android.synthetic.main.dialog_change_view_type.view.change_view_type_dialog_radio
|
||||
import kotlinx.android.synthetic.main.dialog_change_view_type.view.change_view_type_dialog_radio_grid
|
||||
import kotlinx.android.synthetic.main.dialog_change_view_type.view.change_view_type_dialog_radio_list
|
||||
import kotlinx.android.synthetic.main.dialog_change_view_type.view.grid_span_count_slider
|
||||
|
||||
class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String = "", showFolderCheck: Boolean = true, val callback: () -> Unit) {
|
||||
private var view: View
|
||||
@ -22,6 +26,15 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String =
|
||||
VIEW_TYPE_GRID -> change_view_type_dialog_radio_grid.id
|
||||
else -> change_view_type_dialog_radio_list.id
|
||||
}
|
||||
|
||||
change_view_type_dialog_radio_grid.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||
grid_span_count_slider.beVisibleIf(isChecked)
|
||||
}
|
||||
grid_span_count_slider.value = config.gridLayoutSpanCount.toFloat()
|
||||
grid_span_count_slider.stepSize = 1f
|
||||
grid_span_count_slider.valueFrom = GRID_MIN_SPAN_COUNT.toFloat()
|
||||
grid_span_count_slider.valueTo = GRID_MAX_SPAN_COUNT.toFloat()
|
||||
|
||||
change_view_type_dialog_radio.check(viewToCheck)
|
||||
}
|
||||
|
||||
@ -35,6 +48,7 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val path: String =
|
||||
|
||||
private fun dialogConfirmed() {
|
||||
val viewType = if (view.change_view_type_dialog_radio_grid.isChecked) {
|
||||
config.gridLayoutSpanCount = view.grid_span_count_slider.value.toInt()
|
||||
VIEW_TYPE_GRID
|
||||
} else {
|
||||
VIEW_TYPE_LIST
|
||||
|
@ -96,7 +96,7 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
set(viewType) = prefs.edit().putInt(VIEW_TYPE, viewType).apply()
|
||||
|
||||
var gridLayoutSpanCount: Int
|
||||
get() = prefs.getInt(GRID_LAYOUT_SPAN_COUNT, DEFAULT_GRID_SPAN_COUNT)
|
||||
get() = prefs.getInt(GRID_LAYOUT_SPAN_COUNT, GRID_DEFAULT_SPAN_COUNT)
|
||||
set(gridLayoutSpanCount) = prefs.edit().putInt(GRID_LAYOUT_SPAN_COUNT, gridLayoutSpanCount).apply()
|
||||
|
||||
}
|
||||
|
@ -35,4 +35,6 @@ const val DIALPAD_TONE_LENGTH_MS = 150L // The length of DTMF tones in milliseco
|
||||
|
||||
const val MIN_RECENTS_THRESHOLD = 30
|
||||
|
||||
const val DEFAULT_GRID_SPAN_COUNT = 3
|
||||
const val GRID_DEFAULT_SPAN_COUNT = 3
|
||||
const val GRID_MIN_SPAN_COUNT = 2
|
||||
const val GRID_MAX_SPAN_COUNT = 6
|
||||
|
@ -27,6 +27,13 @@
|
||||
android:paddingBottom="@dimen/medium_margin"
|
||||
android:text="@string/grid" />
|
||||
|
||||
<com.google.android.material.slider.Slider
|
||||
android:id="@+id/grid_span_count_slider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stepSize="1.0"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/change_view_type_dialog_radio_list"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user