package com.philliphsu.bottomsheetpickers.view.numberpad;

import android.content.Context;
import android.text.format.DateFormat;
import android.util.AttributeSet;

import com.philliphsu.bottomsheetpickers.view.DateTimeFormatUtils;
import com.philliphsu.bottomsheetpickers.view.GridPickerView;

/**
 * Created by Phillip Hsu on 4/4/2017.
 */

class NumberPadTimePickerView extends GridPickerView {

    public NumberPadTimePickerView(Context context) {
        this(context, null);
    }

    public NumberPadTimePickerView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public NumberPadTimePickerView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        for (int i = 0; i < 9; i++) {
            setTextForPosition(i, String.format("%d", i + 1));
        }

        final String altText1, altText2;
        // TODO: Allow passing in a parameter so the user can set 24hr mode on their own.
        if (DateFormat.is24HourFormat(context)) {
            final String timeSeparator = DateTimeFormatUtils.getTimeSeparator(context, true);
            altText1 = timeSeparator + String.format("%02d", 0);
            altText2 = timeSeparator + String.format("%02d", 30);
        } else  {
            // TODO: Get localized.
            altText1 = "AM";
            altText2 = "PM";
        }
        // TODO: Apply a smaller text size.
        setTextForPosition(9, altText1);
        setTextForPosition(10, String.format("%d", 0));
        // TODO: Apply a smaller text size.
        setTextForPosition(11, altText2);
    }

    void setNumberKeysEnabled(int start, int end) {
        // TODO
    }

    void setOnNumberKeyClickListener(OnClickListener l) {
        setOnButtonClickListener(l);
    }
}

@@ -288,16 +288,53 @@
 rView;%0A%0A
+import java.text.DateFormatSymbols;%0A%0A
 /**%0A * C
@@ -429,16 +429,52 @@
 View %7B%0A%0A
+    private boolean mIs24HourMode;%0A%0A
     publ
@@ -909,25 +909,24 @@
       %7D%0A
-%0A
         
 final St
@@ -921,177 +921,415 @@
     
-final String altText1, altText2;%0A        // TODO: Allow passing in a parameter so the user can set 24hr mode on their own.%0A        if (DateFormat.is24HourFormat(context)
+setTextForPosition(10, String.format(%22%25d%22, 0));%0A        setIs24HourMode(DateFormat.is24HourFormat(context));%0A    %7D%0A%0A    void setNumberKeysEnabled(int start, int end) %7B%0A        // TODO%0A    %7D%0A%0A    void setOnNumberKeyClickListener(OnClickListener l) %7B%0A        setOnButtonClickListener(l);%0A    %7D%0A%0A    void setIs24HourMode(boolean is24HourMode) %7B%0A        final String altText1, altText2;%0A        if (is24HourMode
 ) %7B%0A
@@ -1406,23 +1406,28 @@
 parator(
-c
+getC
 ontext
+()
 , true);
@@ -1592,88 +1592,272 @@
     
-// TODO: Get localized.%0A            altText1 = %22AM%22;%0A            altText2 = %22PM%22
+String%5B%5D amPm = new DateFormatSymbols().getAmPmStrings();%0A            // TODO: Get localized. Or get the same am/pm strings as the framework.%0A            altText1 = amPm%5B0%5D.length() %3E 2 ? %22AM%22 : amPm%5B0%5D;%0A            altText2 = amPm%5B1%5D.length() %3E 2 ? %22PM%22 : amPm%5B1%5D
 ;%0A  
@@ -1953,64 +1953,8 @@
 1);%0A
-        setTextForPosition(10, String.format(%22%25d%22, 0));%0A
     
@@ -2039,183 +2039,45 @@
 2);%0A
+%0A
     
-%7D%0A%0A
     
-void setNumberKeysEnabled(int start, int end) %7B%0A        // TODO%0A    %7D%0A%0A    void setOnNumberKeyClickListener(OnClickListener l) %7B%0A        setOnButtonClickListener(l)
+mIs24HourMode = is24HourMode
 ;%0A  

Allow setting 24 hour mode in NumberPadTimePickerView.