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

Commit b3ace463 authored by Christoph Loy's avatar Christoph Loy Committed by Niedermann IT-Dienstleistungen
Browse files

Remove Butterknife from NoteReadonlyFragment

parent ba3cfe51
Loading
Loading
Loading
Loading
+20 −36
Original line number Original line Diff line number Diff line
@@ -21,17 +21,14 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.core.view.ViewCompat;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;


import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.yydcdut.markdown.MarkdownProcessor;
import com.yydcdut.markdown.MarkdownProcessor;
import com.yydcdut.markdown.MarkdownTextView;
import com.yydcdut.markdown.syntax.text.TextFactory;
import com.yydcdut.markdown.syntax.text.TextFactory;


import butterknife.BindView;
import butterknife.ButterKnife;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.android.activity.EditNoteActivity;
import it.niedermann.owncloud.notes.android.activity.EditNoteActivity;
import it.niedermann.owncloud.notes.databinding.FragmentNotePreviewBinding;
import it.niedermann.owncloud.notes.model.ISyncCallback;
import it.niedermann.owncloud.notes.model.ISyncCallback;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
import it.niedermann.owncloud.notes.util.DisplayUtils;
import it.niedermann.owncloud.notes.util.DisplayUtils;
@@ -42,20 +39,7 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment {


    private MarkdownProcessor markdownProcessor;
    private MarkdownProcessor markdownProcessor;


    @BindView(R.id.swiperefreshlayout)
    private FragmentNotePreviewBinding binding;
    SwipeRefreshLayout swipeRefreshLayout;

    @BindView(R.id.scrollView)
    ScrollView scrollView;

    @BindView(R.id.searchNext)
    FloatingActionButton searchNext;

    @BindView(R.id.searchPrev)
    FloatingActionButton searchPrev;

    @BindView(R.id.single_note_content)
    MarkdownTextView noteContent;


    public static NoteReadonlyFragment newInstance(String content) {
    public static NoteReadonlyFragment newInstance(String content) {
        NoteReadonlyFragment f = new NoteReadonlyFragment();
        NoteReadonlyFragment f = new NoteReadonlyFragment();
@@ -82,40 +66,40 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment {


    @Override
    @Override
    public ScrollView getScrollView() {
    public ScrollView getScrollView() {
        return scrollView;
        return binding.scrollView;
    }
    }


    @Override
    @Override
    protected FloatingActionButton getSearchNextButton() {
    protected FloatingActionButton getSearchNextButton() {
        return searchNext;
        return binding.searchNext;
    }
    }


    @Override
    @Override
    protected FloatingActionButton getSearchPrevButton() {
    protected FloatingActionButton getSearchPrevButton() {
        return searchPrev;
        return binding.searchPrev;
    }
    }


    @Override
    @Override
    protected Layout getLayout() {
    protected Layout getLayout() {
        noteContent.onPreDraw();
        binding.singleNoteContent.onPreDraw();
        return noteContent.getLayout();
        return binding.singleNoteContent.getLayout();
    }
    }


    @Nullable
    @Nullable
    @Override
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
            container, @Nullable Bundle savedInstanceState) {
            container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_note_preview, container, false);
        binding = FragmentNotePreviewBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }
    }


    @Override
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        super.onActivityCreated(savedInstanceState);
        ButterKnife.bind(this, requireView());
        markdownProcessor = new MarkdownProcessor(requireActivity());
        markdownProcessor = new MarkdownProcessor(requireActivity());
        markdownProcessor.factory(TextFactory.create());
        markdownProcessor.factory(TextFactory.create());
        markdownProcessor.config(
        markdownProcessor.config(
                MarkDownUtil.getMarkDownConfiguration(noteContent.getContext())
                MarkDownUtil.getMarkDownConfiguration(binding.singleNoteContent.getContext())
                        .setOnLinkClickCallback((view, link) -> {
                        .setOnLinkClickCallback((view, link) -> {
                            if (NoteLinksUtils.isNoteLink(link)) {
                            if (NoteLinksUtils.isNoteLink(link)) {
                                long noteRemoteId = NoteLinksUtils.extractNoteRemoteId(link);
                                long noteRemoteId = NoteLinksUtils.extractNoteRemoteId(link);
@@ -130,22 +114,22 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment {
                        })
                        })
                        .build());
                        .build());
        try {
        try {
            noteContent.setText(markdownProcessor.parse(note.getContent()));
            binding.singleNoteContent.setText(markdownProcessor.parse(note.getContent()));
            onResume();
            onResume();
        } catch (StringIndexOutOfBoundsException e) {
        } catch (StringIndexOutOfBoundsException e) {
            // Workaround for RxMarkdown: https://github.com/stefan-niedermann/nextcloud-notes/issues/668
            // Workaround for RxMarkdown: https://github.com/stefan-niedermann/nextcloud-notes/issues/668
            Toast.makeText(noteContent.getContext(), R.string.could_not_load_preview_two_digit_numbered_list, Toast.LENGTH_LONG).show();
            Toast.makeText(binding.singleNoteContent.getContext(), R.string.could_not_load_preview_two_digit_numbered_list, Toast.LENGTH_LONG).show();
            e.printStackTrace();
            e.printStackTrace();
        }
        }
        noteContent.setMovementMethod(LinkMovementMethod.getInstance());
        binding.singleNoteContent.setMovementMethod(LinkMovementMethod.getInstance());


        db = NoteSQLiteOpenHelper.getInstance(getActivity());
        db = NoteSQLiteOpenHelper.getInstance(getActivity());
        swipeRefreshLayout.setEnabled(false);
        binding.swiperefreshlayout.setEnabled(false);


        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireActivity().getApplicationContext());
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireActivity().getApplicationContext());
        noteContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(sp));
        binding.singleNoteContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(sp));
        if (sp.getBoolean(getString(R.string.pref_key_font), false)) {
        if (sp.getBoolean(getString(R.string.pref_key_font), false)) {
            noteContent.setTypeface(Typeface.MONOSPACE);
            binding.singleNoteContent.setTypeface(Typeface.MONOSPACE);
        }
        }
    }
    }


@@ -161,8 +145,8 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment {


    @Override
    @Override
    protected void colorWithText(String newText) {
    protected void colorWithText(String newText) {
        if (noteContent != null && ViewCompat.isAttachedToWindow(noteContent)) {
        if (binding != null && ViewCompat.isAttachedToWindow(binding.singleNoteContent)) {
            noteContent.setText(markdownProcessor.parse(DisplayUtils.searchAndColor(getContent(), new SpannableString
            binding.singleNoteContent.setText(markdownProcessor.parse(DisplayUtils.searchAndColor(getContent(), new SpannableString
                            (getContent()), newText, getResources().getColor(R.color.primary))),
                            (getContent()), newText, getResources().getColor(R.color.primary))),
                    TextView.BufferType.SPANNABLE);
                    TextView.BufferType.SPANNABLE);
        }
        }