package net.micode.notes.ui;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import net.micode.notes.data.Notes;
import net.micode.notes.data.NotesDatabaseHelper;
import net.micode.notes.data.NotesProvider;
import net.micode.notes.gtask.data.MetaData;
import net.micode.notes.gtask.data.Node;
import net.micode.notes.gtask.data.SqlNote;
import net.micode.notes.gtask.data.SqlData;
import net.micode.notes.R;
import net.micode.notes.gtask.data.SqlData;
import net.micode.notes.gtask.data.TaskList;
import net.micode.notes.gtask.remote.Network;
import net.micode.notes.gtask.remote.GTaskManager;
import net.micode.notes.tool.GTaskStringUtils;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.data.MetaData;
import net.micode.notes.gtask.data.Node;
import net.micode.notes.gtask.data.SqlNote;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.CookieStore;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

public class syncActivity<c> extends Activity {
    private static final String TAG = SqlData.class.getSimpleName();

    private static final int INVALID_ID = -99999;

    public static final String[] PROJECTION_DATA = new String[] {
            Notes.DataColumns.ID, Notes.DataColumns.MIME_TYPE, Notes.DataColumns.CONTENT, Notes.DataColumns.DATA1,
            Notes.DataColumns.DATA3
    };
    public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + Notes.AUTHORITY + "/note");

    public static final int SYNCUPLOAD = 3;
    /**
     * Uri to query data
     */
    public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + Notes.AUTHORITY + "/data");


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sync);

        findViewById(R.id.syncupload).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)  {

//                Intent intent = new Intent(Addaccount.this, LoginActivity.class);
//                startActivity(intent);
//                finish();
                JSONObject JSnote = new JSONObject();
                JSONObject JSdata = new JSONObject();
                JSONObject JS = new JSONObject();


                try{
                    JSdata = NotesProvider.uploaddata();
                    JSnote = NotesProvider.uploadnote();
                    JS.put("NOTE",JSnote);
                    JS.put("DATA",JSdata);
                }catch (Exception e)
                {
                    e.printStackTrace();
                }

                Network syncupload = new Network(SYNCUPLOAD,JS.toString(),LoginActivity.getUsername());
                try {
                    Thread thread1 = new Thread(syncupload,"syncupload");
                    thread1.start();
                    thread1.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }


                String returnvalue = syncupload.getInTemp();







//                   public SqlNote(Context context, long id) {
//                    mContext = context;
//                    mContentResolver = context.getContentResolver();
//                    mIsCreate = false;
//                    loadFromCursor(id);
//                    mDataList = new ArrayList<SqlData>();
//                    if (mType == Notes.TYPE_NOTE)
//                        loadDataContent();
//                    mDiffNoteValues = new ContentValues();
//
//                }

            }


        });


        findViewById(R.id.syncdownload).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(Addaccount.this, LoginActivity.class);
//                startActivity(intent);
//                finish();
            }
        });



    }

    private void showMessage(final String msg) {
        if (TextUtils.isEmpty(msg))
            return;

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getBaseContext(), msg, Toast.LENGTH_SHORT).show();//暂时提示
            }
        });
    }


}
