// Path: app/src/main/java/com/mitechlt/tvportal/play/databases/FavoritesTable.java
// public class FavoritesTable extends SQLiteOpenHelper {
// 
//     public static final String TABLE_FAVORITES = "favorites";
//     public static final String COLUMN_ID = "_id";
//     public static final String COLUMN_TYPE = "type";
//     public static final String COLUMN_TITLE = "title";
//     public static final String COLUMN_LINK = "link";
//     public static final String COLUMN_IMAGE = "image";
//     public static final String COLUMN_RATING = "rating";
// 
//     private static final String DATABASE_NAME = "favorites.db";
//     private static final int DATABASE_VERSION = 3;
// 
//     private static final String DATABASE_CREATE = "create table "
//             + TABLE_FAVORITES + "("
//             + COLUMN_ID + " integer primary key autoincrement, "
//             + COLUMN_TITLE + " text not null, "
//             + COLUMN_LINK + " text not null, "
//             + COLUMN_IMAGE + " text not null, "
//             + COLUMN_TYPE + " text not null, "
//             + COLUMN_RATING + " integer);";
// 
//     public FavoritesTable(Context context) {
//         super(context, DATABASE_NAME, null, DATABASE_VERSION);
//     }
// 
//     @Override
//     public void onCreate(SQLiteDatabase database) {
//         database.execSQL(DATABASE_CREATE);
//     }
// 
//     @Override
//     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//         Log.w(FavoritesTable.class.getName(),
//                 "Upgrading database from version " + oldVersion + " to "
//                         + newVersion + ", which will destroy all old data"
//         );
//         db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
//         onCreate(db);
//     }
// 
// }


import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.mitechlt.tvportal.play.R;
import com.mitechlt.tvportal.play.databases.FavoritesTable;
import com.squareup.picasso.Picasso;
        mData = new DataHolder[getCount()];
        getColumnIndices(mFavouriteCursor);

        Resources res = mContext.getResources();

        for (int i = 0; i < getCount(); i++) {

            mFavouriteCursor.moveToPosition(i);

            mData[i] = new DataHolder();
            mData[i].title = mFavouriteCursor.getString(mTitleIdx);

            String type = mFavouriteCursor.getString(mTypeIdx);
            if (type != null && type.equals("movie")) {
                mData[i].typeBackgroundColor = res.getColor(R.color.holo_blue);
                type = "Movie";
            }
            if (type != null && type.equals("tvshow")) {
                mData[i].typeBackgroundColor = res.getColor(R.color.holo_green);
                type = "TV Show";

            }
            mData[i].type = type;
            mData[i].imgUri = mFavouriteCursor.getString(mImageIdx);

        }
    }

    private void getColumnIndices(Cursor cursor) {
        if (cursor != null && !cursor.isClosed()) {
// Path: app/src/main/java/com/mitechlt/tvportal/play/databases/FavoritesTable.java
// public class FavoritesTable extends SQLiteOpenHelper {
// 
//     public static final String TABLE_FAVORITES = "favorites";
//     public static final String COLUMN_ID = "_id";
//     public static final String COLUMN_TYPE = "type";
//     public static final String COLUMN_TITLE = "title";
//     public static final String COLUMN_LINK = "link";
//     public static final String COLUMN_IMAGE = "image";
//     public static final String COLUMN_RATING = "rating";
// 
//     private static final String DATABASE_NAME = "favorites.db";
//     private static final int DATABASE_VERSION = 3;
// 
//     private static final String DATABASE_CREATE = "create table "
//             + TABLE_FAVORITES + "("
//             + COLUMN_ID + " integer primary key autoincrement, "
//             + COLUMN_TITLE + " text not null, "
//             + COLUMN_LINK + " text not null, "
//             + COLUMN_IMAGE + " text not null, "
//             + COLUMN_TYPE + " text not null, "
//             + COLUMN_RATING + " integer);";
// 
//     public FavoritesTable(Context context) {
//         super(context, DATABASE_NAME, null, DATABASE_VERSION);
//     }
// 
//     @Override
//     public void onCreate(SQLiteDatabase database) {
//         database.execSQL(DATABASE_CREATE);
//     }
// 
//     @Override
//     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//         Log.w(FavoritesTable.class.getName(),
//                 "Upgrading database from version " + oldVersion + " to "
//                         + newVersion + ", which will destroy all old data"
//         );
//         db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
//         onCreate(db);
//     }
// 
// }


// Path: app/src/main/java/com/mitechlt/tvportal/play/adapters/FavoriteAdapter.java
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.mitechlt.tvportal.play.R;
import com.mitechlt.tvportal.play.databases.FavoritesTable;
import com.squareup.picasso.Picasso;

        mData = new DataHolder[getCount()];
        getColumnIndices(mFavouriteCursor);

        Resources res = mContext.getResources();

        for (int i = 0; i < getCount(); i++) {

            mFavouriteCursor.moveToPosition(i);

            mData[i] = new DataHolder();
            mData[i].title = mFavouriteCursor.getString(mTitleIdx);

            String type = mFavouriteCursor.getString(mTypeIdx);
            if (type != null && type.equals("movie")) {
                mData[i].typeBackgroundColor = res.getColor(R.color.holo_blue);
                type = "Movie";
            }
            if (type != null && type.equals("tvshow")) {
                mData[i].typeBackgroundColor = res.getColor(R.color.holo_green);
                type = "TV Show";

            }
            mData[i].type = type;
            mData[i].imgUri = mFavouriteCursor.getString(mImageIdx);

        }
    }

    private void getColumnIndices(Cursor cursor) {
        if (cursor != null && !cursor.isClosed()) {
            mTitleIdx = cursor.getColumnIndexOrThrow(FavoritesTable.COLUMN_TITLE);