Skip to content

Commit

Permalink
Pull to close down with effect
Browse files Browse the repository at this point in the history
  • Loading branch information
M66B committed Jul 21, 2020
1 parent e5c3d54 commit eb3420a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
1 change: 1 addition & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ FairEmail uses:
* [File Icon Images](https://github.com/dmhendricks/file-icon-vectors). A collection of file type/extension SVG icons, available free for use in your applications. [MIT License](https://github.com/dmhendricks/file-icon-vectors/blob/master/LICENSE).
* [GPX file type icon](https://www.flaticon.com/free-icon/gpx-file-format-variant_29258) made by [Freepik](https://www.flaticon.com/authors/freepik) from [Flaticon](https://www.flaticon.com).
* [Disconnect's tracker protection lists](https://github.com/disconnectme/disconnect-tracking-protection). Copyright 2010-2020 Disconnect, Inc. [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license](https://github.com/disconnectme/disconnect-tracking-protection/blob/master/LICENSE).
* [Over-Scroll Support For Android's RecyclerView, ListView, GridView, ScrollView ...](https://github.com/EverythingMe/overscroll-decor). Copyright (c) 2015, DoAT Media Ltd. [BSD-2-Clause License](https://github.com/EverythingMe/overscroll-decor/blob/master/LICENSE)
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ dependencies {
def markwon_version = "4.4.0"
def bouncycastle_version = "1.66"
def colorpicker_version = "0.0.15"
def overscroll_version = "1.1.0"
def appauth_version = "0.7.1"
def jcharset_version = "2.1"

Expand Down Expand Up @@ -383,6 +384,10 @@ dependencies {
// // https://github.com/QuadFlask/colorpicker
implementation "com.github.QuadFlask:colorpicker:$colorpicker_version"

// https://github.com/EverythingMe/overscroll-decor
// https://mvnrepository.com/artifact/me.everything/overscroll-decor-android?repo=jcenter
implementation "me.everything:overscroll-decor-android:$overscroll_version"

// https://www.bouncycastle.org/latest_releases.html
// https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on
implementation "org.bouncycastle:bcpkix-jdk15to18:$bouncycastle_version"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/assets/ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ FairEmail uses:
* [File Icon Images](https://github.com/dmhendricks/file-icon-vectors). A collection of file type/extension SVG icons, available free for use in your applications. [MIT License](https://github.com/dmhendricks/file-icon-vectors/blob/master/LICENSE).
* [GPX file type icon](https://www.flaticon.com/free-icon/gpx-file-format-variant_29258) made by [Freepik](https://www.flaticon.com/authors/freepik) from [Flaticon](https://www.flaticon.com).
* [Disconnect's tracker protection lists](https://github.com/disconnectme/disconnect-tracking-protection). Copyright 2010-2020 Disconnect, Inc. [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license](https://github.com/disconnectme/disconnect-tracking-protection/blob/master/LICENSE).
* [Over-Scroll Support For Android's RecyclerView, ListView, GridView, ScrollView ...](https://github.com/EverythingMe/overscroll-decor). Copyright (c) 2015, DoAT Media Ltd. [BSD-2-Clause License](https://github.com/EverythingMe/overscroll-decor/blob/master/LICENSE)
49 changes: 32 additions & 17 deletions app/src/main/java/eu/faircode/email/FragmentMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import android.view.MotionEvent;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
Expand Down Expand Up @@ -206,6 +205,11 @@
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import me.everything.android.ui.overscroll.IOverScrollDecor;
import me.everything.android.ui.overscroll.IOverScrollUpdateListener;
import me.everything.android.ui.overscroll.VerticalOverScrollBounceEffectDecorator;
import me.everything.android.ui.overscroll.adapters.RecyclerViewOverScrollDecorAdapter;

import static android.app.Activity.RESULT_OK;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
import static android.text.format.DateUtils.DAY_IN_MILLIS;
Expand All @@ -214,6 +218,9 @@
import static android.view.KeyEvent.ACTION_DOWN;
import static android.view.KeyEvent.ACTION_UP;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import static me.everything.android.ui.overscroll.OverScrollBounceEffectDecoratorBase.DEFAULT_DECELERATE_FACTOR;
import static me.everything.android.ui.overscroll.OverScrollBounceEffectDecoratorBase.DEFAULT_TOUCH_DRAG_MOVE_RATIO_BCK;
import static me.everything.android.ui.overscroll.OverScrollBounceEffectDecoratorBase.DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_KEY_MISSING;
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_NO_SIGNATURE;
import static org.openintents.openpgp.OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED;
Expand Down Expand Up @@ -505,9 +512,6 @@ public void onClick(View v) {
//rvMessage.setItemViewCacheSize(10);
//rvMessage.getRecycledViewPool().setMaxRecycledViews(0, 10);

final int minOverscroll = Helper.dp2pixels(getContext(),
ViewConfiguration.get(getContext()).getScaledPagingTouchSlop());

final LinearLayoutManager llm = new LinearLayoutManager(getContext()) {
private Rect parentRect = new Rect();
private Rect childRect = new Rect();
Expand Down Expand Up @@ -583,19 +587,6 @@ public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State
Log.w(ex);
}
}

@Override
public int scrollVerticallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
int scrollRange = super.scrollVerticallyBy(dx, recycler, state);
boolean swipe_close = prefs.getBoolean("swipe_close", false);
if (swipe_close && viewType == AdapterMessage.ViewType.THREAD) {
int overscroll = dx - scrollRange;
Log.i("Overscroll=" + overscroll + "/" + minOverscroll);
if (overscroll < -minOverscroll)
handleAutoClose();
}
return scrollRange;
}
};
rvMessage.setLayoutManager(llm);

Expand Down Expand Up @@ -1315,6 +1306,30 @@ public boolean canChildScrollUp(@NonNull SwipeRefreshLayout parent, @Nullable Vi
}
});

boolean swipe_close = prefs.getBoolean("swipe_close", false);
if (swipe_close && viewType == AdapterMessage.ViewType.THREAD) {
IOverScrollDecor decor = new VerticalOverScrollBounceEffectDecorator(
new RecyclerViewOverScrollDecorAdapter(rvMessage, touchHelper) {
@Override
public boolean isInAbsoluteEnd() {
return false;
}
},
DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD,
DEFAULT_TOUCH_DRAG_MOVE_RATIO_BCK,
DEFAULT_DECELERATE_FACTOR
);
decor.setOverScrollUpdateListener(new IOverScrollUpdateListener() {
@Override
public void onOverScrollUpdate(IOverScrollDecor decor, int state, float offset) {
float height = decor.getView().getHeight() / DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD;
if (height != 0 && offset > height / 3)
handleAutoClose();
}
});
}


final String pkg = Helper.getOpenKeychainPackage(getContext());
Log.i("PGP binding to " + pkg);
pgpService = new OpenPgpServiceConnection(getContext(), pkg);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/eu/faircode/email/FragmentOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class FragmentOptions extends FragmentBase {
"message_zoom", "addresses", "attachments_alt", "thumbnails",
"contrast", "monospaced", "text_color", "text_size", "text_font", "text_align",
"inline_images", "collapse_quotes", "seekbar", "actionbar", "actionbar_color", "navbar_colorize",
"autoscroll", "swipenav", "autoexpand", "autoclose", "onclose",
"autoscroll", "swipenav", "swipe_close", "autoexpand", "autoclose", "onclose",
"language_detection",
"quick_filter", "quick_scroll",
"experiments", "debug",
Expand Down

0 comments on commit eb3420a

Please sign in to comment.