package com.example.thmonitor;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.thmonitor.config.LineChartConfig;
import com.example.thmonitor.db.Temperature;
import com.example.thmonitor.util.HttpUtil;
import com.example.thmonitor.util.TempStatistics;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.google.gson.Gson;

import org.litepal.crud.DataSupport;
import org.litepal.tablemanager.Connector;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {

    private LineChart lineChart;
    private TextView titleText;
    private TextView minTempTimeText;
    private TextView minTempText;
    private TextView maxTempTimeText;
    private TextView maxTempText;

    public SwipeRefreshLayout swipeRefreshLayout;
    private DrawerLayout drawerLayout;

    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar)findViewById(R.id.tool_bar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if(actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.mipmap.list);
        }

        PanelFragment panelFragment = new PanelFragment();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fragment_layout, panelFragment);
        transaction.commit();

        drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);

        NavigationView navView = (NavigationView)findViewById(R.id.nav_view);
        navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction transaction = fragmentManager.beginTransaction();
                switch(item.getItemId()) {
                    case R.id.plane_item:
                        PanelFragment panelFragment = new PanelFragment();
                        transaction.replace(R.id.fragment_layout, panelFragment);
                        break;
                    case R.id.linechart_item:
                        LineChartFragment lineChartFragment = new LineChartFragment();
                        transaction.replace(R.id.fragment_layout, lineChartFragment);
                        break;
                    case R.id.ip_connect:
                        new AlertDialog.Builder(MainActivity.this).setTitle("将跳转至IP设置界面")
                                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Intent intent = new Intent(MainActivity.this, IPConfig.class);
                                        startActivity(intent);
                                        MainActivity.this.finish();
                                    }
                                }).setNegativeButton("NO", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        }).show();
                        break;
                    case R.id.my_settings:
                        Intent intent = new Intent(MainActivity.this, SettingsActivty.class);
                        startActivity(intent);
                        break;
                    case R.id.temp_list:
                        Intent myIntent = new Intent(MainActivity.this, ListActivity.class);
                        startActivity(myIntent);
                        break;
                    default:
                        break;
                }
                transaction.commit();
                drawerLayout.closeDrawers();
                return true;
            }
        });

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                drawerLayout.openDrawer(GravityCompat.START);
                break;
            default:
                break;
        }
        return true;
    }


}

@@ -939,16 +939,45 @@
 extView;
+%0Aimport android.widget.Toast;
 %0A%0Aimport
@@ -2498,24 +2498,53 @@
 werLayout;%0A%0A
+    private boolean myFlag;%0A%0A
     @Overrid
@@ -2787,24 +2787,87 @@
 ity_main);%0A%0A
+        myFlag = getIntent().getExtras().getBoolean(%22visit%22);%0A%0A
         Tool
@@ -5726,16 +5726,58 @@
 p_list:%0A
+                        if(!myFlag) %7B%0A    
         
@@ -5877,32 +5877,36 @@
                 
+    
 startActivity(my
@@ -5906,32 +5906,193 @@
 vity(myIntent);%0A
+                        %7D else %7B%0A                            Toast.makeText(MainActivity.this, %22%E8%AF%A5%E6%A8%A1%E5%BC%8F%E4%B8%8B%E4%B8%8D%E8%83%BD%E8%AE%BF%E9%97%AE%22, Toast.LENGTH_SHORT).show();%0A                        %7D%0A
                 

修改VISIT模式无法查询数据库.