Adds home message for discord + upgrade of the messaging system to add an action button

od
Laurent 6 years ago
parent a508604b2a
commit 62503c0c2d
  1. 10
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 17
      app/src/main/java/net/pokeranalytics/android/ui/extensions/UIExtensions.kt
  3. 29
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FeedFragment.kt
  4. 4
      app/src/main/java/net/pokeranalytics/android/util/Global.kt
  5. 44
      app/src/main/java/net/pokeranalytics/android/util/Preferences.kt
  6. 12
      app/src/main/res/layout/fragment_feed.xml
  7. 2
      app/src/main/res/values-de/strings.xml
  8. 2
      app/src/main/res/values-es/strings.xml
  9. 2
      app/src/main/res/values-fr/strings.xml
  10. 2
      app/src/main/res/values-hi/strings.xml
  11. 2
      app/src/main/res/values-it/strings.xml
  12. 2
      app/src/main/res/values-ja/strings.xml
  13. 2
      app/src/main/res/values-pt/strings.xml
  14. 2
      app/src/main/res/values-ru/strings.xml
  15. 2
      app/src/main/res/values-v24/strings.xml
  16. 2
      app/src/main/res/values-zh/strings.xml
  17. 2
      app/src/main/res/values/strings.xml
  18. 5
      app/src/main/res/values/styles.xml

@ -1,6 +1,7 @@
package net.pokeranalytics.android package net.pokeranalytics.android
import android.app.Application import android.app.Application
import android.content.Context
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
import com.crashlytics.android.core.CrashlyticsCore import com.crashlytics.android.core.CrashlyticsCore
import io.fabric.sdk.android.Fabric import io.fabric.sdk.android.Fabric
@ -22,6 +23,15 @@ import timber.log.Timber
class PokerAnalyticsApplication : Application() { class PokerAnalyticsApplication : Application() {
companion object {
fun timeSinceInstall(context: Context): Long {
val installTime: Long = context.packageManager.getPackageInfo(context.packageName, 0).firstInstallTime
return System.currentTimeMillis() - installTime
}
}
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
UserDefaults.init(this) UserDefaults.init(this)

@ -1,5 +1,6 @@
package net.pokeranalytics.android.ui.extensions package net.pokeranalytics.android.ui.extensions
import android.app.Activity
import android.content.ActivityNotFoundException import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -16,10 +17,10 @@ import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import net.pokeranalytics.android.BuildConfig import net.pokeranalytics.android.BuildConfig
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.components.BaseActivity import net.pokeranalytics.android.ui.activity.components.BaseActivity
import net.pokeranalytics.android.ui.fragment.components.BaseFragment
import net.pokeranalytics.android.util.DeviceUtils import net.pokeranalytics.android.util.DeviceUtils
import net.pokeranalytics.android.util.TextFormat import net.pokeranalytics.android.util.TextFormat
import net.pokeranalytics.android.util.URL import net.pokeranalytics.android.util.URL
@ -39,16 +40,16 @@ val Float.px: Float
// Toast // Toast
fun BaseActivity.toast(message: String) { fun Activity.toast(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show() Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
} }
fun BaseFragment.toast(message: String) { fun Fragment.toast(message: String) {
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show() Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
} }
// Open Play Store for rating // Open Play Store for rating
fun BaseActivity.openPlayStorePage() { fun Activity.openPlayStorePage() {
val uri = Uri.parse("market://details?id=$packageName") val uri = Uri.parse("market://details?id=$packageName")
val goToMarket = Intent(Intent.ACTION_VIEW, uri) val goToMarket = Intent(Intent.ACTION_VIEW, uri)
goToMarket.addFlags( goToMarket.addFlags(
@ -94,19 +95,19 @@ fun BaseActivity.openContactMail(subjectStringRes: Int, filePath: String? = null
} }
// Open custom tab // Open custom tab
fun BaseActivity.openUrl(url: String) { fun Context.openUrl(url: String) {
val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder() val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(this, net.pokeranalytics.android.R.color.colorPrimary)) builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
val customTabsIntent = builder.build() val customTabsIntent = builder.build()
customTabsIntent.launchUrl(this, Uri.parse(url)) customTabsIntent.launchUrl(this, Uri.parse(url))
} }
// Display Alert Dialog // Display Alert Dialog
fun BaseActivity.showAlertDialog(title: Int? = null, message: Int? = null) { fun Activity.showAlertDialog(title: Int? = null, message: Int? = null) {
showAlertDialog(this, title, message) showAlertDialog(this, title, message)
} }
fun BaseFragment.showAlertDialog(title: Int? = null, message: Int? = null) { fun Fragment.showAlertDialog(title: Int? = null, message: Int? = null) {
context?.let { context?.let {
showAlertDialog(it, title, message) showAlertDialog(it, title, message)
} }

@ -221,13 +221,21 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
messageBox.isVisible = true messageBox.isVisible = true
message.text = getString(messageToShow.resId) message.text = getString(messageToShow.resId)
messageBoxDismiss.setOnClickListener { messageToShow.actionResId?.let {
Preferences.setStopShowingMessage(messageToShow, requireContext()) messageBoxAction.text = requireContext().getString(it)
messageToShow.action(requireContext())?.let { action ->
messageBoxAction.setOnClickListener {
action.invoke(it)
hideMessageBox(messageToShow)
}
}
} ?: run {
messageBoxAction.visibility = View.GONE
}
messageBox.animate().translationY(messageBox.height.toFloat()) messageBoxDismiss.text = requireContext().getString(messageToShow.dismissResId)
.setInterpolator(FastOutSlowInInterpolator()) messageBoxDismiss.setOnClickListener {
.withEndAction { messageBox?.isVisible = false } hideMessageBox(messageToShow)
.start()
} }
} else { } else {
messageBox.isVisible = false messageBox.isVisible = false
@ -265,6 +273,15 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
} }
private fun hideMessageBox(message: Preferences.FeedMessage) {
Preferences.setStopShowingMessage(message, requireContext())
messageBox.animate().translationY(messageBox.height.toFloat())
.setInterpolator(FastOutSlowInInterpolator())
.withEndAction { messageBox?.isVisible = false }
.start()
}
/** /**
* Init data * Init data
*/ */

@ -1,3 +1,5 @@
package net.pokeranalytics.android.util package net.pokeranalytics.android.util
val NULL_TEXT: String = "--" import android.content.Context
const val NULL_TEXT: String = "--"

@ -2,9 +2,12 @@ package net.pokeranalytics.android.util
import android.content.Context import android.content.Context
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.view.View
import io.realm.Realm import io.realm.Realm
import net.pokeranalytics.android.PokerAnalyticsApplication
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.extensions.openUrl
import net.pokeranalytics.android.util.extensions.count import net.pokeranalytics.android.util.extensions.count
import java.util.* import java.util.*
@ -29,6 +32,7 @@ class Preferences {
FIRST_LAUNCH("firstLaunch"), FIRST_LAUNCH("firstLaunch"),
STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"), STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"),
STOP_SHOWING_DUPLICATE("stopShowingDuplicate"), STOP_SHOWING_DUPLICATE("stopShowingDuplicate"),
STOP_SHOWING_DISCORD("stopShowingDiscord"),
ACTIVE_FILTER_ID("ActiveFilterId"), ACTIVE_FILTER_ID("ActiveFilterId"),
LATEST_PURCHASE("latestPurchase"), LATEST_PURCHASE("latestPurchase"),
PATCH_BREAK("patchBreaks"), PATCH_BREAK("patchBreaks"),
@ -40,6 +44,7 @@ class Preferences {
enum class FeedMessage { enum class FeedMessage {
DISCLAIMER, DISCLAIMER,
DISCORD,
DUPLICATE; DUPLICATE;
val resId: Int val resId: Int
@ -47,6 +52,7 @@ class Preferences {
return when (this) { return when (this) {
DISCLAIMER -> R.string.disclaimer DISCLAIMER -> R.string.disclaimer
DUPLICATE -> R.string.longtap_to_duplicate DUPLICATE -> R.string.longtap_to_duplicate
DISCORD -> R.string.discord_feed_message
} }
} }
@ -55,6 +61,30 @@ class Preferences {
return when (this) { return when (this) {
DISCLAIMER -> Keys.STOP_SHOWING_DISCLAIMER DISCLAIMER -> Keys.STOP_SHOWING_DISCLAIMER
DUPLICATE -> Keys.STOP_SHOWING_DUPLICATE DUPLICATE -> Keys.STOP_SHOWING_DUPLICATE
DISCORD -> Keys.STOP_SHOWING_DISCORD
}
}
val actionResId: Int?
get() {
return when (this) {
DISCORD -> R.string.join_discord
else -> null
}
}
fun action(context: Context): ((View) -> (Unit))? {
return when (this) {
DISCORD -> { { context.openUrl(URL.DISCORD.value) } }
else -> null
}
}
val dismissResId: Int
get() {
return when (this) {
DISCORD -> R.string.good_for_you
else -> R.string.iunderstand
} }
} }
@ -88,7 +118,11 @@ 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)
} }
@ -133,10 +167,11 @@ class Preferences {
} }
fun setStopShowingMessage(message: FeedMessage, context: Context) { fun setStopShowingMessage(message: FeedMessage, context: Context) {
setBoolean(message.key,true, context) setBoolean(message.key, true, context)
} }
fun feedMessageToShow(context: Context): FeedMessage? { fun feedMessageToShow(context: Context): FeedMessage? {
// return FeedMessage.DISCORD
if (!getBoolean(Keys.STOP_SHOWING_DISCLAIMER, context)) { if (!getBoolean(Keys.STOP_SHOWING_DISCLAIMER, context)) {
return FeedMessage.DISCLAIMER return FeedMessage.DISCLAIMER
@ -148,6 +183,11 @@ class Preferences {
if (sessionCount > 1 && !getBoolean(Keys.STOP_SHOWING_DUPLICATE, context)) { if (sessionCount > 1 && !getBoolean(Keys.STOP_SHOWING_DUPLICATE, context)) {
return FeedMessage.DUPLICATE return FeedMessage.DUPLICATE
} }
if (!getBoolean(Keys.STOP_SHOWING_DISCORD, context) && PokerAnalyticsApplication.timeSinceInstall(context) > 1000 * 3600 * 24 * 30L) {
return FeedMessage.DISCORD
}
return null return null
} }

@ -125,6 +125,15 @@
android:textColor="@color/white" android:textColor="@color/white"
tools:visibility="visible" /> tools:visibility="visible" />
<com.google.android.material.button.MaterialButton
android:id="@+id/messageBoxAction"
style="@style/PokerAnalyticsTheme.SecondaryButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/messageBoxDismiss" android:id="@+id/messageBoxDismiss"
style="@style/PokerAnalyticsTheme.Button" style="@style/PokerAnalyticsTheme.Button"
@ -132,8 +141,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"/>
android:text="@string/iunderstand" />
</androidx.appcompat.widget.LinearLayoutCompat> </androidx.appcompat.widget.LinearLayoutCompat>

@ -691,5 +691,7 @@
<string name="face_id_usage_description">Poker Analytics benötigt Zugriff auf Face ID, damit Sie die App per Gesichtserkennung entsperren können.</string> <string name="face_id_usage_description">Poker Analytics benötigt Zugriff auf Face ID, damit Sie die App per Gesichtserkennung entsperren können.</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -692,5 +692,7 @@
<string name="face_id_usage_description">Poker Analytics desea acceder a Face ID para permitir desbloquear la aplicación con reconocimiento facial.</string> <string name="face_id_usage_description">Poker Analytics desea acceder a Face ID para permitir desbloquear la aplicación con reconocimiento facial.</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -760,5 +760,7 @@
<string name="do_you_really_to_delete_this_game">Voulez-vous vraiment supprimer cette partie ?</string> <string name="do_you_really_to_delete_this_game">Voulez-vous vraiment supprimer cette partie ?</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -691,5 +691,7 @@
<string name="face_id_usage_description">Poker Analytics आपकहर पहचन कर एपप खलन अनमतििए Face ID तक पहच चहत</string> <string name="face_id_usage_description">Poker Analytics आपकहर पहचन कर एपप खलन अनमतििए Face ID तक पहच चहत</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -691,5 +691,7 @@
<string name="face_id_usage_description">Poker Analytics vuole accedere a Face ID per consentirti di sbloccare l\'app tramite riconoscimento facciale</string> <string name="face_id_usage_description">Poker Analytics vuole accedere a Face ID per consentirti di sbloccare l\'app tramite riconoscimento facciale</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -691,5 +691,7 @@
<string name="face_id_usage_description">顔認識でアプリのロックを解除できるようにするため、Poker AnalyticsがFace IDをへのアクセスを要求しています</string> <string name="face_id_usage_description">顔認識でアプリのロックを解除できるようにするため、Poker AnalyticsがFace IDをへのアクセスを要求しています</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -690,5 +690,7 @@
<string name="photo_library_add_usage_description">O Poker Analytics deseja salvar esta imagem na sua biblioteca de Fotos</string> <string name="photo_library_add_usage_description">O Poker Analytics deseja salvar esta imagem na sua biblioteca de Fotos</string>
<string name="face_id_usage_description">O Poker Analytics deseja acessar o Face ID para permitir que você desbloqueie o aplicativo com reconhecimento facial</string> <string name="face_id_usage_description">O Poker Analytics deseja acessar o Face ID para permitir que você desbloqueie o aplicativo com reconhecimento facial</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -692,5 +692,7 @@
<string name="face_id_usage_description">Poker Analytics хочет получить доступ к Face ID, чтобы вы могли разблокировать приложение c помощью идентификации по лицу</string> <string name="face_id_usage_description">Poker Analytics хочет получить доступ к Face ID, чтобы вы могли разблокировать приложение c помощью идентификации по лицу</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -687,5 +687,7 @@
<string name="face_id_usage_description">Poker Analytics希望访问Face ID以便通过人脸识别解锁本应用</string> <string name="face_id_usage_description">Poker Analytics希望访问Face ID以便通过人脸识别解锁本应用</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -771,5 +771,7 @@
<string name="face_id_usage_description">Poker Analytics wants to access Face ID to let you unlock the app with face recognition</string> <string name="face_id_usage_description">Poker Analytics wants to access Face ID to let you unlock the app with face recognition</string>
<string name="poker_rumble">Poker Rumble</string> <string name="poker_rumble">Poker Rumble</string>
<string name="join_discord">Join us on Discord!</string> <string name="join_discord">Join us on Discord!</string>
<string name="discord_feed_message">We\'ve opened our Discord channel! Come to hang out, talk about poker or about the app!</string>
<string name="good_for_you">Good for you!</string>
</resources> </resources>

@ -341,13 +341,16 @@
<item name="android:textSize">12sp</item> <item name="android:textSize">12sp</item>
</style> </style>
<style name="PokerAnalyticsTheme.SecondaryButton" parent="PokerAnalyticsTheme.Button">
<item name="backgroundTint">@color/white</item>
</style>
<style name="PokerAnalyticsTheme.Button.Borderless" parent="Widget.MaterialComponents.Button"> <style name="PokerAnalyticsTheme.Button.Borderless" parent="Widget.MaterialComponents.Button">
<item name="android:background">?selectableItemBackgroundBorderless</item> <item name="android:background">?selectableItemBackgroundBorderless</item>
<item name="android:textColor">@color/green</item> <item name="android:textColor">@color/green</item>
<item name="android:fontFamily">@font/roboto_bold</item> <item name="android:fontFamily">@font/roboto_bold</item>
</style> </style>
<!-- Chip --> <!-- Chip -->
<style name="PokerAnalyticsTheme.Chip" parent="Widget.MaterialComponents.Chip.Choice"> <style name="PokerAnalyticsTheme.Chip" parent="Widget.MaterialComponents.Chip.Choice">

Loading…
Cancel
Save