display the current directory/photo name at the actionbar

This commit is contained in:
tibbi 2016-02-25 22:53:33 +01:00
parent 2e93991b6e
commit 1045b53f9a
5 changed files with 58 additions and 22 deletions

View File

@ -0,0 +1,7 @@
package com.simplemobiletools.gallery;
public class Helpers {
public static String getFilename(final String path) {
return path.substring(path.lastIndexOf("/") + 1);
}
}

View File

@ -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<Directory> 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());

View File

@ -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<String> 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<String> getPhotos() {
final String path = getIntent().getStringExtra(Constants.DIRECTORY);
private List<String> 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());

View File

@ -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<String> getPhotos() {
private List<String> getPhotos(final String path) {
final List<String> 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) {
}
}

View File

@ -12,7 +12,7 @@
<item name="android:actionBarStyle">@style/MyFullScreenActionBar</item>
</style>
<style name="MyFullScreenActionBar" parent="@android:style/Widget.Holo.ActionBar">
<style name="MyFullScreenActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="background">@color/actionbar_grey</item>
<item name="android:background">@color/actionbar_grey</item>
</style>