Add Bottom Sheet Edit Text management & session comment example

dev_raz_wip
Aurelien Hubert 7 years ago
parent 79a4bc10d1
commit 857d307799
  1. 4
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 12
      app/src/main/java/net/pokeranalytics/android/ui/adapter/components/DynamicRowInterface.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt
  4. 23
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetEditTextFragment.kt
  5. 1
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt
  6. 29
      app/src/main/res/layout/bottom_sheet_edit_text.xml
  7. 1
      app/src/main/res/values/strings.xml

@ -142,6 +142,7 @@ open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, Displa
SessionRow.LOCATION -> location?.title ?: "--"
SessionRow.BANKROLL -> bankroll?.title ?: "--"
SessionRow.DATE -> if (timeFrame != null) timeFrame?.startDate.toString() else "--"
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--"
else -> "--"
}
}
@ -172,6 +173,9 @@ open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, Displa
data.add(BottomSheetData(cgSmallBlind, "Small blind", InputType.TYPE_CLASS_NUMBER))
data.add(BottomSheetData(cgBigBlind, "Big blind", InputType.TYPE_CLASS_NUMBER))
}
SessionRow.COMMENT -> {
data.add(BottomSheetData(comment, "Comment", InputType.TYPE_CLASS_TEXT))
}
}
return data

@ -1,12 +1,8 @@
package net.pokeranalytics.android.ui.adapter.components
import android.content.Context
import io.realm.Realm
import io.realm.RealmObject
import io.realm.RealmResults
import io.realm.Sort
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.model.realm.DataList
import net.pokeranalytics.android.ui.fragment.components.BottomSheetType
@ -42,7 +38,8 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface {
BLINDS(R.string.blinds),
LOCATION(R.string.location),
BANKROLL(R.string.bankroll),
DATE(R.string.date);
DATE(R.string.date),
COMMENT(R.string.comment);
override fun localizedTitle(context: Context): String {
return context.getString(this.resId)
@ -51,7 +48,7 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface {
override val viewType: Int
get() {
return when (this) {
BLINDS, GAME, DATE, BANKROLL, LOCATION -> RowViewType.TITLE_VALUE.ordinal
BLINDS, GAME, DATE, BANKROLL, LOCATION, COMMENT -> RowViewType.TITLE_VALUE.ordinal
}
}
@ -63,6 +60,7 @@ enum class SessionRow(val resId: Int) : DynamicRowInterface {
LOCATION -> BottomSheetType.LIST
BANKROLL -> BottomSheetType.LIST
DATE -> BottomSheetType.DATE
COMMENT -> BottomSheetType.EDIT_TEXT
}
}

@ -56,6 +56,7 @@ class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomS
currentSession.cgSmallBlind = null
currentSession.cgBigBlind = null
}
SessionRow.COMMENT -> currentSession.comment = ""
}
sessionAdapter.notifyItemChanged(SessionRow.values().indexOf(row))
}
@ -73,6 +74,7 @@ class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomS
currentSession.cgSmallBlind = (value[0] as String? ?: "0").toDouble()
currentSession.cgBigBlind = (value[1] as String? ?: "0").toDouble()
}
SessionRow.COMMENT -> if (value is String) currentSession.comment = value
}
sessionAdapter.notifyItemChanged(SessionRow.values().indexOf(row))
}

@ -1,8 +1,10 @@
package net.pokeranalytics.android.ui.fragment.components
import android.os.Bundle
import android.text.InputType
import android.view.LayoutInflater
import android.view.View
import android.view.inputmethod.EditorInfo
import kotlinx.android.synthetic.main.bottom_sheet_edit_text.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
@ -25,7 +27,6 @@ class BottomSheetEditTextFragment : BottomSheetFragment() {
* Init data
*/
private fun initData() {
val data = getData()
}
/**
@ -33,8 +34,28 @@ class BottomSheetEditTextFragment : BottomSheetFragment() {
*/
private fun initUI() {
setAddButtonVisible(false)
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_edit_text, view?.bottomSheetContainer, true)
val data = getData()
if (data.size == 1) {
editText1.hint = data[0].hint
editText1.setText((data[0].defaultValue ?: "").toString())
editText1.inputType = data[0].inputType ?: InputType.TYPE_CLASS_TEXT
editText1.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
val value = editText1.text.toString()
bottomSheetDelegate.setValue(value, row)
dismiss()
true
} else {
false
}
}
}
}
}

@ -48,6 +48,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
BottomSheetType.DATE -> BottomSheetDateFragment()
BottomSheetType.LIST -> BottomSheetListFragment()
BottomSheetType.DOUBLE_LIST -> BottomSheetDoubleListFragment()
BottomSheetType.EDIT_TEXT -> BottomSheetEditTextFragment()
BottomSheetType.DOUBLE_EDIT_TEXT -> BottomSheetDoubleEditTextFragment()
else -> BottomSheetFragment()
}

@ -7,37 +7,20 @@
android:orientation="vertical"
tools:background="@color/gray_darker">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:textColor="@color/white"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/editText1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Blinds" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editText1"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="end|center_vertical"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:lines="1"
android:textColor="@color/white"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:hint="Test" />
tools:text="10" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -13,6 +13,7 @@
<string name="session">Session</string>
<string name="tournament_type">Tournament Type</string>
<string name="transaction_type">Transaction Type</string>
<string name="comment">Comment</string>
<string name="name">Name</string>
<string name="live">Live</string>

Loading…
Cancel
Save