Remove unnecessary code from base ui preferences
This commit is contained in:
parent
c54dc6c526
commit
85c614da14
2 changed files with 45 additions and 60 deletions
|
@ -896,68 +896,64 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
inner class SendMyLocPref : NumericPref(
|
||||
inner class SendMyLocPref : ListPreference(
|
||||
R.drawable.ic_action_share_location,
|
||||
R.string.send_my_location,
|
||||
R.string.send_my_location_desc,
|
||||
SEND_MY_LOC_VALUES_SEC
|
||||
R.string.send_my_location_desc
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() =
|
||||
OsmandFormatter.getFormattedDuration(app, sendMyLocInterval)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
sendMyLocInterval = values[index].toLong()
|
||||
sendMyLocInterval = SEND_MY_LOC_VALUES_SEC[index]
|
||||
app.updateSendLocationInterval()
|
||||
}
|
||||
|
||||
override fun getMenuItems() =
|
||||
values.map { OsmandFormatter.getFormattedDuration(app, it.toLong()) }
|
||||
SEND_MY_LOC_VALUES_SEC.map { OsmandFormatter.getFormattedDuration(app, it) }
|
||||
}
|
||||
|
||||
inner class StaleLocPref : NumericPref(
|
||||
inner class StaleLocPref : ListPreference(
|
||||
R.drawable.ic_action_time_span,
|
||||
R.string.stale_location,
|
||||
R.string.stale_location_desc,
|
||||
STALE_LOC_VALUES_SEC
|
||||
R.string.stale_location_desc
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() =
|
||||
OsmandFormatter.getFormattedDuration(app, staleLocTime)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
staleLocTime = values[index].toLong()
|
||||
staleLocTime = STALE_LOC_VALUES_SEC[index]
|
||||
}
|
||||
|
||||
override fun getMenuItems() =
|
||||
values.map { OsmandFormatter.getFormattedDuration(app, it.toLong()) }
|
||||
STALE_LOC_VALUES_SEC.map { OsmandFormatter.getFormattedDuration(app, it) }
|
||||
}
|
||||
|
||||
inner class LocHistoryPref : NumericPref(
|
||||
inner class LocHistoryPref : ListPreference(
|
||||
R.drawable.ic_action_location_history,
|
||||
R.string.location_history,
|
||||
R.string.location_history_desc,
|
||||
LOC_HISTORY_VALUES_SEC
|
||||
R.string.location_history_desc
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() =
|
||||
OsmandFormatter.getFormattedDuration(app, locHistoryTime)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = values[index]
|
||||
locHistoryTime = value.toLong()
|
||||
app.telegramHelper.messageActiveTimeSec = value.toLong()
|
||||
val value = LOC_HISTORY_VALUES_SEC[index]
|
||||
locHistoryTime = value
|
||||
app.telegramHelper.messageActiveTimeSec = value
|
||||
}
|
||||
|
||||
override fun getMenuItems() =
|
||||
values.map { OsmandFormatter.getFormattedDuration(app, it.toLong()) }
|
||||
LOC_HISTORY_VALUES_SEC.map { OsmandFormatter.getFormattedDuration(app, it) }
|
||||
}
|
||||
|
||||
inner class ShareTypePref : NumericPref(
|
||||
inner class ShareTypePref : ListPreference(
|
||||
R.drawable.ic_action_location_history,
|
||||
R.string.send_location_as,
|
||||
R.string.send_location_as_descr,
|
||||
emptyList()
|
||||
R.string.send_location_as_descr
|
||||
) {
|
||||
|
||||
override fun getCurrentValue(): String {
|
||||
|
@ -989,20 +985,17 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
inner class MinLocationDistance : NumericPref(
|
||||
0, R.string.min_logging_distance,
|
||||
R.string.min_logging_distance_descr,
|
||||
MIN_LOCATION_DISTANCE
|
||||
) {
|
||||
inner class MinLocationDistance :
|
||||
ListPreference(0, R.string.min_logging_distance, R.string.min_logging_distance_descr) {
|
||||
|
||||
override fun getCurrentValue() = getFormattedValue(minLocationDistance)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = values[index]
|
||||
minLocationDistance = value.toFloat()
|
||||
val value = MIN_LOCATION_DISTANCE[index]
|
||||
minLocationDistance = value
|
||||
}
|
||||
|
||||
override fun getMenuItems() = values.map { getFormattedValue(it.toFloat()) }
|
||||
override fun getMenuItems() = MIN_LOCATION_DISTANCE.map { getFormattedValue(it) }
|
||||
|
||||
private fun getFormattedValue(value: Float): String {
|
||||
return if (value == 0f) app.getString(R.string.shared_string_select)
|
||||
|
@ -1010,20 +1003,17 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
inner class MinLocationAccuracy : NumericPref(
|
||||
0, R.string.min_logging_accuracy,
|
||||
R.string.min_logging_accuracy_descr,
|
||||
MIN_LOCATION_ACCURACY
|
||||
) {
|
||||
inner class MinLocationAccuracy :
|
||||
ListPreference(0, R.string.min_logging_accuracy, R.string.min_logging_accuracy_descr) {
|
||||
|
||||
override fun getCurrentValue() = getFormattedValue(minLocationAccuracy)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = values[index]
|
||||
minLocationAccuracy = value.toFloat()
|
||||
val value = MIN_LOCATION_ACCURACY[index]
|
||||
minLocationAccuracy = value
|
||||
}
|
||||
|
||||
override fun getMenuItems() = values.map { getFormattedValue(it.toFloat()) }
|
||||
override fun getMenuItems() = MIN_LOCATION_ACCURACY.map { getFormattedValue(it) }
|
||||
|
||||
private fun getFormattedValue(value: Float): String {
|
||||
return if (value == 0f) app.getString(R.string.shared_string_select)
|
||||
|
@ -1031,20 +1021,17 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
inner class MinLocationSpeed : NumericPref(
|
||||
0, R.string.min_logging_speed,
|
||||
R.string.min_logging_speed_descr,
|
||||
MIN_LOCATION_SPEED
|
||||
) {
|
||||
inner class MinLocationSpeed :
|
||||
ListPreference(0, R.string.min_logging_speed, R.string.min_logging_speed_descr) {
|
||||
|
||||
override fun getCurrentValue() = getFormattedValue(minLocationSpeed)
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = values[index]
|
||||
minLocationSpeed = value.toFloat()
|
||||
val value = MIN_LOCATION_SPEED[index]
|
||||
minLocationSpeed = value
|
||||
}
|
||||
|
||||
override fun getMenuItems() = values.map { getFormattedValue(it.toFloat()) }
|
||||
override fun getMenuItems() = MIN_LOCATION_SPEED.map { getFormattedValue(it) }
|
||||
|
||||
private fun getFormattedValue(value: Float): String {
|
||||
return when (value) {
|
||||
|
@ -1055,10 +1042,10 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
}
|
||||
}
|
||||
|
||||
inner class UnitsOfSpeed : NumericPref(
|
||||
R.drawable.ic_action_speed, R.string.unit_of_speed_system,
|
||||
R.string.unit_of_speed_system_descr,
|
||||
emptyList()
|
||||
inner class UnitsOfSpeed : ListPreference(
|
||||
R.drawable.ic_action_speed,
|
||||
R.string.unit_of_speed_system,
|
||||
R.string.unit_of_speed_system_descr
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() = speedConstants.toShortString(app)
|
||||
|
@ -1070,10 +1057,9 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
override fun getMenuItems() = SpeedConstants.values().map { it.toShortString(app) }
|
||||
}
|
||||
|
||||
inner class UnitsOfLength : NumericPref(
|
||||
inner class UnitsOfLength : ListPreference(
|
||||
R.drawable.ic_action_ruler_unit, R.string.unit_of_length,
|
||||
R.string.unit_of_length_descr,
|
||||
emptyList()
|
||||
R.string.unit_of_length_descr
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() = metricsConstants.toHumanString(app)
|
||||
|
@ -1085,11 +1071,10 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
override fun getMenuItems() = MetricsConstants.values().map { it.toHumanString(app) }
|
||||
}
|
||||
|
||||
abstract inner class NumericPref(
|
||||
abstract inner class ListPreference(
|
||||
@DrawableRes val iconId: Int,
|
||||
@StringRes val titleId: Int,
|
||||
@StringRes val descriptionId: Int,
|
||||
val values: List<Number>
|
||||
@StringRes val descriptionId: Int
|
||||
) {
|
||||
|
||||
abstract fun getCurrentValue(): String
|
||||
|
|
|
@ -17,7 +17,7 @@ import android.view.ViewGroup
|
|||
import android.widget.*
|
||||
import net.osmand.telegram.R
|
||||
import net.osmand.telegram.TelegramSettings
|
||||
import net.osmand.telegram.TelegramSettings.NumericPref
|
||||
import net.osmand.telegram.TelegramSettings.ListPreference
|
||||
import net.osmand.telegram.helpers.TelegramHelper.Companion.OSMAND_BOT_USERNAME
|
||||
import net.osmand.telegram.helpers.TelegramUiHelper
|
||||
import net.osmand.telegram.utils.AndroidUtils
|
||||
|
@ -50,7 +50,7 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
var container = mainView.findViewById<ViewGroup>(R.id.gps_and_loc_container)
|
||||
settings.gpsAndLocPrefs.forEach {
|
||||
createNumericPref(inflater, container, it)
|
||||
createListPref(inflater, container, it)
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
|
@ -68,7 +68,7 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
|
||||
container = mainView.findViewById<ViewGroup>(R.id.units_and_formats_container)
|
||||
settings.unitsAndFormatsPrefs.forEach {
|
||||
createNumericPref(inflater, container, it)
|
||||
createListPref(inflater, container, it)
|
||||
}
|
||||
|
||||
container = mainView.findViewById<ViewGroup>(R.id.gps_points_container)
|
||||
|
@ -144,7 +144,7 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
|
||||
container = mainView.findViewById<ViewGroup>(R.id.gpx_settings_container)
|
||||
settings.gpxLoggingPrefs.forEach {
|
||||
createNumericPref(inflater, container, it)
|
||||
createListPref(inflater, container, it)
|
||||
}
|
||||
|
||||
container = mainView.findViewById(R.id.osmand_connect_container)
|
||||
|
@ -248,7 +248,7 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun createNumericPref(inflater: LayoutInflater, container: ViewGroup, pref: NumericPref) {
|
||||
private fun createListPref(inflater: LayoutInflater, container: ViewGroup, pref: ListPreference) {
|
||||
inflater.inflate(R.layout.item_with_desc_and_right_value, container, false).apply {
|
||||
findViewById<ImageView>(R.id.icon).apply {
|
||||
if (pref.iconId != 0) {
|
||||
|
@ -289,7 +289,7 @@ class SettingsDialogFragment : BaseDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun showPopupMenu(pref: NumericPref, valueView: TextView) {
|
||||
private fun showPopupMenu(pref: ListPreference, valueView: TextView) {
|
||||
val menuList = pref.getMenuItems()
|
||||
val ctx = valueView.context
|
||||
ListPopupWindow(ctx).apply {
|
||||
|
|
Loading…
Reference in a new issue