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