Update BottomSheet management

dev_raz_wip
Aurelien Hubert 7 years ago
parent 5fc55d04e7
commit 4c99335838
  1. 15
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/EditableDataFragment.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/NewSessionFragment.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetData.kt
  5. 120
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDateFragment.kt
  6. 25
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetDoubleEditTextFragment.kt
  7. 14
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetEditTextFragment.kt
  8. 10
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/BottomSheetFragment.kt
  9. 4
      app/src/main/java/net/pokeranalytics/android/util/Extensions.kt
  10. 1
      app/src/main/res/layout/row_title_value.xml
  11. 12
      app/src/main/res/layout/row_title_value_action.xml
  12. 2
      app/src/main/res/values/strings.xml

@ -145,7 +145,7 @@ open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, Displa
SessionRow.LOCATION -> location?.title ?: "--"
SessionRow.BANKROLL -> bankroll?.title ?: "--"
SessionRow.START_DATE -> if (timeFrame != null) timeFrame?.startDate?.short() ?: "--" else "--"
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.short() ?: "--" else "--"
SessionRow.END_DATE -> if (timeFrame != null) timeFrame?.endDate?.short() ?: "--" else "--"
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else "--"
else -> "--"
}
@ -168,23 +168,22 @@ open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, Displa
val data = ArrayList<BottomSheetData>()
// Todo: Localize & set real data
when (row) {
SessionRow.GAME -> {
data.add(BottomSheetData(game, "", 0, DataList.GAME.items(realm)))
data.add(BottomSheetData(game, inputType = InputType.TYPE_NULL, data = DataList.GAME.items(realm)))
}
SessionRow.LOCATION -> {
data.add(BottomSheetData(location, "", 0, DataList.LOCATION.items(realm)))
data.add(BottomSheetData(location, inputType = InputType.TYPE_NULL, data = DataList.LOCATION.items(realm)))
}
SessionRow.BANKROLL -> {
data.add(BottomSheetData(bankroll, "", 0, DataList.BANKROLL.items(realm)))
data.add(BottomSheetData(bankroll, inputType = InputType.TYPE_NULL, data = DataList.BANKROLL.items(realm)))
}
SessionRow.BLINDS -> {
data.add(BottomSheetData(cgSmallBlind, "Small blind", InputType.TYPE_CLASS_NUMBER))
data.add(BottomSheetData(cgBigBlind, "Big blind", InputType.TYPE_CLASS_NUMBER))
data.add(BottomSheetData(cgSmallBlind, R.string.small_blind, InputType.TYPE_CLASS_NUMBER))
data.add(BottomSheetData(cgBigBlind, R.string.big_blind, InputType.TYPE_CLASS_NUMBER))
}
SessionRow.COMMENT -> {
data.add(BottomSheetData(comment, "Comment", InputType.TYPE_CLASS_TEXT))
data.add(BottomSheetData(comment, R.string.comment, InputType.TYPE_CLASS_TEXT))
}
}

@ -50,10 +50,6 @@ class EditableDataFragment : PokerAnalyticsFragment(), DynamicRowCallback, Botto
Toast.makeText(requireContext(), "Clear: $row", Toast.LENGTH_SHORT).show()
}
override fun clickOnDone(row: DynamicRowInterface) {
Toast.makeText(requireContext(), "Done: $row", Toast.LENGTH_SHORT).show()
}
override fun setValue(value: Any, row: DynamicRowInterface) {
Toast.makeText(requireContext(), "Callback for ${row.localizedTitle(requireContext())} ($value)", Toast.LENGTH_SHORT).show()
}

@ -8,8 +8,8 @@ import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.fragment_new_session.*
import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.model.DataList
import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.ui.activity.EditableDataActivity
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
import net.pokeranalytics.android.ui.adapter.components.DynamicListAdapter
@ -72,10 +72,6 @@ class NewSessionFragment : PokerAnalyticsFragment(), DynamicRowCallback, BottomS
sessionAdapter.notifyItemChanged(SessionRow.values().indexOf(row))
}
override fun clickOnDone(row: DynamicRowInterface) {
Toast.makeText(requireContext(), "clickOnDone: $row", Toast.LENGTH_SHORT).show()
}
override fun setValue(value: Any, row: DynamicRowInterface) {
when(row) {
SessionRow.GAME -> if (value is Game) currentSession.game = value

@ -5,7 +5,7 @@ import io.realm.RealmResults
class BottomSheetData(
var defaultValue: Any? = null,
var hint: String? = "",
var hint: Int? = null,
var inputType: Int? = InputType.TYPE_CLASS_TEXT,
var data: RealmResults<*>? = null
)

@ -1,120 +0,0 @@
package net.pokeranalytics.android.ui.fragment.components
import android.app.DatePickerDialog
import android.app.TimePickerDialog
import android.os.Bundle
import android.text.format.DateFormat
import android.view.View
import android.widget.DatePicker
import android.widget.TimePicker
import kotlinx.android.synthetic.main.bottom_sheet_date.*
import timber.log.Timber
import java.util.*
class BottomSheetDateFragment : BottomSheetFragment(), DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
enum class DateEdition {
START,
END
}
private val calendar = Calendar.getInstance()
private val calendarStart = Calendar.getInstance()
private val calendarEnd = Calendar.getInstance()
private var currentDateEdition = DateEdition.START
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
initUI()
}
override fun onDateSet(view: DatePicker?, year: Int, month: Int, dayOfMonth: Int) {
when(currentDateEdition) {
DateEdition.START -> {
calendarStart.set(Calendar.YEAR, year)
calendarStart.set(Calendar.MONTH, month)
calendarStart.set(Calendar.DAY_OF_MONTH, dayOfMonth)
}
DateEdition.END -> {
calendarEnd.set(Calendar.YEAR, year)
calendarEnd.set(Calendar.MONTH, month)
calendarEnd.set(Calendar.DAY_OF_MONTH, dayOfMonth)
}
}
showTimePicker()
}
override fun onTimeSet(view: TimePicker?, hourOfDay: Int, minute: Int) {
when(currentDateEdition) {
DateEdition.START -> {
calendarStart.set(Calendar.HOUR_OF_DAY, hourOfDay)
calendarStart.set(Calendar.MINUTE, minute)
}
DateEdition.END -> {
calendarEnd.set(Calendar.HOUR_OF_DAY, hourOfDay)
calendarEnd.set(Calendar.MINUTE, minute)
}
}
Timber.d("Start date: ${calendarStart.time}")
Timber.d("End date: ${calendarEnd.time}")
}
/**
* Init data
*/
private fun initData() {
val data = getData()
}
/**
* Init UI
*/
private fun initUI() {
//LayoutInflater.from(requireContext()).inflate(net.pokeranalytics.android.R.layout.bottom_sheet_date, view?.bottomSheetContainer, true)
//setAddButtonVisible(false)
startDate.setOnClickListener {
currentDateEdition = DateEdition.START
showDatePicker()
}
endDate.setOnClickListener {
currentDateEdition = DateEdition.END
showDatePicker()
}
currentDateEdition = DateEdition.START
showDatePicker()
}
/**
* Show the date picker
*/
private fun showDatePicker() {
val year = calendar.get(Calendar.YEAR)
val month = calendar.get(Calendar.MONTH)
val day = calendar.get(Calendar.DAY_OF_MONTH)
val datePickerDialog = DatePickerDialog(requireContext(), this, year, month, day)
datePickerDialog.show()
}
/**
* Show the time picker
*/
private fun showTimePicker() {
val hour = calendar.get(Calendar.YEAR)
val minute = calendar.get(Calendar.MONTH)
val timePickerDialog = TimePickerDialog(activity, this, hour, minute, DateFormat.is24HourFormat(activity))
timePickerDialog.show()
}
}

@ -5,6 +5,7 @@ import android.text.InputType
import android.view.LayoutInflater
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.core.widget.addTextChangedListener
import kotlinx.android.synthetic.main.bottom_sheet_double_edit_text.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
@ -12,6 +13,8 @@ import net.pokeranalytics.android.R
class BottomSheetDoubleEditTextFragment : BottomSheetFragment() {
private val values = ArrayList<String>()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
@ -23,6 +26,10 @@ class BottomSheetDoubleEditTextFragment : BottomSheetFragment() {
editText1.requestFocus()
}
override fun getValue(): Any {
return values
}
/**
* Init data
*/
@ -36,24 +43,26 @@ class BottomSheetDoubleEditTextFragment : BottomSheetFragment() {
val data = getData()
values.add(0, "")
values.add(1, "")
LayoutInflater.from(requireContext())
.inflate(R.layout.bottom_sheet_double_edit_text, view?.bottomSheetContainer, true)
if (data.size == 2) {
editText1.hint = data[0].hint
editText1.setText((data[0].defaultValue ?: "").toString())
data[0].hint?.let { editText1.hint = getString(it) }
editText1.inputType = data[0].inputType ?: InputType.TYPE_CLASS_TEXT
editText1.addTextChangedListener { values[0] = it?.toString() ?: "" }
editText1.setText((data[0].defaultValue ?: "").toString())
editText2.hint = data[1].hint
editText2.setText((data[1].defaultValue ?: "").toString())
data[1].hint?.let { editText2.hint = getString(it) }
editText2.inputType = data[1].inputType ?: InputType.TYPE_CLASS_TEXT
editText2.addTextChangedListener { values[1] = it?.toString() ?: "" }
editText2.setText((data[1].defaultValue ?: "").toString())
editText2.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
val values = ArrayList<String>()
values.add(editText1.text.toString())
values.add(editText2.text.toString())
bottomSheetDelegate.setValue(values, row)
dismiss()
true
@ -61,10 +70,8 @@ class BottomSheetDoubleEditTextFragment : BottomSheetFragment() {
false
}
}
}
}
}

@ -5,6 +5,7 @@ import android.text.InputType
import android.view.LayoutInflater
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.core.widget.addTextChangedListener
import kotlinx.android.synthetic.main.bottom_sheet_edit_text.*
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.*
import net.pokeranalytics.android.R
@ -12,6 +13,8 @@ import net.pokeranalytics.android.R
class BottomSheetEditTextFragment : BottomSheetFragment() {
private var value = ""
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initData()
@ -23,6 +26,10 @@ class BottomSheetEditTextFragment : BottomSheetFragment() {
editText1.requestFocus()
}
override fun getValue(): Any {
return value
}
/**
* Init data
*/
@ -41,13 +48,14 @@ class BottomSheetEditTextFragment : BottomSheetFragment() {
val data = getData()
if (data.size == 1) {
editText1.hint = data[0].hint
editText1.setText((data[0].defaultValue ?: "").toString())
data[0].hint?.let { editText1.hint = getString(it) }
editText1.inputType = data[0].inputType ?: InputType.TYPE_CLASS_TEXT
editText1.addTextChangedListener { value = it?.toString() ?: "" }
editText1.setText((data[0].defaultValue ?: "").toString())
editText1.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
val value = editText1.text.toString()
bottomSheetDelegate.setValue(value, row)
dismiss()
true

@ -24,7 +24,6 @@ enum class BottomSheetType {
interface BottomSheetDelegate {
fun clickOnAdd(row: DynamicRowInterface)
fun clickOnClear(row: DynamicRowInterface)
fun clickOnDone(row: DynamicRowInterface)
fun setValue(value: Any, row: DynamicRowInterface)
}
@ -45,7 +44,6 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
): BottomSheetFragment {
val bottomSheetFragment = when (row.bottomSheetType) {
BottomSheetType.DATE -> BottomSheetDateFragment()
BottomSheetType.LIST -> BottomSheetListFragment()
BottomSheetType.DOUBLE_LIST -> BottomSheetDoubleListFragment()
BottomSheetType.EDIT_TEXT -> BottomSheetEditTextFragment()
@ -100,13 +98,11 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
true
}
bottomSheetToolbar.menu.findItem(R.id.actionCheck).setOnMenuItemClickListener {
bottomSheetDelegate.clickOnDone(row)
bottomSheetDelegate.setValue(getValue(), row)
dismiss()
true
}
}
}
/**
@ -116,6 +112,10 @@ open class BottomSheetFragment : BottomSheetDialogFragment() {
return data
}
open fun getValue(): Any {
return Any()
}
/**
* Set clear button visibility
*/

@ -4,6 +4,10 @@ import java.text.DateFormat
import java.util.*
// Date
fun Date.short(): String {
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(this)
}

@ -15,7 +15,6 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"

@ -26,13 +26,13 @@
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/value"
android:layout_width="0dp"
android:layout_height="16dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:ellipsize="end"
android:gravity="end"
android:gravity="end|center_vertical"
android:maxLines="1"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
@ -45,12 +45,14 @@
android:id="@+id/action"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="?selectableItemBackgroundBorderless"
android:padding="4dp"
android:visibility="visible"
android:background="?selectableItemBackgroundBorderless"
tools:src="@drawable/ic_close_white_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_close_white_24dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -7,6 +7,8 @@
<string name="bankroll">Bankroll</string>
<string name="blinds">Blinds</string>
<string name="small_blind">Small blind</string>
<string name="big_blind">Big blind</string>
<string name="game">Game</string>
<string name="date">Date</string>
<string name="start_date">Start date</string>

Loading…
Cancel
Save