package com.hc.webapp;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

public class GetSXHeZiParam {
    private Context context;
    private static GetSXHeZiParam instance;

    public static GetSXHeZiParam getInstance(Context context){
        if(instance == null){
            instance = new GetSXHeZiParam(context);
        }
        return instance;
    }

    public GetSXHeZiParam(Context context){
        this.context = context;
    }

    public String getUserName(){
        try{
            Uri queryUri = Uri.parse("content://stbauthinfo/authentication/");
            Cursor cursor = context.getContentResolver().query(queryUri,new String[]{"value"},"name='username'",null,null);
            if(cursor == null){
                return "";
            }
            cursor.moveToFirst();
            String userName = cursor.getString(cursor.getColumnIndexOrThrow("value"));
            cursor.close();
            return userName;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }



    public String getUserToken(){
        try{
            Uri queryUri = Uri.parse("content://stbauthinfo/authentication/");
            Cursor cursor = context.getContentResolver().query(queryUri,new String[]{"value"},"name='user_token'",null,null);
            if(cursor == null){
                return "";
            }
            cursor.moveToFirst();
            String userToken = cursor.getString(cursor.getColumnIndexOrThrow("value"));
            cursor.close();
            return userToken;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }

    public String getUserEpgServer(){
        try{
            Uri queryUri = Uri.parse("content://stbauthinfo/authentication/");
            Cursor cursor = context.getContentResolver().query(queryUri,new String[]{"value"},"name='epg_server'",null,null);
            if(cursor == null){
                return "";
            }
            cursor.moveToFirst();
            String epgServer = cursor.getString(cursor.getColumnIndexOrThrow("value"));
            cursor.close();
            return epgServer;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }
}
