Show free timeline once a day
This commit is contained in:
parent
965314f9b7
commit
17bfc651a5
2 changed files with 29 additions and 10 deletions
|
@ -66,6 +66,7 @@ private val BUFFER_TIME = listOf(60 * 60L, 2 * 60 * 60L, 4 * 60 * 60L, 8 * 60 *
|
|||
12 * 60 * 60L, 24 * 60 * 60L)
|
||||
private const val BUFFER_TIME_INDEX = 0
|
||||
private const val BUFFER_TIME_KEY = "buffer_time"
|
||||
private const val FREE_TIMELINE_INFO_SHOWN_TIME_KEY = "free_timeline_info_shown_time"
|
||||
|
||||
private const val SETTINGS_NAME = "osmand_telegram_settings"
|
||||
|
||||
|
@ -164,6 +165,8 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
|
||||
var bufferTime = BUFFER_TIME[BUFFER_TIME_INDEX]
|
||||
|
||||
var freeTimelineInfoShownTime = 0L
|
||||
|
||||
init {
|
||||
updatePrefs()
|
||||
read()
|
||||
|
@ -645,6 +648,8 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
|
||||
edit.putLong(BUFFER_TIME_KEY, bufferTime)
|
||||
|
||||
edit.putLong(FREE_TIMELINE_INFO_SHOWN_TIME_KEY, freeTimelineInfoShownTime)
|
||||
|
||||
val jArray = convertShareChatsInfoToJson()
|
||||
if (jArray != null) {
|
||||
edit.putString(SHARE_CHATS_INFO_KEY, jArray.toString())
|
||||
|
@ -741,6 +746,8 @@ class TelegramSettings(private val app: TelegramApplication) {
|
|||
|
||||
bufferTime = prefs.getLong(BUFFER_TIME_KEY, BUFFER_TIME[BUFFER_TIME_INDEX])
|
||||
|
||||
freeTimelineInfoShownTime = prefs.getLong(FREE_TIMELINE_INFO_SHOWN_TIME_KEY, 0L)
|
||||
|
||||
try {
|
||||
parseProxyPreferences(JSONObject(prefs.getString(PROXY_PREFERENCES_KEY, "")))
|
||||
} catch (e: JSONException) {
|
||||
|
|
|
@ -35,6 +35,9 @@ import net.osmand.telegram.utils.OsmandApiUtils
|
|||
import org.drinkless.td.libcore.telegram.TdApi
|
||||
import java.io.File
|
||||
import java.lang.ref.WeakReference
|
||||
import java.time.MonthDay
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
const val OPEN_MY_LOCATION_TAB_KEY = "open_my_location_tab"
|
||||
|
||||
|
@ -69,8 +72,6 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
private lateinit var coordinatorLayout: CoordinatorLayout
|
||||
private lateinit var viewPager: ViewPager
|
||||
|
||||
private var snackbarShown = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
@ -110,7 +111,9 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
TIMELINE_TAB_POS -> {
|
||||
liveNowTabFragment?.tabClosed()
|
||||
timelineTabFragment?.tabOpened()
|
||||
showSnackBar()
|
||||
if (shouldShowFreeTimelineInfo()) {
|
||||
showFreeTimelineInfo()
|
||||
}
|
||||
}
|
||||
}
|
||||
viewPager.currentItem = pos
|
||||
|
@ -329,7 +332,7 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
settings.removeNonexistingChats(presentChatTitles)
|
||||
}
|
||||
|
||||
fun stopShowingChatsOnMap(forceStop: Boolean) {
|
||||
private fun stopShowingChatsOnMap(forceStop: Boolean) {
|
||||
settings.getShowOnMapChats().forEach { app.showLocationHelper.hideChatMessages(it) }
|
||||
app.showLocationHelper.stopShowingLocation(forceStop)
|
||||
}
|
||||
|
@ -382,13 +385,22 @@ class MainActivity : AppCompatActivity(), TelegramListener, ActionButtonsListene
|
|||
imageView.setOnClickListener { showOptionsPopupMenu(imageView) }
|
||||
}
|
||||
|
||||
fun showSnackBar() {
|
||||
if (!snackbarShown) {
|
||||
private fun shouldShowFreeTimelineInfo(): Boolean {
|
||||
val freeTimelineInfoShownTime = settings.freeTimelineInfoShownTime
|
||||
if (freeTimelineInfoShownTime != 0L) {
|
||||
val cal = Calendar.getInstance()
|
||||
val day = cal.get(Calendar.DAY_OF_MONTH)
|
||||
cal.timeInMillis = freeTimelineInfoShownTime
|
||||
return day != cal.get(Calendar.DAY_OF_MONTH)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun showFreeTimelineInfo() {
|
||||
val snackbar = Snackbar.make(coordinatorLayout, R.string.timeline_available_for_free_now, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_ok) {}
|
||||
AndroidUtils.setSnackbarTextColor(snackbar, R.color.ctrl_active_dark)
|
||||
snackbar.show()
|
||||
snackbarShown = true
|
||||
}
|
||||
settings.freeTimelineInfoShownTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
private fun showOptionsPopupMenu(anchor: View) {
|
||||
|
|
Loading…
Reference in a new issue