Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/edit/details/NoteDetailsViewModel.java')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/edit/details/NoteDetailsViewModel.java43
1 files changed, 32 insertions, 11 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/details/NoteDetailsViewModel.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/details/NoteDetailsViewModel.java
index 5306bf0d..028ff0fd 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/edit/details/NoteDetailsViewModel.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/details/NoteDetailsViewModel.java
@@ -8,37 +8,58 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.SavedStateHandle;
+import java.time.Instant;
+import java.util.Calendar;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import it.niedermann.owncloud.notes.persistence.NotesRepository;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.Note;
+import it.niedermann.owncloud.notes.shared.model.IResponseCallback;
public class NoteDetailsViewModel extends AndroidViewModel {
- private static final String TAG = NoteDetailsViewModel.class.getSimpleName();
-
private final ExecutorService executor = Executors.newCachedThreadPool();
- private final SavedStateHandle state;
-
@NonNull
private final NotesRepository repo;
-
- public NoteDetailsViewModel(@NonNull Application application, @NonNull SavedStateHandle savedStateHandle) {
+ public NoteDetailsViewModel(@NonNull Application application) {
super(application);
this.repo = NotesRepository.getInstance(application);
- this.state = savedStateHandle;
}
- public LiveData<Note> getNote$(long noteId) {
- return repo.getNoteById$(noteId);
+ public void getNoteById(long noteId, @NonNull IResponseCallback<Note> callback) {
+ executor.submit(() -> callback.onSuccess(repo.getNoteById(noteId)));
+ }
+
+ public LiveData<String> getTitle$(long noteId) {
+ return repo.getTitle$(noteId);
+ }
+
+ public LiveData<Calendar> getModified$(long noteId) {
+ return repo.getModified$(noteId);
+ }
+
+ public LiveData<String> getCategory$(long noteId) {
+ return repo.getCategory$(noteId);
+ }
+
+ public LiveData<Boolean> isFavorite$(long noteId) {
+ return repo.isFavorite$(noteId);
}
@AnyThread
- public void toggleFavorite(long noteId) {
- repo.toggleFavorite(noteId);
+ public void toggleFavorite(@NonNull Account account, long noteId) {
+ repo.toggleFavoriteAndSync(account, noteId);
+ }
+
+ public void commit(@NonNull Account account, long noteId, String title, String category) {
+ executor.submit(() -> {
+ final Note note = repo.getNoteById(noteId);
+ note.setCategory(category);
+ repo.updateNoteAndSync(account, note, note.getContent(), title, null);
+ });
}
} \ No newline at end of file