Add Welcome message

feature/top10
Aurelien Hubert 7 years ago
parent c92a8b970e
commit b1db4ddbb1
  1. 18
      app/src/main/java/net/pokeranalytics/android/ui/activity/HomeActivity.kt
  2. 17
      app/src/main/java/net/pokeranalytics/android/util/Preferences.kt

@ -3,12 +3,13 @@ package net.pokeranalytics.android.ui.activity
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.android.synthetic.main.activity_home.* import kotlinx.android.synthetic.main.activity_home.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.adapter.HomePagerAdapter import net.pokeranalytics.android.ui.adapter.HomePagerAdapter
import net.pokeranalytics.android.util.Preferences
class HomeActivity : PokerAnalyticsActivity() { class HomeActivity : PokerAnalyticsActivity() {
@ -44,6 +45,7 @@ class HomeActivity : PokerAnalyticsActivity() {
setContentView(R.layout.activity_home) setContentView(R.layout.activity_home)
initUI() initUI()
checkFirstLaunch()
} }
/** /**
@ -60,6 +62,20 @@ class HomeActivity : PokerAnalyticsActivity() {
} }
/**
* Check first launch
*/
private fun checkFirstLaunch() {
if (Preferences.getBoolean(Preferences.Keys.FIRST_LAUNCH, this, true)) {
Preferences.setBoolean(Preferences.Keys.FIRST_LAUNCH, false, this)
val builder = AlertDialog.Builder(this)
.setTitle(String.format(getString(R.string.welcome_in_), getString(R.string.app_name)))
.setMessage(R.string.popup_message_welcome)
.setNegativeButton(R.string.ok, null)
builder.show()
}
}
/** /**
* Display a new fragment * Display a new fragment
*/ */

@ -7,7 +7,8 @@ import java.util.*
class Preferences { class Preferences {
enum class Keys(var identifier: String) { enum class Keys(var identifier: String) {
CURRENCY_CODE("CurrencyCode") CURRENCY_CODE("CurrencyCode"),
FIRST_LAUNCH("firstLaunch")
} }
companion object { companion object {
@ -18,7 +19,7 @@ class Preferences {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val editor = preferences.edit() val editor = preferences.edit()
editor.putString(key.identifier, value) editor.putString(key.identifier, value)
editor.commit() editor.apply()
} }
fun getString(key: Keys, context: Context) : String? { fun getString(key: Keys, context: Context) : String? {
@ -26,6 +27,18 @@ class Preferences {
return preferences.getString(key.identifier, null) return preferences.getString(key.identifier, null)
} }
fun setBoolean(key: Keys, value: Boolean, context: Context) {
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val editor = preferences.edit()
editor.putBoolean(key.identifier, value)
editor.apply()
}
fun getBoolean(key: Keys, context: Context, defaultValue: Boolean? = false) : Boolean {
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
return preferences.getBoolean(key.identifier, defaultValue ?: false)
}
fun setCurrencyCode(currencyCode: String, context: Context) { fun setCurrencyCode(currencyCode: String, context: Context) {
Preferences.setString(Keys.CURRENCY_CODE, currencyCode, context) Preferences.setString(Keys.CURRENCY_CODE, currencyCode, context)
currencyLocale = null currencyLocale = null

Loading…
Cancel
Save