parent
5acf6970eb
commit
ec5d419f61
@ -0,0 +1,77 @@ |
|||||||
|
package net.pokeranalytics.android.ui.fragment.components |
||||||
|
|
||||||
|
import android.app.DatePickerDialog |
||||||
|
import android.app.TimePickerDialog |
||||||
|
import android.content.Context |
||||||
|
import android.text.format.DateFormat |
||||||
|
import android.widget.DatePicker |
||||||
|
import android.widget.TimePicker |
||||||
|
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
class DateTimePickerManager : DatePickerDialog.OnDateSetListener, |
||||||
|
TimePickerDialog.OnTimeSetListener { |
||||||
|
|
||||||
|
private var context: Context? = null |
||||||
|
private val calendar = Calendar.getInstance() |
||||||
|
|
||||||
|
lateinit var row: DynamicRowInterface |
||||||
|
lateinit var bottomSheetDelegate: BottomSheetDelegate |
||||||
|
|
||||||
|
|
||||||
|
companion object { |
||||||
|
fun create( |
||||||
|
context: Context, |
||||||
|
row: DynamicRowInterface, |
||||||
|
bottomSheetDelegate: BottomSheetDelegate, |
||||||
|
date: Date? |
||||||
|
) : DateTimePickerManager { |
||||||
|
val dateTimePickerManager = DateTimePickerManager() |
||||||
|
dateTimePickerManager.context = context |
||||||
|
dateTimePickerManager.showDatePicker() |
||||||
|
dateTimePickerManager.row = row |
||||||
|
dateTimePickerManager.bottomSheetDelegate = bottomSheetDelegate |
||||||
|
return dateTimePickerManager |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
override fun onDateSet(view: DatePicker?, year: Int, month: Int, dayOfMonth: Int) { |
||||||
|
calendar.set(Calendar.YEAR, year) |
||||||
|
calendar.set(Calendar.MONTH, month) |
||||||
|
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth) |
||||||
|
showTimePicker() |
||||||
|
} |
||||||
|
|
||||||
|
override fun onTimeSet(view: TimePicker?, hourOfDay: Int, minute: Int) { |
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay) |
||||||
|
calendar.set(Calendar.MINUTE, minute) |
||||||
|
bottomSheetDelegate.setValue(calendar.time, row) |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 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) |
||||||
|
context?.let { |
||||||
|
val datePickerDialog = DatePickerDialog(it, 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) |
||||||
|
context?.let { |
||||||
|
val timePickerDialog = TimePickerDialog(context, this, hour, minute, DateFormat.is24HourFormat(context)) |
||||||
|
timePickerDialog.show() |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,17 @@ |
|||||||
|
package net.pokeranalytics.android.util |
||||||
|
|
||||||
|
import java.text.DateFormat |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
|
||||||
|
fun Date.short(): String { |
||||||
|
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(this) |
||||||
|
} |
||||||
|
|
||||||
|
fun Date.medium(): String { |
||||||
|
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(this) |
||||||
|
} |
||||||
|
|
||||||
|
fun Date.full(): String { |
||||||
|
return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(this) |
||||||
|
} |
||||||
@ -0,0 +1,56 @@ |
|||||||
|
<?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:id="@+id/container" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:background="?selectableItemBackground" |
||||||
|
android:padding="16dp"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
android:id="@+id/title" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
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" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
tools:text="Title" /> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
android:id="@+id/value" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="16dp" |
||||||
|
android:layout_marginStart="16dp" |
||||||
|
android:layout_marginTop="8dp" |
||||||
|
android:layout_marginEnd="8dp" |
||||||
|
android:layout_marginBottom="8dp" |
||||||
|
android:ellipsize="end" |
||||||
|
android:gravity="end" |
||||||
|
android:maxLines="1" |
||||||
|
android:textSize="14sp" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintEnd_toStartOf="@+id/action" |
||||||
|
app:layout_constraintStart_toEndOf="@+id/title" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
tools:text="Value" /> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView |
||||||
|
android:id="@+id/action" |
||||||
|
android:layout_width="32dp" |
||||||
|
android:layout_height="32dp" |
||||||
|
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" /> |
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
||||||
Loading…
Reference in new issue