mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 04:28:00 +01:00
use the first image in the directory as thumbnail
This commit is contained in:
parent
a410e4371c
commit
c2762ab014
3 changed files with 26 additions and 29 deletions
|
@ -1,25 +1,29 @@
|
|||
package gallery.simplemobiletools.com;
|
||||
|
||||
public class Directory {
|
||||
private final String path;
|
||||
private final String thumbnail;
|
||||
private final String name;
|
||||
private final String photoCnt;
|
||||
private int photoCnt;
|
||||
|
||||
public Directory(String path, String name, String photoCnt) {
|
||||
this.path = path;
|
||||
public Directory(String thumbnail, String name, int photoCnt) {
|
||||
this.thumbnail = thumbnail;
|
||||
this.name = name;
|
||||
this.photoCnt = photoCnt;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
public String getThumbnail() {
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPhotoCnt() {
|
||||
public int getPhotoCnt() {
|
||||
return photoCnt;
|
||||
}
|
||||
|
||||
public void setPhotoCnt(int cnt) {
|
||||
photoCnt = cnt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class DirectoryAdapter extends BaseAdapter {
|
|||
|
||||
Directory dir = dirs.get(position);
|
||||
holder.dirName.setText(dir.getName());
|
||||
holder.photoCnt.setText(dir.getPhotoCnt());
|
||||
holder.photoCnt.setText(String.valueOf(dir.getPhotoCnt()));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -9,36 +9,24 @@ import android.widget.GridView;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
private List<Directory> dirs;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
final Map<String, Integer> directories = getImages();
|
||||
dirs = new ArrayList<>(directories.size());
|
||||
|
||||
for (Map.Entry<String, Integer> dir : directories.entrySet()) {
|
||||
final String path = dir.getKey();
|
||||
final String dirName = path.substring(path.lastIndexOf("/") + 1);
|
||||
final String cnt = String.valueOf(dir.getValue());
|
||||
dirs.add(new Directory(path, dirName, cnt));
|
||||
}
|
||||
|
||||
final GridView gridView = (GridView) findViewById(R.id.photo_grid);
|
||||
DirectoryAdapter adapter = new DirectoryAdapter(this, dirs);
|
||||
|
||||
final List<Directory> dirs = new ArrayList<>(getDirectories().values());
|
||||
final DirectoryAdapter adapter = new DirectoryAdapter(this, dirs);
|
||||
gridView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private Map<String, Integer> getImages() {
|
||||
final Map<String, Integer> directories = new TreeMap<>();
|
||||
private Map<String, Directory> getDirectories() {
|
||||
final Map<String, Directory> directories = new TreeMap<>();
|
||||
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||
final Cursor cursor = getContentResolver().query(uri, null, null, null, null);
|
||||
|
||||
|
@ -46,11 +34,16 @@ public class MainActivity extends AppCompatActivity {
|
|||
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||
do {
|
||||
final File file = new File(cursor.getString(pathIndex));
|
||||
final String path = file.getParent().toLowerCase();
|
||||
if (directories.containsKey(path)) {
|
||||
directories.put(path, directories.get(path) + 1);
|
||||
final String fileDir = file.getParent().toLowerCase();
|
||||
|
||||
if (directories.containsKey(fileDir)) {
|
||||
final Directory directory = directories.get(fileDir);
|
||||
final int newImageCnt = directory.getPhotoCnt() + 1;
|
||||
directory.setPhotoCnt(newImageCnt);
|
||||
} else {
|
||||
directories.put(path, 1);
|
||||
final String thumbnail = file.getAbsolutePath();
|
||||
final String dirName = fileDir.substring(fileDir.lastIndexOf("/") + 1);
|
||||
directories.put(fileDir, new Directory(thumbnail, dirName, 1));
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
cursor.close();
|
||||
|
|
Loading…
Reference in a new issue