package com.xlythe.dao.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;

import com.xlythe.dao.sample.model.Note;

public class DetailActivity extends AppCompatActivity {
    public static final String EXTRA_NOTE = "note";

    private Note mNote;

    private EditText mTitleView;
    private EditText mBodyView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

        mTitleView = (EditText) findViewById(R.id.title);
        mBodyView = (EditText) findViewById(R.id.body);

        if (getIntent().hasExtra(EXTRA_NOTE)) {
            mNote = (Note) getIntent().getSerializableExtra(EXTRA_NOTE);
            mNote.setContext(this);

            mTitleView.setText(mNote.getTitle());
            mBodyView.setText(mNote.getBody());
        }
    }

    public void save(View view) {
        if (mNote != null) {
            mNote.setTitle(mTitleView.getText().toString());
            mNote.setBody(mBodyView.getText().toString());
            mNote.save();
        } else {
            new Note.Query(this)
                    .title(mTitleView.getText().toString())
                    .body(mBodyView.getText().toString())
                    .insert();
        }
        supportFinishAfterTransition();
    }

}

@@ -100,16 +100,72 @@
 tivity;%0A
+import android.text.TextUtils;%0Aimport android.util.Log;%0A
 import a
@@ -313,16 +313,92 @@
 ivity %7B%0A
+    private static final String TAG = DetailActivity.class.getSimpleName();%0A
     publ
@@ -1117,24 +1117,216 @@
 iew view) %7B%0A
+        if (TextUtils.isEmpty(getNoteTitle())) %7B%0A            Log.w(TAG, %22Ignoring attempt to set empty note title%22);%0A            supportFinishAfterTransition();%0A            return;%0A        %7D%0A%0A
         if (
@@ -1373,37 +1373,20 @@
 tle(
-mTitleView.getText().toString
+getNoteTitle
 ());
@@ -1416,36 +1416,19 @@
 ody(
-mBodyView.getText().toString
+getNoteBody
 ());
@@ -1535,37 +1535,20 @@
 tle(
-mTitleView.getText().toString
+getNoteTitle
 ())%0A
@@ -1577,36 +1577,19 @@
 ody(
-mBodyView.getText().toString
+getNoteBody
 ())%0A
@@ -1676,10 +1676,190 @@
 %0A    %7D%0A%0A
+    private String getNoteTitle() %7B%0A        return mTitleView.getText().toString();%0A    %7D%0A%0A    private String getNoteBody() %7B%0A        return mBodyView.getText().toString();%0A    %7D%0A%0A
 %7D%0A

clean up detail activity