From 130ab5ffcd115c7bed328f014dd48808fc3f0092 Mon Sep 17 00:00:00 2001 From: Dar9586 Date: Sun, 20 Jan 2019 21:53:54 +0100 Subject: [PATCH] NClientV2 1.6.7 + Volume button to change page * Bug fixes --- .../java/com/dar/nclientv2/TagFilter.java | 2 +- .../java/com/dar/nclientv2/ZoomActivity.java | 86 ++++++++++++------- .../adapters/{paged => }/TagsAdapter.java | 5 +- .../com/dar/nclientv2/async/ScrapeTags.java | 2 +- .../com/dar/nclientv2/loginapi/LoadTags.java | 2 +- app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/settings.xml | 7 ++ 7 files changed, 68 insertions(+), 39 deletions(-) rename app/src/main/java/com/dar/nclientv2/adapters/{paged => }/TagsAdapter.java (99%) diff --git a/app/src/main/java/com/dar/nclientv2/TagFilter.java b/app/src/main/java/com/dar/nclientv2/TagFilter.java index df56a678..d3c69ac4 100644 --- a/app/src/main/java/com/dar/nclientv2/TagFilter.java +++ b/app/src/main/java/com/dar/nclientv2/TagFilter.java @@ -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; diff --git a/app/src/main/java/com/dar/nclientv2/ZoomActivity.java b/app/src/main/java/com/dar/nclientv2/ZoomActivity.java index f2e761eb..ab1037b8 100644 --- a/app/src/main/java/com/dar/nclientv2/ZoomActivity.java +++ b/app/src/main/java/com/dar/nclientv2/ZoomActivity.java @@ -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; @@ -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 @@ -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()); @@ -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(position0)changePage(mViewPager.getCurrentItem()-1); + return true; + } + return super.onKeyDown(keyCode, event); + } @Override public void onConfigurationChanged(Configuration newConfig) { @@ -156,6 +164,7 @@ private void changeLayout(boolean landscape){ } private void changePage(int newPage){ + PlaceholderFragment.current=newPage; mViewPager.setCurrentItem(newPage); seekBar.setProgress(newPage); } @@ -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(); @@ -223,6 +237,8 @@ private void downloadPage() { public static class PlaceholderFragment extends Fragment { + public static int current=0; + public PlaceholderFragment() { } @@ -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); } diff --git a/app/src/main/java/com/dar/nclientv2/adapters/paged/TagsAdapter.java b/app/src/main/java/com/dar/nclientv2/adapters/TagsAdapter.java similarity index 99% rename from app/src/main/java/com/dar/nclientv2/adapters/paged/TagsAdapter.java rename to app/src/main/java/com/dar/nclientv2/adapters/TagsAdapter.java index cfcd82b8..0f092b92 100644 --- a/app/src/main/java/com/dar/nclientv2/adapters/paged/TagsAdapter.java +++ b/app/src/main/java/com/dar/nclientv2/adapters/TagsAdapter.java @@ -1,4 +1,4 @@ -package com.dar.nclientv2.adapters.paged; +package com.dar.nclientv2.adapters; import android.database.Cursor; import android.graphics.Color; @@ -88,8 +88,6 @@ protected void publishResults(CharSequence constraint, FilterResults results) { } }; } - - static class ViewHolder extends RecyclerView.ViewHolder { final ImageView imgView; final TextView title,count; @@ -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); diff --git a/app/src/main/java/com/dar/nclientv2/async/ScrapeTags.java b/app/src/main/java/com/dar/nclientv2/async/ScrapeTags.java index 4d65ed31..af6ffe77 100644 --- a/app/src/main/java/com/dar/nclientv2/async/ScrapeTags.java +++ b/app/src/main/java/com/dar/nclientv2/async/ScrapeTags.java @@ -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; diff --git a/app/src/main/java/com/dar/nclientv2/loginapi/LoadTags.java b/app/src/main/java/com/dar/nclientv2/loginapi/LoadTags.java index cd5a2dcd..2ddce195 100644 --- a/app/src/main/java/com/dar/nclientv2/loginapi/LoadTags.java +++ b/app/src/main/java/com/dar/nclientv2/loginapi/LoadTags.java @@ -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; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1b959d7f..81704a95 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -204,6 +204,9 @@ Set minimum count Sort by title Sort by popular + volume_override + The volume keys will change page + The volume keys will change system volume diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 29a37f71..9f194873 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -44,6 +44,12 @@ android:summaryOn="@string/setting_on_ignore_tags" android:summaryOff="@string/setting_off_ignore_tags" android:title="@string/ignore_tags" /> + +