remove unnecessary changes in MyLocationTabFragment and OsmandFormatter
This commit is contained in:
parent
dd08aa3d31
commit
76fba24c4d
3 changed files with 38 additions and 76 deletions
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.telegram.ui
|
||||
|
||||
import android.animation.*
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Build
|
||||
|
@ -48,7 +49,6 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
private lateinit var textContainer: LinearLayout
|
||||
private lateinit var titleContainer: LinearLayout
|
||||
private lateinit var optionsBtn: ImageView
|
||||
private lateinit var optionsBtnTitle: ImageView
|
||||
private lateinit var title: TextView
|
||||
private lateinit var description: TextView
|
||||
private lateinit var searchBox: FrameLayout
|
||||
|
@ -114,12 +114,12 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
|
||||
optionsBtn = mainView.findViewById<ImageView>(R.id.options).apply {
|
||||
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||
setOnClickListener { showPopupMenu(optionsBtn) }
|
||||
setOnClickListener { showPopupMenu(this) }
|
||||
}
|
||||
|
||||
optionsBtnTitle = mainView.findViewById<ImageView>(R.id.options_title).apply {
|
||||
mainView.findViewById<ImageView>(R.id.options_title).apply {
|
||||
setImageDrawable(app.uiUtils.getThemedIcon(R.drawable.ic_action_other_menu))
|
||||
setOnClickListener { showPopupMenu(optionsBtnTitle) }
|
||||
setOnClickListener { showPopupMenu(this) }
|
||||
}
|
||||
|
||||
imageContainer = mainView.findViewById<FrameLayout>(R.id.image_container)
|
||||
|
@ -166,9 +166,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
setOnCheckedChangeListener { _, isChecked ->
|
||||
if (!isChecked) {
|
||||
app.settings.stopSharingLocationToChats()
|
||||
if (!app.settings.hasAnyChatToShareLocation()) {
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
}
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
updateContent()
|
||||
}
|
||||
}
|
||||
|
@ -240,9 +238,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
}
|
||||
|
||||
override fun onChatLiveMessagesUpdated(messages: List<TdApi.Message>) {
|
||||
app.runInUIThread {
|
||||
updateContent()
|
||||
}
|
||||
app.runInUIThread { updateContent() }
|
||||
}
|
||||
|
||||
fun onPrimaryBtnClick() {
|
||||
|
@ -447,6 +443,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
|
||||
val chat = chats[position]
|
||||
val lastItem = position == itemCount - 1
|
||||
|
@ -479,9 +476,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
holder.itemView.setOnClickListener {
|
||||
if (live) {
|
||||
app.settings.shareLocationToChat(chat.id, false)
|
||||
if (!app.settings.hasAnyChatToShareLocation()) {
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
}
|
||||
app.shareLocationHelper.stopSharingLocation()
|
||||
notifyItemChanged(position)
|
||||
} else {
|
||||
holder.checkBox?.apply {
|
||||
|
@ -505,11 +500,10 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
|
||||
val duration = settings.getChatLivePeriod(chat.id)?.toInt()
|
||||
if (duration != null && duration > 0) {
|
||||
holder.descriptionDuration?.text = OsmandFormatter.getFormattedDuration(context!!, duration, false)
|
||||
holder.descriptionDuration?.text = OsmandFormatter.getFormattedDuration(context!!, duration)
|
||||
holder.description?.apply {
|
||||
visibility = View.VISIBLE
|
||||
val sharingTimeDescription = "${getText(R.string.sharing_time)}:"
|
||||
text = sharingTimeDescription
|
||||
text = "${getText(R.string.sharing_time)}:"
|
||||
}
|
||||
}
|
||||
val message = telegramHelper.getChatLiveMessages()[chat.id]
|
||||
|
@ -519,10 +513,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
val expiresIn = content.expiresIn
|
||||
holder.textInArea?.apply {
|
||||
visibility = View.VISIBLE
|
||||
val addDuration = OsmandFormatter.getFormattedDuration(context!!,
|
||||
TelegramHelper.MESSAGE_ADD_ACTIVE_TIME_SEC, false)
|
||||
val textInAreaDescription = "${getText(R.string.plus)} $addDuration"
|
||||
text = textInAreaDescription
|
||||
text = "${getText(R.string.plus)} ${OsmandFormatter.getFormattedDuration(context!!,
|
||||
TelegramHelper.MESSAGE_ADD_ACTIVE_TIME_SEC)}"
|
||||
setOnClickListener {
|
||||
var newLivePeriod = app.settings.getChatLivePeriod(chat.id)
|
||||
if (newLivePeriod != null) {
|
||||
|
@ -536,8 +528,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
}
|
||||
holder.stopSharingDescr?.apply {
|
||||
visibility = View.VISIBLE
|
||||
val stopDescription = "${getText(R.string.stop_at)}:"
|
||||
text = stopDescription
|
||||
text = "${getText(R.string.stop_at)}:"
|
||||
}
|
||||
|
||||
holder.stopSharingFirstPart?.apply {
|
||||
|
@ -547,9 +538,8 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
|
|||
|
||||
holder.stopSharingSecondPart?.apply {
|
||||
visibility = View.VISIBLE
|
||||
val stopSharingSecondPart = "(${getString(R.string.in_time,
|
||||
text = "(${getString(R.string.in_time,
|
||||
OsmandFormatter.getFormattedDuration(context!!, expiresIn, true))})"
|
||||
text = stopSharingSecondPart
|
||||
}
|
||||
if (expiresIn == 0) {
|
||||
removeItem(chat)
|
||||
|
|
|
@ -103,10 +103,10 @@ class SettingsDialogFragment : DialogFragment() {
|
|||
listOf(30 * 60, 60 * 60, 90 * 60)
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0],false)
|
||||
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0])
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = OsmandFormatter.getFormattedDuration(app, values[index],false)
|
||||
val value = OsmandFormatter.getFormattedDuration(app, values[index])
|
||||
Toast.makeText(context, value, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
@ -119,10 +119,10 @@ class SettingsDialogFragment : DialogFragment() {
|
|||
listOf(30 * 60, 60 * 60, 90 * 60)
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0],false)
|
||||
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0])
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = OsmandFormatter.getFormattedDuration(app, values[index],false)
|
||||
val value = OsmandFormatter.getFormattedDuration(app, values[index])
|
||||
Toast.makeText(context, value, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
@ -135,10 +135,10 @@ class SettingsDialogFragment : DialogFragment() {
|
|||
listOf(30 * 60, 60 * 60, 90 * 60)
|
||||
) {
|
||||
|
||||
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0],false)
|
||||
override fun getCurrentValue() = OsmandFormatter.getFormattedDuration(app, values[0])
|
||||
|
||||
override fun setCurrentValue(index: Int) {
|
||||
val value = OsmandFormatter.getFormattedDuration(app, values[index],false)
|
||||
val value = OsmandFormatter.getFormattedDuration(app, values[index])
|
||||
Toast.makeText(context, value, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class SettingsDialogFragment : DialogFragment() {
|
|||
|
||||
abstract fun setCurrentValue(index: Int)
|
||||
|
||||
fun getMenuItems() = values.map { OsmandFormatter.getFormattedDuration(app, it, false) }
|
||||
fun getMenuItems() = values.map { OsmandFormatter.getFormattedDuration(app, it) }
|
||||
}
|
||||
|
||||
private enum class AppConnect(
|
||||
|
|
|
@ -19,6 +19,9 @@ object OsmandFormatter {
|
|||
val FEET_IN_ONE_METER = YARDS_IN_ONE_METER * 3f
|
||||
private val fixed2 = DecimalFormat("0.00")
|
||||
private val fixed1 = DecimalFormat("0.0")
|
||||
|
||||
private const val SHORT_TIME_FORMAT = "%02d:%02d"
|
||||
private const val SHORT_SIMPLE_DATE_FORMAT = "HH:mm"
|
||||
|
||||
private val dateFormatSymbols = DateFormatSymbols.getInstance()
|
||||
private val localDaysStr = getLettersStringArray(dateFormatSymbols.shortWeekdays, 2)
|
||||
|
@ -30,11 +33,11 @@ object OsmandFormatter {
|
|||
fixed2.minimumIntegerDigits = 1
|
||||
}
|
||||
|
||||
fun getFormattedDuration(ctx: Context, seconds: Int, short: Boolean): String {
|
||||
fun getFormattedDuration(ctx: Context, seconds: Int, short: Boolean = false): String {
|
||||
val hours = seconds / (60 * 60)
|
||||
val minutes = seconds / 60 % 60
|
||||
if (short) {
|
||||
return String.format("%02d:%02d", hours, minutes)
|
||||
return String.format(SHORT_TIME_FORMAT, hours, minutes)
|
||||
}
|
||||
return when {
|
||||
hours > 0 -> {
|
||||
|
@ -53,9 +56,9 @@ object OsmandFormatter {
|
|||
val calendar = Calendar.getInstance()
|
||||
calendar.timeInMillis = System.currentTimeMillis() + (seconds * 1000)
|
||||
return if (isSameDay(calendar, Calendar.getInstance())) {
|
||||
SimpleDateFormat("HH:mm", Locale.getDefault()).format(calendar.time)
|
||||
SimpleDateFormat(SHORT_SIMPLE_DATE_FORMAT, Locale.getDefault()).format(calendar.time)
|
||||
} else {
|
||||
SimpleDateFormat("HH:mm", Locale.getDefault()).format(calendar.time) +
|
||||
SimpleDateFormat(SHORT_SIMPLE_DATE_FORMAT, Locale.getDefault()).format(calendar.time) +
|
||||
" " + localDaysStr[calendar.get(Calendar.DAY_OF_WEEK)]
|
||||
}
|
||||
}
|
||||
|
@ -127,11 +130,7 @@ object OsmandFormatter {
|
|||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun getFormattedDistance(
|
||||
meters: Float,
|
||||
ctx: TelegramApplication,
|
||||
forceTrailingZeros: Boolean = true
|
||||
): String {
|
||||
fun getFormattedDistance(meters: Float, ctx: TelegramApplication, forceTrailingZeros: Boolean = true): String {
|
||||
val format1 = if (forceTrailingZeros) "{0,number,0.0} " else "{0,number,0.#} "
|
||||
val format2 = if (forceTrailingZeros) "{0,number,0.00} " else "{0,number,0.##} "
|
||||
|
||||
|
@ -150,39 +149,19 @@ object OsmandFormatter {
|
|||
}
|
||||
|
||||
if (meters >= 100 * mainUnitInMeters) {
|
||||
return (meters / mainUnitInMeters + 0.5).toInt().toString() + " " + ctx.getString(
|
||||
mainUnitStr
|
||||
) //$NON-NLS-1$
|
||||
return (meters / mainUnitInMeters + 0.5).toInt().toString() + " " + ctx.getString(mainUnitStr) //$NON-NLS-1$
|
||||
} else if (meters > 9.99f * mainUnitInMeters) {
|
||||
return MessageFormat.format(
|
||||
format1 + ctx.getString(mainUnitStr),
|
||||
meters / mainUnitInMeters
|
||||
).replace('\n', ' ') //$NON-NLS-1$
|
||||
return MessageFormat.format(format1 + ctx.getString(mainUnitStr), meters / mainUnitInMeters).replace('\n', ' ') //$NON-NLS-1$
|
||||
} else if (meters > 0.999f * mainUnitInMeters) {
|
||||
return MessageFormat.format(
|
||||
format2 + ctx.getString(mainUnitStr),
|
||||
meters / mainUnitInMeters
|
||||
).replace('\n', ' ') //$NON-NLS-1$
|
||||
return MessageFormat.format(format2 + ctx.getString(mainUnitStr), meters / mainUnitInMeters).replace('\n', ' ') //$NON-NLS-1$
|
||||
} else if (mc == MetricsConstants.MILES_AND_FEET && meters > 0.249f * mainUnitInMeters) {
|
||||
return MessageFormat.format(
|
||||
format2 + ctx.getString(mainUnitStr),
|
||||
meters / mainUnitInMeters
|
||||
).replace('\n', ' ') //$NON-NLS-1$
|
||||
return MessageFormat.format(format2 + ctx.getString(mainUnitStr), meters / mainUnitInMeters).replace('\n', ' ') //$NON-NLS-1$
|
||||
} else if (mc == MetricsConstants.MILES_AND_METERS && meters > 0.249f * mainUnitInMeters) {
|
||||
return MessageFormat.format(
|
||||
format2 + ctx.getString(mainUnitStr),
|
||||
meters / mainUnitInMeters
|
||||
).replace('\n', ' ') //$NON-NLS-1$
|
||||
return MessageFormat.format(format2 + ctx.getString(mainUnitStr), meters / mainUnitInMeters).replace('\n', ' ') //$NON-NLS-1$
|
||||
} else if (mc == MetricsConstants.MILES_AND_YARDS && meters > 0.249f * mainUnitInMeters) {
|
||||
return MessageFormat.format(
|
||||
format2 + ctx.getString(mainUnitStr),
|
||||
meters / mainUnitInMeters
|
||||
).replace('\n', ' ') //$NON-NLS-1$
|
||||
return MessageFormat.format(format2 + ctx.getString(mainUnitStr), meters / mainUnitInMeters).replace('\n', ' ') //$NON-NLS-1$
|
||||
} else if (mc == MetricsConstants.NAUTICAL_MILES && meters > 0.99f * mainUnitInMeters) {
|
||||
return MessageFormat.format(
|
||||
format2 + ctx.getString(mainUnitStr),
|
||||
meters / mainUnitInMeters
|
||||
).replace('\n', ' ') //$NON-NLS-1$
|
||||
return MessageFormat.format(format2 + ctx.getString(mainUnitStr), meters / mainUnitInMeters).replace('\n', ' ') //$NON-NLS-1$
|
||||
} else {
|
||||
if (mc == MetricsConstants.KILOMETERS_AND_METERS || mc == MetricsConstants.MILES_AND_METERS) {
|
||||
return (meters + 0.5).toInt().toString() + " " + ctx.getString(R.string.m) //$NON-NLS-1$
|
||||
|
@ -265,13 +244,6 @@ object OsmandFormatter {
|
|||
return (kmh10 / 10f).toString() + " " + SpeedConstants.METERS_PER_SECOND.toShortString(ctx)
|
||||
}
|
||||
}
|
||||
fun capitalizeFirstLetter(s: String?): String? {
|
||||
return if (s != null && s.isNotEmpty()) {
|
||||
Character.toUpperCase(s[0]) + if (s.length > 1) s.substring(1) else ""
|
||||
} else {
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSameDay(cal1: Calendar, cal2: Calendar): Boolean {
|
||||
return cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
|
||||
|
@ -283,9 +255,9 @@ object OsmandFormatter {
|
|||
val newStrings = arrayOfNulls<String>(strings.size)
|
||||
for (i in strings.indices) {
|
||||
if (strings[i].length > letters) {
|
||||
newStrings[i] = capitalizeFirstLetter(strings[i].substring(0, letters))
|
||||
newStrings[i] = (strings[i].substring(0, letters)).capitalize()
|
||||
} else {
|
||||
newStrings[i] = capitalizeFirstLetter(strings[i])
|
||||
newStrings[i] = strings[i].capitalize()
|
||||
}
|
||||
}
|
||||
return newStrings
|
||||
|
|
Loading…
Reference in a new issue