package com.olddriver.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import butterknife.BindInt;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


import com.olddriver.R;

import java.io.IOException;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
public class AddActivity extends Activity {

    private static final int IMAGE_PICK_REQUEST = 0;
    Context context;

    @BindView(R.id.editText)
    EditText editText;

    @BindView(R.id.image)
    ImageView imageView;

    @BindView(R.id.imageAction)
    Button imageAction;
    boolean haveImage = false;
    Bitmap bitmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;
        setContentView(R.layout.activity_add);
        ButterKnife.bind(this);
        setButtonAndImage();
    }

    void setButtonAndImage() {
        imageView.setImageBitmap(bitmap);
        if (haveImage) {
            imageAction.setText(R.string.status_cancelImage);
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageAction.setText(R.string.status_addImage);
            imageView.setVisibility(View.INVISIBLE);
        }
    }

    @OnClick(R.id.send)
    void send() {
        String text = editText.getText().toString();
        if (TextUtils.isEmpty(text) == false || bitmap != null) {
//            final ProgressDialog dialog = StatusUtils.showSpinnerDialog(this);
//            StatusService.sendStatus(text, bitmap, new SaveCallback() {
//                @Override
//                public void done(AVException e) {
//                    dialog.dismiss();
//                    if (StatusUtils.filterException(context, e)) {
//                        setResult(RESULT_OK);
//                        finish();
//                    }
//                }
//            });
        }
    }

    public static void pickImage(Activity activity, int requestCode) {
        Intent intent = new Intent(Intent.ACTION_PICK, null);
        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
        activity.startActivityForResult(intent, requestCode);
    }

    @OnClick(R.id.imageAction)
    void imageAction() {
        if (haveImage == false) {
            pickImage(this, IMAGE_PICK_REQUEST);
        } else {
            bitmap = null;
            haveImage = false;
            setButtonAndImage();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == IMAGE_PICK_REQUEST) {
                Uri uri = data.getData();
                try {
                    bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
                    haveImage = true;
                    setButtonAndImage();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

@@ -296,16 +296,41 @@
 tUtils;%0A
+import android.util.Log;%0A
 import a
@@ -576,19 +576,135 @@
 com.
-olddriver.R
+avos.avoscloud.AVException;%0Aimport com.avos.avoscloud.SaveCallback;%0Aimport com.olddriver.R;%0Aimport com.olddriver.data.AVService
 ;%0A%0Ai
@@ -1879,19 +1879,22 @@
  String 
+con
 te
-x
+n
 t = edit
@@ -1950,19 +1950,22 @@
 isEmpty(
+con
 te
-x
+n
 t) == fa
@@ -1985,26 +1985,25 @@
  != null) %7B%0A
-//
+%0A
             
@@ -2006,128 +2006,34 @@
     
-final ProgressDialog dialog = StatusUtils.showSpinnerDialog(this);%0A//            StatusService.sendStatus(text, bitmap, 
+SaveCallback saveCallback=
 new 
@@ -2045,26 +2045,24 @@
 allback() %7B%0A
-//
             
@@ -2075,18 +2075,16 @@
 verride%0A
-//
         
@@ -2121,26 +2121,24 @@
 eption e) %7B%0A
-//
             
@@ -2149,28 +2149,27 @@
     
-dialog.dismiss();%0A//
+// done%E6%96%B9%E6%B3%95%E4%B8%80%E5%AE%9A%E5%9C%A8UI%E7%BA%BF%E7%A8%8B%E6%89%A7%E8%A1%8C%0A
     
@@ -2192,53 +2192,93 @@
 if (
-StatusUtils.filterException(context, e)) %7B%0A//
+e != null) %7B%0A                        Log.e(%22CreateTodo%22, %22Update todo failed.%22, e);%0A 
     
@@ -2274,32 +2274,44 @@
 , e);%0A          
+          %7D%0A
                s
@@ -2331,18 +2331,16 @@
 LT_OK);%0A
-//
         
@@ -2354,17 +2354,16 @@
         
- 
 finish()
@@ -2364,20 +2364,17 @@
 nish();%0A
-//  
+%0A
         
@@ -2373,39 +2373,34 @@
                 
-  %7D%0A// 
+%7D%0A
                %7D
@@ -2399,15 +2399,12 @@
     
-   %7D%0A//
+%7D;%0A%0A
     
@@ -2415,12 +2415,70 @@
     
-%7D
+AVService.createOrUpdateTodo(content, bitmap, saveCallback
 );%0A
+%0A
     

add UpLoad