package gallery.simplemobiletools.com;

import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
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 name = path.substring(path.lastIndexOf("/") + 1);
            final String cnt = String.valueOf(dir.getValue());
            dirs.add(new Directory(path, name, cnt));
        }

        final GridView gridView = (GridView) findViewById(R.id.photo_grid);
        DirectoryAdapter adapter = new DirectoryAdapter(this, dirs);
        gridView.setAdapter(adapter);
    }

    private Map<String, Integer> getImages() {
        final Map<String, Integer> dirs = new TreeMap<>();
        final Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        final Cursor cursor = getContentResolver().query(uri, null, null, null, null);

        if (cursor != null && cursor.moveToFirst()) {
            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 (dirs.containsKey(path)) {
                    dirs.put(path, dirs.get(path) + 1);
                } else {
                    dirs.put(path, 1);
                }
            } while (cursor.moveToNext());
            cursor.close();
        }

        return dirs;
    }
}

@@ -891,17 +891,20 @@
  String 
-n
+dirN
 ame = pa
@@ -1048,17 +1048,20 @@
 y(path, 
-n
+dirN
 ame, cnt
@@ -1346,24 +1346,31 @@
 Integer%3E dir
+ectorie
 s = new Tree
@@ -1858,16 +1858,23 @@
  if (dir
+ectorie
 s.contai
@@ -1903,32 +1903,39 @@
              dir
+ectorie
 s.put(path, dirs
@@ -1933,16 +1933,23 @@
 ath, dir
+ectorie
 s.get(pa
@@ -2006,16 +2006,23 @@
      dir
+ectorie
 s.put(pa
@@ -2147,16 +2147,23 @@
 turn dir
+ectorie
 s;%0A    %7D

rename some variables