Skip to content

Commit

Permalink
Cleanups and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed May 23, 2024
1 parent b676364 commit fcb98de
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,6 @@ public static void showHeadlineDialog(
final int index = filtered.get(result.get(0));
TextViewUtils.selectLines(edit, headings.get(index).line);

// Scroll to the heading in webview
// This needs improvement - does not handle duplicated headers etc
final String header = headings.get(index).str;
final String headerText = header.substring(header.lastIndexOf('#') + 1).trim();
final String id = MarkdownTextConverter.generateHeaderId(headerText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public class GsFileBrowserListAdapter extends RecyclerView.Adapter<GsFileBrowser
private final SharedPreferences _prefApp;
private final HashMap<File, File> _virtualMapping = new HashMap<>();
private final Map<File, Integer> _fileIdMap = new HashMap<>();
private GsCallback.a0 _blinkCallback;

//########################
//## Methods
Expand Down Expand Up @@ -194,7 +193,6 @@ public void onBindViewHolder(@NonNull FilesystemViewerViewHolder holder, int pos
}

holder.itemRoot.setContentDescription((descriptionRes != 0 ? (_context.getString(descriptionRes) + " ") : "") + holder.title.getText().toString() + " " + holder.description.getText().toString());
// holder.itemRoot.setBackgroundColor(ContextCompat.getColor(_context, isSelected ? _dopt.primaryColor : _dopt.backgroundColor));
holder.image.setOnLongClickListener(view -> {
Toast.makeText(_context, file.getAbsolutePath(), Toast.LENGTH_SHORT).show();
return true;
Expand Down Expand Up @@ -549,8 +547,9 @@ public void doAfterChange(final GsCallback.a0 callback) {
@Override
public void onChanged() {
super.onChanged();
// Ignore if the load takes too long
if ((System.currentTimeMillis() - init) < 2000) {
_recyclerView.postDelayed(callback::callback, 250);
_recyclerView.post(callback::callback);
}
unregisterAdapterDataObserver(this);
}
Expand Down Expand Up @@ -597,9 +596,9 @@ private void showAndFlash(final File file) {
_recyclerView.postDelayed(() -> {
final RecyclerView.ViewHolder holder = _recyclerView.findViewHolderForLayoutPosition(pos);
if (holder != null) {
_blinkCallback = GsContextUtils.blinkView(holder.itemView);
GsContextUtils.blinkView(holder.itemView);
}
}, 250);
}, 100);
}
}

Expand All @@ -620,9 +619,10 @@ public int getFilePosition(final File file) {

// Stop blinking if we are currently blinking
private void stopBlinking() {
if (_blinkCallback != null) {
_blinkCallback.callback();
_blinkCallback = null;
if (_recyclerView != null) {
for (int i = 0; i < _recyclerView.getChildCount(); i++) {
GsContextUtils.stopBlinking(_recyclerView.getChildAt(i));
}
}
}

Expand Down
40 changes: 26 additions & 14 deletions app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ protected <T extends GsContextUtils> T thisp() {
public final static int REQUEST_STORAGE_PERMISSION_M = 50004;
public final static int REQUEST_STORAGE_PERMISSION_R = 50005;
public final static int REQUEST_RECORD_AUDIO = 50006;
private final static int BLINK_ANIMATOR_TAG = -1206813720;

public static int TEXTFILE_OVERWRITE_MIN_TEXT_LENGTH = 2;
protected static Pair<File, List<Pair<String, String>>> m_cacheLastExtractFileMetadata;
Expand Down Expand Up @@ -2884,35 +2885,46 @@ public boolean isDarkModeEnabled(final Context context) {
* Blinks the view passed in as parameter
*
* @param view View to be blinked
* @return A callback to terminate the blinking
*/
public static @Nullable GsCallback.a0 blinkView(final View view) {
public static void blinkView(final View view) {

if (view == null) {
return null;
return;
}

final ObjectAnimator animator = ObjectAnimator.ofFloat(
view, View.ALPHA, 1.0f, 0.1f, 1.0f, 0.1f, 1.0f)
.setDuration(800);
view, View.ALPHA, 0.1f, 1.0f, 0.1f, 1.0f)
.setDuration(500);

view.setTag(BLINK_ANIMATOR_TAG, new WeakReference<>(animator));

animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setAlpha(1.0f);
view.setTag(BLINK_ANIMATOR_TAG, null);
}
});

final WeakReference<ObjectAnimator> animatorRef = new WeakReference<>(animator);
final GsCallback.a0 terminateCallback = () -> {
final ObjectAnimator a = animatorRef.get();
if (a != null) {
a.cancel();
}
};

animator.start();
}

public static void stopBlinking(final View view) {
if (view == null) {
return;
}

final Object tagRef = view.getTag(BLINK_ANIMATOR_TAG);
if (tagRef instanceof WeakReference) {
final Object tag = ((WeakReference<?>) tagRef).get();
if (tag instanceof ObjectAnimator) {
final ObjectAnimator anim = ((ObjectAnimator) tag);
if (anim.isRunning()) {
anim.cancel();
}
}
}

return terminateCallback;
}

public static boolean fadeInOut(final View in, final View out, final boolean animate) {
Expand Down

0 comments on commit fcb98de

Please sign in to comment.