From 1045b53f9a6055575c09b3b13c6238066a59f885 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 25 Feb 2016 22:53:33 +0100 Subject: [PATCH] display the current directory/photo name at the actionbar --- .../simplemobiletools/gallery/Helpers.java | 7 ++++ .../gallery/activities/MainActivity.java | 15 ++++---- .../gallery/activities/PhotosActivity.java | 20 ++++++----- .../gallery/activities/ViewPagerActivity.java | 36 +++++++++++++++---- app/src/main/res/values/styles.xml | 2 +- 5 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 app/src/main/java/com/simplemobiletools/gallery/Helpers.java diff --git a/app/src/main/java/com/simplemobiletools/gallery/Helpers.java b/app/src/main/java/com/simplemobiletools/gallery/Helpers.java new file mode 100644 index 000000000..682fae675 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/gallery/Helpers.java @@ -0,0 +1,7 @@ +package com.simplemobiletools.gallery; + +public class Helpers { + public static String getFilename(final String path) { + return path.substring(path.lastIndexOf("/") + 1); + } +} diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index f60776446..563a0bc32 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -11,17 +11,18 @@ import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; +import com.simplemobiletools.gallery.Constants; +import com.simplemobiletools.gallery.Directory; +import com.simplemobiletools.gallery.Helpers; +import com.simplemobiletools.gallery.R; +import com.simplemobiletools.gallery.adapters.DirectoryAdapter; + import java.io.File; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import com.simplemobiletools.gallery.Constants; -import com.simplemobiletools.gallery.Directory; -import com.simplemobiletools.gallery.R; -import com.simplemobiletools.gallery.adapters.DirectoryAdapter; - public class MainActivity extends AppCompatActivity implements OnItemClickListener { private List dirs; @@ -49,14 +50,14 @@ public class MainActivity extends AppCompatActivity implements OnItemClickListen do { final String path = cursor.getString(pathIndex); final File file = new File(path); - final String fileDir = file.getParent().toLowerCase(); + final String fileDir = file.getParent(); if (directories.containsKey(fileDir)) { final Directory directory = directories.get(fileDir); final int newImageCnt = directory.getPhotoCnt() + 1; directory.setPhotoCnt(newImageCnt); } else { - final String dirName = fileDir.substring(fileDir.lastIndexOf("/") + 1); + final String dirName = Helpers.getFilename(fileDir); directories.put(fileDir, new Directory(fileDir, path, dirName, 1)); } } while (cursor.moveToNext()); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java index 3e31d0e91..8db9f6f79 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java @@ -10,14 +10,15 @@ import android.view.View; import android.widget.AdapterView; import android.widget.GridView; +import com.simplemobiletools.gallery.Constants; +import com.simplemobiletools.gallery.Helpers; +import com.simplemobiletools.gallery.R; +import com.simplemobiletools.gallery.adapters.PhotosAdapter; + import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -import com.simplemobiletools.gallery.Constants; -import com.simplemobiletools.gallery.R; -import com.simplemobiletools.gallery.adapters.PhotosAdapter; - public class PhotosActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private List photos; @@ -27,14 +28,17 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI setContentView(R.layout.activity_photos); photos = new ArrayList<>(); + final String path = getIntent().getStringExtra(Constants.DIRECTORY); final GridView gridView = (GridView) findViewById(R.id.photos_grid); - final PhotosAdapter adapter = new PhotosAdapter(this, getPhotos()); + final PhotosAdapter adapter = new PhotosAdapter(this, getPhotos(path)); gridView.setAdapter(adapter); gridView.setOnItemClickListener(this); + + final String dirName = Helpers.getFilename(path); + setTitle(dirName); } - private List getPhotos() { - final String path = getIntent().getStringExtra(Constants.DIRECTORY); + private List getPhotos(final String path) { final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; final String where = MediaStore.Images.Media.DATA + " like ? "; final String[] args = new String[]{path + "%"}; @@ -47,7 +51,7 @@ public class PhotosActivity extends AppCompatActivity implements AdapterView.OnI final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); do { final String curPath = cursor.getString(pathIndex); - if (curPath.toLowerCase().matches(pattern)) { + if (curPath.matches(pattern)) { photos.add(cursor.getString(pathIndex)); } } while (cursor.moveToNext()); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index dc3e40c08..07ddbd0a0 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -5,6 +5,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; +import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.view.Menu; @@ -12,6 +13,7 @@ import android.view.MenuItem; import android.view.View; import com.simplemobiletools.gallery.Constants; +import com.simplemobiletools.gallery.Helpers; import com.simplemobiletools.gallery.MyViewPager; import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.adapters.MyPagerAdapter; @@ -21,7 +23,7 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -public class ViewPagerActivity extends AppCompatActivity { +public class ViewPagerActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener { private int pos; private boolean isFullScreen; private ActionBar actionbar; @@ -38,12 +40,14 @@ public class ViewPagerActivity extends AppCompatActivity { actionbar = getSupportActionBar(); hideSystemUI(); + final String path = getIntent().getStringExtra(Constants.PHOTO); final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager()); pager = (MyViewPager) findViewById(R.id.view_pager); - photos = getPhotos(); + photos = getPhotos(path); adapter.setPaths(photos); pager.setAdapter(adapter); pager.setCurrentItem(pos); + pager.addOnPageChangeListener(this); getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override @@ -53,6 +57,8 @@ public class ViewPagerActivity extends AppCompatActivity { } } }); + + updateActionbarTitle(); } @Override @@ -83,10 +89,9 @@ public class ViewPagerActivity extends AppCompatActivity { startActivity(Intent.createChooser(sendIntent, shareTitle)); } - private List getPhotos() { + private List getPhotos(final String path) { final List photos = new ArrayList<>(); - final String path = getIntent().getStringExtra(Constants.PHOTO); - final String fileDir = new File(path).getParent().toLowerCase(); + final String fileDir = new File(path).getParent(); final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; final String where = MediaStore.Images.Media.DATA + " like ? "; final String[] args = new String[]{fileDir + "%"}; @@ -100,7 +105,7 @@ public class ViewPagerActivity extends AppCompatActivity { final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA); do { final String curPath = cursor.getString(pathIndex); - if (curPath.toLowerCase().matches(pattern)) { + if (curPath.matches(pattern)) { photos.add(curPath); if (curPath.equals(path)) @@ -143,4 +148,23 @@ public class ViewPagerActivity extends AppCompatActivity { View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } + + private void updateActionbarTitle() { + setTitle(Helpers.getFilename(photos.get(pager.getCurrentItem()))); + } + + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(int position) { + updateActionbarTitle(); + } + + @Override + public void onPageScrollStateChanged(int state) { + + } } diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 12e6d228d..2b17c658c 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -12,7 +12,7 @@ @style/MyFullScreenActionBar -