From b2c19db626a1657d2f9cb669b30e04a2f3a6b0df Mon Sep 17 00:00:00 2001 From: Dmitriy Ruban Date: Wed, 8 Jan 2020 13:56:02 +0200 Subject: [PATCH 1/2] corrections --- .../src/net/osmand/telegram/TelegramSettings.kt | 10 +++++----- .../src/net/osmand/telegram/ui/MainActivity.kt | 8 ++------ .../net/osmand/telegram/ui/MyLocationTabFragment.kt | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index b35d004c43..227215c03c 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -998,12 +998,12 @@ class TelegramSettings(private val app: TelegramApplication) { } fun calcLivePeriod(periods: LinkedList): Long { - val copy = periods.toLongArray() - copy.sort() - return if (copy.size % 2 == 0) { - (copy[copy.size / 2] + copy[copy.size / 2 - 1]) / 2 + val sortedPeriods = periods.toLongArray() + sortedPeriods.sort() + return if (sortedPeriods.size % 2 == 0) { + (sortedPeriods[sortedPeriods.size / 2] + sortedPeriods[sortedPeriods.size / 2 - 1]) / 2 } else { - copy[copy.size / 2] + sortedPeriods[sortedPeriods.size / 2] } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index 493f376c36..8f439b79d7 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -44,7 +44,7 @@ private const val MY_LOCATION_TAB_POS = 0 private const val LIVE_NOW_TAB_POS = 1 private const val TIMELINE_TAB_POS = 2 -class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListener, TelegramIncomingMessagesListener, DataSetListener { +class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListener, TelegramIncomingMessagesListener { private val log = PlatformUtil.getLog(MainActivity::class.java) @@ -486,7 +486,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene } } - override fun onDataSetChanged() { + fun onDataSetChanged() { viewPager.adapter?.notifyDataSetChanged() } @@ -522,7 +522,3 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene } } } - -interface DataSetListener { - fun onDataSetChanged() -} diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index d3f07aea04..9596d6114a 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -856,7 +856,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { } else { settings.shareLocationToChat(lastChat.chat.id, true, lastChat.time) app.shareLocationHelper.startSharingLocation() - (activity as DataSetListener).onDataSetChanged() + (activity as MainActivity).onDataSetChanged() } } From 7031e79b5984c40cc77c1bcec43c6625292283ac Mon Sep 17 00:00:00 2001 From: Dmitriy Ruban Date: Wed, 8 Jan 2020 14:05:08 +0200 Subject: [PATCH 2/2] refactor --- OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt | 2 +- .../src/net/osmand/telegram/ui/MyLocationTabFragment.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt index 8f439b79d7..885deeec36 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MainActivity.kt @@ -486,7 +486,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene } } - fun onDataSetChanged() { + fun refreshPages() { viewPager.adapter?.notifyDataSetChanged() } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt index 9596d6114a..35ea29009b 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/MyLocationTabFragment.kt @@ -856,7 +856,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener { } else { settings.shareLocationToChat(lastChat.chat.id, true, lastChat.time) app.shareLocationHelper.startSharingLocation() - (activity as MainActivity).onDataSetChanged() + (activity as MainActivity).refreshPages() } }