Add message to duplicate

csv
Laurent 6 years ago
parent 05afd66d73
commit 3bde851bd5
  1. 9
      app/src/main/java/net/pokeranalytics/android/ui/adapter/FeedSessionRowRepresentableAdapter.kt
  2. 17
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FeedFragment.kt
  3. 65
      app/src/main/java/net/pokeranalytics/android/util/Preferences.kt
  4. 6
      app/src/main/res/layout/fragment_feed.xml
  5. 2
      app/src/main/res/values-fr/strings.xml
  6. 4
      app/src/main/res/values/strings.xml

@ -77,14 +77,13 @@ class FeedSessionRowRepresentableAdapter(
val layout = LayoutInflater.from(parent.context).inflate(net.pokeranalytics.android.R.layout.row_header_title, parent, false) val layout = LayoutInflater.from(parent.context).inflate(net.pokeranalytics.android.R.layout.row_header_title, parent, false)
HeaderTitleViewHolder(layout) HeaderTitleViewHolder(layout)
} }
} }
override fun getItemViewType(position: Int): Int { override fun getItemViewType(position: Int): Int {
if (sortedHeaders.containsKey(position)) { return if (sortedHeaders.containsKey(position)) {
return RowViewType.HEADER_TITLE.ordinal RowViewType.HEADER_TITLE.ordinal
} else { } else {
return RowViewType.ROW_SESSION.ordinal RowViewType.ROW_SESSION.ordinal
} }
} }
@ -187,8 +186,6 @@ class FeedSessionRowRepresentableAdapter(
*/ */
private fun checkHeaderCondition(currentCalendar: Calendar, previousYear: Int, previousMonth: Int) : Boolean { private fun checkHeaderCondition(currentCalendar: Calendar, previousYear: Int, previousMonth: Int) : Boolean {
return currentCalendar.get(Calendar.YEAR) == previousYear && currentCalendar.get(Calendar.MONTH) < previousMonth || (currentCalendar.get(Calendar.YEAR) < previousYear) return currentCalendar.get(Calendar.YEAR) == previousYear && currentCalendar.get(Calendar.MONTH) < previousMonth || (currentCalendar.get(Calendar.YEAR) < previousYear)
} }
} }

@ -191,16 +191,23 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
registerForContextMenu(this.recyclerView) registerForContextMenu(this.recyclerView)
disclaimerContainer.isVisible = Preferences.shouldShowDisclaimer(requireContext()) val messageToShow: Preferences.FeedMessage? = Preferences.feedMessageToShow(requireContext())
disclaimerDismiss.setOnClickListener { if (messageToShow != null) {
Preferences.setStopShowingDisclaimer(requireContext()) messageBox.isVisible = true
message.text = getString(messageToShow.resId)
disclaimerContainer.animate().translationY(disclaimerContainer.height.toFloat()) messageBoxDismiss.setOnClickListener {
Preferences.setStopShowingMessage(messageToShow, requireContext())
messageBox.animate().translationY(messageBox.height.toFloat())
.setInterpolator(FastOutSlowInInterpolator()) .setInterpolator(FastOutSlowInInterpolator())
.withEndAction { disclaimerContainer?.isVisible = false } .withEndAction { messageBox?.isVisible = false }
.start() .start()
} }
} else {
messageBox.isVisible = false
}
addButton.setOnClickListener { addButton.setOnClickListener {
activity?.let { activity?.let {

@ -2,6 +2,10 @@ package net.pokeranalytics.android.util
import android.content.Context import android.content.Context
import android.preference.PreferenceManager import android.preference.PreferenceManager
import io.realm.Realm
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.extensions.count
import java.util.* import java.util.*
class Preferences { class Preferences {
@ -24,6 +28,7 @@ class Preferences {
LOCALE_CODE("LocaleCode"), LOCALE_CODE("LocaleCode"),
FIRST_LAUNCH("firstLaunch"), FIRST_LAUNCH("firstLaunch"),
STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"), STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"),
STOP_SHOWING_DUPLICATE("stopShowingDuplicate"),
ACTIVE_FILTER_ID("ActiveFilterId"), ACTIVE_FILTER_ID("ActiveFilterId"),
LATEST_PURCHASE("latestPurchase"), LATEST_PURCHASE("latestPurchase"),
PATCH_BREAK("patchBreaks"), PATCH_BREAK("patchBreaks"),
@ -31,6 +36,28 @@ class Preferences {
PATCH_BLINDS_FORMAT("patchBlindFormat") PATCH_BLINDS_FORMAT("patchBlindFormat")
} }
enum class FeedMessage {
DISCLAIMER,
DUPLICATE;
val resId: Int
get() {
return when (this) {
DISCLAIMER -> R.string.disclaimer
DUPLICATE -> R.string.longtap_to_duplicate
}
}
val key: Keys
get() {
return when (this) {
DISCLAIMER -> Keys.STOP_SHOWING_DISCLAIMER
DUPLICATE -> Keys.STOP_SHOWING_DUPLICATE
}
}
}
companion object { companion object {
fun setString(key: PreferenceKey, value: String, context: Context) { fun setString(key: PreferenceKey, value: String, context: Context) {
@ -47,7 +74,7 @@ class Preferences {
editor.apply() editor.apply()
} }
fun getString(key: Keys, context: Context) : String? { fun getString(key: Keys, context: Context): String? {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) val preferences = PreferenceManager.getDefaultSharedPreferences(context)
return preferences.getString(key.identifier, null) return preferences.getString(key.identifier, null)
} }
@ -59,7 +86,7 @@ class Preferences {
editor.apply() editor.apply()
} }
fun getBoolean(key: PreferenceKey, context: Context, defaultValue: Boolean? = false) : Boolean { fun getBoolean(key: PreferenceKey, context: Context, defaultValue: Boolean? = false): Boolean {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) val preferences = PreferenceManager.getDefaultSharedPreferences(context)
return preferences.getBoolean(key.identifier, defaultValue ?: false) return preferences.getBoolean(key.identifier, defaultValue ?: false)
} }
@ -73,7 +100,7 @@ class Preferences {
setString(Keys.ACTIVE_FILTER_ID, filterId, context) setString(Keys.ACTIVE_FILTER_ID, filterId, context)
} }
fun getActiveFilterId(context: Context) : String? { fun getActiveFilterId(context: Context): String? {
return getString(Keys.ACTIVE_FILTER_ID, context) return getString(Keys.ACTIVE_FILTER_ID, context)
} }
@ -81,11 +108,11 @@ class Preferences {
removeKey(Keys.ACTIVE_FILTER_ID, context) removeKey(Keys.ACTIVE_FILTER_ID, context)
} }
private fun getCurrencyCode(context: Context) : String? { private fun getCurrencyCode(context: Context): String? {
return getString(Keys.CURRENCY_CODE, context) return getString(Keys.CURRENCY_CODE, context)
} }
fun getCurrencyLocale(context : Context) : Locale? { fun getCurrencyLocale(context: Context): Locale? {
getCurrencyCode(context)?.let { currencyCode -> getCurrencyCode(context)?.let { currencyCode ->
UserDefaults.availableCurrencyLocales.filter { UserDefaults.availableCurrencyLocales.filter {
Currency.getInstance(it).currencyCode == currencyCode Currency.getInstance(it).currencyCode == currencyCode
@ -96,19 +123,30 @@ class Preferences {
return null return null
} }
fun getDefaultCurrency(context: Context) : Currency? { fun getDefaultCurrency(context: Context): Currency? {
getCurrencyLocale(context)?.let { getCurrencyLocale(context)?.let {
return Currency.getInstance(it) return Currency.getInstance(it)
} }
return null return null
} }
fun setStopShowingDisclaimer(context: Context) { fun setStopShowingMessage(message: FeedMessage, context: Context) {
setBoolean(Keys.STOP_SHOWING_DISCLAIMER, true, context) setBoolean(message.key,true, context)
}
fun feedMessageToShow(context: Context): FeedMessage? {
if (!getBoolean(Keys.STOP_SHOWING_DISCLAIMER, context)) {
return FeedMessage.DISCLAIMER
} }
fun shouldShowDisclaimer(context: Context) : Boolean { val realm = Realm.getDefaultInstance()
return !getBoolean(Keys.STOP_SHOWING_DISCLAIMER, context) val sessionCount = realm.count(Session::class.java)
realm.close()
if (sessionCount in 2..10 && !getBoolean(Keys.STOP_SHOWING_DUPLICATE, context)) {
return FeedMessage.DUPLICATE
}
return null
} }
fun executeOnce(key: Keys, context: Context, executable: () -> Unit) { fun executeOnce(key: Keys, context: Context, executable: () -> Unit) {
@ -128,7 +166,7 @@ class UserDefaults private constructor(context: Context) {
} }
companion object : SingletonHolder<UserDefaults, Context>(::UserDefaults) { companion object : SingletonHolder<UserDefaults, Context>(::UserDefaults) {
lateinit var currency : Currency lateinit var currency: Currency
fun setCurrencyValues(context: Context) { fun setCurrencyValues(context: Context) {
currency = Preferences.getDefaultCurrency(context) ?: getLocaleCurrency() currency = Preferences.getDefaultCurrency(context) ?: getLocaleCurrency()
@ -146,7 +184,7 @@ class UserDefaults private constructor(context: Context) {
/** /**
* Return the locale currency, or en_US if there * Return the locale currency, or en_US if there
*/ */
fun getLocaleCurrency() : Currency { fun getLocaleCurrency(): Currency {
return try { return try {
Currency.getInstance(Locale.getDefault()) Currency.getInstance(Locale.getDefault())
} catch (ex: Exception) { } catch (ex: Exception) {
@ -167,7 +205,8 @@ class UserDefaults private constructor(context: Context) {
open class SingletonHolder<out T, in A>(creator: (A) -> T) { open class SingletonHolder<out T, in A>(creator: (A) -> T) {
private var creator: ((A) -> T)? = creator private var creator: ((A) -> T)? = creator
@Volatile private var instance: T? = null @Volatile
private var instance: T? = null
fun init(context: A): T { fun init(context: A): T {
val i = instance val i = instance

@ -103,7 +103,7 @@
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent" />
<androidx.appcompat.widget.LinearLayoutCompat <androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/disclaimerContainer" android:id="@+id/messageBox"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/green_darker" android:background="@color/green_darker"
@ -115,18 +115,18 @@
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/message"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:text="@string/disclaimer"
android:textSize="18sp" android:textSize="18sp"
android:textColor="@color/white" android:textColor="@color/white"
tools:visibility="visible" /> tools:visibility="visible" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/disclaimerDismiss" android:id="@+id/messageBoxDismiss"
style="@style/PokerAnalyticsTheme.Button" style="@style/PokerAnalyticsTheme.Button"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

@ -60,7 +60,7 @@
<string name="tournament_names">Noms de tournoi</string> <string name="tournament_names">Noms de tournoi</string>
<string name="tournament_features">Propriétés de tournoi</string> <string name="tournament_features">Propriétés de tournoi</string>
<string name="pending">En attente</string> <string name="pending">En attente</string>
<string name="disclaimer">Poker Analytics est un tracker de sessions. Il s\'agit pour l\'instant d\'une version allégée de la version iOS existante. Nous allons ajouter les fonctionnalités au fur et à mesure. L\'app fonctionnera avec un abonnement illimité de 29,99€ par an, mais nous la proposons gratuitement en attendant plus de fonctionnalités</string> <string name="disclaimer">Poker Analytics est un tracker de sessions. L\'app fonctionne avec un abonnement illimité annuel, mais vous disposez de 10 sessions + un essai limité dans le temps pour la tester.</string>
<string name="iunderstand">C\'est compris !</string> <string name="iunderstand">C\'est compris !</string>
<string name="tournament_feature_empty_field_error">La propriété doit avoir un nom</string> <string name="tournament_feature_empty_field_error">La propriété doit avoir un nom</string>
<string name="duplicate_tournament_feature_error">Une propriété utilise déjà ce nom</string> <string name="duplicate_tournament_feature_error">Une propriété utilise déjà ce nom</string>

@ -50,7 +50,7 @@
<string name="tournament_feature">Tournament feature</string> <string name="tournament_feature">Tournament feature</string>
<string name="tournament_features">Tournament features</string> <string name="tournament_features">Tournament features</string>
<string name="pending">Pending</string> <string name="pending">Pending</string>
<string name="disclaimer">Poker Analytics is a poker tracking app. We’re currently on our way to reproduce the iOS app and you’re currently using a lighter version. The app will work with a US$29.99 yearly subscription for an unlimited usage, but will be free until reaching the appropriate feature coverage.</string> <string name="disclaimer">Poker Analytics is a poker tracking app.\nThe app works with a yearly subscription for an unlimited usage, but you get 10 sessions + a free trial to test the app.</string>
<string name="iunderstand">I understand</string> <string name="iunderstand">I understand</string>
<string name="tournament_feature_empty_field_error">You need to give a name to this tournament feature</string> <string name="tournament_feature_empty_field_error">You need to give a name to this tournament feature</string>
<string name="duplicate_tournament_feature_error">A tournament feature with the same name already exists.</string> <string name="duplicate_tournament_feature_error">A tournament feature with the same name already exists.</string>
@ -660,7 +660,7 @@
<string name="subscription_text">Subscription terms of use:\n• Payment will be charged to iTunes Account at confirmation of purchase\n• Subscription automatically renews unless auto-renew is turned off at least 24-hours before the end of the current period\n• Account will be charged for renewal within 24-hours prior to the end of the current period, and identify the cost of the renewal\n• Subscriptions may be managed by the user and auto-renewal may be turned off by going to the user\'s Account Settings after purchase\n• Any unused portion of a free trial period, if offered, will be forfeited when the user purchases a subscription to that publication, where applicable</string> <string name="subscription_text">Subscription terms of use:\n• Payment will be charged to iTunes Account at confirmation of purchase\n• Subscription automatically renews unless auto-renew is turned off at least 24-hours before the end of the current period\n• Account will be charged for renewal within 24-hours prior to the end of the current period, and identify the cost of the renewal\n• Subscriptions may be managed by the user and auto-renewal may be turned off by going to the user\'s Account Settings after purchase\n• Any unused portion of a free trial period, if offered, will be forfeited when the user purchases a subscription to that publication, where applicable</string>
<string name="privacy_policy">Privacy policy</string> <string name="privacy_policy">Privacy policy</string>
<string name="bug_report_message">We\'re truly sorry, but something is wrong here&#8230;You may be waiting for iCloud sync. Please wait and retry later. Would you mind sending us a report explaining your current state to help us solve this issue?</string> <string name="bug_report_message">We\'re truly sorry, but something is wrong here&#8230;You may be waiting for iCloud sync. Please wait and retry later. Would you mind sending us a report explaining your current state to help us solve this issue?</string>
<string name="longtap_to_duplicate">Tap and hold on a session to duplicate it.</string> <string name="longtap_to_duplicate">Tap and hold on a session to duplicate it!</string>
<string name="change_statistic">Change statistic</string> <string name="change_statistic">Change statistic</string>
<string name="compare">Compare</string> <string name="compare">Compare</string>
<string name="gross_amount">Gross Amount</string> <string name="gross_amount">Gross Amount</string>

Loading…
Cancel
Save