parent
5c2542f758
commit
e437591748
@ -0,0 +1,10 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.handhistory |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.widget.FrameLayout |
||||||
|
|
||||||
|
abstract class AbstractKeyboardView(context: Context) : FrameLayout(context) { |
||||||
|
|
||||||
|
var keyboardListener: KeyboardListener? = null |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,58 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.handhistory |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.view.LayoutInflater |
||||||
|
import androidx.recyclerview.widget.GridLayoutManager |
||||||
|
import kotlinx.android.synthetic.main.bottom_sheet_grid.view.* |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.realm.handhistory.Action |
||||||
|
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.extensions.px |
||||||
|
import net.pokeranalytics.android.ui.view.GridSpacingItemDecoration |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
|
||||||
|
|
||||||
|
class KeyboardActionView(context: Context) : AbstractKeyboardView(context), |
||||||
|
StaticRowRepresentableDataSource, RowRepresentableDelegate { |
||||||
|
|
||||||
|
private var dataAdapter: RowRepresentableAdapter |
||||||
|
|
||||||
|
init { |
||||||
|
|
||||||
|
LayoutInflater.from(context) |
||||||
|
.inflate(R.layout.bottom_sheet_grid, this, true) |
||||||
|
|
||||||
|
val viewManager = GridLayoutManager(context, 3) |
||||||
|
this.dataAdapter = RowRepresentableAdapter(this, this) |
||||||
|
|
||||||
|
val spanCount = 3 |
||||||
|
val spacing = 2.px |
||||||
|
val includeEdge = false |
||||||
|
|
||||||
|
this.recyclerView.apply { |
||||||
|
setHasFixedSize(true) |
||||||
|
layoutManager = viewManager |
||||||
|
adapter = dataAdapter |
||||||
|
addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, includeEdge)) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
override fun adapterRows(): List<RowRepresentable>? { |
||||||
|
return Action.Type.defaultTypes |
||||||
|
} |
||||||
|
|
||||||
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
||||||
|
this.keyboardListener?.actionSelected(row as Action.Type) |
||||||
|
} |
||||||
|
|
||||||
|
// override fun stringForRow(row: RowRepresentable): String { |
||||||
|
// this.context?.let { |
||||||
|
// return row.localizedTitle(it) |
||||||
|
// } |
||||||
|
// return "UNKNOWN CONTEXT FOR ROW $row" |
||||||
|
// } |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.handhistory |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
|
||||||
|
class KeyboardAmountView(context: Context) : AbstractKeyboardView(context) { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.handhistory |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
|
||||||
|
class KeyboardCardView(context: Context) : AbstractKeyboardView(context) { |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,80 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view.handhistory |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.util.AttributeSet |
||||||
|
import android.widget.FrameLayout |
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout |
||||||
|
import androidx.core.view.isVisible |
||||||
|
import net.pokeranalytics.android.R |
||||||
|
import net.pokeranalytics.android.model.realm.handhistory.Action |
||||||
|
import net.pokeranalytics.android.model.realm.handhistory.Card |
||||||
|
|
||||||
|
interface KeyboardListener { |
||||||
|
fun actionSelected(action: Action.Type) |
||||||
|
fun cardSelected(value: Card, suit: Card.Suit) |
||||||
|
fun amountSelected(amount: Double) |
||||||
|
} |
||||||
|
|
||||||
|
enum class HandHistoryKeyboard { |
||||||
|
ACTION, |
||||||
|
AMOUNT, |
||||||
|
CARD |
||||||
|
} |
||||||
|
|
||||||
|
class KeyboardContainer(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { |
||||||
|
|
||||||
|
var keyboardListener: KeyboardListener? = null |
||||||
|
|
||||||
|
val keyboards = HashMap<HandHistoryKeyboard, AbstractKeyboardView>() |
||||||
|
|
||||||
|
private lateinit var constraintLayout: ConstraintLayout |
||||||
|
|
||||||
|
init { |
||||||
|
this.setBackgroundColor(context.getColor(R.color.kaki)) |
||||||
|
} |
||||||
|
|
||||||
|
private fun show() { |
||||||
|
this.isVisible = true |
||||||
|
} |
||||||
|
|
||||||
|
fun hide() { |
||||||
|
this.isVisible = false |
||||||
|
} |
||||||
|
|
||||||
|
fun show(type: HandHistoryKeyboard) { |
||||||
|
|
||||||
|
show() |
||||||
|
|
||||||
|
var view = this.keyboards[type] |
||||||
|
|
||||||
|
if (view == null) { |
||||||
|
view = when(type) { |
||||||
|
HandHistoryKeyboard.ACTION -> { KeyboardActionView(context) } |
||||||
|
HandHistoryKeyboard.AMOUNT -> { KeyboardAmountView(context) } |
||||||
|
HandHistoryKeyboard.CARD -> { KeyboardCardView(context) } |
||||||
|
} |
||||||
|
view.keyboardListener = this.keyboardListener |
||||||
|
addView(view) |
||||||
|
} |
||||||
|
|
||||||
|
show(view) |
||||||
|
} |
||||||
|
|
||||||
|
private fun show(keyboardView: AbstractKeyboardView) { |
||||||
|
this.keyboards.values.forEach { kbView -> |
||||||
|
kbView.isVisible = (kbView == keyboardView) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// private fun loadView(layoutId: Int) { |
||||||
|
// val layoutInflater = LayoutInflater.from(context) |
||||||
|
// constraintLayout = layoutInflater.inflate(layoutId, this, false) as ConstraintLayout |
||||||
|
// val layoutParams = LayoutParams( |
||||||
|
// LayoutParams.MATCH_PARENT, |
||||||
|
// LayoutParams.MATCH_PARENT |
||||||
|
// ) |
||||||
|
// addView(constraintLayout, layoutParams) |
||||||
|
// |
||||||
|
// } |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||||
|
|
||||||
|
<LinearLayout |
||||||
|
android:orientation="horizontal" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintBottom_toTopOf="@id/recyclerView"> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/closeButton" |
||||||
|
app:icon="@drawable/ic_close" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
<com.google.android.material.chip.ChipGroup |
||||||
|
android:id="@+id/chipGroup" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:orientation="horizontal" |
||||||
|
app:chipSpacingHorizontal="8dp" |
||||||
|
app:singleSelection="true"/> |
||||||
|
|
||||||
|
</LinearLayout> |
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView |
||||||
|
android:id="@+id/recyclerView" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="200dp" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
/> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||||
|
|
||||||
|
<LinearLayout |
||||||
|
android:orientation="horizontal" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent"> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/closeButton" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/clearButton" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/kiloButton" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/millionButton" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/nextButton" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
</LinearLayout> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
@ -0,0 +1,72 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||||
|
|
||||||
|
<LinearLayout |
||||||
|
android:orientation="horizontal" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintBottom_toTopOf="@id/valueRecyclerView"> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/closeButton" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
app:icon="@drawable/ic_close" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_weight="1" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
<Space |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_weight="2"/> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/clearButton" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
android:text="@string/clear" |
||||||
|
android:layout_weight="1" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
<Space |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_weight="2"/> |
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton |
||||||
|
android:id="@+id/doneButton" |
||||||
|
style="@style/PokerAnalyticsTheme.Button" |
||||||
|
android:text="@string/done" |
||||||
|
android:layout_weight="1" |
||||||
|
android:layout_width="44dp" |
||||||
|
android:layout_height="44dp" |
||||||
|
android:layout_marginStart="8dp"/> |
||||||
|
|
||||||
|
</LinearLayout> |
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView |
||||||
|
android:id="@+id/valueRecyclerView" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="100dp" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintBottom_toTopOf="@id/suitRecyclerView" |
||||||
|
/> |
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView |
||||||
|
android:id="@+id/suitRecyclerView" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="50dp" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintEnd_toEndOf="parent" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
/> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
Loading…
Reference in new issue