// Path: app/src/main/java/com/antest1/kcanotify/DropLogActivity.java
// public static String convertMillsToDate(long timestamp) {
//     Date d = new Date(timestamp);
//     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.US);
//     return dateFormat.format(d);
// }
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final String ERROR_TYPE_RESLOG = "RL";
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final int KCANOTIFY_DB_VERSION = 5;
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final int KCANOTIFY_RESOURCELOG_VERSION = 1;


import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.graphics.PorterDuff;
import android.os.AsyncTask;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.JsonObject;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import static com.antest1.kcanotify.DropLogActivity.convertMillsToDate;
import static com.antest1.kcanotify.KcaConstants.ERROR_TYPE_RESLOG;
import static com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION;
import static com.antest1.kcanotify.KcaConstants.KCANOTIFY_RESOURCELOG_VERSION;
        interval_select = findViewById(R.id.reslog_date_interval);
        final ArrayAdapter<CharSequence> interval_adapter = ArrayAdapter.createFromResource(this,
                R.array.time_interval_array, R.layout.spinner_item_14dp);
        interval_adapter.setDropDownViewResource(R.layout.spinner_dropdown_item_14dp);
        interval_select.setAdapter(interval_adapter);
        interval_select.setSelection(INTERVAL_1D);
        interval_select.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                Log.e("KCA-RL", "onItemSelected");
                interval_value = position;
                setFragmentChartInfo(interval_value);
                KcaResourcelogItemAdpater.setListViewItemList(convertData(resourceLog));
                pageAdapter.notifyDataSetChanged();
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

        long current_time = System.currentTimeMillis();
        current_time = KcaUtils.getCurrentDateTimestamp(current_time);
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy", Locale.US);
        String[] time_list = dateFormat.format(new Date(current_time)).split("\\-");
        int year = Integer.parseInt(time_list[2]);
        int month = Integer.parseInt(time_list[0]);
        start_timestamp = current_time - DAY_MILLISECOND * KcaUtils.getLastDay(year, month == 1 ? 12 : month - 1);
        end_timestamp = current_time + DAY_MILLISECOND - 1;

// Path: app/src/main/java/com/antest1/kcanotify/DropLogActivity.java
// public static String convertMillsToDate(long timestamp) {
//     Date d = new Date(timestamp);
//     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.US);
//     return dateFormat.format(d);
// }
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final String ERROR_TYPE_RESLOG = "RL";
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final int KCANOTIFY_DB_VERSION = 5;
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final int KCANOTIFY_RESOURCELOG_VERSION = 1;


// Path: app/src/main/java/com/antest1/kcanotify/ResourceLogActivity.java
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.graphics.PorterDuff;
import android.os.AsyncTask;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import androidx.core.content.ContextCompat;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.JsonObject;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import static com.antest1.kcanotify.DropLogActivity.convertMillsToDate;
import static com.antest1.kcanotify.KcaConstants.ERROR_TYPE_RESLOG;
import static com.antest1.kcanotify.KcaConstants.KCANOTIFY_DB_VERSION;
import static com.antest1.kcanotify.KcaConstants.KCANOTIFY_RESOURCELOG_VERSION;

        interval_select = findViewById(R.id.reslog_date_interval);
        final ArrayAdapter<CharSequence> interval_adapter = ArrayAdapter.createFromResource(this,
                R.array.time_interval_array, R.layout.spinner_item_14dp);
        interval_adapter.setDropDownViewResource(R.layout.spinner_dropdown_item_14dp);
        interval_select.setAdapter(interval_adapter);
        interval_select.setSelection(INTERVAL_1D);
        interval_select.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                Log.e("KCA-RL", "onItemSelected");
                interval_value = position;
                setFragmentChartInfo(interval_value);
                KcaResourcelogItemAdpater.setListViewItemList(convertData(resourceLog));
                pageAdapter.notifyDataSetChanged();
            }
            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

        long current_time = System.currentTimeMillis();
        current_time = KcaUtils.getCurrentDateTimestamp(current_time);
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy", Locale.US);
        String[] time_list = dateFormat.format(new Date(current_time)).split("\\-");
        int year = Integer.parseInt(time_list[2]);
        int month = Integer.parseInt(time_list[0]);
        start_timestamp = current_time - DAY_MILLISECOND * KcaUtils.getLastDay(year, month == 1 ? 12 : month - 1);
        end_timestamp = current_time + DAY_MILLISECOND - 1;

        start_date.setText(convertMillsToDate(start_timestamp));