Improve Settings

feature/top10
Aurelien Hubert 7 years ago
parent 89f6200aed
commit 85ca451541
  1. 12
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SettingRow.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/util/Global.kt
  4. 49
      app/src/main/java/net/pokeranalytics/android/util/UIExtensions.kt

@ -10,15 +10,19 @@ import kotlinx.android.synthetic.main.fragment_settings.*
import net.pokeranalytics.android.BuildConfig
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.DataListActivity
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.SettingRow
import net.pokeranalytics.android.util.*
class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, StaticRowRepresentableDataSource {
private lateinit var parentActivity: PokerAnalyticsActivity
companion object {
/**
@ -60,6 +64,12 @@ class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Sta
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) {
when (row) {
SettingRow.RATE_APP -> parentActivity.openPlayStorePage()
SettingRow.CONTACT_US -> parentActivity.openContactMail()
SettingRow.BUG_REPORT -> Toast.makeText(requireContext(), "Bug report", Toast.LENGTH_SHORT).show()
SettingRow.CURRENCY -> Toast.makeText(requireContext(), "Currency", Toast.LENGTH_SHORT).show()
SettingRow.PRIVACY_POLICY -> parentActivity.openUrl(URL_PRIVACY_POLICY)
SettingRow.TERMS_OF_USE -> parentActivity.openUrl(URL_TERMS)
SettingRow.GDPR -> Toast.makeText(requireContext(), "Show GDPR", Toast.LENGTH_SHORT).show()
}
@ -73,6 +83,8 @@ class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Sta
*/
private fun initData() {
parentActivity = activity as PokerAnalyticsActivity
val viewManager = LinearLayoutManager(requireContext())
settingsAdapterRow = RowRepresentableAdapter(
this, this

@ -90,7 +90,7 @@ enum class SettingRow : RowRepresentable {
get() {
return when (this) {
VERSION -> RowViewType.TITLE_VALUE.ordinal
else -> RowViewType.TITLE.ordinal
else -> RowViewType.TITLE_ARROW.ordinal
}
}

@ -1,3 +1,8 @@
package net.pokeranalytics.android.util
const val SUPPORT_EMAIL = "support@pokeranalytics.net"
const val URL_PRIVACY_POLICY = "https://www.poker-analytics.net/privacypolicy.html"
const val URL_TERMS = "https://www.poker-analytics.net/terms.html"
val NULL_TEXT: String = "--"

@ -1,7 +1,14 @@
package net.pokeranalytics.android.util
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.res.Resources
import android.net.Uri
import android.widget.Toast
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import net.pokeranalytics.android.BuildConfig
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
@ -17,13 +24,49 @@ val Float.px: Float
get() = (this * Resources.getSystem().displayMetrics.density)
// Toast
fun PokerAnalyticsActivity.toast(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
fun PokerAnalyticsFragment.toast(message: String) {
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
}
// Open Play Store for rating
fun PokerAnalyticsActivity.openPlayStorePage() {
val uri = Uri.parse("market://details?id=$packageName")
val goToMarket = Intent(Intent.ACTION_VIEW, uri)
goToMarket.addFlags(
Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
Intent.FLAG_ACTIVITY_MULTIPLE_TASK
)
try {
startActivity(goToMarket)
} catch (e: ActivityNotFoundException) {
startActivity(
Intent(
Intent.ACTION_VIEW, Uri.parse(
"http://play.google.com/store/apps/details?id=$packageName"
)
)
)
}
}
// Open email for "Contact us"
fun PokerAnalyticsActivity.openContactMail() {
val info = "${BuildConfig.VERSION_NAME}(${BuildConfig.VERSION_CODE}), ${android.os.Build.VERSION.SDK_INT}"
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:$SUPPORT_EMAIL")
intent.putExtra(Intent.EXTRA_EMAIL, SUPPORT_EMAIL)
intent.putExtra(Intent.EXTRA_TEXT, "<br/><br/>$info")
startActivity(Intent.createChooser(intent, getString(R.string.contact)))
}
// Open custom tab
fun PokerAnalyticsActivity.openUrl(url: String) {
val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
val customTabsIntent = builder.build()
customTabsIntent.launchUrl(this, Uri.parse(url))
}

Loading…
Cancel
Save