package com.icaynia.soundki.Data;

import android.content.Context;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;

import com.icaynia.soundki.Model.PlayList;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * Created by icaynia on 01/03/2017.
 */

public class FileManager
{
    public Context context;
    public String TAG = "FileManager";

    String dirPath;

    public FileManager(Context context)
    {
        init();
    }

    public void init()
    {
        dirPath = context.getFilesDir().getPath();
        File file = new File(dirPath);
        if( !file.exists() ) {
            file.mkdirs();
        }
        file = new File(dirPath+"/playlist");
        if( !file.exists() ) {
            file.mkdirs();
        }
    }

    public void savePlaylist(PlayList playlist)
    {
        try
        {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("dg.ser"));
            oos.writeObject(playlist);
            oos.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}


@@ -893,32 +893,324 @@
 playlist)%0A    %7B%0A
+        String filename = playlist.getName();%0A        if (isFileAvailable(filename))%0A        %7B%0A            Log.e(TAG, %22File is already created%22);%0A            return;%0A        %7D%0A        if (playlist.getName().equals(%22%22))%0A        %7B%0A            Log.e(TAG, %22Playlist name isn't set.%22);%0A        %7D%0A%0A
         try%0A    
@@ -1205,16 +1205,16 @@
     try%0A
-
         
@@ -1469,11 +1469,202 @@
 %7D%0A    %7D%0A
-%7D
+%0A    public boolean isFileAvailable(String file)%0A    %7B%0A        File tmpFile = new File(file);%0A        if( tmpFile.exists() ) %7B%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%7D%0A
 %0A%0A

Add saveplaylist