Merge branch 'master' of gitlab.com:stax-river/poker-analytics

feature/top10
Laurent 7 years ago
commit 6867c9b257
  1. 46
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 18
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
  3. 47
      app/src/main/java/net/pokeranalytics/android/ui/view/FormattedTextView.kt
  4. 39
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  5. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
  6. 5
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/HeaderRowRepresentable.kt
  7. 14
      app/src/main/java/net/pokeranalytics/android/util/Global.kt
  8. 4
      app/src/main/java/net/pokeranalytics/android/util/UIExtensions.kt
  9. 23
      app/src/main/java/net/pokeranalytics/android/util/URL.kt
  10. 2
      app/src/main/res/layout/row_header_title_amount.xml
  11. 2
      app/src/main/res/layout/row_header_title_amount_big.xml
  12. 2
      app/src/main/res/layout/row_header_title_value.xml
  13. 7
      app/src/main/res/layout/row_session_view.xml
  14. 16
      app/src/main/res/layout/row_title_switch.xml
  15. 7
      app/src/main/res/values/attrs.xml

@ -9,7 +9,9 @@ import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.ComputedStat
import net.pokeranalytics.android.calculus.SessionInterface
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.TableSize
@ -214,7 +216,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
* Return the formatted blinds
*/
fun getBlinds(): String {
return if (cgSmallBlind == null) "--" else "${cgSmallBlind?.toCurrency()}/${cgBigBlind?.round()}"
return if (cgSmallBlind == null) NULL_TEXT else "${cgSmallBlind?.toCurrency()}/${cgBigBlind?.round()}"
}
/**
@ -228,7 +230,7 @@ open class Session : RealmObject(), SessionInterface, Savable,
if (game != null) {
gameTitle += game?.name
}
return if (gameTitle.isNotBlank()) gameTitle else "--"
return if (gameTitle.isNotBlank()) gameTitle else NULL_TEXT
}
@ -345,26 +347,30 @@ open class Session : RealmObject(), SessionInterface, Savable,
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT_BIG,
title = getDuration(), value = result?.net.toString()
title = getDuration(),
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0)
)
)
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_AMOUNT,
resId = R.string.hour_rate_without_pauses,
value = this.sessionSet?.hourlyRate.toString()
computedStat = ComputedStat(Stat.NETRESULT, this.sessionSet?.hourlyRate ?: 0.0)
)
)
//TODO V2: Add Bankroll variation
/*
if (!isTournament()) {
rows.add(
HeaderRowRepresentable(
RowViewType.HEADER_TITLE_VALUE,
resId = R.string.bankroll_variation,
value = result?.net.toString()
computedStat = ComputedStat(Stat.HOURLY_RATE, 0.0)
)
)
}
*/
rows.add(SeparatorRowRepresentable())
}
@ -383,23 +389,25 @@ open class Session : RealmObject(), SessionInterface, Savable,
override fun stringForRow(row: RowRepresentable, context: Context): String {
return when (row) {
SessionRow.BANKROLL -> bankroll?.name ?: "--"
SessionRow.BANKROLL -> bankroll?.name ?: NULL_TEXT
SessionRow.BLINDS -> getBlinds()
SessionRow.BREAK_TIME -> timeFrame?.breakDuration?.toMinutes() ?: "--"
SessionRow.BREAK_TIME -> timeFrame?.breakDuration?.toMinutes() ?: NULL_TEXT
SessionRow.BUY_IN -> buyin.toCurrency()
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> result?.cashout?.toCurrency() ?: "--"
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--"
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime() ?: "--" else "--"
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> result?.cashout?.toCurrency() ?: NULL_TEXT
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else NULL_TEXT
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.shortDateTime()
?: NULL_TEXT else NULL_TEXT
SessionRow.GAME -> getGameTitle()
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: "--"
SessionRow.LOCATION -> location?.name ?: "--"
SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: "--"
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: "--"
SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime() ?: "--" else "--"
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: "--"
SessionRow.TIPS -> result?.tips?.toCurrency() ?: "--"
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: "--"
else -> "--"
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: NULL_TEXT
SessionRow.LOCATION -> location?.name ?: NULL_TEXT
SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: NULL_TEXT
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: NULL_TEXT
SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.shortDateTime()
?: NULL_TEXT else NULL_TEXT
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT
SessionRow.TIPS -> result?.tips?.toCurrency() ?: NULL_TEXT
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: NULL_TEXT
else -> NULL_TEXT
}
}

@ -17,8 +17,10 @@ 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.*
import android.content.Intent
import net.pokeranalytics.android.util.URL
import net.pokeranalytics.android.util.openContactMail
import net.pokeranalytics.android.util.openPlayStorePage
import net.pokeranalytics.android.util.openUrl
@ -75,14 +77,14 @@ class SettingsFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Sta
}
SettingRow.FOLLOW_US -> {
when(position) {
0 -> parentActivity.openUrl(BLOG)
1 -> parentActivity.openUrl(INSTAGRAM)
2 -> parentActivity.openUrl(TWITTER)
3 -> parentActivity.openUrl(FACEBOOK)
0 -> parentActivity.openUrl(URL.BLOG.value)
1 -> parentActivity.openUrl(URL.INSTAGRAM.value)
2 -> parentActivity.openUrl(URL.TWITTER.value)
3 -> parentActivity.openUrl(URL.FACEBOOK.value)
}
}
SettingRow.PRIVACY_POLICY -> parentActivity.openUrl(URL_PRIVACY_POLICY)
SettingRow.TERMS_OF_USE -> parentActivity.openUrl(URL_TERMS)
SettingRow.PRIVACY_POLICY -> parentActivity.openUrl(URL.PRIVACY_POLICY.value)
SettingRow.TERMS_OF_USE -> parentActivity.openUrl(URL.TERMS.value)
SettingRow.GDPR -> Toast.makeText(requireContext(), "Show GDPR", Toast.LENGTH_SHORT).show()
}

@ -1,47 +0,0 @@
package net.pokeranalytics.android.ui.view
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import net.pokeranalytics.android.calculus.TextFormat
/**
* Extended TextView to display a TextFormat object
*/
class FormattedTextView: AppCompatTextView {
var textFormat: TextFormat? = null
set(value) {
field = value
updateUI()
}
constructor(context: Context?) : super(context) {
init(null)
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
init(attrs)
}
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init(attrs)
}
/**
* Init class
*/
private fun init(attrs: AttributeSet?) {
}
/**
* Update the UI to manage currency format & color management
*/
private fun updateUI() {
textFormat?.let {
setTextColor(it.getColor(context))
text = it.text
}
}
}

@ -5,13 +5,12 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.appcompat.widget.SwitchCompat
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.row_history_session.view.*
import kotlinx.android.synthetic.main.row_stats_title_value.view.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.ComputedStat
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.view.rowrepresentable.HeaderRowRepresentable
@ -64,9 +63,7 @@ enum class RowViewType(private var layoutRes: Int) {
return when (this) {
// Header Row View Holder
HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG -> {
HeaderViewHolder(layout)
}
HEADER_TITLE, HEADER_TITLE_VALUE, HEADER_TITLE_AMOUNT, HEADER_TITLE_AMOUNT_BIG -> HeaderViewHolder(layout)
// Row View Holder
TITLE, TITLE_VALUE, TITLE_ARROW, TITLE_GRID, TITLE_SWITCH, DATA, BOTTOM_SHEET_DATA -> RowViewHolder(layout)
@ -86,7 +83,7 @@ enum class RowViewType(private var layoutRes: Int) {
// Separator
SEPARATOR -> SeparatorViewHolder(layout)
else -> throw Exception("Undefined rowViewType's holder")
//else -> throw Exception("Undefined rowViewType's holder")
}
}
@ -105,17 +102,14 @@ enum class RowViewType(private var layoutRes: Int) {
}
// Value
itemView.findViewById<FormattedTextView?>(R.id.value)?.let {
val value = try {
row.value?.toDouble() ?: 0.0
} catch (e: Exception) {
0.0
itemView.findViewById<AppCompatTextView?>(R.id.value)?.let {
if (row.computedStat != null) {
val format = row.computedStat!!.format(itemView.context)
it.setTextColor(format.getColor(itemView.context))
it.text = format.text
} else if (row.value != null) {
it.text = row.value
}
//TODO: Manage multiple stat type
val stat = ComputedStat(Stat.NETRESULT, value)
it.textFormat = stat.format(itemView.context)
//it.text = adapter.dataSource.stringForRow(row, itemView.context)
}
}
}
@ -141,10 +135,22 @@ enum class RowViewType(private var layoutRes: Int) {
it.text = adapter.dataSource.stringForRow(row, itemView.context)
}
// Switch
itemView.findViewById<SwitchCompat?>(R.id.switchView)?.let {
it.isChecked = adapter.dataSource.boolForRow(row)
it.setOnCheckedChangeListener { _, isChecked ->
adapter.delegate?.onRowValueChanged(isChecked, row)
}
}
// Listener
val listener = View.OnClickListener {
itemView.findViewById<SwitchCompat?>(R.id.switchView)?.let {
it.isChecked = !it.isChecked
} ?: run {
adapter.delegate?.onRowSelected(position, row)
}
}
itemView.findViewById<View?>(R.id.container)?.let {
it.setOnClickListener(listener)
@ -216,7 +222,6 @@ enum class RowViewType(private var layoutRes: Int) {
}
}
/**
* Display a separator
*/

@ -134,8 +134,9 @@ class SessionRowView : FrameLayout {
rowHistorySession.infoTitle.isVisible = false
val result = session.result?.net ?: 0.0
val stat = ComputedStat(Stat.NETRESULT, result)
rowHistorySession.gameResult.textFormat = stat.format(context)
val formattedStat = ComputedStat(Stat.NETRESULT, result).format(context)
rowHistorySession.gameResult.setTextColor(formattedStat.getColor(context))
rowHistorySession.gameResult.text = formattedStat.text
}
}

@ -1,6 +1,7 @@
package net.pokeranalytics.android.ui.view.rowrepresentable
import android.content.Context
import net.pokeranalytics.android.calculus.ComputedStat
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
@ -11,7 +12,8 @@ class HeaderRowRepresentable(
var customViewType: RowViewType? = RowViewType.HEADER_TITLE,
override var resId: Int? = null,
var title: String? = null,
var value: String? = null
var value: String? = null,
var computedStat: ComputedStat? = null
) : RowRepresentable {
override fun localizedTitle(context: Context): String {
@ -26,6 +28,7 @@ class HeaderRowRepresentable(
}
override val viewType: Int = customViewType?.ordinal ?: RowViewType.HEADER_TITLE.ordinal
}

@ -1,17 +1,3 @@
package net.pokeranalytics.android.util
val NULL_TEXT: String = "--"
// Support
const val SUPPORT_EMAIL = "support@pokeranalytics.net"
// Terms
const val URL_PRIVACY_POLICY = "https://www.poker-analytics.net/privacypolicy.html"
const val URL_TERMS = "https://www.poker-analytics.net/terms.html"
// Social Network
const val BLOG = "https://medium.com/poker-analytics"
const val INSTAGRAM = "https://www.instagram.com/pokeranalytics"
const val TWITTER = "https://twitter.com/paapptweet"
const val FACEBOOK = "https://www.facebook.com/171053452998758"

@ -57,8 +57,8 @@ fun PokerAnalyticsActivity.openPlayStorePage() {
fun PokerAnalyticsActivity.openContactMail() {
val info = "v${BuildConfig.VERSION_NAME}(${BuildConfig.VERSION_CODE}), Android ${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.data = Uri.parse("mailto:${URL.SUPPORT_EMAIL.value}")
intent.putExtra(Intent.EXTRA_EMAIL, URL.SUPPORT_EMAIL.value)
intent.putExtra(Intent.EXTRA_TEXT, "\n\n$info")
startActivity(Intent.createChooser(intent, getString(R.string.contact)))
}

@ -0,0 +1,23 @@
package net.pokeranalytics.android.util
/**
* URL enum
*/
enum class URL(var value: String) {
// Terms
PRIVACY_POLICY("https://www.poker-analytics.net/privacypolicy.html"),
TERMS("https://www.poker-analytics.net/terms.html"),
// Social Network
BLOG("https://medium.com/poker-analytics"),
INSTAGRAM("https://www.instagram.com/pokeranalytics"),
TWITTER("https://twitter.com/paapptweet"),
FACEBOOK("https://www.facebook.com/171053452998758"),
// Support
SUPPORT_EMAIL("support@pokeranalytics.net")
}

@ -24,7 +24,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<net.pokeranalytics.android.ui.view.FormattedTextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/value"
style="@style/PokerAnalyticsTheme.TextView.RowValue"
android:layout_width="0dp"

@ -24,7 +24,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<net.pokeranalytics.android.ui.view.FormattedTextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/value"
style="@style/PokerAnalyticsTheme.TextView.RowValue"
android:layout_width="0dp"

@ -22,7 +22,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<net.pokeranalytics.android.ui.view.FormattedTextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/value"
style="@style/PokerAnalyticsTheme.TextView.RowValue"
android:layout_width="0dp"

@ -151,15 +151,14 @@
app:layout_constraintEnd_toStartOf="@+id/nextArrow"
app:layout_constraintTop_toTopOf="@+id/sessionTitle">
<net.pokeranalytics.android.ui.view.FormattedTextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/gameResult"
style="@style/PokerAnalyticsTheme.TextView.SessionRow.Result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:isCurrency="true"
tools:amount="1000"
tools:visibility="visible" />
tools:visibility="visible"
tools:text="$ 1000"/>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/infoIcon"

@ -22,6 +22,14 @@
app:layout_constraintVertical_bias="0.0"
tools:text="Data Type Title" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guidelineEnd"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
@ -36,12 +44,4 @@
android:orientation="vertical"
app:layout_constraintGuide_end="16dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guidelineEnd"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="FormattedTextView">
<attr name="isCurrency" format="boolean" />
<attr name="amount" format="float" />
</declare-styleable>
</resources>
Loading…
Cancel
Save