diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt index 061e9891..15a647f4 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt @@ -127,6 +127,13 @@ class SettingsFragment : RealmFragment(), RowRepresentableDelegate, StaticRowRep } } + override fun boolForRow(row: RowRepresentable): Boolean { + return when (row) { + SettingRow.STOP_NOTIFICATION -> Preferences.showStopNotifications(requireContext()) + else -> false + } + } + override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) { when (row) { SettingRow.BANKROLL_REPORT -> BankrollActivity.newInstance(requireContext()) @@ -165,6 +172,14 @@ class SettingsFragment : RealmFragment(), RowRepresentableDelegate, StaticRowRep } } + override fun onRowValueChanged(value: Any?, row: RowRepresentable) { + when (row) { + SettingRow.STOP_NOTIFICATION -> { + Preferences.setShowStopNotifications(value as Boolean, requireContext()) + } + else -> {} + } + } /** * Init UI diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/session/SessionFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/session/SessionFragment.kt index 9894de1d..7d1aa705 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/session/SessionFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/session/SessionFragment.kt @@ -38,9 +38,11 @@ import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentableDiffCallback import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow +import net.pokeranalytics.android.util.Preferences import net.pokeranalytics.android.util.extensions.findById import net.pokeranalytics.android.util.extensions.formattedHourlyDuration import net.pokeranalytics.android.util.extensions.getNextMinuteInMilliseconds +import timber.log.Timber import java.util.* import kotlin.coroutines.CoroutineContext @@ -358,8 +360,10 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate { SessionState.PENDING, SessionState.PLANNED, SessionState.PAUSED -> { // if not started computed cash game optimal duration - if (state != SessionState.PAUSED && this.currentSession.isCashGame()) { - computeOptimalDuration() + if (Preferences.showStopNotifications(requireContext())) { + if (state != SessionState.PAUSED && this.currentSession.isCashGame()) { + computeOptimalDuration() + } } currentSession.startOrContinue() @@ -377,18 +381,23 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate { private fun computeOptimalDuration() { + Timber.d("Start optimal duration finding attempt...") + val isLive = this.currentSession.isLive + GlobalScope.launch(coroutineContext) { var optimalDuration: Double? = null val cr = GlobalScope.async { - optimalDuration = CashGameOptimalDurationCalculator.start(currentSession.isLive) + optimalDuration = CashGameOptimalDurationCalculator.start(isLive) } cr.await() if (!isDetached) { optimalDuration?.let { - val formattedDuration = it.formattedHourlyDuration() + // TODO setup a notification + val formattedDuration = (it / 3600 / 1000).formattedHourlyDuration() + Timber.d("Setting stop notification in: $formattedDuration") val message = requireContext().getString(R.string.stop_notification_in_, formattedDuration) Toast.makeText(requireContext(), message, Toast.LENGTH_LONG).show() } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt index 7b99d734..00baf8a6 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt @@ -13,6 +13,10 @@ enum class SettingRow : RowRepresentable { TOP_10, PLAYERS, + // Cash Game + STOP_NOTIFICATION, + STOP_NOTIFICATION_MESSAGE, + // About SUBSCRIPTION, VERSION, @@ -59,6 +63,9 @@ enum class SettingRow : RowRepresentable { rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.reports)) rows.addAll(arrayListOf(BANKROLL_REPORT, TOP_10, PLAYERS)) + rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.cash_game)) + rows.addAll(arrayListOf(STOP_NOTIFICATION, STOP_NOTIFICATION_MESSAGE)) + rows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.information)) rows.addAll(arrayListOf(SUBSCRIPTION, VERSION, RATE_APP, CONTACT_US, BUG_REPORT, DISCORD)) @@ -96,6 +103,8 @@ enum class SettingRow : RowRepresentable { BANKROLL_REPORT -> R.string.bankroll TOP_10 -> R.string.top_10 PLAYERS -> R.string.players + STOP_NOTIFICATION -> R.string.stop_notifications + STOP_NOTIFICATION_MESSAGE -> R.string.stop_notifications_explanation SUBSCRIPTION -> R.string.subscription VERSION -> R.string.version RATE_APP -> R.string.releasenote_rating @@ -124,6 +133,8 @@ enum class SettingRow : RowRepresentable { VERSION, SUBSCRIPTION -> RowViewType.TITLE_VALUE.ordinal LANGUAGE, CURRENCY -> RowViewType.TITLE_VALUE_ARROW.ordinal FOLLOW_US -> RowViewType.ROW_FOLLOW_US.ordinal + STOP_NOTIFICATION -> RowViewType.TITLE_SWITCH.ordinal + STOP_NOTIFICATION_MESSAGE -> RowViewType.INFO.ordinal else -> RowViewType.TITLE_ARROW.ordinal } } diff --git a/app/src/main/java/net/pokeranalytics/android/util/Preferences.kt b/app/src/main/java/net/pokeranalytics/android/util/Preferences.kt index a24dfaaf..ea44b3e9 100644 --- a/app/src/main/java/net/pokeranalytics/android/util/Preferences.kt +++ b/app/src/main/java/net/pokeranalytics/android/util/Preferences.kt @@ -30,6 +30,7 @@ class Preferences { PATCH_SESSION_SETS("patchSessionSet"), PATCH_TRANSACTION_TYPES_NAMES("patchTransactionTypesNames"), PATCH_BLINDS_FORMAT("patchBlindFormat"), + SHOW_STOP_NOTIFICATIONS("showStopNotifications"), ADD_NEW_TRANSACTION_TYPES("addNewTransactionTypes") } @@ -90,13 +91,6 @@ class Preferences { editor.apply() } -// private fun removeKey(key: Keys, context: Context) { -// val preferences = PreferenceManager.getDefaultSharedPreferences(context) -// val editor = preferences.edit() -// editor.remove(key.identifier) -// editor.apply() -// } - fun getString(key: Keys, context: Context): String? { val preferences = PreferenceManager.getDefaultSharedPreferences(context) return preferences.getString(key.identifier, null) @@ -131,10 +125,6 @@ class Preferences { return getString(Keys.ACTIVE_FILTER_ID, context) } -// fun removeActiveFilterId(context: Context) { -// removeKey(Keys.ACTIVE_FILTER_ID, context) -// } - private fun getCurrencyCode(context: Context): String? { return getString(Keys.CURRENCY_CODE, context) } @@ -157,12 +147,19 @@ class Preferences { return null } + fun setShowStopNotifications(show: Boolean, context: Context) { + setBoolean(Keys.SHOW_STOP_NOTIFICATIONS, show, context) + } + + fun showStopNotifications(context: Context): Boolean { + return getBoolean(Keys.SHOW_STOP_NOTIFICATIONS, context, true) + } + fun setStopShowingMessage(message: FeedMessage, context: Context) { setBoolean(message.key, true, context) } fun feedMessageToShow(context: Context): FeedMessage? { -// return FeedMessage.DISCORD if (!getBoolean(Keys.STOP_SHOWING_DISCLAIMER, context)) { return FeedMessage.DISCLAIMER diff --git a/app/src/main/java/net/pokeranalytics/android/util/billing/AppGuard.kt b/app/src/main/java/net/pokeranalytics/android/util/billing/AppGuard.kt index 02f707b9..8a27f7d1 100644 --- a/app/src/main/java/net/pokeranalytics/android/util/billing/AppGuard.kt +++ b/app/src/main/java/net/pokeranalytics/android/util/billing/AppGuard.kt @@ -64,7 +64,7 @@ object AppGuard : PurchasesUpdatedListener { if (this.endOfUse != null) return true return if (BuildConfig.DEBUG) { - false //true + true //false //true } else { this._isProUser }