From 358e5dccedc283ed40b24896e203f35437f2f5f7 Mon Sep 17 00:00:00 2001 From: dar9586 Date: Mon, 26 Oct 2020 22:45:30 +0100 Subject: [PATCH] NClientV2 2.6.3 + Vertical scroll mode --- app/build.gradle | 4 +- .../java/com/dar/nclientv2/ZoomActivity.java | 37 ++++- .../components/views/VerticalViewPager.java | 142 ++++++++++++++++++ .../components/views/ZoomFragment.java | 1 + app/src/main/res/layout/activity_zoom.xml | 4 +- app/src/main/res/menu/menu_zoom.xml | 4 + app/src/main/res/values-ar-rSA/strings.xml | 7 + app/src/main/res/values-de-rDE/strings.xml | 8 + .../{values-es => values-es-rES}/strings.xml | 11 +- app/src/main/res/values-it-rIT/strings.xml | 48 +++--- app/src/main/res/values-tr-rTR/strings.xml | 7 + app/src/main/res/values-zh-rCN/strings.xml | 7 + app/src/main/res/values-zh-rTW/strings.xml | 6 + app/src/main/res/values/strings.xml | 7 + 14 files changed, 262 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/com/dar/nclientv2/components/views/VerticalViewPager.java rename app/src/main/res/{values-es => values-es-rES}/strings.xml (98%) diff --git a/app/build.gradle b/app/build.gradle index 83c550eb..00f3d0ac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.dar.nclientv2" minSdkVersion 14 targetSdkVersion 29 - versionCode 262 - versionName "2.6.2" + versionCode 263 + versionName "2.6.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/com/dar/nclientv2/ZoomActivity.java b/app/src/main/java/com/dar/nclientv2/ZoomActivity.java index fee38613..2dae7729 100644 --- a/app/src/main/java/com/dar/nclientv2/ZoomActivity.java +++ b/app/src/main/java/com/dar/nclientv2/ZoomActivity.java @@ -4,6 +4,7 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.os.Build; @@ -29,8 +30,8 @@ import com.dar.nclientv2.api.components.GenericGallery; import com.dar.nclientv2.async.database.Queries; import com.dar.nclientv2.components.activities.GeneralActivity; +import com.dar.nclientv2.components.views.VerticalViewPager; import com.dar.nclientv2.components.views.ZoomFragment; -import com.dar.nclientv2.components.widgets.CustomViewPager; import com.dar.nclientv2.settings.DefaultDialogs; import com.dar.nclientv2.settings.Global; import com.dar.nclientv2.utility.LogUtility; @@ -49,22 +50,27 @@ public class ZoomActivity extends GeneralActivity { | (Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT?View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY:0); @TargetApi(16) private final static int showFlags=View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE; - + private static final String VOLUME_SIDE_KEY="volumeSide"; + private static final String SCROLL_TYPE_KEY="zoomScrollType"; + private enum ScrollType{HORIZONTAL,VERTICAL} private GenericGallery gallery; private int actualPage=0; private boolean isHidden=false; - private CustomViewPager mViewPager; + private VerticalViewPager mViewPager; private TextView pageManagerLabel, cornerPageViewer; private View pageSwitcher; private SeekBar seekBar; private Toolbar toolbar; private View view; private File directory; + private ScrollType scrollType=ScrollType.HORIZONTAL,tmpScrollType; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Global.initActivity(this); - side=getSharedPreferences("Settings",0).getBoolean("volumeSide",true); + SharedPreferences preferences=getSharedPreferences("Settings",0); + side=preferences.getBoolean(VOLUME_SIDE_KEY,true); + scrollType=ScrollType.values()[preferences.getInt(SCROLL_TYPE_KEY,ScrollType.HORIZONTAL.ordinal())]; setContentView(R.layout.activity_zoom); //read arguments @@ -91,6 +97,7 @@ protected void onCreate(Bundle savedInstanceState) { SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); + mViewPager.setVerticalMode(scrollType==ScrollType.VERTICAL); pageSwitcher =findViewById(R.id.page_switcher); pageManagerLabel =findViewById(R.id.pages); cornerPageViewer =findViewById(R.id.page_text); @@ -194,7 +201,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event){ return super.onKeyDown(keyCode, event); } private void changeSide(){ - getSharedPreferences("Settings",0).edit().putBoolean("volumeSide",side=!side).apply(); + getSharedPreferences("Settings",0).edit().putBoolean(VOLUME_SIDE_KEY,side=!side).apply(); Toast.makeText(this, side?R.string.next_page_volume_up:R.string.next_page_volume_down, Toast.LENGTH_SHORT).show(); } private void changeClosePage(boolean next){ @@ -230,6 +237,22 @@ private void changePage(int newPage){ } + + private void changeScrollTypeDialog(){ + MaterialAlertDialogBuilder builder=new MaterialAlertDialogBuilder(this); + tmpScrollType=scrollType; + builder.setTitle(getString(R.string.change_scroll_type)+":"); + builder.setSingleChoiceItems(R.array.scroll_type, scrollType.ordinal(), (dialog, which) -> tmpScrollType=ScrollType.values()[which]); + builder.setPositiveButton(R.string.ok, (dialog, which) -> { + if(tmpScrollType!=scrollType){ + scrollType=tmpScrollType; + mViewPager.setVerticalMode(scrollType==ScrollType.VERTICAL); + getSharedPreferences("Settings",0).edit().putInt(SCROLL_TYPE_KEY,scrollType.ordinal()).apply(); + } + }).setNegativeButton(R.string.cancel,null); + builder.show(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. @@ -262,6 +285,10 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; case R.id.bookmark: Queries.ResumeTable.insert(gallery.getId(),actualPage+1); + break; + case R.id.scrollType: + changeScrollTypeDialog(); + break; } return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/com/dar/nclientv2/components/views/VerticalViewPager.java b/app/src/main/java/com/dar/nclientv2/components/views/VerticalViewPager.java new file mode 100644 index 00000000..730cfa4d --- /dev/null +++ b/app/src/main/java/com/dar/nclientv2/components/views/VerticalViewPager.java @@ -0,0 +1,142 @@ +package com.dar.nclientv2.components.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.GestureDetector; +import android.view.MotionEvent; +import android.view.View; + +import androidx.viewpager.widget.ViewPager; + +import com.dar.nclientv2.components.widgets.CustomViewPager; +import com.dar.nclientv2.utility.LogUtility; + +public class VerticalViewPager extends ViewPager { + private CustomViewPager.OnItemClickListener mOnItemClickListener; + private boolean verticalMode=true; + public VerticalViewPager(Context context) { + this(context, null); + init(); + } + + public VerticalViewPager(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + @Override + public boolean canScrollHorizontally(int direction) { + if(verticalMode) return false; + else return super.canScrollHorizontally(direction); + } + + public void setVerticalMode(boolean verticalMode) { + this.verticalMode = verticalMode; + init(); + } + + @Override + public boolean canScrollVertically(int direction) { + if(verticalMode) return super.canScrollHorizontally(direction); + else return super.canScrollVertically(direction); + } + + private void init() { + setPageTransformer(true,verticalMode?new VerticalPageTransformer():null); + setOverScrollMode(View.OVER_SCROLL_NEVER); + setup(); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + + try { + final boolean toIntercept = super.onInterceptTouchEvent(flipXY(ev)); + flipXY(ev); + return toIntercept; + } catch (IllegalArgumentException ex) { + ex.printStackTrace(); + } + return false; + } + @Override + public boolean performClick() { + try { + return super.performClick(); + } catch (IllegalArgumentException ex) { + LogUtility.e(ex.getLocalizedMessage(),ex); + } + return false; + } + @Override + public boolean onTouchEvent(MotionEvent ev) { + try { + performClick(); + final boolean toHandle = super.onTouchEvent(flipXY(ev)); + flipXY(ev); + return toHandle; + } catch (IllegalArgumentException ex) { + LogUtility.e(ex.getLocalizedMessage(),ex); + } + return false; + } + + + private MotionEvent flipXY(MotionEvent ev) { + if(!verticalMode)return ev; + final float width = getWidth(); + final float height = getHeight(); + final float x = (ev.getY() / height) * width; + final float y = (ev.getX() / width) * height; + ev.setLocation(x, y); + return ev; + } + + private static final class VerticalPageTransformer implements ViewPager.PageTransformer { + @Override + public void transformPage(View view, float position) { + final int pageWidth = view.getWidth(); + final int pageHeight = view.getHeight(); + if (position < -1) { + view.setAlpha(0); + } else if (position <= 1) { + view.setAlpha(1); + view.setTranslationX(pageWidth * -position); + float yPosition = position * pageHeight; + view.setTranslationY(yPosition); + } else { + view.setAlpha(0); + } + } + } + + private void setup() { + final GestureDetector tapGestureDetector = new GestureDetector(getContext(), new VerticalViewPager.TapGestureListener()); + setOnTouchListener((v, event) -> { + tapGestureDetector.onTouchEvent(event); + performClick(); + return false; + }); + } + + public void setOnItemClickListener(CustomViewPager.OnItemClickListener onItemClickListener) { + mOnItemClickListener = onItemClickListener; + } + + public interface OnItemClickListener { + void onItemClick(int position); + } + + private class TapGestureListener extends GestureDetector.SimpleOnGestureListener { + + @Override + public boolean onSingleTapConfirmed(MotionEvent e) { + if(mOnItemClickListener != null) { + mOnItemClickListener.onItemClick(getCurrentItem()); + } + return true; + } + } + + +} diff --git a/app/src/main/java/com/dar/nclientv2/components/views/ZoomFragment.java b/app/src/main/java/com/dar/nclientv2/components/views/ZoomFragment.java index 8a47c147..315054b9 100644 --- a/app/src/main/java/com/dar/nclientv2/components/views/ZoomFragment.java +++ b/app/src/main/java/com/dar/nclientv2/components/views/ZoomFragment.java @@ -85,6 +85,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c url=getArguments().getString("URL"); LogUtility.d("Requested: "+page); if(path!=null)galleryFolder=new File(path); + photoView.setAllowParentInterceptOnEdge(true); photoView.setOnClickListener(v -> { if(clickListener!=null)clickListener.onClick(v); }); diff --git a/app/src/main/res/layout/activity_zoom.xml b/app/src/main/res/layout/activity_zoom.xml index ad3fd721..05f6e097 100644 --- a/app/src/main/res/layout/activity_zoom.xml +++ b/app/src/main/res/layout/activity_zoom.xml @@ -23,7 +23,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - + + diff --git a/app/src/main/res/values-ar-rSA/strings.xml b/app/src/main/res/values-ar-rSA/strings.xml index 8e179035..1e2b400b 100644 --- a/app/src/main/res/values-ar-rSA/strings.xml +++ b/app/src/main/res/values-ar-rSA/strings.xml @@ -262,6 +262,12 @@ Size Descending order The comment must be at least %d characters + Change scroll type + + + Horizontal + Vertical + System Default @@ -272,6 +278,7 @@ Italian German Arabic + Spanish diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index f3ba18ca..0a76c68c 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -286,6 +286,13 @@ Size Descending order The comment must be at least %d characters + Change scroll type + + + Horizontal + Vertical + + System Default Englisch @@ -295,6 +302,7 @@ Italienisch Deutsch Arabisch + Spanish diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es-rES/strings.xml similarity index 98% rename from app/src/main/res/values-es/strings.xml rename to app/src/main/res/values-es-rES/strings.xml index 2c8b22cd..4fff3298 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -261,6 +261,13 @@ Seleccion de numero de columna de historial Seleccion de numero de columna de descargas Seleccion de numero de columna de favoritos + Change scroll type + + + Horizontal + Vertical + + Por Defecto English @@ -270,7 +277,7 @@ Italian German Arabic - + Español Claro @@ -283,4 +290,4 @@ Arreglado - \ No newline at end of file + diff --git a/app/src/main/res/values-it-rIT/strings.xml b/app/src/main/res/values-it-rIT/strings.xml index ddc0dfb1..5831b7a3 100644 --- a/app/src/main/res/values-it-rIT/strings.xml +++ b/app/src/main/res/values-it-rIT/strings.xml @@ -266,27 +266,34 @@ Giorni Settimane Scegli unità di tempo: - Change status - Create new status: - Black and white can not be used - Select new status: - None - Name too short - Duplicated name - Manage statuses - Update status: - View statuses - Select status column count - Status viewer - Hide app content in multitasking - Title - Download date - Page count - Size - Descending order - The comment must be at least %d characters + Cambia status + Crea nuovo status: + Bianco e nero non possono essere usati + Scegli nuovo status: + Nessuno + Nome troppo piccolo + Nome duplicato + Gestisci status + Cambia status: + Vedi status + Scegliil numero di colonne nello status + Controlla status + Nascondi app dal multitasking + Titolo + Data di download + Numero di pagine + Grandezza + Ordine decrescente + Il commento deve essere di almeno %d caratteri + Cambia scorrimento + + + Orizzontale + Verticale + + - System Default + Predefinito Inglese Cinese (Tradizionale) Cinese (Semplificate) @@ -294,6 +301,7 @@ Italiano Tedesco Arabo + Spagnolo diff --git a/app/src/main/res/values-tr-rTR/strings.xml b/app/src/main/res/values-tr-rTR/strings.xml index b7274c0a..b0ac88c6 100644 --- a/app/src/main/res/values-tr-rTR/strings.xml +++ b/app/src/main/res/values-tr-rTR/strings.xml @@ -205,6 +205,11 @@ Yanlış PIN Fotoğrafı çevir + + Horizontal + Vertical + + Sistem Dili İngilizce @@ -214,6 +219,7 @@ İtalyanca Almanca Arapça + Spanish Beyaz Tema @@ -306,4 +312,5 @@ Size Descending order The comment must be at least %d characters + Change scroll type diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 41cde65a..18c23a15 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -263,6 +263,12 @@ Size Descending order The comment must be at least %d characters + Change scroll type + + + Horizontal + Vertical + 默认 @@ -273,6 +279,7 @@ 意大利语 德语 阿拉伯语 + Spanish 亮色 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 098f7625..638fdb70 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -288,7 +288,12 @@ Size Descending order The comment must be at least %d characters + Change scroll type + + Horizontal + Vertical + 系統預設 @@ -299,6 +304,7 @@ 義大利文 德語 阿拉伯 + Spanish 淺色 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 05cc8520..92b7c804 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -320,7 +320,12 @@ Size Descending order The comment must be at least %d characters + Change scroll type + + Horizontal + Vertical + System Default English @@ -330,6 +335,7 @@ Italian German Arabic + Spanish @@ -341,6 +347,7 @@ it-IT de-DE ar-SA + es-ES