parent
5fc55d04e7
commit
4c99335838
@ -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() |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue