Skip to content

Commit

Permalink
NClientV2 2.6.3
Browse files Browse the repository at this point in the history
+ Vertical scroll mode
  • Loading branch information
Dar9586 committed Oct 26, 2020
1 parent 2475d77 commit 358e5dc
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 31 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 32 additions & 5 deletions app/src/main/java/com/dar/nclientv2/ZoomActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_zoom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.dar.nclientv2.components.widgets.CustomViewPager
<com.dar.nclientv2.components.views.VerticalViewPager

android:id="@+id/container"
android:layout_width="0dp"
Expand All @@ -36,7 +36,7 @@
tools:context=".ZoomActivity">


</com.dar.nclientv2.components.widgets.CustomViewPager>
</com.dar.nclientv2.components.views.VerticalViewPager>
<androidx.appcompat.widget.Toolbar
android:alpha="0.75"
android:paddingTop="@dimen/status_bar_height"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/menu/menu_zoom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
android:icon="@drawable/ic_bookmark"
android:title="@string/bookmark_here"
app:showAsAction="ifRoom|collapseActionView" />
<item
android:id="@+id/scrollType"
android:title="@string/change_scroll_type"
app:showAsAction="never" />
</menu>
7 changes: 7 additions & 0 deletions app/src/main/res/values-ar-rSA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@
<string name="size">Size</string>
<string name="descending_order">Descending order</string>
<string name="minimum_comment_length" formatted="true">The comment must be at least %d characters</string>
<string name="change_scroll_type">Change scroll type</string>

<string-array name="scroll_type">
<item>Horizontal</item>
<item>Vertical</item>
</string-array>

<string-array name="language">
<item>System Default</item>
Expand All @@ -272,6 +278,7 @@
<item>Italian</item>
<item>German</item>
<item>Arabic</item>
<item>Spanish</item>
</string-array>

<string-array name="theme">
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@
<string name="size">Size</string>
<string name="descending_order">Descending order</string>
<string name="minimum_comment_length" formatted="true">The comment must be at least %d characters</string>
<string name="change_scroll_type">Change scroll type</string>

<string-array name="scroll_type">
<item>Horizontal</item>
<item>Vertical</item>
</string-array>

<string-array name="language">
<item>System Default</item>
<item>Englisch</item>
Expand All @@ -295,6 +302,7 @@
<item>Italienisch</item>
<item>Deutsch</item>
<item>Arabisch</item>
<item>Spanish</item>
</string-array>

<string-array name="theme">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@
<string name="history_column_count">Seleccion de numero de columna de historial</string>
<string name="download_column_count">Seleccion de numero de columna de descargas</string>
<string name="favorite_column_count">Seleccion de numero de columna de favoritos</string>
<string name="change_scroll_type">Change scroll type</string>

<string-array name="scroll_type">
<item>Horizontal</item>
<item>Vertical</item>
</string-array>

<string-array name="language">
<item>Por Defecto</item>
<item>English</item>
Expand All @@ -270,7 +277,7 @@
<item>Italian</item>
<item>German</item>
<item>Arabic</item>
<!-- <item>Español</item>-->
<item>Español</item>
</string-array>
<string-array name="theme">
<item>Claro</item>
Expand All @@ -283,4 +290,4 @@
<item>Arreglado</item>
</string-array>

</resources>
</resources>
Loading

0 comments on commit 358e5dc

Please sign in to comment.