package org.tndata.officehours.activity;


import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import org.tndata.officehours.R;
import org.tndata.officehours.databinding.ActivityRangeRecurrencePickerBinding;


/**
 * Lets the user choose a time range.
 *
 * @author Ismael Alonso
 */
public class RangeRecurrencePickerActivity extends AppCompatActivity{
    private static final String MC_KEY = "org.tndata.officehours.RRP.MultipleChoice";

    public static Intent getIntent(@NonNull Context context, boolean multipleChoice){
        return new Intent(context, RangeRecurrencePickerActivity.class)
                .putExtra(MC_KEY, multipleChoice);
    }


    private ActivityRangeRecurrencePickerBinding binding;
    private boolean multipleChoice;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_range_recurrence_picker);

        multipleChoice = getIntent().getBooleanExtra(MC_KEY, false);

        if (multipleChoice){
            binding.rrpRadio.setVisibility(View.GONE);
        }
        else{
            binding.rrpCheck.setVisibility(View.GONE);
        }
    }
}

@@ -36,16 +36,53 @@
 vity;%0A%0A%0A
+import android.app.TimePickerDialog;%0A
 import a
@@ -105,16 +105,16 @@
 ontext;%0A
-
 import a
@@ -367,16 +367,82 @@
 ew.View;
+%0Aimport android.widget.EditText;%0Aimport android.widget.TimePicker;
 %0A%0Aimport
@@ -549,16 +549,44 @@
 nding;%0A%0A
+import java.util.Calendar;%0A%0A
 %0A/**%0A * 
@@ -720,16 +720,48 @@
 Activity
+ implements View.OnClickListener
 %7B%0A    pr
@@ -841,16 +841,17 @@
 oice%22;%0A%0A
+%0A
     publ
@@ -1154,16 +1154,123 @@
 hoice;%0A%0A
+    private int fromHour;%0A    private int fromMinute;%0A%0A    private int toHour;%0A    private int toMinute;%0A%0A%0A
     @Ove
@@ -1710,32 +1710,32 @@
 ity(View.GONE);%0A
-
         %7D%0A    %7D%0A
@@ -1723,21 +1723,1565 @@
 );%0A        %7D
+%0A%0A        binding.rrpFrom.setOnClickListener(this);%0A        binding.rrpTo.setOnClickListener(this);%0A%0A        fromHour = -1;%0A        fromMinute = -1;%0A%0A        toHour = -1;%0A        toMinute = -1;%0A    %7D%0A%0A    @Override%0A    public void onClick(View view)%7B%0A        switch (view.getId())%7B%0A            case R.id.rrp_from:%0A                selectTime(fromHour, fromMinute, binding.rrpFrom);%0A                break;%0A%0A            case R.id.rrp_to:%0A                selectTime(toHour, toMinute, binding.rrpTo);%0A                break;%0A        %7D%0A    %7D%0A%0A    //TODO Haphazard!! I can and will do better than this when time allows%0A    private void selectTime(int currentHour, int currentMinute, final EditText target)%7B%0A        Calendar calendar = Calendar.getInstance();%0A        if (currentHour == -1)%7B%0A            currentHour = calendar.get(Calendar.HOUR_OF_DAY);%0A        %7D%0A        if (currentMinute == -1)%7B%0A            currentMinute = calendar.get(Calendar.MINUTE);%0A        %7D%0A%0A        new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener()%7B%0A            @Override%0A            public void onTimeSet(TimePicker timePicker, int hour, int minute)%7B%0A                if (target == binding.rrpFrom)%7B%0A                    fromHour = hour;%0A                    fromMinute = minute;%0A                %7D%0A                else if (target == binding.rrpTo)%7B%0A                    toHour = hour;%0A                    toMinute = minute;%0A                %7D%0A                target.setText(hour + %22:%22 + minute);%0A            %7D%0A        %7D, currentHour, currentMinute, true).show();
 %0A    %7D%0A%7D%0A

Add time picking capability