heysupratim / material-daterange-picker

A material Date Range Picker based on wdullaers MaterialDateTimePicker
Apache License 2.0
1.33k stars 266 forks source link

Adding singledatepicker #72

Closed christianCallelero closed 7 years ago

christianCallelero commented 7 years ago

Hi I would like to add a feature wherein we can use this library to somewhat disable the two tabs (From,To). So we can use it for just getting a single date. However I'm new to library cloning so can anyone help me with this? I know how to clone but my idea for adding this as a module is limited. Thanks

PunchyRascal commented 7 years ago

In this case use the native Android date picker :)

https://developer.android.com/guide/topics/ui/controls/pickers.html

christianCallelero commented 7 years ago

Yeah its possible but I want to keep the design consistent to all my datepicker. Anyway I was able to clone the project and create an option for single date. closing this thread now.

RamithRD commented 6 years ago

@christianCallelero Hi, can you share the single date selection option you implemented?

dmz9 commented 5 years ago

@christianCallelero Hi, can you share the single date selection option you implemented?

maybe it's late, but anyway: you could just subclass the datepicker, and override #onViewCreated. use findViewById(android.R.id.tabs) to get "tabs" layout at hands and make it's visibility = GONE, so it is not displayed anymore. works with config change/screen rotation, because when view recreated - tabs are "GONE" again. the ondatechange listener stays the same, except you do not use "end" dates, since user intacts with the first tab only.

probably you need to recreate static constructors too (#newInstance methods)


internal class OnlyDatePickerDialog : com.borax12.materialdaterangepicker.date.DatePickerDialog() {
    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
// hide tabs heading so user cant see it
        view?.findViewById<TabWidget>(android.R.id.tabs)?.let{
            it.visibility = View.GONE
        }
    }
// static constructors are not inherited in kotlin, so recreate them
    companion object {
        fun newInstance(
            callBack: OnDateSetListener, year: Int,
            monthOfYear: Int,
            dayOfMonth: Int
        ): OnlyDatePickerDialog {
            val ret = OnlyDatePickerDialog()
            ret.initialize(callBack, year, monthOfYear, dayOfMonth)
            return ret
        }

        fun newInstance(
            callBack: OnDateSetListener, year: Int,
            monthOfYear: Int,
            dayOfMonth: Int,
            yearEnd: Int,
            montOfYearEnd: Int,
            dayOfMonthEnd: Int
        ): OnlyDatePickerDialog {
            val ret = OnlyDatePickerDialog()
            ret.initialize(callBack, year, monthOfYear, dayOfMonth, yearEnd, montOfYearEnd, dayOfMonthEnd)
            return ret
        }
    }
}
`