11 package com.freerdp.freerdpcore.services;
13 import android.database.Cursor;
14 import android.database.SQLException;
15 import android.database.sqlite.SQLiteDatabase;
16 import android.database.sqlite.SQLiteException;
17 import android.database.sqlite.SQLiteOpenHelper;
18 import android.util.Log;
20 import com.freerdp.freerdpcore.domain.BookmarkBase;
21 import com.freerdp.freerdpcore.domain.QuickConnectBookmark;
23 import java.util.ArrayList;
27 private final static String TAG =
"QuickConnectHistoryGateway";
28 private SQLiteOpenHelper historyDB;
32 this.historyDB = historyDB;
35 public ArrayList<BookmarkBase> findHistory(String filter)
37 String[] column = {
HistoryDB.QUICK_CONNECT_TABLE_COL_ITEM };
39 SQLiteDatabase db = getReadableDatabase();
42 ? (
HistoryDB.QUICK_CONNECT_TABLE_COL_ITEM +
" LIKE '%" + filter +
"%'")
44 Cursor cursor = db.query(
HistoryDB.QUICK_CONNECT_TABLE_NAME, column, selection,
null,
null,
45 null,
HistoryDB.QUICK_CONNECT_TABLE_COL_TIMESTAMP);
47 ArrayList<BookmarkBase> result =
new ArrayList<>(cursor.getCount());
48 if (cursor.moveToFirst())
53 cursor.getString(cursor.getColumnIndex(
HistoryDB.QUICK_CONNECT_TABLE_COL_ITEM));
55 bookmark.setLabel(hostname);
56 bookmark.setHostname(hostname);
58 }
while (cursor.moveToNext());
64 public void addHistoryItem(String item)
66 String insertHistoryItem =
"INSERT OR REPLACE INTO " +
HistoryDB.QUICK_CONNECT_TABLE_NAME +
67 " (" +
HistoryDB.QUICK_CONNECT_TABLE_COL_ITEM +
", " +
68 HistoryDB.QUICK_CONNECT_TABLE_COL_TIMESTAMP +
") VALUES('" +
69 item +
"', datetime('now'))";
70 SQLiteDatabase db = getWritableDatabase();
73 db.execSQL(insertHistoryItem);
75 catch (SQLException e)
77 Log.v(TAG, e.toString());
81 public boolean historyItemExists(String item)
83 String[] column = {
HistoryDB.QUICK_CONNECT_TABLE_COL_ITEM };
84 SQLiteDatabase db = getReadableDatabase();
85 Cursor cursor = db.query(
HistoryDB.QUICK_CONNECT_TABLE_NAME, column,
86 HistoryDB.QUICK_CONNECT_TABLE_COL_ITEM +
" = '" + item +
"'",
null,
88 boolean exists = (cursor.getCount() == 1);
93 public void removeHistoryItem(String hostname)
95 SQLiteDatabase db = getWritableDatabase();
96 db.delete(
HistoryDB.QUICK_CONNECT_TABLE_NAME,
97 HistoryDB.QUICK_CONNECT_TABLE_COL_ITEM +
" = '" + hostname +
"'",
null);
103 private SQLiteDatabase getWritableDatabase()
105 return historyDB.getWritableDatabase();
108 private SQLiteDatabase getReadableDatabase()
113 db = historyDB.getReadableDatabase();
115 catch (SQLiteException e)
117 db = historyDB.getWritableDatabase();