Skip to content

Commit

Permalink
NClientV2 1.6.7
Browse files Browse the repository at this point in the history
+ Volume button to change page
* Bug fixes
  • Loading branch information
Dar9586 committed Jan 20, 2019
1 parent bfa1286 commit 130ab5f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/dar/nclientv2/TagFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import android.view.View;
import android.view.ViewGroup;

import com.dar.nclientv2.adapters.paged.TagsAdapter;
import com.dar.nclientv2.adapters.TagsAdapter;
import com.dar.nclientv2.api.enums.TagType;
import com.dar.nclientv2.async.scrape.BulkScraper;
import com.dar.nclientv2.settings.DefaultDialogs;
Expand Down
86 changes: 54 additions & 32 deletions app/src/main/java/com/dar/nclientv2/ZoomActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -42,8 +43,8 @@

public class ZoomActivity extends AppCompatActivity {
private GenericGallery gallery;
private boolean overrideVolume;
public int actualPage=0;
private static final Object preloadTag=new Object();
private final static int hideFlags=View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Expand All @@ -63,6 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Global.loadTheme(this);
Global.initHideFromGallery(this);
overrideVolume=getSharedPreferences("Settings",0).getBoolean(getString(R.string.key_override_volume),true);
setContentView(R.layout.activity_zoom);
Toolbar toolbar = findViewById(R.id.toolbar);
//toolbar.setPadding(toolbar.getPaddingLeft(),Global.getStatusBarHeight(this),toolbar.getPaddingRight(),toolbar.getTitleMarginBottom());
Expand All @@ -83,24 +85,17 @@ protected void onCreate(Bundle savedInstanceState) {
pageSwitcher =findViewById(R.id.page_switcher);
pageManager=findViewById(R.id.pages);
seekBar=findViewById(R.id.seekBar);
//mViewPager.setOffscreenPageLimit(1);
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { }

@Override
public void onPageSelected(int position) {
actualPage=position;
pageManager.setText(getString(R.string.page_format,position+1,gallery.getPageCount()));
seekBar.setProgress(position);
/*if(!gallery.isLocal()){
Picasso.get().cancelTag(preloadTag);
Gallery gallery=(Gallery)ZoomActivity.this.gallery;
if(position>0)Picasso.get().load(gallery.getPage(position-1)).tag(preloadTag).priority(Picasso.Priority.LOW).fetch();
if(position<gallery.getPageCount()-1)Picasso.get().load(gallery.getPage(position+1)).tag(preloadTag).priority(Picasso.Priority.LOW).fetch();
}*/
PlaceholderFragment.current=position;
}

@Override
Expand Down Expand Up @@ -137,6 +132,19 @@ public void onStopTrackingTouch(SeekBar seekBar) {

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if(!overrideVolume)return super.onKeyDown(keyCode, event);
switch(keyCode){
case KeyEvent.KEYCODE_VOLUME_UP:
if(mViewPager.getCurrentItem()<(mViewPager.getAdapter().getCount()-1))changePage(mViewPager.getCurrentItem()+1);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if(mViewPager.getCurrentItem()>0)changePage(mViewPager.getCurrentItem()-1);
return true;
}
return super.onKeyDown(keyCode, event);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
Expand All @@ -156,6 +164,7 @@ private void changeLayout(boolean landscape){
}

private void changePage(int newPage){
PlaceholderFragment.current=newPage;
mViewPager.setCurrentItem(newPage);
seekBar.setProgress(newPage);
}
Expand Down Expand Up @@ -199,12 +208,17 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
downloadPage();

}

private PlaceholderFragment getActualFragment(){
return getActualFragment(mViewPager.getCurrentItem());
}
private PlaceholderFragment getActualFragment(int position){
return (PlaceholderFragment) getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.container + ":" + position);
}
private void downloadPage() {
Global.saveNoMedia(this);
final File output=new File(Global.GALLERYFOLDER,gallery.getId()+"-"+(mViewPager.getCurrentItem()+1)+".jpg");
Bitmap bitmap;
PlaceholderFragment page =(PlaceholderFragment) getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.container + ":" + mViewPager.getCurrentItem());
PlaceholderFragment page =getActualFragment();
//is useless to download the vector used by the app
if(page!=null&&page.photoView.getDrawable() instanceof BitmapDrawable){
bitmap=((BitmapDrawable)page.photoView.getDrawable()).getBitmap();
Expand All @@ -223,6 +237,8 @@ private void downloadPage() {

public static class PlaceholderFragment extends Fragment {

public static int current=0;

public PlaceholderFragment() {
}

Expand All @@ -234,54 +250,60 @@ public static PlaceholderFragment newInstance(int sectionNumber) {
return fragment;
}
PhotoView photoView;
private int page;
private ZoomActivity activity;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final ZoomActivity x=(ZoomActivity)getActivity();
activity =(ZoomActivity)getActivity();
View rootView = inflater.inflate(R.layout.fragment_zoom, container, false);
photoView = rootView.findViewById(R.id.image);

photoView.setOnMatrixChangeListener(rect -> photoView.setAllowParentInterceptOnEdge(photoView.getScale()<=1f));
photoView.setOnClickListener(v -> {

/*x.getWindow().getDecorView().setSystemUiVisibility(x.isHidden?showFlags:hideFlags);
x.findViewById(R.id.page_switcher).setVisibility(x.isHidden?View.VISIBLE:View.GONE);
x.findViewById(R.id.appbar).setVisibility(x.isHidden?View.VISIBLE:View.GONE);
x.isHidden=!x.isHidden;*/
final View y=x.findViewById(R.id.page_switcher);
final View z=x.findViewById(R.id.appbar);
x.isHidden=!x.isHidden;
x.getWindow().getDecorView().setSystemUiVisibility(x.isHidden?hideFlags:showFlags);
/*activity.getWindow().getDecorView().setSystemUiVisibility(activity.isHidden?showFlags:hideFlags);
activity.findViewById(R.id.page_switcher).setVisibility(activity.isHidden?View.VISIBLE:View.GONE);
activity.findViewById(R.id.appbar).setVisibility(activity.isHidden?View.VISIBLE:View.GONE);
activity.isHidden=!activity.isHidden;*/
final View y= activity.findViewById(R.id.page_switcher);
final View z= activity.findViewById(R.id.appbar);
activity.isHidden=!activity.isHidden;
activity.getWindow().getDecorView().setSystemUiVisibility(activity.isHidden?hideFlags:showFlags);
y.setVisibility(View.VISIBLE);
z.setVisibility(View.VISIBLE);
y.animate().alpha(x.isHidden?0f:0.75f).setDuration(150).setListener(new AnimatorListenerAdapter() {
y.animate().alpha(activity.isHidden?0f:0.75f).setDuration(150).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if(x.isHidden)y.setVisibility(View.GONE);
if(activity.isHidden)y.setVisibility(View.GONE);
}
}).start();

z.animate().alpha(x.isHidden?0f:0.75f).setDuration(150).setListener(new AnimatorListenerAdapter() {
z.animate().alpha(activity.isHidden?0f:0.75f).setDuration(150).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if(x.isHidden)z.setVisibility(View.GONE);
if(activity.isHidden)z.setVisibility(View.GONE);
}
}).start();

});
int page=getArguments().getInt("PAGE",0);
File file=x.directory==null?null:new File(x.directory,("000"+(page+1)+".jpg").substring(Integer.toString(page+1).length()));
page=getArguments().getInt("PAGE",0);
Log.d(Global.LOGTAG,"Loaded page: "+page);
if(page==current)loadPage(true);
else if(page==(current-1)||page==(current+1))loadPage(false);
return rootView;
}
public void loadPage(boolean high){
File file= activity.directory==null?null:new File(activity.directory,("000"+(page+1)+".jpg").substring(Integer.toString(page+1).length()));
if(file==null||!file.exists()){
if(x.gallery.isLocal())Picasso.get().load(R.mipmap.ic_launcher).into(photoView);
else Picasso.get().load(((Gallery)x.gallery).getPage(page)).into(photoView);
if(activity.gallery.isLocal())Picasso.get().load(R.mipmap.ic_launcher).into(photoView);
else Picasso.get().load(((Gallery)activity.gallery).getPage(page)).priority(high? Picasso.Priority.HIGH: Picasso.Priority.LOW).into(photoView);
}
else Picasso.get().load(file).into(photoView);
return rootView;
}
}

public class SectionsPagerAdapter extends FragmentPagerAdapter {

public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dar.nclientv2.adapters.paged;
package com.dar.nclientv2.adapters;

import android.database.Cursor;
import android.graphics.Color;
Expand Down Expand Up @@ -88,8 +88,6 @@ protected void publishResults(CharSequence constraint, FilterResults results) {
}
};
}


static class ViewHolder extends RecyclerView.ViewHolder {
final ImageView imgView;
final TextView title,count;
Expand Down Expand Up @@ -119,7 +117,6 @@ public boolean areContentsTheSame(@NonNull Tag oldItem, @NonNull Tag newItem){
public TagsAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new TagsAdapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.entry_tag_layout, parent, false));
}

@Override
public void onBindViewHolder(@NonNull final TagsAdapter.ViewHolder holder, int position) {
if(black)holder.master.setBackgroundColor(Color.BLACK);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/dar/nclientv2/async/ScrapeTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.content.Context;
import android.util.Log;

import com.dar.nclientv2.adapters.paged.TagsAdapter;
import com.dar.nclientv2.adapters.TagsAdapter;
import com.dar.nclientv2.api.components.Tag;
import com.dar.nclientv2.api.enums.TagStatus;
import com.dar.nclientv2.api.enums.TagType;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/dar/nclientv2/loginapi/LoadTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.util.JsonReader;
import android.util.Log;

import com.dar.nclientv2.adapters.paged.TagsAdapter;
import com.dar.nclientv2.adapters.TagsAdapter;
import com.dar.nclientv2.api.components.Tag;
import com.dar.nclientv2.api.enums.TagType;
import com.dar.nclientv2.settings.Global;
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@
<string name="set_minimum_count">Set minimum count</string>
<string name="sort_by_title">Sort by title</string>
<string name="sort_by_popular">Sort by popular</string>
<string name="key_override_volume">volume_override</string>
<string name="setting_on_override_volume">The volume keys will change page</string>
<string name="setting_off_override_volume">The volume keys will change system volume</string>


<string-array name="theme">
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@
android:summaryOn="@string/setting_on_ignore_tags"
android:summaryOff="@string/setting_off_ignore_tags"
android:title="@string/ignore_tags" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/key_override_volume"
android:summaryOn="@string/setting_on_override_volume"
android:summaryOff="@string/setting_off_override_volume"
android:title="Change page with volume buttons" />
<SwitchPreference
android:defaultValue="false"
android:enabled="false"
android:key="@string/key_use_account_tag"
android:summaryOn="@string/setting_on_use_account_tag"
android:summaryOff="@string/setting_off_use_account_tag"
android:title="@string/use_account_tag" />

<SwitchPreference
android:defaultValue="true"
android:key="@string/key_check_update"
Expand Down

0 comments on commit 130ab5f

Please sign in to comment.