Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
android:screenOrientation="locked"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.note.NotesListActivity"
android:name=".activity.note.list.NotesListActivity"
android:exported="false"
android:screenOrientation="locked"
android:theme="@style/AppTheme" />
<activity
android:name=".activity.note.OpenNoteActivity"
android:name=".activity.note.editor.OpenNoteActivity"
android:exported="false"
android:screenOrientation="locked"
android:theme="@style/AppTheme" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/notesr/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import app.notesr.service.AndroidServiceRegistry;
import app.notesr.service.lifecycle.AppCloseAndroidService;
import app.notesr.service.lifecycle.AppCloseAndroidServiceStarter;
import app.notesr.activity.note.NotesListActivity;
import app.notesr.activity.note.list.NotesListActivity;
import app.notesr.activity.security.AuthActivity;
import app.notesr.activity.security.KeyRecoveryActivity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import app.notesr.service.exporter.ExportAndroidServiceStarter;
import app.notesr.service.exporter.ExportStatus;
import app.notesr.service.file.FileService;
import app.notesr.activity.note.NotesListActivity;
import app.notesr.activity.note.list.NotesListActivity;
import app.notesr.service.note.NoteService;
import app.notesr.util.VersionFetcherImpl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import app.notesr.activity.DialogFactory;
import app.notesr.data.AppDatabase;
import app.notesr.data.DatabaseProvider;
import app.notesr.activity.note.OpenNoteActivity;
import app.notesr.activity.note.editor.OpenNoteActivity;
import app.notesr.service.file.FileService;
import app.notesr.service.note.NoteService;
import app.notesr.data.model.FileInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import app.notesr.R;
import app.notesr.activity.ActivityBase;
import app.notesr.activity.note.NotesListActivity;
import app.notesr.activity.note.list.NotesListActivity;
import app.notesr.service.AndroidServiceRegistry;
import app.notesr.service.importer.ImportAndroidService;
import app.notesr.service.importer.ImportAndroidServiceStarter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import app.notesr.BuildConfig;
import app.notesr.R;
import app.notesr.activity.ActivityBase;
import app.notesr.activity.note.NotesListActivity;
import app.notesr.activity.note.list.NotesListActivity;
import app.notesr.service.AndroidServiceRegistry;
import app.notesr.service.migration.AppMigrationAndroidService;
import app.notesr.service.migration.AppMigrationAndroidServiceStarter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,42 @@
* SPDX-License-Identifier: MIT
*/

package app.notesr.activity.note;
package app.notesr.activity.note.editor;

import static java.util.concurrent.Executors.newSingleThreadExecutor;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.MenuItem;

import androidx.annotation.NonNull;

import java.io.IOException;

import app.notesr.R;
import app.notesr.activity.ActivityBase;
import app.notesr.activity.DialogFactory;
import app.notesr.activity.note.list.NotesListActivity;
import app.notesr.data.model.Note;
import app.notesr.service.file.FileService;
import app.notesr.service.note.NoteService;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public final class DeleteNoteOnClick implements MenuItem.OnMenuItemClickListener {
final class DeleteNoteAction {

private final ActivityBase activity;
private final Note note;
private final NoteService noteService;
private final FileService fileService;
private final DialogFactory dialogFactory;

@Override
public boolean onMenuItemClick(@NonNull MenuItem item) {
void execute() {
DialogInterface.OnClickListener buttonHandler = deleteNoteDialogOnClick();
dialogFactory.getThemedAlertDialogBuilder(R.layout.dialog_action_cannot_be_undo)
.setTitle(R.string.warning)
.setPositiveButton(R.string.delete_caps, buttonHandler)
.setNegativeButton(R.string.no, buttonHandler)
.create()
.show();

return true;
}

private DialogInterface.OnClickListener deleteNoteDialogOnClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,22 @@
* SPDX-License-Identifier: MIT
*/

package app.notesr.activity.note;
package app.notesr.activity.note.editor;

import android.content.Intent;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;

import app.notesr.activity.ActivityBase;
import app.notesr.activity.file.FilesListActivity;
import app.notesr.data.model.Note;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public final class OpenFilesListOnClick implements MenuItem.OnMenuItemClickListener, View.OnClickListener {
final class OpenFilesListAction {

private final ActivityBase activity;
private final Note note;

@Override
public boolean onMenuItemClick(@NonNull MenuItem item) {
onClickAction();
return true;
}

@Override
public void onClick(View v) {
onClickAction();
}

private void onClickAction() {
void execute() {
Intent intent = new Intent(activity.getApplicationContext(), FilesListActivity.class);

intent.putExtra(FilesListActivity.EXTRA_NOTE_ID, note.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: MIT
*/

package app.notesr.activity.note;
package app.notesr.activity.note.editor;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
Expand All @@ -25,6 +26,7 @@
import app.notesr.R;
import app.notesr.activity.ActivityBase;
import app.notesr.activity.DialogFactory;
import app.notesr.activity.note.list.NotesListActivity;
import app.notesr.data.AppDatabase;
import app.notesr.data.DatabaseProvider;
import app.notesr.service.file.FileService;
Expand All @@ -48,23 +50,27 @@
public final class OpenNoteActivity extends ActivityBase {
public static final String EXTRA_NOTE_ID = "noteId";
public static final String EXTRA_NOTE_MODIFIED = "modified";
private static final String STATE_OPEN_MODE = "openMode";
private static final long MAX_COUNT_IN_BADGE = 9;

private NoteService noteService;
private FileService fileService;
private Note note;
private ActionBar actionBar;
private Menu activityMenu;
private Menu menu;
private DialogFactory dialogFactory;
private boolean isNoteModified;
private EditText nameField;
private EditText textField;
private TextView markdownViewer;
private ScrollView markdownViewerContainer;
private Markwon markwon;
private static final String STATE_OPEN_MODE = "openMode";
private SaveNoteAction saveNoteAction;
private OpenFilesListAction openFilesListAction;
private DeleteNoteAction deleteNoteAction;
private boolean isNoteModified;
private OpenNoteMode openMode = OpenNoteMode.EDIT;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -140,6 +146,13 @@ private void prepareViews() {
markdownViewer = findViewById(R.id.markdownViewer);
markdownViewerContainer = findViewById(R.id.markdownViewerContainer);

saveNoteAction = new SaveNoteAction(this, note, noteService, dialogFactory,
nameField, textField);
openFilesListAction = new OpenFilesListAction(this, note);
deleteNoteAction = new DeleteNoteAction(this, note, noteService, fileService,
dialogFactory);


nameField.setImeOptions(IME_FLAG_NO_PERSONALIZED_LEARNING);
textField.setImeOptions(IME_FLAG_NO_PERSONALIZED_LEARNING);

Expand All @@ -150,7 +163,7 @@ private void prepareViews() {
if (!isNoteModified) {
isNoteModified = true;

MenuItem saveNoteButton = activityMenu.findItem(R.id.saveNoteButton);
MenuItem saveNoteButton = menu.findItem(R.id.saveNoteButton);
saveNoteButton.setVisible(true);
}

Expand All @@ -169,7 +182,7 @@ private boolean isNewNote() {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_open_note, menu);
this.activityMenu = menu;
this.menu = menu;

MenuItem changeModeButton = menu.findItem(R.id.changeOpenModeButton);
MenuItem saveNoteButton = menu.findItem(R.id.saveNoteButton);
Expand All @@ -181,15 +194,21 @@ public boolean onCreateOptionsMenu(Menu menu) {
return true;
});

saveNoteButton.setOnMenuItemClickListener(new SaveNoteOnClick(this, note,
noteService, dialogFactory, nameField, textField));
saveNoteButton.setOnMenuItemClickListener((item) -> {
saveNoteAction.execute();
return true;
});

if (!isNewNote()) {
openFilesListButton.setOnMenuItemClickListener(
new OpenFilesListOnClick(this, note));
openFilesListButton.setOnMenuItemClickListener(item -> {
openFilesListAction.execute();
return true;
});

deleteNoteButton.setOnMenuItemClickListener(new DeleteNoteOnClick(this, note,
noteService, fileService, dialogFactory));
deleteNoteButton.setOnMenuItemClickListener(item -> {
deleteNoteAction.execute();
return true;
});

setAttachedFilesCountBadge(openFilesListButton);
} else {
Expand Down Expand Up @@ -221,30 +240,55 @@ private void setAttachedFilesCountBadge(MenuItem openFilesListButton) {

badge.setText(badgeText);
badge.setVisibility(View.VISIBLE);
view.setOnClickListener(new OpenFilesListOnClick(this, note));
view.setOnClickListener(v -> openFilesListAction.execute());
}
});
});

}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == android.R.id.home) {
if (isNoteModified) {
Intent intent = new Intent(getApplicationContext(), NotesListActivity.class);
startActivity(intent);
} else {
finish();
}
backButtonOnClick();
return true;
}

return super.onOptionsItemSelected(item);
}

private void backButtonOnClick() {
if (isNoteModified) {
if (!saveNoteAction.isFormCorrect()) {
finish();
return;
}

DialogInterface.OnClickListener buttonHandler = (dialog, result) -> {
if (result == DialogInterface.BUTTON_POSITIVE) {
saveNoteAction.execute();
Intent intent = new Intent(getApplicationContext(), NotesListActivity.class);
startActivity(intent);
} else if (result == DialogInterface.BUTTON_NEUTRAL) {
finish();
}
};

dialogFactory.getThemedAlertDialogBuilder(R.layout.dialog_unsaved_note_changes)
.setTitle(R.string.warning)
.setPositiveButton(R.string.save, buttonHandler)
.setNeutralButton(R.string.dont_save, buttonHandler)
.setNegativeButton(R.string.cancel, null)
.create()
.show();
} else {
finish();
}
}

private void changeOpenModeButtonOnClick() {
View anchor = findViewById(R.id.popupMenuAnchor);
PopupMenu popup = new PopupMenu(this, anchor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: MIT
*/

package app.notesr.activity.note;
package app.notesr.activity.note.editor;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@
* SPDX-License-Identifier: MIT
*/

package app.notesr.activity.note;
package app.notesr.activity.note.editor;

import static java.util.concurrent.Executors.newSingleThreadExecutor;

import android.app.Dialog;
import android.content.Intent;
import android.view.MenuItem;
import android.widget.EditText;

import androidx.annotation.NonNull;

import java.time.LocalDateTime;

import app.notesr.R;
import app.notesr.activity.ActivityBase;
import app.notesr.activity.DialogFactory;
import app.notesr.activity.note.list.NotesListActivity;
import app.notesr.data.model.Note;
import app.notesr.service.note.NoteService;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public final class SaveNoteOnClick implements MenuItem.OnMenuItemClickListener {
final class SaveNoteAction {

private final ActivityBase activity;
private final Note note;
Expand All @@ -33,14 +31,15 @@ public final class SaveNoteOnClick implements MenuItem.OnMenuItemClickListener {
private final EditText nameField;
private final EditText textField;

@Override
public boolean onMenuItemClick(@NonNull MenuItem item) {
String name = nameField.getText().toString();
String text = textField.getText().toString();
boolean isFormCorrect() {
return !nameField.getText().toString().isBlank()
&& !textField.getText().toString().isBlank();
}

if (!name.isBlank() && !text.isBlank()) {
note.setName(name);
note.setText(text);
void execute() {
if (isFormCorrect()) {
note.setName(nameField.getText().toString());
note.setText(textField.getText().toString());
note.setUpdatedAt(LocalDateTime.now());

Dialog progressDialog = dialogFactory
Expand All @@ -56,7 +55,5 @@ public boolean onMenuItemClick(@NonNull MenuItem item) {
});
});
}

return true;
}
}
Loading
Loading