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

Commit 6d2b74fe authored by alperozturk's avatar alperozturk Committed by backportbot[bot]
Browse files

npe checks

parent da759084
Loading
Loading
Loading
Loading
+35 −11
Original line number Original line 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.NextcloudFilesAppAccountNotFoundException;
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.owncloud.android.lib.common.utils.Log_OC;


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

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

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

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

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


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

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


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

        this.originalScrollY = note.getScrollY();
        this.originalScrollY = note.getScrollY();
        scrollToY(originalScrollY);
        scrollToY(originalScrollY);
        final var scrollView = getScrollView();
        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) -> {
        scrollView.setOnScrollChangeListener((View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) -> {
            if (scrollY > 0) {
            if (scrollY > 0) {
                note.setScrollY(scrollY);
                note.setScrollY(scrollY);
@@ -304,7 +329,6 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
            onScroll(scrollY, oldScrollY);
            onScroll(scrollY, oldScrollY);
        });
        });
    }
    }
    }


    /**
    /**
     * Scroll callback, to be overridden by subclasses. Default implementation is empty
     * Scroll callback, to be overridden by subclasses. Default implementation is empty