parent
1248aa213e
commit
e2fefb778f
@ -0,0 +1,124 @@ |
||||
package net.pokeranalytics.android.ui.fragment.components.bottomsheet |
||||
|
||||
import android.os.Bundle |
||||
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_sum.* |
||||
import kotlinx.android.synthetic.main.fragment_bottom_sheet.view.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.util.round |
||||
import net.pokeranalytics.android.util.toCurrency |
||||
|
||||
|
||||
class BottomSheetSumFragment : BottomSheetFragment() { |
||||
|
||||
private var value = 0.0 |
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
||||
super.onViewCreated(view, savedInstanceState) |
||||
initData() |
||||
initUI() |
||||
} |
||||
|
||||
override fun onStart() { |
||||
super.onStart() |
||||
editText1.requestFocus() |
||||
} |
||||
|
||||
override fun getValue(): Any { |
||||
return value |
||||
} |
||||
|
||||
/** |
||||
* Init data |
||||
*/ |
||||
private fun initData() { |
||||
} |
||||
|
||||
/** |
||||
* Init UI |
||||
*/ |
||||
private fun initUI() { |
||||
|
||||
val data = getData() |
||||
|
||||
setAddButtonVisible(false) |
||||
|
||||
LayoutInflater.from(requireContext()).inflate(R.layout.bottom_sheet_sum, view?.bottomSheetContainer, true) |
||||
|
||||
if (data.size == 5) { |
||||
|
||||
// Default value for the sum |
||||
val currentDefaultValue = try { |
||||
data[2].defaultValue as Double |
||||
} catch (e: Exception) { |
||||
0.0 |
||||
} |
||||
|
||||
currentValue.text = currentDefaultValue.toCurrency() |
||||
|
||||
// First value |
||||
val defaultValue1 = try { |
||||
data[0].defaultValue as Double |
||||
} catch (e: Exception) { |
||||
0.0 |
||||
} |
||||
|
||||
button1.text = defaultValue1.toCurrency() |
||||
button1.visibility = if (defaultValue1 > 0) View.VISIBLE else View.GONE |
||||
button1.setOnClickListener { |
||||
bottomSheetDelegate.setValue(currentDefaultValue + defaultValue1, row) |
||||
dismiss() |
||||
} |
||||
|
||||
// Second value |
||||
val defaultValue2 = try { |
||||
data[1].defaultValue as Double |
||||
} catch (e: Exception) { |
||||
0.0 |
||||
} |
||||
|
||||
button2.text = defaultValue2.toCurrency() |
||||
button2.visibility = if (defaultValue2 > 0) View.VISIBLE else View.GONE |
||||
button2.setOnClickListener { |
||||
bottomSheetDelegate.setValue(currentDefaultValue + defaultValue2, row) |
||||
dismiss() |
||||
} |
||||
|
||||
// First edit text |
||||
data[3].hint?.let { editText1.hint = getString(it) } |
||||
editText1.inputType = data[3].inputType ?: InputType.TYPE_CLASS_TEXT |
||||
editText1.addTextChangedListener { |
||||
val valueToAdd = try { |
||||
editText1.text.toString().toDouble() |
||||
} catch (e: Exception) { |
||||
0.0 |
||||
} |
||||
editText2.setText((currentDefaultValue + valueToAdd).round()) |
||||
|
||||
} |
||||
|
||||
// Second edit text |
||||
data[4].hint?.let { editText2.hint = getString(it) } |
||||
editText2.inputType = data[4].inputType ?: InputType.TYPE_CLASS_TEXT |
||||
editText2.addTextChangedListener { |
||||
value = it.toString().toDouble() |
||||
} |
||||
|
||||
editText2.setOnEditorActionListener { v, actionId, event -> |
||||
if (actionId == EditorInfo.IME_ACTION_DONE) { |
||||
bottomSheetDelegate.setValue(value, row) |
||||
dismiss() |
||||
true |
||||
} else { |
||||
false |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,119 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical" |
||||
tools:background="@color/gray_darker"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatButton |
||||
android:id="@+id/button1" |
||||
style="@style/PokerAnalyticsTheme.Button.Borderless" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
app:layout_constraintEnd_toStartOf="@+id/button2" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintHorizontal_chainStyle="packed" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
android:text="+ 1000 $" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatButton |
||||
android:id="@+id/button2" |
||||
style="@style/PokerAnalyticsTheme.Button.Borderless" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintStart_toEndOf="@+id/button1" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
android:text="+ 2000 $" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/currentValue" |
||||
style="@style/PokerAnalyticsTheme.TextView.BottomSheetValue" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginBottom="8dp" |
||||
android:gravity="center" |
||||
app:layout_constraintBottom_toBottomOf="@+id/editText1" |
||||
app:layout_constraintEnd_toStartOf="@+id/more" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintHorizontal_chainStyle="packed" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="@+id/editText1" |
||||
tools:text="0 $" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/more" |
||||
style="@style/PokerAnalyticsTheme.TextView.BottomSheetValue" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="8dp" |
||||
android:gravity="center" |
||||
android:padding="4dp" |
||||
android:text="+" |
||||
app:layout_constraintBottom_toBottomOf="@+id/editText1" |
||||
app:layout_constraintEnd_toStartOf="@+id/editText1" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintStart_toEndOf="@+id/currentValue" |
||||
app:layout_constraintTop_toTopOf="@+id/editText1" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText |
||||
android:id="@+id/editText1" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:layout_marginBottom="8dp" |
||||
android:gravity="center" |
||||
android:imeOptions="actionNext" |
||||
android:lines="1" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toStartOf="@+id/equal" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintStart_toEndOf="@+id/more" |
||||
app:layout_constraintTop_toBottomOf="@+id/button1" |
||||
tools:text="1000000" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/equal" |
||||
style="@style/PokerAnalyticsTheme.TextView.BottomSheetValue" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="8dp" |
||||
android:gravity="center" |
||||
android:padding="4dp" |
||||
android:text="=" |
||||
app:layout_constraintBottom_toBottomOf="@+id/editText1" |
||||
app:layout_constraintEnd_toStartOf="@+id/editText2" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintStart_toEndOf="@+id/editText1" |
||||
app:layout_constraintTop_toTopOf="@+id/editText1" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText |
||||
android:id="@+id/editText2" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:gravity="center" |
||||
android:imeOptions="actionDone" |
||||
android:lines="1" |
||||
app:layout_constraintBottom_toBottomOf="@+id/editText1" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintHorizontal_bias="0.5" |
||||
app:layout_constraintStart_toEndOf="@+id/equal" |
||||
app:layout_constraintTop_toTopOf="@+id/editText1" |
||||
tools:text="20" /> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
Loading…
Reference in new issue