mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48: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;
|
package gallery.simplemobiletools.com;
|
||||||
|
|
||||||
public class Directory {
|
public class Directory {
|
||||||
private final String path;
|
private final String thumbnail;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String photoCnt;
|
private int photoCnt;
|
||||||
|
|
||||||
public Directory(String path, String name, String photoCnt) {
|
public Directory(String thumbnail, String name, int photoCnt) {
|
||||||
this.path = path;
|
this.thumbnail = thumbnail;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.photoCnt = photoCnt;
|
this.photoCnt = photoCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
public String getThumbnail() {
|
||||||
return path;
|
return thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPhotoCnt() {
|
public int getPhotoCnt() {
|
||||||
return photoCnt;
|
return photoCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPhotoCnt(int cnt) {
|
||||||
|
photoCnt = cnt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class DirectoryAdapter extends BaseAdapter {
|
||||||
|
|
||||||
Directory dir = dirs.get(position);
|
Directory dir = dirs.get(position);
|
||||||
holder.dirName.setText(dir.getName());
|
holder.dirName.setText(dir.getName());
|
||||||
holder.photoCnt.setText(dir.getPhotoCnt());
|
holder.photoCnt.setText(String.valueOf(dir.getPhotoCnt()));
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,36 +9,24 @@ import android.widget.GridView;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
private List<Directory> dirs;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
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);
|
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);
|
gridView.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Integer> getImages() {
|
private Map<String, Directory> getDirectories() {
|
||||||
final Map<String, Integer> directories = new TreeMap<>();
|
final Map<String, Directory> directories = new TreeMap<>();
|
||||||
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
final Cursor cursor = getContentResolver().query(uri, null, null, null, null);
|
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);
|
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
do {
|
do {
|
||||||
final File file = new File(cursor.getString(pathIndex));
|
final File file = new File(cursor.getString(pathIndex));
|
||||||
final String path = file.getParent().toLowerCase();
|
final String fileDir = file.getParent().toLowerCase();
|
||||||
if (directories.containsKey(path)) {
|
|
||||||
directories.put(path, directories.get(path) + 1);
|
if (directories.containsKey(fileDir)) {
|
||||||
|
final Directory directory = directories.get(fileDir);
|
||||||
|
final int newImageCnt = directory.getPhotoCnt() + 1;
|
||||||
|
directory.setPhotoCnt(newImageCnt);
|
||||||
} else {
|
} 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());
|
} while (cursor.moveToNext());
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
Loading…
Reference in a new issue