package com.michaldabski.fileexplorer.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;

import com.michaldabski.fileexplorer.R;
import com.michaldabski.fileexplorer.favourites.FavouriteFolder;
import com.michaldabski.msqlite.MSQLiteOpenHelper;

public class SQLiteHelper extends MSQLiteOpenHelper
{
	private static final String DB_NAME = "file_manager.db";
	private static final int DB_VERSION = 1;
	
	private final Context context;

	public SQLiteHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION,
				new Class[] { FavouriteFolder.class });
		this.context = context;
	}
	
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		super.onCreate(db);
		
		for (FavouriteFolder favouriteFolder : new FavouriteFolder[]{
				new FavouriteFolder(Environment.getExternalStorageDirectory(), getString(R.string.sd_card)),
				new FavouriteFolder(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), getString(R.string.music)),
				new FavouriteFolder(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), getString(R.string.music)),
				new FavouriteFolder(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), getString(R.string.photos)),
		})
		{
			if (favouriteFolder.exists())
				insert(db, favouriteFolder);
		}
		
	}
	
	protected String getString(int res)
	{
		return context.getString(res);
	}

}

@@ -40,16 +40,68 @@
 qlite;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import a
@@ -124,16 +124,16 @@
 ontext;%0A
-
 import a
@@ -794,13 +794,13 @@
 %09%0A%09%09
-for (
+List%3C
 Favo
@@ -810,16 +810,17 @@
 teFolder
+%3E
  favouri
@@ -831,15 +831,26 @@
 lder
- :
+s =
  new 
+ArrayList%3C
 Favo
@@ -864,16 +864,104 @@
 lder
-%5B%5D%7B%0A%09%09%09%09
+%3E();%0A%09%09if (Environment.getExternalStorageDirectory().isDirectory())%0A%09%09%7B%0A%09%09%09favouriteFolders.add(
 new 
@@ -1047,22 +1047,145 @@
 d_card))
-,
+);
 %0A%09%09%09
-%09
+if (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).isDirectory())%0A%09%09%09%09favouriteFolders.add(
 new Favo
@@ -1294,38 +1294,157 @@
 R.string.music))
-,
+);
 %0A%09%09%09
-%09
+if (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).isDirectory())%0A%09%09%09%09favouriteFolders.add(
 new FavouriteFol
@@ -1549,22 +1549,140 @@
 .music))
-,%0A%09%09%09%09
+);%0A%09%09%09if (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).isDirectory())%0A%09%09%09%09favouriteFolders.add(
 new Favo
@@ -1799,13 +1799,203 @@
 os))
-,
+);
 %0A%09%09%7D
+%0A%09%09else favouriteFolders.add(new FavouriteFolder(Environment.getExternalStoragePublicDirectory(%22/%22), getString(R.string.root)));%0A%09%09%0A%09%09for (FavouriteFolder favouriteFolder : favouriteFolders
 )%0A%09%09

Add only root folder is sdcard is not detected