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

Unverified Commit 08115c57 authored by Andy Scherzinger's avatar Andy Scherzinger Committed by GitHub
Browse files

Merge pull request #2739 from nextcloud/backport/2736/stable-4.4

[stable-4.4] BaseNoteFragment NPE Checks
parents da759084 798b7f80
Loading
Loading
Loading
Loading
+35 −11
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import androidx.core.graphics.drawable.IconCompat;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.owncloud.android.lib.common.utils.Log_OC;

import java.util.ArrayList;
import java.util.Calendar;
@@ -141,7 +142,7 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
                    requireActivity().invalidateOptionsMenu();
                }
            } catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
                e.printStackTrace();
               Log_OC.e(TAG, e.getLocalizedMessage());
            }
        });
        setHasOptionsMenu(true);
@@ -240,16 +241,26 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
                    repo.updateNoteAndSync(localAccount, originalNote, null, null, null);
                }
            });

            if (listener != null) {
                listener.close();
            }
            return true;
        } else if (itemId == R.id.menu_delete) {
            repo.deleteNoteAndSync(localAccount, note.getId());

            if (listener != null) {
                listener.close();
            }
            return true;
        } else if (itemId == R.id.menu_favorite) {
            note.setFavorite(!note.getFavorite());
            repo.toggleFavoriteAndSync(localAccount, note);

            if (listener != null) {
                listener.onNoteUpdated(note);
            }

            prepareFavoriteOption(item);
            return true;
        } else if (itemId == R.id.menu_category) {
@@ -288,15 +299,29 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
    }

    protected void shareNote() {
        if (note == null) {
            Log_OC.w(TAG, "Note is null in shareNote");
            return;
        }

        ShareUtil.openShareDialog(requireContext(), note.getTitle(), note.getContent());
    }

    @CallSuper
    protected void onNoteLoaded(Note note) {
        if (note == null) {
            Log_OC.w(TAG, "Note is null in onNoteLoaded");
            return;
        }

        this.originalScrollY = note.getScrollY();
        scrollToY(originalScrollY);
        final var scrollView = getScrollView();
        if (scrollView != null) {
        if (scrollView == null) {
            Log_OC.w(TAG, "Scroll view is null, onNoteLoaded");
            return;
        }

        scrollView.setOnScrollChangeListener((View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) -> {
            if (scrollY > 0) {
                note.setScrollY(scrollY);
@@ -304,7 +329,6 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
            onScroll(scrollY, oldScrollY);
        });
    }
    }

    /**
     * Scroll callback, to be overridden by subclasses. Default implementation is empty
+6 −1
Original line number Diff line number Diff line
@@ -148,8 +148,13 @@ class NoteDirectEditFragment : BaseNoteFragment(), Branded {
        disposables.add(timeoutDisposable)
    }

    override fun onNoteLoaded(note: Note) {
    override fun onNoteLoaded(note: Note?) {
        super.onNoteLoaded(note)
        if (note == null) {
            Log_OC.w(TAG, "Note is null, onNoteLoaded")
            return
        }

        Log.d(TAG, "onNoteLoaded() called")
        val newNoteParam = arguments?.getSerializable(PARAM_NEWNOTE) as Note?
        if (newNoteParam != null || note.remoteId == null) {
+3 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import androidx.preference.PreferenceManager;

import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.owncloud.android.lib.common.utils.Log_OC;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
@@ -182,7 +183,8 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
    @Override
    protected void onNoteLoaded(Note note) {
        super.onNoteLoaded(note);
        if (binding == null) {
        if (binding == null || note == null) {
            Log_OC.w(TAG, "Note is null, onNoteLoaded");
            return;
        }

+5 −0
Original line number Diff line number Diff line
@@ -137,6 +137,11 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
    @Override
    protected void onNoteLoaded(Note note) {
        super.onNoteLoaded(note);
        if (note == null) {
            Log_OC.w(TAG, "Note is null, onNoteLoaded");
            return;
        }

        noteLoaded = true;
        registerInternalNoteLinkHandler();