// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/models/Application.java
// @DatabaseTable(tableName = "Applications", daoClass = ApplicationDaoImpl.class)
// public class Application {
//     public static final String FIELD_TABLE_NAME = "Applications";
//     public static final String FIELD_PACKAGE_NAME = "PackageName";
//     public static final String FIELD_IGNORE = "Ignore";
// 
//     @DatabaseField(columnName = FIELD_PACKAGE_NAME, id = true, generatedId = false)
//     private String PackageName;
//     @DatabaseField(columnName = FIELD_IGNORE, canBeNull = false)
//     private Boolean Ignore;
// 
//     public Application() {
//         //ORMLite needs a no-arg constructor.
//     }
// 
//     public Application(String packageName, Boolean ignore) {
//         this.PackageName = packageName;
//         this.Ignore = ignore;
//     }
// 
//     public String getPackageName() {
//         return PackageName;
//     }
// 
//     public void setPackageName(String packageName) {
//         PackageName = packageName;
//     }
// 
//     public Boolean getIgnore() {
//         return Ignore;
//     }
// 
//     public void setIgnore(Boolean ignore) {
//         Ignore = ignore;
//     }
// }
// 
// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/models/ApplicationDao.java
// public interface ApplicationDao extends Dao<Application, String> {
//     public List<Application> getIgnoredApps() throws SQLException;
// 
// }
// 
// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/models/DatabaseHelper.java
// public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
//     private static final String DATABASE_NAME = "notifications.db";
// 
//     private static final int DATABASE_VERSION = 2;
// 
//     private ApplicationDao applicationDao = null;
//     private NotificationItemDao notificationDao = null;
// 
//     public DatabaseHelper(Context context) {
//         super(context, DATABASE_NAME, null, DATABASE_VERSION);
//     }
// 
//     /**
//      * This is called when the database is first created. This call createTable statements here to
//      * create the tables that will store your data.
//      */
//     @Override
//     public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
//         try {
//             TableUtils.createTable(connectionSource, NotificationItem.class);
//             TableUtils.createTable(connectionSource, Application.class);
//         } catch (SQLException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int oldVersion, int newVersion) {
//         if (oldVersion < 2) {
//             // Do changes from version 1 to 2
//             try {
//                 NotificationItemDao dao = getNotificationDao();
//                 dao.executeRawNoArgs("ALTER TABLE " + NotificationItem.FIELD_TABLE_NAME + " ADD COLUMN " + NotificationItem.FIELD_MESSAGE + " TEXT");
//             } catch (SQLException e) {
//                 e.printStackTrace();
//             }
// 
//         }
// 
//         if (oldVersion < 3) {
//             // Do changes from version 2 to 3
//         }
//     }
// 
//     /**
//      * Returns the Database Access Object (DAO) for Application class. It will create it or
//      * just give the cached value.
//      */
//     public ApplicationDao getApplicationDao() throws SQLException {
//         if (applicationDao == null) {
//             applicationDao = getDao(Application.class);
//         }
//         return applicationDao;
//     }
// 
//     /**
//      * Returns the Database Access Object (DAO) for NotificationItem class. It will create it or
//      * just give the cached value.
//      */
//     public NotificationItemDao getNotificationDao() throws SQLException {
//         if (notificationDao == null) {
//             notificationDao = getDao(NotificationItem.class);
//         }
//         return notificationDao;
//     }
// 
//     /**
//      * Close the database connections and clear any cached DAOs.
//      */
//     @Override
//     public void close() {
//         super.close();
//         applicationDao = null;
//         notificationDao = null;
//     }
// }


import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.tierep.notificationanalyser.R;
import com.tierep.notificationanalyser.models.Application;
import com.tierep.notificationanalyser.models.ApplicationDao;
import com.tierep.notificationanalyser.models.DatabaseHelper;
import java.sql.SQLException;
import java.util.List;
import de.timroes.android.listview.EnhancedListView;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ignored_apps);
        getActionBar().setDisplayHomeAsUpEnabled(true);

        listView = (EnhancedListView) findViewById(R.id.list_ignored_apps);
        try {
            List<Application> applicationList = getDatabaseHelper().getApplicationDao().getIgnoredApps();
            applicationList.add(0, new Application()); // Insert empty element for header
            ignoredAppsAdapter = new ApplicationIgnoreAdapter(this, applicationList);
            listView.setAdapter(ignoredAppsAdapter);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        listView.setDismissCallback(new EnhancedListView.OnDismissCallback() {
            @Override
            public EnhancedListView.Undoable onDismiss(EnhancedListView enhancedListView, final int i) {
                final Application item = ignoredAppsAdapter.getItem(i);
                ignoredAppsAdapter.remove(item);

                return new EnhancedListView.Undoable() {
                    @Override
                    public void undo() {
                        ignoredAppsAdapter.insert(item, i);
                    }

                    @Override
                    public void discard() {
                        try {
// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/models/Application.java
// @DatabaseTable(tableName = "Applications", daoClass = ApplicationDaoImpl.class)
// public class Application {
//     public static final String FIELD_TABLE_NAME = "Applications";
//     public static final String FIELD_PACKAGE_NAME = "PackageName";
//     public static final String FIELD_IGNORE = "Ignore";
// 
//     @DatabaseField(columnName = FIELD_PACKAGE_NAME, id = true, generatedId = false)
//     private String PackageName;
//     @DatabaseField(columnName = FIELD_IGNORE, canBeNull = false)
//     private Boolean Ignore;
// 
//     public Application() {
//         //ORMLite needs a no-arg constructor.
//     }
// 
//     public Application(String packageName, Boolean ignore) {
//         this.PackageName = packageName;
//         this.Ignore = ignore;
//     }
// 
//     public String getPackageName() {
//         return PackageName;
//     }
// 
//     public void setPackageName(String packageName) {
//         PackageName = packageName;
//     }
// 
//     public Boolean getIgnore() {
//         return Ignore;
//     }
// 
//     public void setIgnore(Boolean ignore) {
//         Ignore = ignore;
//     }
// }
// 
// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/models/ApplicationDao.java
// public interface ApplicationDao extends Dao<Application, String> {
//     public List<Application> getIgnoredApps() throws SQLException;
// 
// }
// 
// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/models/DatabaseHelper.java
// public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
//     private static final String DATABASE_NAME = "notifications.db";
// 
//     private static final int DATABASE_VERSION = 2;
// 
//     private ApplicationDao applicationDao = null;
//     private NotificationItemDao notificationDao = null;
// 
//     public DatabaseHelper(Context context) {
//         super(context, DATABASE_NAME, null, DATABASE_VERSION);
//     }
// 
//     /**
//      * This is called when the database is first created. This call createTable statements here to
//      * create the tables that will store your data.
//      */
//     @Override
//     public void onCreate(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource) {
//         try {
//             TableUtils.createTable(connectionSource, NotificationItem.class);
//             TableUtils.createTable(connectionSource, Application.class);
//         } catch (SQLException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public void onUpgrade(SQLiteDatabase sqLiteDatabase, ConnectionSource connectionSource, int oldVersion, int newVersion) {
//         if (oldVersion < 2) {
//             // Do changes from version 1 to 2
//             try {
//                 NotificationItemDao dao = getNotificationDao();
//                 dao.executeRawNoArgs("ALTER TABLE " + NotificationItem.FIELD_TABLE_NAME + " ADD COLUMN " + NotificationItem.FIELD_MESSAGE + " TEXT");
//             } catch (SQLException e) {
//                 e.printStackTrace();
//             }
// 
//         }
// 
//         if (oldVersion < 3) {
//             // Do changes from version 2 to 3
//         }
//     }
// 
//     /**
//      * Returns the Database Access Object (DAO) for Application class. It will create it or
//      * just give the cached value.
//      */
//     public ApplicationDao getApplicationDao() throws SQLException {
//         if (applicationDao == null) {
//             applicationDao = getDao(Application.class);
//         }
//         return applicationDao;
//     }
// 
//     /**
//      * Returns the Database Access Object (DAO) for NotificationItem class. It will create it or
//      * just give the cached value.
//      */
//     public NotificationItemDao getNotificationDao() throws SQLException {
//         if (notificationDao == null) {
//             notificationDao = getDao(NotificationItem.class);
//         }
//         return notificationDao;
//     }
// 
//     /**
//      * Close the database connections and clear any cached DAOs.
//      */
//     @Override
//     public void close() {
//         super.close();
//         applicationDao = null;
//         notificationDao = null;
//     }
// }


// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/ui/IgnoredApps.java
import android.app.Activity;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.tierep.notificationanalyser.R;
import com.tierep.notificationanalyser.models.Application;
import com.tierep.notificationanalyser.models.ApplicationDao;
import com.tierep.notificationanalyser.models.DatabaseHelper;
import java.sql.SQLException;
import java.util.List;
import de.timroes.android.listview.EnhancedListView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ignored_apps);
        getActionBar().setDisplayHomeAsUpEnabled(true);

        listView = (EnhancedListView) findViewById(R.id.list_ignored_apps);
        try {
            List<Application> applicationList = getDatabaseHelper().getApplicationDao().getIgnoredApps();
            applicationList.add(0, new Application()); // Insert empty element for header
            ignoredAppsAdapter = new ApplicationIgnoreAdapter(this, applicationList);
            listView.setAdapter(ignoredAppsAdapter);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        listView.setDismissCallback(new EnhancedListView.OnDismissCallback() {
            @Override
            public EnhancedListView.Undoable onDismiss(EnhancedListView enhancedListView, final int i) {
                final Application item = ignoredAppsAdapter.getItem(i);
                ignoredAppsAdapter.remove(item);

                return new EnhancedListView.Undoable() {
                    @Override
                    public void undo() {
                        ignoredAppsAdapter.insert(item, i);
                    }

                    @Override
                    public void discard() {
                        try {
                            ApplicationDao dao = getDatabaseHelper().getApplicationDao();