package com.hswt.broihier.sfwiaudio.sfwiaudio;

import android.util.Log;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.os.Environment.DIRECTORY_PODCASTS;
import static android.os.Environment.getExternalStorageDirectory;

public class audioFiles {

    public static final List<PodCastItem> ITEMS = new ArrayList<PodCastItem>();

    public static final Map<String, PodCastItem> ITEM_MAP = new HashMap<String, PodCastItem>();

    private static final String TAG="audioFiles";
    static {
        String path = getExternalStorageDirectory() + "/" + DIRECTORY_PODCASTS;
        Log.d(TAG,"attempted path: "+path);
        File directory = new File(path);
        File[] files = directory.listFiles();
        if (files != null) {
            Log.d(TAG,"Size: "+files.length);
            int storageIndex = 0;
            for (int i = 0; i < files.length; i++) {
                if (files[i].getName().equals("state.bin")) continue;
                Log.d(TAG, "File " + i + ":" + files[i].getName());
                addItem(storageIndex++, files[i].getName());
            }
        } else {
            addItem(0,"There are no podcasts in the podcast directory or you have not given the app permission to access external storage");
        }

    }

    private static void addItem(int id, String item){
        PodCastItem fullitem = new PodCastItem(id, item,"");
        ITEMS.add(fullitem);
        ITEM_MAP.put(fullitem.id, fullitem);
    }


    public static class PodCastItem {
        public final String id;
        public final String content;
        public final String details;

        public PodCastItem(int id, String content, String details) {
            this.id = ""+id;
            this.content = content;
            this.details = details;
        }

        @Override
        public String toString() {
            return content;
        }
    }
}

@@ -1162,24 +1162,152 @@
           %7D%0A
+            if (storageIndex == 0) %7B%0A                addItem(0,%22There are no podcasts in the podcast directory%22);%0A            %7D%0A
         %7D el

Handle empty podcast directory