package com.example.reproductordelistasmultimedia;

import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.HashMap;

public class ListaCanalesTv extends ListActivity {

    private String [] listaCanales = new String [] {"Canal 16 Tv","Canal Oasis Tv","Canal Magazine","Canal 26 Tv","Canal Todonoticias TN","Canal Vale Tv","Canal HCH Tv","Canal Rural","Canal 13 Digital","Alfa Tv"};
    private String [] listaCanalesGlobal = new String [] {"Canal 16 Tv","Canal Oasis Tv","Canal Magazine","Canal 26 Tv","Canal Todonoticias TN","Canal Vale Tv","Canal HCH Tv","Canal Rural","Canal 13 Digital","Alfa Tv","vercanalestv.com","Eurosport"};
    private static String LINK;
    // Preferencias
    SharedPreferences prefs;

    @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listacanales);

        // Activar las Preferencias
        prefs = PreferenceManager.getDefaultSharedPreferences(this);

        RellenarListView();
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onListItemClick(ListView listView, View view, int position, long id)
    {
        super.onListItemClick(listView, view, position, id);

            switch (position) {
                case 0:
                    LINK = "rtsp://mek2.mekstream.com:1935/noticias16/live3";
                    break; // Funciona (Canal 16 Tv)
                case 1:
                    LINK = "rtsp://edge.wms28.lorini.net/oasistv/oasistv";
                    break; // Funciona (Canal Oasis Tv)
                case 2:
                    LINK = "rtsp://stream.mgzn.tv/live/mgzntv/mgzntv";
                    break; // Funciona (Canal Magazine Tv)
                case 3:
                    LINK = "rtsp://live-edge01.telecentro.net.ar:80/live/26hd-720";
                    break; // Funciona (Canal 26 Tv)
                case 4:
                    LINK = "rtsp://stream.tn.com.ar/live/tnhd1";
                    break; // Funciona (Canal TodoNoticias TN)
                case 5:
                    LINK = "rtsp://edge.wms28.lorini.net/valetv/valetv";
                    break; // Funciona (Canal Vale Tv)
                case 6:
                    LINK = "rtsp://4.31.30.140:1935/live/hchtvdigital";
                    break; // Funciona (Canal HCH Tv)
                case 7:
                    LINK = "rtsp://streamrural.cmd.com.ar:554/liverural/crural/rural3";
                    break; // Funciona (Canal Rural)
                case 8:
                    LINK = "rtsp://stream.eltrecetv.com.ar/live13/13tv/13tv1";
                    break; //Funciona (Canal 13 Digital)
                case 9:
                    LINK = "rtsp://streamer1.streamhost.org:1935/salive/GMIalfah";
                    break; //Funciona (Alfa Tv)
                case 10:
                    LINK = "http://www.vercanalestv.com/category/canales-de-espana/";
                    break; // (Web vercanalestv.com)
                case 11:
                    LINK = "file:///android_asset/EjemploFicheroWeb.html";
                    break; //  (Eurosport)
            }

        // Código para diferenciar que clase cargar.
        if  (position >= 0  && position<=9) {
            if (prefs.getBoolean("miracast", true)) {
                Intent intent = new Intent(this, Streamingtv_miracast.class);
                this.startActivity(intent);
                Toast.makeText(this, "Selección: Canal nº " + Integer.toString(position + 1), Toast.LENGTH_LONG).show();
            }
            else
            {
                Intent intent = new Intent(this, Streamingtv_simple.class);
                this.startActivity(intent);
                Toast.makeText(this, "Selección: Canal nº " + Integer.toString(position + 1), Toast.LENGTH_LONG).show();
            }
        }
        if  (position >= 10) {
            Intent intent = new Intent(this, StreamingWebView.class);
            this.startActivity(intent);
            Toast.makeText(this, "Visor canales tv, solo pantalla única", Toast.LENGTH_LONG).show();
        }
    }

    // Método para establecer el enlace en la clase Videoplayer
    public static String setEnlaceTv() {
        Log.d("Videoplayer_tvOnline", "setEnlaceTv");
        return LINK;
    }

    private void RellenarListView() {
        if (prefs.getBoolean("canales", true)) {
            setListAdapter(new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1,
                    listaCanalesGlobal));
        }
        else {
            setListAdapter(new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1,
                    listaCanales));
        }

    }


}

