Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c4f6f20 authored by Stefan Niedermann's avatar Stefan Niedermann Committed by Niedermann IT-Dienstleistungen
Browse files

#227 Remember last scrolling position per note

parent 6ef22884
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -64,8 +64,10 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
    private SingleSignOnAccount ssoAccount;

    protected DBNote note;
    // TODO do we really need this? The reference to note is currently the same
    @Nullable
    private DBNote originalNote;
    private int originalScrollY;
    protected NotesDatabase db;
    private NoteFragmentListener listener;

@@ -134,7 +136,8 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
        super.onActivityCreated(savedInstanceState);
        final ScrollView scrollView = getScrollView();
        if (scrollView != null) {
            scrollView.post(() -> scrollView.scrollTo(0, note.getScrollY()));
            this.originalScrollY = note.getScrollY();
            scrollView.post(() -> scrollView.scrollTo(0, originalScrollY));
        }
    }

@@ -287,7 +290,12 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
        if (note != null) {
            String newContent = getContent();
            if (note.getContent().equals(newContent)) {
                if (note.getScrollY() != originalScrollY) {
                    Log.v(TAG, "... only saving new scroll state, since content did not change");
                    db.updateScrollY(note.getId(), note.getScrollY());
                } else {
                    Log.v(TAG, "... not saving, since nothing has changed");
                }
            } else {
                note = db.updateNoteAndSync(ssoAccount, localAccount.getId(), note, newContent, callback);
                listener.onNoteUpdated(note);
+2 −1
Original line number Diff line number Diff line
@@ -540,10 +540,11 @@ public class NotesDatabase extends AbstractNotesDatabase {
    }

    public void updateScrollY(long noteId, int scrollY) {
        Log.e(TAG, "Updated scrollY: " + scrollY);
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues(1);
        values.put(key_scroll_y, scrollY);
        db.update(table_notes, values, key_id + " = ? ", new String[]{String.valueOf(scrollY)});
        db.update(table_notes, values, key_id + " = ? ", new String[]{String.valueOf(noteId)});
    }

    /**