Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
private static final int delay = 50; // If the search string does not change after $delay ms, then the search task starts.
private static final int shortStringDelay = 200; // A longer delay for short search strings.
private static final int shortStringSize = 3; // The maximum length of a short search string.
private boolean directEditRemotelyAvailable = false; // avoid using this directly, instead use: isDirectEditEnabled()
private boolean directEditEnabled = false;

@ColorInt
private int color;
Expand All @@ -75,20 +75,23 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
@Override
protected void onScroll(int scrollY, int oldScrollY) {
super.onScroll(scrollY, oldScrollY);
if (isDirectEditEnabled()) {
// only show FAB if search is not active
if (getSearchNextButton() == null || getSearchNextButton().getVisibility() != View.VISIBLE) {
final ExtendedFloatingActionButton directFab = getDirectEditingButton();
// only show FAB if search is not active
if (getSearchNextButton() == null || getSearchNextButton().getVisibility() != View.VISIBLE) {
final ExtendedFloatingActionButton directFab = getDirectEditingButton();
final ExtendedFloatingActionButton normalFab = getNormalEditButton();
if (directEditEnabled) {
ExtendedFabUtil.toggleVisibilityOnScroll(directFab, scrollY, oldScrollY);
} else if (normalFab != null) {
ExtendedFabUtil.toggleVisibilityOnScroll(normalFab, scrollY, oldScrollY);
}
}
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
checkDirectEditingAvailable();
if (isDirectEditEnabled()) {
directEditEnabled = checkDirectEditingAvailableAndEnabled();
if (directEditEnabled) {
ExtendedFloatingActionButton edit = getNormalEditButton();
if (edit != null) edit.setVisibility(View.GONE);
final ExtendedFloatingActionButton directEditingButton = getDirectEditingButton();
Expand All @@ -103,7 +106,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
} else {
getDirectEditingButton().setVisibility(View.GONE);
ExtendedFloatingActionButton edit = getNormalEditButton();
if(edit!=null) {
if (edit != null) {
edit.setExtended(false);
edit.setVisibility(View.VISIBLE);
edit.setOnClickListener(v -> {
if (listener != null) {
Expand All @@ -114,21 +118,18 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}
}

private void checkDirectEditingAvailable() {
private boolean checkDirectEditingAvailableAndEnabled() {
// Check availability
try {
final SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireContext());
final Account localAccount = repo.getAccountByName(ssoAccount.name);
directEditRemotelyAvailable = localAccount != null && localAccount.isDirectEditingAvailable();
if (localAccount == null || !localAccount.isDirectEditingAvailable())
return false;
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
Log.w(TAG, "checkDirectEditingAvailable: ", e);
directEditRemotelyAvailable = false;
}
}

protected boolean isDirectEditEnabled() {
if (!directEditRemotelyAvailable) {
return false;
}
// Check if enabled in settings
final var sp = PreferenceManager.getDefaultSharedPreferences(requireContext().getApplicationContext());
return sp.getBoolean(getString(R.string.pref_key_enable_direct_edit), true);
}
Expand Down Expand Up @@ -285,6 +286,10 @@ public void onSaveInstanceState(@NonNull Bundle outState) {

private void showSearchFabs() {
ExtendedFabUtil.setExtendedFabVisibility(getDirectEditingButton(), false);
final ExtendedFloatingActionButton normalFab = getNormalEditButton();
if (normalFab != null) {
ExtendedFabUtil.setExtendedFabVisibility(normalFab, false);
}
final var next = getSearchNextButton();
final var prev = getSearchPrevButton();
if (prev != null) {
Expand All @@ -304,6 +309,14 @@ private void hideSearchFabs() {
if (next != null) {
next.hide();
}
if (directEditEnabled) {
ExtendedFabUtil.setExtendedFabVisibility(getDirectEditingButton(), true);
} else {
final ExtendedFloatingActionButton normalFab = getNormalEditButton();
if (normalFab != null) {
ExtendedFabUtil.setExtendedFabVisibility(normalFab, true);
}
}
}

private void jumpToOccurrence() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_note_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@
android:visibility="visible"
app:backgroundTint="@color/defaultBrand"
app:icon="@drawable/ic_edit_grey600_24dp"
app:layout_anchor="@+id/direct_editing"
app:layout_anchorGravity="center" />
app:layout_anchor="@id/scrollView"
app:layout_anchorGravity="bottom|end" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading