package com.philliphsu.bottomsheetpickers.view.numberpad;

import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import static com.philliphsu.bottomsheetpickers.view.Preconditions.checkNotNull;
import static java.util.Calendar.AM;
import static java.util.Calendar.PM;

/**
 * Controller that manages the UI states of a number pad time picker.
 */
final class NumberPadTimePickerController {

    // Determines how the time should be formatted for display.
    @IntDef({AM, PM, NOT_APPLICABLE})
    @Retention(RetentionPolicy.SOURCE)
    private @interface HalfDay {}

    private static final int NOT_APPLICABLE = -1;

    // (M)odel: Simply stores data and provides us access to that data.
    private final DigitwiseTimeModel mDigitwiseTimeModel = new DigitwiseTimeModel();

    // Used by the (C)ontroller to format/process the data from the model for
    // consumption by the end user.
    // We do not set an initial capacity because the length of a complete time
    // string is locale-dependent.
    private final StringBuilder mTimeFormatter = new StringBuilder();

    // (V)iews
    private final @NonNull NumberPadTimePickerView mNumberPadView;
    private final @NonNull TextView mTimeDisplayView;
    private final @Nullable TextView mAmPmDisplayView;
    private final @NonNull View mBackspaceButton;
    private final @NonNull View mOkButton;

    private @HalfDay int mChosenHalfDay;

    public NumberPadTimePickerController(@NonNull NumberPadTimePickerView numberPadView,
                                         @NonNull TextView timeDisplayView,
                                         @Nullable TextView ampmDisplayView,
                                         @NonNull View backspaceButton,
                                         @NonNull View okButton) {
        mNumberPadView = checkNotNull(numberPadView);
        mTimeDisplayView = checkNotNull(timeDisplayView);
        mBackspaceButton = checkNotNull(backspaceButton);
        mOkButton = checkNotNull(okButton);
        mAmPmDisplayView = ampmDisplayView;
    }

    void onButtonClick(TextView button) {
        final String text = button.getText().toString();
        try {
            mDigitwiseTimeModel.storeDigit(Integer.parseInt(text));
        } catch (NumberFormatException e) {
            // TODO: This is either an AM/PM state, or an alt button.
        }
        updateViews();
    }

    void onBackspaceClick() {
        mDigitwiseTimeModel.removeDigit();
        updateViews();
    }

    private void updateViews() {
        // TODO: Update number key states.
        // TODO: Update backspace state.
        // TODO: Update ok button state.
        // TODO: Format text for display and update time display view.
    }

}

@@ -141,52 +141,8 @@
 ll;%0A
-import android.support.annotation.Nullable;%0A
 impo
@@ -791,80 +791,8 @@
 1;%0A%0A
-    // (M)odel: Simply stores data and provides us access to that data.%0A
     
@@ -877,122 +877,8 @@
 );%0A%0A
-    // Used by the (C)ontroller to format/process the data from the model for%0A    // consumption by the end user.%0A
     
@@ -1062,23 +1062,8 @@
 );%0A%0A
-    // (V)iews%0A
     
@@ -1108,822 +1108,302 @@
 cker
-View mNumberPadView;%0A    private final @NonNull TextView mTimeDisplayView;%0A    private final @Nullable TextView mAmPmDisplayView;%0A    private final @NonNull View mBackspaceButton;%0A    private final @NonNull View mOkButton;%0A%0A    private @HalfDay int mChosenHalfDay;%0A%0A    public NumberPadTimePickerController(@NonNull NumberPadTimePickerView numberPadView,%0A                                         @NonNull TextView timeDisplayView,%0A                                         @Nullable TextView ampmDisplayView,%0A                                         @NonNull View backspaceButton,%0A                                         @NonNull View okButton) %7B%0A        mNumberPadView = checkNotNull(numberPadView);%0A        mTimeDisplayView = checkNotNull(timeDisplayView);%0A        mBackspaceButton = checkNotNull(backspaceButton
+ mTimePicker;%0A    private final @NonNull View mOkButton;%0A%0A    private @HalfDay int mChosenHalfDay;%0A%0A    public NumberPadTimePickerController(@NonNull NumberPadTimePicker timePicker,%0A                                         @NonNull View okButton) %7B%0A        mTimePicker = checkNotNull(timePicker
 );%0A 
@@ -1449,52 +1449,8 @@
 n);%0A
-        mAmPmDisplayView = ampmDisplayView;%0A
     

Change constructor parameters of NumberPadTimePickerController using NumberPadTimePicker class.