diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java index 90b7ed53..bf6e0f10 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentEditActivity.java @@ -2,19 +2,25 @@ package com.sismics.docs.activity; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; +import android.widget.EditText; import android.widget.Spinner; import com.sismics.docs.R; import com.sismics.docs.adapter.LanguageAdapter; import com.sismics.docs.adapter.TagAutoCompleteAdapter; +import com.sismics.docs.ui.view.DatePickerView; import com.sismics.docs.ui.view.TagsCompleteTextView; import com.sismics.docs.util.PreferenceUtil; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -23,6 +29,11 @@ import java.util.List; * @author bgamard. */ public class DocumentEditActivity extends ActionBarActivity { + /** + * Document edited. + */ + JSONObject document; + @Override protected void onCreate(Bundle args) { super.onCreate(args); @@ -33,14 +44,28 @@ public class DocumentEditActivity extends ActionBarActivity { return; } + // Parse input document + String documentJson = getIntent().getStringExtra("document"); + if (documentJson != null) { + try { + document = new JSONObject(documentJson); + } catch (JSONException e) { + finish(); + return; + } + } + // Setup the activity setContentView(R.layout.document_edit_activity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); + // Language spinner Spinner languageSpinner = (Spinner) findViewById(R.id.languageSpinner); - languageSpinner.setAdapter(new LanguageAdapter(this)); + LanguageAdapter languageAdapter = new LanguageAdapter(this); + languageSpinner.setAdapter(languageAdapter); + // Tags auto-complete JSONObject tags = PreferenceUtil.getCachedJson(this, PreferenceUtil.PREF_CACHED_TAGS_JSON); if (tags == null) { finish(); @@ -56,11 +81,45 @@ public class DocumentEditActivity extends ActionBarActivity { TagsCompleteTextView tagsEditText = (TagsCompleteTextView) findViewById(R.id.tagsEditText); tagsEditText.allowDuplicates(false); tagsEditText.setAdapter(new TagAutoCompleteAdapter(this, 0, tagList)); + + // Fill the activity + DatePickerView datePickerView = (DatePickerView) findViewById(R.id.dateEditText); + if (document == null) { + datePickerView.setDate(new Date()); + } else { + setTitle(R.string.edit_document); + + EditText titleEditText = (EditText) findViewById(R.id.titleEditText); + titleEditText.setText(document.optString("title")); + + EditText descriptionEditText = (EditText) findViewById(R.id.descriptionEditText); + descriptionEditText.setText(document.optString("description")); + + datePickerView.setDate(new Date(document.optLong("create_date"))); + + languageSpinner.setSelection(languageAdapter.getItemPosition(document.optString("language"))); + + JSONArray documentTags = document.optJSONArray("tags"); + for (int i = 0; i < documentTags.length(); i++) { + tagsEditText.addObject(documentTags.optJSONObject(i)); + } + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.document_edit_activity, menu); + return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.save: + finish(); + return true; + case android.R.id.home: finish(); return true; diff --git a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java index dec36ddb..40df90b6 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java +++ b/docs-android/app/src/main/java/com/sismics/docs/activity/DocumentViewActivity.java @@ -206,6 +206,12 @@ public class DocumentViewActivity extends ActionBarActivity { startActivityForResult(Intent.createChooser(intent, getText(R.string.upload_from)), 1); return true; + case R.id.edit: + intent = new Intent(this, DocumentEditActivity.class); + intent.putExtra("document", getIntent().getStringExtra("document")); + startActivityForResult(intent, 2); + return true; + case android.R.id.home: finish(); return true; @@ -217,6 +223,7 @@ public class DocumentViewActivity extends ActionBarActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + // TODO Reload the current document from data after document edition } /** diff --git a/docs-android/app/src/main/java/com/sismics/docs/adapter/LanguageAdapter.java b/docs-android/app/src/main/java/com/sismics/docs/adapter/LanguageAdapter.java index fe0d76e1..65891530 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/adapter/LanguageAdapter.java +++ b/docs-android/app/src/main/java/com/sismics/docs/adapter/LanguageAdapter.java @@ -67,6 +67,22 @@ public class LanguageAdapter extends BaseAdapter { return view; } + /** + * Return the position of a language. + * 0 if it doesn't exists. + * + * @param languageId Language ID + * @return Position + */ + public int getItemPosition(String languageId) { + for (Language language : languageList) { + if (language.id.equals(languageId)) { + return languageList.indexOf(language); + } + } + return 0; + } + /** * A language. */ diff --git a/docs-android/app/src/main/java/com/sismics/docs/fragment/DocListFragment.java b/docs-android/app/src/main/java/com/sismics/docs/fragment/DocListFragment.java index 17099d06..3919677a 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/fragment/DocListFragment.java +++ b/docs-android/app/src/main/java/com/sismics/docs/fragment/DocListFragment.java @@ -133,6 +133,11 @@ public class DocListFragment extends Fragment { return view; } + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + // TODO Reload the documents after document creation and open it from data + } + @Override public void onDestroyView() { EventBus.getDefault().unregister(this); diff --git a/docs-android/app/src/main/java/com/sismics/docs/ui/view/DatePickerView.java b/docs-android/app/src/main/java/com/sismics/docs/ui/view/DatePickerView.java index 974aa9e0..83475819 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/ui/view/DatePickerView.java +++ b/docs-android/app/src/main/java/com/sismics/docs/ui/view/DatePickerView.java @@ -2,15 +2,25 @@ package com.sismics.docs.ui.view; import android.app.DatePickerDialog; import android.content.Context; +import android.text.format.DateFormat; import android.util.AttributeSet; import android.view.View; import android.widget.DatePicker; import android.widget.TextView; import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +/** + * Date picker widget. + * + * @author bgamard + */ +public class DatePickerView extends TextView implements DatePickerDialog.OnDateSetListener { + + private Date date; -public class DatePickerView extends TextView implements DatePickerDialog.OnDateSetListener{ - public DatePickerView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @@ -41,6 +51,17 @@ public class DatePickerView extends TextView implements DatePickerDialog.OnDateS @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { - setText(String.format("%s/%s/%s", monthOfYear, dayOfMonth, year)); + Date date = new GregorianCalendar(year, monthOfYear, dayOfMonth).getTime(); + setDate(date); + } + + public void setDate(Date date) { + this.date = date; + String formattedDate = DateFormat.getDateFormat(getContext()).format(date); + setText(formattedDate); + } + + public Date getDate() { + return date; } } \ No newline at end of file diff --git a/docs-android/app/src/main/java/com/sismics/docs/ui/view/DividerItemDecoration.java b/docs-android/app/src/main/java/com/sismics/docs/ui/view/DividerItemDecoration.java index 98b61596..b65b4ea2 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/ui/view/DividerItemDecoration.java +++ b/docs-android/app/src/main/java/com/sismics/docs/ui/view/DividerItemDecoration.java @@ -10,6 +10,11 @@ import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; import android.view.View; +/** + * Divider item decoration for recycler view. + * + * @author bgamard + */ public class DividerItemDecoration extends RecyclerView.ItemDecoration { private Drawable mDivider; diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png new file mode 100644 index 00000000..7f0ea51b Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_create_white_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xhdpi/ic_done_white_24dp.png b/docs-android/app/src/main/res/drawable-xhdpi/ic_done_white_24dp.png new file mode 100644 index 00000000..e5024472 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xhdpi/ic_done_white_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png new file mode 100644 index 00000000..34ec7092 Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_create_white_24dp.png differ diff --git a/docs-android/app/src/main/res/drawable-xxhdpi/ic_done_white_24dp.png b/docs-android/app/src/main/res/drawable-xxhdpi/ic_done_white_24dp.png new file mode 100644 index 00000000..f801e7ab Binary files /dev/null and b/docs-android/app/src/main/res/drawable-xxhdpi/ic_done_white_24dp.png differ diff --git a/docs-android/app/src/main/res/menu/document_activity.xml b/docs-android/app/src/main/res/menu/document_activity.xml index 46a3be04..d42c1b79 100644 --- a/docs-android/app/src/main/res/menu/document_activity.xml +++ b/docs-android/app/src/main/res/menu/document_activity.xml @@ -2,6 +2,13 @@