mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 12:56:02 +03:00
merge create and edit note activity
This commit is contained in:
parent
32cd544ef9
commit
baff508376
15 changed files with 145 additions and 225 deletions
|
@ -58,9 +58,12 @@
|
|||
/>
|
||||
|
||||
<activity
|
||||
android:name="it.niedermann.owncloud.notes.android.activity.CreateNoteActivity"
|
||||
android:label="@string/action_create"
|
||||
android:windowSoftInputMode="stateVisible">
|
||||
android:name="it.niedermann.owncloud.notes.android.activity.EditNoteActivity"
|
||||
android:label="@string/menu_edit"
|
||||
android:parentActivityName="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:launchMode="singleTask"
|
||||
>
|
||||
<intent-filter android:label="@string/action_create">
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
@ -68,14 +71,6 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="it.niedermann.owncloud.notes.android.activity.EditNoteActivity"
|
||||
android:label="@string/menu_edit"
|
||||
android:parentActivityName="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:launchMode="singleTask"
|
||||
/>
|
||||
|
||||
<activity
|
||||
android:name="it.niedermann.owncloud.notes.android.activity.AboutActivity"
|
||||
android:label="@string/menu_about"
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
package it.niedermann.owncloud.notes.android.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yydcdut.rxmarkdown.RxMDEditText;
|
||||
import com.yydcdut.rxmarkdown.RxMarkdown;
|
||||
import com.yydcdut.rxmarkdown.syntax.edit.EditFactory;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.model.Category;
|
||||
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
|
||||
import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper;
|
||||
import it.niedermann.owncloud.notes.util.MarkDownUtil;
|
||||
import rx.Subscriber;
|
||||
|
||||
public class CreateNoteActivity extends AppCompatActivity {
|
||||
|
||||
public static final String PARAM_CATEGORY = "category";
|
||||
private final static int server_settings = 2;
|
||||
|
||||
private RxMDEditText editTextField = null;
|
||||
private Category categoryPreselection;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (!NoteServerSyncHelper.isConfigured(this)) {
|
||||
Intent settingsIntent = new Intent(this, SettingsActivity.class);
|
||||
startActivityForResult(settingsIntent, server_settings);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_create);
|
||||
editTextField = (RxMDEditText) findViewById(R.id.createContent);
|
||||
|
||||
// Get intent, action and MIME type
|
||||
Intent intent = getIntent();
|
||||
String action = intent.getAction();
|
||||
String type = intent.getType();
|
||||
|
||||
if(intent.hasExtra(PARAM_CATEGORY)) {
|
||||
categoryPreselection = (Category) intent.getSerializableExtra(PARAM_CATEGORY);
|
||||
}
|
||||
|
||||
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||
if ("text/plain".equals(type)) {
|
||||
editTextField.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||
}
|
||||
}
|
||||
|
||||
RxMarkdown.live(editTextField)
|
||||
.config(MarkDownUtil.getMarkDownConfiguration(getApplicationContext()))
|
||||
.factory(EditFactory.create())
|
||||
.intoObservable()
|
||||
.subscribe(new Subscriber<CharSequence>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(CharSequence charSequence) {
|
||||
editTextField.setText(charSequence, TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_menu_create, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main-Menu
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_create_save:
|
||||
saveAndClose(false);
|
||||
return true;
|
||||
case R.id.action_create_cancel:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
saveAndClose(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves as new note and closes the Activity.
|
||||
* @param implicit If <code>true</code>, the note is only saved if non-empty.
|
||||
*/
|
||||
private void saveAndClose(boolean implicit) {
|
||||
editTextField.setEnabled(false);
|
||||
String content = editTextField.getText().toString();
|
||||
if(!implicit || !content.isEmpty()) {
|
||||
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(this);
|
||||
Intent data = new Intent(this, NotesListViewActivity.class);
|
||||
String category = categoryPreselection==null ? null : categoryPreselection.category;
|
||||
boolean favorite = categoryPreselection!=null && categoryPreselection.favorite!=null ? categoryPreselection.favorite : false;
|
||||
data.putExtra(NotesListViewActivity.CREATED_NOTE, db.getNote(db.addNoteAndSync(content, category, favorite)));
|
||||
setResult(RESULT_OK, data);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == server_settings) {
|
||||
if (resultCode != RESULT_OK) {
|
||||
// User has not setup the server config and no note can be created
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,16 +11,21 @@ import android.util.Log;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.android.fragment.BaseNoteFragment;
|
||||
import it.niedermann.owncloud.notes.android.fragment.NoteEditFragment;
|
||||
import it.niedermann.owncloud.notes.android.fragment.NotePreviewFragment;
|
||||
import it.niedermann.owncloud.notes.model.Category;
|
||||
import it.niedermann.owncloud.notes.model.CloudNote;
|
||||
import it.niedermann.owncloud.notes.model.DBNote;
|
||||
import it.niedermann.owncloud.notes.util.NoteUtil;
|
||||
|
||||
public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragment.NoteFragmentListener {
|
||||
|
||||
public static final String PARAM_NOTE_ID = "noteId";
|
||||
public static final String PARAM_CATEGORY = "category";
|
||||
|
||||
private BaseNoteFragment fragment;
|
||||
|
||||
|
@ -29,7 +34,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
|
|||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
createFragmentByPreference();
|
||||
launchNoteFragment();
|
||||
} else {
|
||||
fragment = (BaseNoteFragment) getFragmentManager().findFragmentById(android.R.id.content);
|
||||
}
|
||||
|
@ -48,16 +53,32 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
|
|||
getFragmentManager().beginTransaction().detach(fragment).commit();
|
||||
fragment = null;
|
||||
}
|
||||
createFragmentByPreference();
|
||||
launchNoteFragment();
|
||||
}
|
||||
|
||||
private long getNoteId() {
|
||||
return getIntent().getLongExtra(PARAM_NOTE_ID, 0);
|
||||
}
|
||||
|
||||
private void createFragmentByPreference() {
|
||||
/**
|
||||
* Starts the note fragment for an existing note or a new note.
|
||||
* The actual behavior is triggered by the activity's intent.
|
||||
*/
|
||||
private void launchNoteFragment() {
|
||||
long noteId = getNoteId();
|
||||
if(noteId>0) {
|
||||
launchExistingNote(noteId);
|
||||
} else {
|
||||
launchNewNote();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a {@link NoteEditFragment} or {@link NotePreviewFragment} for an existing note.
|
||||
* The type of fragment (view-mode) is chosen based on the user preferences.
|
||||
* @param noteId ID of the existing note.
|
||||
*/
|
||||
private void launchExistingNote(long noteId) {
|
||||
final String prefKeyNoteMode = getString(R.string.pref_key_note_mode);
|
||||
final String prefKeyLastMode = getString(R.string.pref_key_last_note_mode);
|
||||
final String prefValueEdit = getString(R.string.pref_value_mode_edit);
|
||||
|
@ -67,19 +88,21 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
|
|||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
String mode = preferences.getString(prefKeyNoteMode, prefValueEdit);
|
||||
String lastMode = preferences.getString(prefKeyLastMode, prefValueEdit);
|
||||
boolean editMode = true;
|
||||
if (prefValuePreview.equals(mode) || (prefValueLast.equals(mode) && prefValuePreview.equals(lastMode))) {
|
||||
createFragment(noteId, false);
|
||||
/* TODO enhancement: store last mode in note
|
||||
for cross device functionality per note mode should be stored on the server.
|
||||
} else if(prefValueLast.equals(mode) && prefValuePreview.equals(note.getMode())) {
|
||||
createPreviewFragment(note);
|
||||
*/
|
||||
} else {
|
||||
createFragment(noteId, true);
|
||||
editMode = false;
|
||||
}
|
||||
launchExistingNote(noteId, editMode);
|
||||
}
|
||||
|
||||
private void createFragment(long noteId, boolean edit) {
|
||||
/**
|
||||
* Starts a {@link NoteEditFragment} or {@link NotePreviewFragment} for an existing note.
|
||||
* @param noteId ID of the existing note.
|
||||
* @param edit View-mode of the fragment:
|
||||
* <code>true</code> for {@link NoteEditFragment},
|
||||
* <code>false</code> for {@link NotePreviewFragment}.
|
||||
*/
|
||||
private void launchExistingNote(long noteId, boolean edit) {
|
||||
// save state of the fragment in order to resume with the same note and originalNote
|
||||
Fragment.SavedState savedState = null;
|
||||
if(fragment != null) {
|
||||
|
@ -96,6 +119,31 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
|
|||
getFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the {@link NoteEditFragment} with a new note.
|
||||
* Content ("share" functionality), category and favorite attribute can be preset.
|
||||
*/
|
||||
private void launchNewNote() {
|
||||
Intent intent = getIntent();
|
||||
|
||||
String category = null;
|
||||
boolean favorite = false;
|
||||
if(intent.hasExtra(PARAM_CATEGORY)) {
|
||||
Category categoryPreselection = (Category) intent.getSerializableExtra(PARAM_CATEGORY);
|
||||
category = categoryPreselection.category;
|
||||
favorite = categoryPreselection.favorite!=null ? categoryPreselection.favorite : false;
|
||||
}
|
||||
|
||||
String content = "";
|
||||
if (Intent.ACTION_SEND.equals(intent.getAction()) && "text/plain".equals(intent.getType())) {
|
||||
content = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
}
|
||||
|
||||
CloudNote newNote = new CloudNote(0, Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(content, this), content, favorite, category, null);
|
||||
fragment = NoteEditFragment.newInstanceWithNewNote(newNote);
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
fragment.onPrepareClose();
|
||||
|
@ -117,11 +165,11 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
|
|||
return true;
|
||||
case R.id.menu_preview:
|
||||
fragment.onPrepareClose();
|
||||
createFragment(getNoteId(), false);
|
||||
launchExistingNote(getNoteId(), false);
|
||||
return true;
|
||||
case R.id.menu_edit:
|
||||
fragment.onPrepareClose();
|
||||
createFragment(getNoteId(), true);
|
||||
launchExistingNote(getNoteId(), true);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -143,6 +191,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
|
|||
} else {
|
||||
preferences.edit().putString(prefKeyLastMode, getString(R.string.pref_value_mode_preview)).apply();
|
||||
}
|
||||
fragment.onFinalClose();
|
||||
finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -182,8 +182,8 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
|
|||
findViewById(R.id.fab_create).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent createIntent = new Intent(getApplicationContext(), CreateNoteActivity.class);
|
||||
createIntent.putExtra(CreateNoteActivity.PARAM_CATEGORY, navigationSelection);
|
||||
Intent createIntent = new Intent(getApplicationContext(), EditNoteActivity.class);
|
||||
createIntent.putExtra(EditNoteActivity.PARAM_CATEGORY, navigationSelection);
|
||||
startActivityForResult(createIntent, create_note_cmd);
|
||||
}
|
||||
});
|
||||
|
@ -362,7 +362,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
|
|||
// add notification
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
||||
PendingIntent newNoteIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, CreateNoteActivity.class)
|
||||
new Intent(this, EditNoteActivity.class)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
|
||||
0);
|
||||
builder.setSmallIcon(R.drawable.ic_action_new)
|
||||
|
|
|
@ -8,7 +8,7 @@ import android.content.Intent;
|
|||
import android.widget.RemoteViews;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.android.activity.CreateNoteActivity;
|
||||
import it.niedermann.owncloud.notes.android.activity.EditNoteActivity;
|
||||
|
||||
/**
|
||||
* Implementation of App Widget functionality.
|
||||
|
@ -20,7 +20,7 @@ public class CreateNoteWidget extends AppWidgetProvider {
|
|||
|
||||
// Construct the RemoteViews object
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_create_note);
|
||||
Intent intent = new Intent(context, CreateNoteActivity.class);
|
||||
Intent intent = new Intent(context, EditNoteActivity.class);
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
views.setOnClickPendingIntent(R.id.widget_create_note, pendingIntent);
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.net.Uri;
|
|||
import android.widget.RemoteViews;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.android.activity.CreateNoteActivity;
|
||||
import it.niedermann.owncloud.notes.android.activity.EditNoteActivity;
|
||||
import it.niedermann.owncloud.notes.android.activity.NotesListViewActivity;
|
||||
|
||||
|
@ -35,7 +34,7 @@ public class NoteListWidget extends AppWidgetProvider {
|
|||
views.setOnClickPendingIntent(R.id.widget_note_list_title, pendingIntent);
|
||||
|
||||
// Launch create note activity if user taps "+" sign in header
|
||||
intent = new Intent(context, CreateNoteActivity.class);
|
||||
intent = new Intent(context, EditNoteActivity.class);
|
||||
pendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.model.CloudNote;
|
||||
import it.niedermann.owncloud.notes.model.DBNote;
|
||||
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
|
||||
import it.niedermann.owncloud.notes.util.ICallback;
|
||||
|
@ -26,10 +27,12 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
}
|
||||
|
||||
public static final String PARAM_NOTE_ID = "noteId";
|
||||
public static final String PARAM_NEWNOTE = "newNote";
|
||||
private static final String SAVEDKEY_NOTE = "note";
|
||||
private static final String SAVEDKEY_ORIGINAL_NOTE = "original_note";
|
||||
|
||||
protected DBNote note;
|
||||
@Nullable
|
||||
private DBNote originalNote;
|
||||
private NoteSQLiteOpenHelper db;
|
||||
private NoteFragmentListener listener;
|
||||
|
@ -39,7 +42,16 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
super.onCreate(savedInstanceState);
|
||||
if(savedInstanceState==null) {
|
||||
long id = getArguments().getLong(PARAM_NOTE_ID);
|
||||
note = originalNote = db.getNote(id);
|
||||
if(id>0) {
|
||||
note = originalNote = db.getNote(id);
|
||||
} else {
|
||||
CloudNote cloudNote = (CloudNote) getArguments().getSerializable(PARAM_NEWNOTE);
|
||||
if(cloudNote == null) {
|
||||
throw new IllegalArgumentException(PARAM_NOTE_ID + " is not given and argument " + PARAM_NEWNOTE +" is missing.");
|
||||
}
|
||||
note = db.getNote(db.addNoteAndSync(cloudNote));
|
||||
originalNote = null;
|
||||
}
|
||||
} else {
|
||||
note = (DBNote) savedInstanceState.getSerializable(SAVEDKEY_NOTE);
|
||||
originalNote = (DBNote) savedInstanceState.getSerializable(SAVEDKEY_ORIGINAL_NOTE);
|
||||
|
@ -101,11 +113,15 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_cancel:
|
||||
db.updateNoteAndSync(originalNote, null, null);
|
||||
if(originalNote == null) {
|
||||
db.deleteNoteAndSync(note.getId());
|
||||
} else {
|
||||
db.updateNoteAndSync(originalNote, null, null);
|
||||
}
|
||||
listener.close();
|
||||
return true;
|
||||
case R.id.menu_delete:
|
||||
db.deleteNoteAndSync(originalNote.getId());
|
||||
db.deleteNoteAndSync(note.getId());
|
||||
listener.close();
|
||||
return true;
|
||||
case R.id.menu_favorite:
|
||||
|
@ -135,6 +151,12 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
|
|||
saveNote(null);
|
||||
}
|
||||
|
||||
public void onFinalClose() {
|
||||
if(originalNote==null && getContent().isEmpty()) {
|
||||
db.deleteNoteAndSync(note.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the current state in the database and schedule synchronization if needed.
|
||||
*
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yydcdut.rxmarkdown.RxMDEditText;
|
||||
|
@ -18,6 +19,7 @@ import com.yydcdut.rxmarkdown.RxMarkdown;
|
|||
import com.yydcdut.rxmarkdown.syntax.edit.EditFactory;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.model.CloudNote;
|
||||
import it.niedermann.owncloud.notes.util.ICallback;
|
||||
import it.niedermann.owncloud.notes.util.MarkDownUtil;
|
||||
import rx.Subscriber;
|
||||
|
@ -35,7 +37,15 @@ public class NoteEditFragment extends BaseNoteFragment {
|
|||
public static NoteEditFragment newInstance(long noteId) {
|
||||
NoteEditFragment f = new NoteEditFragment();
|
||||
Bundle b = new Bundle();
|
||||
b.putSerializable(PARAM_NOTE_ID, noteId);
|
||||
b.putLong(PARAM_NOTE_ID, noteId);
|
||||
f.setArguments(b);
|
||||
return f;
|
||||
}
|
||||
|
||||
public static NoteEditFragment newInstanceWithNewNote(CloudNote newNote) {
|
||||
NoteEditFragment f = new NoteEditFragment();
|
||||
Bundle b = new Bundle();
|
||||
b.putSerializable(PARAM_NEWNOTE, newNote);
|
||||
f.setArguments(b);
|
||||
return f;
|
||||
}
|
||||
|
@ -63,6 +73,10 @@ public class NoteEditFragment extends BaseNoteFragment {
|
|||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
if(note.getContent().isEmpty()) {
|
||||
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
}
|
||||
|
||||
// workaround for issue yydcdut/RxMarkdown#41
|
||||
note.setContent(note.getContent().replace("\r\n", "\n"));
|
||||
|
||||
|
@ -139,7 +153,7 @@ public class NoteEditFragment extends BaseNoteFragment {
|
|||
}
|
||||
|
||||
private RxMDEditText getContentView() {
|
||||
return (RxMDEditText) getView().findViewById(R.id.editContent);
|
||||
return getView().findViewById(R.id.editContent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@ public class NotePreviewFragment extends BaseNoteFragment {
|
|||
public static NotePreviewFragment newInstance(long noteId) {
|
||||
NotePreviewFragment f = new NotePreviewFragment();
|
||||
Bundle b = new Bundle();
|
||||
b.putSerializable(PARAM_NOTE_ID, noteId);
|
||||
b.putLong(PARAM_NOTE_ID, noteId);
|
||||
f.setArguments(b);
|
||||
return f;
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
|
|||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public long addNoteAndSync(String content, String category, boolean favorite) {
|
||||
CloudNote note = new CloudNote(0, Calendar.getInstance(), NoteUtil.generateNoteTitle(content), content, favorite, category, null);
|
||||
CloudNote note = new CloudNote(0, Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(content, getContext()), content, favorite, category, null);
|
||||
return addNoteAndSync(note);
|
||||
}
|
||||
|
||||
|
@ -429,7 +429,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
|
|||
if(newContent==null) {
|
||||
newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED);
|
||||
} else {
|
||||
newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), NoteUtil.generateNoteTitle(newContent), newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED);
|
||||
newNote = new DBNote(oldNote.getId(), oldNote.getRemoteId(), Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(newContent, getContext()), newContent, oldNote.isFavorite(), oldNote.getCategory(), oldNote.getEtag(), DBStatus.LOCAL_EDITED);
|
||||
}
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package it.niedermann.owncloud.notes.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
|
||||
/**
|
||||
* Provides basic functionality for Note operations.
|
||||
* Created by stefan on 06.10.15.
|
||||
|
@ -50,7 +53,7 @@ public class NoteUtil {
|
|||
* @param line String - a single Line which ends with \n
|
||||
* @return boolean isEmpty
|
||||
*/
|
||||
public static boolean isEmptyLine(@Nullable String line) {
|
||||
private static boolean isEmptyLine(@Nullable String line) {
|
||||
return removeMarkDown(line).trim().length() == 0;
|
||||
}
|
||||
|
||||
|
@ -62,7 +65,7 @@ public class NoteUtil {
|
|||
* @return truncated string
|
||||
*/
|
||||
@NonNull
|
||||
public static String truncateString(@NonNull String str, int len) {
|
||||
private static String truncateString(@NonNull String str, int len) {
|
||||
return str.substring(0, Math.min(len, str.length()));
|
||||
}
|
||||
|
||||
|
@ -80,6 +83,15 @@ public class NoteUtil {
|
|||
return "";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String generateNonEmptyNoteTitle(@NonNull String content, Context context) {
|
||||
String title = generateNoteTitle(content);
|
||||
if(title.isEmpty()) {
|
||||
title = context.getString(R.string.action_create);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a title of a content String (reads fist linew which is not empty)
|
||||
*
|
||||
|
@ -87,7 +99,7 @@ public class NoteUtil {
|
|||
* @return excerpt String
|
||||
*/
|
||||
@NonNull
|
||||
public static String generateNoteTitle(@NonNull String content) {
|
||||
static String generateNoteTitle(@NonNull String content) {
|
||||
return getLineWithoutMarkDown(content, 0);
|
||||
}
|
||||
|
||||
|
@ -99,7 +111,7 @@ public class NoteUtil {
|
|||
* @return lineContent String
|
||||
*/
|
||||
@NonNull
|
||||
public static String getLineWithoutMarkDown(@NonNull String content, int lineNumber) {
|
||||
private static String getLineWithoutMarkDown(@NonNull String content, int lineNumber) {
|
||||
String line = "";
|
||||
if (content.contains("\n")) {
|
||||
String[] lines = content.split("\n");
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/createContentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:weightSum="1"
|
||||
tools:context="it.niedermann.owncloud.notes.android.activity.CreateNoteActivity">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.yydcdut.rxmarkdown.RxMDEditText
|
||||
android:id="@+id/createContent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textMultiLine|textCapSentences"
|
||||
android:padding="16dp" />
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,23 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/editContentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="it.niedermann.owncloud.notes.android.activity.CreateNoteActivity">
|
||||
tools:context="it.niedermann.owncloud.notes.android.activity.EditNoteActivity">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.yydcdut.rxmarkdown.RxMDEditText
|
||||
<com.yydcdut.rxmarkdown.RxMDEditText
|
||||
android:id="@+id/editContent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textMultiLine|textCapSentences"
|
||||
android:padding="16dp" />
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
|
@ -1,18 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/editContentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="it.niedermann.owncloud.notes.android.activity.CreateNoteActivity">
|
||||
tools:context="it.niedermann.owncloud.notes.android.activity.EditNoteActivity">
|
||||
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.yydcdut.rxmarkdown.RxMDTextView
|
||||
<com.yydcdut.rxmarkdown.RxMDTextView
|
||||
android:id="@+id/single_note_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -20,7 +15,5 @@
|
|||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="@color/fg_default"
|
||||
android:textIsSelectable="true" />
|
||||
</ScrollView>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
|
@ -9,7 +9,7 @@
|
|||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:targetPackage="it.niedermann.owncloud.notes"
|
||||
android:targetClass="it.niedermann.owncloud.notes.android.activity.CreateNoteActivity" />
|
||||
android:targetClass="it.niedermann.owncloud.notes.android.activity.EditNoteActivity" />
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
</shortcut>
|
||||
</shortcuts>
|
Loading…
Reference in a new issue