// Path: app/src/main/java/info/curtbinder/reefangel/db/NotificationTable.java
// public class NotificationTable {
// 	// Database constants
// 	public static final String TABLE_NAME = "notifications";
// 	// columns
// 	public static final String COL_ID = "_id";
// 	public static final String COL_PARAM = "param";
// 	public static final String COL_CONDITION = "condition";
// 	public static final String COL_VALUE = "value";
// 
// 	private static final String CREATE_TABLE =
// 			"CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" + COL_ID
// 					+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_PARAM
// 					+ " INTEGER, " + COL_CONDITION + " INTEGER, " + COL_VALUE
// 					+ " TEXT);";
// 	private static final String DROP_TABLE = "DROP TABLE IF EXISTS "
// 												+ TABLE_NAME;
// 
// 	public static void onCreate ( SQLiteDatabase db ) {
// 		db.execSQL( CREATE_TABLE );
// 	}
// 
// 	public static void onUpgrade (
// 			SQLiteDatabase db,
// 			int oldVersion,
// 			int newVersion ) {
//         int curVer = oldVersion;
//         while ( curVer < newVersion ) {
//             curVer++;
//             switch (curVer) {
//                 default:
//                     break;
//                 case 6:
//                     upgradeToVersion6(db);
//                     break;
//             }
//         }
// 	}
// 
//     private static void upgradeToVersion6 ( SQLiteDatabase db ) {
//         // table did no exist prior to version 6, so just drop it as a safety precaution
//         // then create it
//         dropTable(db);
//         onCreate(db);
//     }
// 
// 	private static void dropTable ( SQLiteDatabase db ) {
// 		db.execSQL( DROP_TABLE );
// 	}
// 
// 	public static void onDowngrade (
// 			SQLiteDatabase db,
// 			int oldVersion,
// 			int newVersion ) {
//         int curVer = oldVersion;
//         while ( curVer > newVersion ) {
//             curVer--;
//             switch ( curVer ) {
//                 default:
//                     break;
//                 case 5:
//                 case 4:
//                 case 3:
//                 case 2:
//                 case 1:
//                     // drop the table if the downgraded version is less than 6
//                     dropTable(db);
//                     break;
//             }
//         }
// 	}
// }


import android.view.ViewGroup;
import android.widget.TextView;
import java.util.Locale;
import info.curtbinder.reefangel.db.NotificationTable;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 Curt Binder
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package info.curtbinder.reefangel.phone;




/**
 * Created by binder on 3/23/14.
 */

public class NotificationListCursorAdapter extends CursorAdapter {

    static private String[] deviceParameters;
    static private String[] notifyConditions;
    private final int LAYOUT = R.layout.frag_notification_item;

    public NotificationListCursorAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);
        final Resources r = context.getResources();
        deviceParameters = r.getStringArray(R.array.deviceParameters);
        notifyConditions = r.getStringArray(R.array.notifyConditions);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        final ViewHolder vh = (ViewHolder) view.getTag();
        setViews(vh, cursor);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(LAYOUT, parent, false);
        ViewHolder vh = new ViewHolder();
        vh.item = (TextView) v.findViewById(R.id.notification_item);
        setViews(vh, cursor);
        v.setTag(vh);
        return v;
    }

    private void setViews(ViewHolder v, Cursor c) {
// Path: app/src/main/java/info/curtbinder/reefangel/db/NotificationTable.java
// public class NotificationTable {
// 	// Database constants
// 	public static final String TABLE_NAME = "notifications";
// 	// columns
// 	public static final String COL_ID = "_id";
// 	public static final String COL_PARAM = "param";
// 	public static final String COL_CONDITION = "condition";
// 	public static final String COL_VALUE = "value";
// 
// 	private static final String CREATE_TABLE =
// 			"CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" + COL_ID
// 					+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_PARAM
// 					+ " INTEGER, " + COL_CONDITION + " INTEGER, " + COL_VALUE
// 					+ " TEXT);";
// 	private static final String DROP_TABLE = "DROP TABLE IF EXISTS "
// 												+ TABLE_NAME;
// 
// 	public static void onCreate ( SQLiteDatabase db ) {
// 		db.execSQL( CREATE_TABLE );
// 	}
// 
// 	public static void onUpgrade (
// 			SQLiteDatabase db,
// 			int oldVersion,
// 			int newVersion ) {
//         int curVer = oldVersion;
//         while ( curVer < newVersion ) {
//             curVer++;
//             switch (curVer) {
//                 default:
//                     break;
//                 case 6:
//                     upgradeToVersion6(db);
//                     break;
//             }
//         }
// 	}
// 
//     private static void upgradeToVersion6 ( SQLiteDatabase db ) {
//         // table did no exist prior to version 6, so just drop it as a safety precaution
//         // then create it
//         dropTable(db);
//         onCreate(db);
//     }
// 
// 	private static void dropTable ( SQLiteDatabase db ) {
// 		db.execSQL( DROP_TABLE );
// 	}
// 
// 	public static void onDowngrade (
// 			SQLiteDatabase db,
// 			int oldVersion,
// 			int newVersion ) {
//         int curVer = oldVersion;
//         while ( curVer > newVersion ) {
//             curVer--;
//             switch ( curVer ) {
//                 default:
//                     break;
//                 case 5:
//                 case 4:
//                 case 3:
//                 case 2:
//                 case 1:
//                     // drop the table if the downgraded version is less than 6
//                     dropTable(db);
//                     break;
//             }
//         }
// 	}
// }


// Path: app/src/main/java/info/curtbinder/reefangel/phone/NotificationListCursorAdapter.java
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.Locale;
import info.curtbinder.reefangel.db.NotificationTable;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 Curt Binder
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package info.curtbinder.reefangel.phone;




/**
 * Created by binder on 3/23/14.
 */

public class NotificationListCursorAdapter extends CursorAdapter {

    static private String[] deviceParameters;
    static private String[] notifyConditions;
    private final int LAYOUT = R.layout.frag_notification_item;

    public NotificationListCursorAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);
        final Resources r = context.getResources();
        deviceParameters = r.getStringArray(R.array.deviceParameters);
        notifyConditions = r.getStringArray(R.array.notifyConditions);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        final ViewHolder vh = (ViewHolder) view.getTag();
        setViews(vh, cursor);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(LAYOUT, parent, false);
        ViewHolder vh = new ViewHolder();
        vh.item = (TextView) v.findViewById(R.id.notification_item);
        setViews(vh, cursor);
        v.setTag(vh);
        return v;
    }

    private void setViews(ViewHolder v, Cursor c) {
        int param = c.getInt(c.getColumnIndex(NotificationTable.COL_PARAM));