package app.mar.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;

import app.mar.activities.ImageViewerActivity;
import app.mar.activities.MediaViewerAcitvity;
import app.mar.activities.ModelViewerActivity;
import app.mar.game.Game;
import app.mar.game.Resource;
import min3d.core.Object3d;
import min3d.parser.IParser;
import min3d.parser.Parser;

/**
 * Created by ptitcois on 14/03/17.
 */
public class AndroidResources {
    public static Object3d getModel(Activity context, String name)
    {
        IParser myParser = Parser.createParser(context, Parser.Type.OBJ, context.getResources(), "app.brest.testmin3d:raw/"+name+"_obj",true);
        myParser.parse();
        return myParser.getParsedObject();
    }

    private static Uri _getAudioVideo(String name, String suffix)
    {
        String path="android.resource://app.brest.testmin3d/raw/"+name+"_"+suffix;
        return Uri.parse(path);
    }

    public static Uri getVideo(String name)
    {
        return _getAudioVideo(name, "video");
    }


    public static Uri getAudio(String name)
    {
        return _getAudioVideo(name, "audio");
    }

    public static Drawable getImage()
    {
        return null;
    }


    public static Intent getViewerIntent(Context c, Resource re)
    {
        Intent intent =null ;
        if(re.isAudio() || re.isVideo())
            intent = new Intent(c, MediaViewerAcitvity.class);
        else if(re.is3D())
            intent= new Intent(c, ModelViewerActivity.class);
        else if(re.isImage())
            intent= new Intent(c, ImageViewerActivity.class);

        intent.putExtra("resource", re);

        return intent;
    }



    public static Intent getMapIntent(Context c, Game g)
    {
        Intent intent = new Intent(c, ImageViewerActivity.class);
        intent.putExtra("map", g.getName()+"_map");
        return intent;
    }
    //ImageViewerActivity.class
}
