package org.mattvchandler.progressbars;

import android.databinding.ObservableField;
import android.os.Handler;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

// struct bound to progress_bar_row layout
public final class Progress_bar_data
{
    public final ObservableField<String>  title      = new ObservableField<>();

    public final ObservableField<String>  start_date    = new ObservableField<>();
    public final ObservableField<String>  start_time    = new ObservableField<>();
    public final ObservableField<String>  end_date      = new ObservableField<>();
    public final ObservableField<String>  end_time      = new ObservableField<>();

    public final ObservableField<String>  percentage    = new ObservableField<>();
    public final ObservableField<Integer> progress      = new ObservableField<>();

    public final ObservableField<String>  time_text     = new ObservableField<>();

    public final ObservableField<Boolean> show_start    = new ObservableField<>();
    public final ObservableField<Boolean> show_end      = new ObservableField<>();
    public final ObservableField<Boolean> show_progress = new ObservableField<>();


    private Date start_time_date = new Date();
    private Date end_time_date   = new Date();

    private String pre_text         = new String();
    private String countdown_text   = new String();
    private String complete_text    = new String();
    private String post_text        = new String();

    private Integer precision       = new Integer(2);

    private Boolean show_years      = new Boolean(true);
    private Boolean show_months     = new Boolean(true);
    private Boolean show_weeks      = new Boolean(true);
    private Boolean show_days       = new Boolean(true);
    private Boolean show_hours      = new Boolean(true);
    private Boolean show_minutes    = new Boolean(true);
    private Boolean show_seconds    = new Boolean(true);

    private Boolean terminate       = new Boolean(true);

    private class Update implements Runnable
    {
        public Handler handler = new Handler();
        public int delay = 1000; // 1000ms
        public void run()
        {
            int progress_data = (progress.get() + 1) % 100;
            progress.set(progress_data);
            percentage.set(String.valueOf(progress_data) + ".00%");

            handler.postDelayed(this, delay);

            time_text.set(countdown_text);
        }
    }

    Update updater = new Update();

    Progress_bar_data(long posix_start_time_in,
                      long posix_end_time_in,
                      String title_in,
                      String pre_text_in,
                      String countdown_text_in,
                      String complete_text_in,
                      String post_text_in,
                      Integer precision_in,
                      Boolean show_start_in,
                      Boolean show_end_in,
                      Boolean show_progress_in,
                      Boolean show_years_in,
                      Boolean show_months_in,
                      Boolean show_weeks_in,
                      Boolean show_days_in,
                      Boolean show_hours_in,
                      Boolean show_minutes_in,
                      Boolean show_seconds_in,
                      Boolean terminate_in)
    {
        start_time_date.setTime(posix_start_time_in * 1000L);
        end_time_date.setTime(posix_end_time_in * 1000L);

        title.set(title_in);

        pre_text = pre_text_in;
        countdown_text = countdown_text_in;
        complete_text = complete_text_in;
        post_text = post_text_in;

        precision = precision_in;

        show_start.set(show_start_in);
        show_end.set(show_end_in);
        show_progress.set(show_progress_in);

        show_years = show_years_in;
        show_months = show_months_in;
        show_weeks = show_weeks_in;
        show_days = show_days_in;
        show_hours = show_hours_in;
        show_minutes = show_minutes_in;
        show_seconds = show_seconds_in;

        terminate = terminate_in;

        SimpleDateFormat date_df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        SimpleDateFormat time_df = new SimpleDateFormat("HH:mm:SS", Locale.US);

        start_date.set(date_df.format(start_time_date));
        start_time.set(time_df.format(start_time_date));
        end_date.set(date_df.format(end_time_date));
        end_time.set(time_df.format(end_time_date));

        //percentage.set(new String());
        progress.set(0);
        //time_text.set(new String());

        updater.run();
    }

}

@@ -71,21 +71,109 @@
 servable
-Field
+Boolean;%0Aimport android.databinding.ObservableField;%0Aimport android.databinding.ObservableInt
 ;%0Aimport
@@ -409,24 +409,27 @@
  title      
+   
 = new Observ
@@ -891,22 +891,22 @@
 able
-Field%3CInteger%3E
+Int           
  pro
@@ -924,39 +924,35 @@
 = new Observable
-Field%3C%3E
+Int
 ();%0A%0A    public 
@@ -1047,38 +1047,38 @@
 l Observable
-Field%3C
 Boolean
-%3E
+       
  show_start 
@@ -1088,39 +1088,39 @@
 = new Observable
-Field%3C%3E
+Boolean
 ();%0A    public f
@@ -1130,38 +1130,38 @@
 l Observable
-Field%3C
 Boolean
-%3E
+       
  show_end   
@@ -1171,39 +1171,39 @@
 = new Observable
-Field%3C%3E
+Boolean
 ();%0A    public f
@@ -1221,22 +1221,22 @@
 able
-Field%3C
 Boolean
-%3E
+       
  sho
@@ -1258,31 +1258,31 @@
 w Observable
-Field%3C%3E
+Boolean
 ();%0A%0A%0A    pr

fix boxed bool/int warnings