diff options
author | David Luhmer <david-dev@live.de> | 2018-07-12 22:18:09 +0300 |
---|---|---|
committer | David Luhmer <david-dev@live.de> | 2018-07-12 22:18:09 +0300 |
commit | afa43059481beb86bd27920deae864136e05de8b (patch) | |
tree | 12f8349e6c0e030394e39fe5bbb664a8b364cdba /News-Android-App | |
parent | 4ea52ce24a5f641ff0578f01eee1bc4544d0fe51 (diff) |
Search in both read and unread items / small fixes
Diffstat (limited to 'News-Android-App')
-rw-r--r-- | News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java | 31 | ||||
-rw-r--r-- | News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/Search.java | 32 |
2 files changed, 30 insertions, 33 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java index 37e702ad..fd78fd70 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java @@ -18,7 +18,6 @@ import java.util.List; import de.greenrobot.dao.query.LazyList; import de.greenrobot.dao.query.WhereCondition; import de.luhmer.owncloudnewsreader.Constants; -import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemView; import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemViewDao; import de.luhmer.owncloudnewsreader.database.model.DaoSession; import de.luhmer.owncloudnewsreader.database.model.Feed; @@ -536,23 +535,31 @@ public class DatabaseConnectionOrm { else if(ID_FOLDER == ALL_STARRED_ITEMS.getValue()) buildSQL += " WHERE " + RssItemDao.Properties.Starred_temp.columnName + " = 1"; - buildSQL += " ORDER BY " + RssItemDao.Properties.PubDate.columnName + " " + sortDirection.toString(); - return buildSQL; } - public String getAllItemsIdsForFolderSQLFilteredByTitle(final long ID_FOLDER, final boolean onlyUnread, final SORT_DIRECTION sortDirection, final String searchString) { - String buildSQL = getAllItemsIdsForFolderSQL(ID_FOLDER, onlyUnread, sortDirection); - return new StringBuilder( - buildSQL).insert(buildSQL.indexOf("ORDER"), " AND " + RssItemDao.Properties.Title.columnName + " LIKE \"%" + searchString + "%\" ").toString(); - } + public String getAllItemsIdsForFolderSQLSearch(long ID_FOLDER, SORT_DIRECTION sortDirection, String searchPredicate, String searchString) { + String buildSQL = "SELECT " + RssItemDao.Properties.Id.columnName + + " FROM " + RssItemDao.TABLENAME; - public String getAllItemsIdsForFolderSQLFilteredByBody(final long ID_FOLDER, final boolean onlyUnread, final SORT_DIRECTION sortDirection, final String searchString) { - String buildSQL = getAllItemsIdsForFolderSQL(ID_FOLDER, onlyUnread, sortDirection); - return new StringBuilder( - buildSQL).insert(buildSQL.indexOf("ORDER"), " AND " + RssItemDao.Properties.Title.columnName + " LIKE \"%" + searchString + "%\" ").toString(); + if (!(ID_FOLDER == ALL_UNREAD_ITEMS.getValue() || ID_FOLDER == ALL_STARRED_ITEMS.getValue()) || ID_FOLDER == ALL_ITEMS.getValue())//Wenn nicht Alle Artikel ausgewaehlt wurde (-10) oder (-11) fuer Starred Feeds + { + buildSQL += " WHERE " + RssItemDao.Properties.FeedId.columnName + " IN " + + "(SELECT sc." + FeedDao.Properties.Id.columnName + + " FROM " + FeedDao.TABLENAME + " sc " + + " JOIN " + FolderDao.TABLENAME + " f ON sc." + FeedDao.Properties.FolderId.columnName + " = f." + FolderDao.Properties.Id.columnName + + " WHERE f." + FolderDao.Properties.Id.columnName + " = " + ID_FOLDER + ") AND "; + } else { + buildSQL += " WHERE "; + } + + buildSQL += searchPredicate + " LIKE \"%" + searchString + "%\""; + + buildSQL += " ORDER BY " + RssItemDao.Properties.PubDate.columnName + " " + sortDirection.toString(); + + return buildSQL; } public void insertIntoRssCurrentViewTable(String SQL_SELECT) { diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/Search.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/Search.java index 31135a27..6782d72c 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/Search.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/Search.java @@ -4,41 +4,34 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import java.util.ArrayList; import java.util.List; -import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter; import de.luhmer.owncloudnewsreader.NewsDetailActivity; import de.luhmer.owncloudnewsreader.SettingsActivity; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; import de.luhmer.owncloudnewsreader.database.model.RssItem; +import de.luhmer.owncloudnewsreader.database.model.RssItemDao; public class Search { private static final String SEARCH_IN_TITLE = "0"; private static final String SEARCH_IN_BODY = "1"; - + public static List<RssItem> PerformSearch(Context context, Long idFolder, Long idFeed, String searchString) { DatabaseConnectionOrm.SORT_DIRECTION sortDirection = NewsDetailActivity.getSortDirectionFromSettings(context); DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context); - - boolean onlyUnreadItems = mPrefs.getBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, false); - boolean onlyStarredItems = false; - String sqlSelectStatement = null; if (idFeed != null) { - sqlSelectStatement = getFeedSQLStatement(idFeed, onlyUnreadItems, onlyStarredItems, sortDirection, searchString, dbConn, mPrefs); - + sqlSelectStatement = getFeedSQLStatement(idFeed, sortDirection, searchString, dbConn, mPrefs); } else if (idFolder != null) { - if (idFolder == SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_STARRED_ITEMS.getValue()) { - onlyUnreadItems = false; - } - sqlSelectStatement = getFolderSQLStatement(idFolder, onlyUnreadItems, sortDirection, searchString, dbConn, mPrefs); + sqlSelectStatement = getFolderSQLStatement(idFolder, sortDirection, searchString, dbConn, mPrefs); } - List<RssItem> items = null; - if (!sqlSelectStatement.equals("")) { + List<RssItem> items = new ArrayList<>(); + if (sqlSelectStatement != null) { dbConn.insertIntoRssCurrentViewTable(sqlSelectStatement); items = dbConn.getCurrentRssItemView(0); } @@ -49,8 +42,6 @@ public class Search { private static String getFeedSQLStatement(final long idFeed, - final boolean onlyUnreadItems, - final boolean onlyStarredItems, final DatabaseConnectionOrm.SORT_DIRECTION sortDirection, final String searchString, final DatabaseConnectionOrm dbConn, @@ -58,15 +49,14 @@ public class Search { String sql = ""; String searchIn = mPrefs.getString(SettingsActivity.SP_SEARCH_IN,"0"); if(searchIn.equals(SEARCH_IN_TITLE)) { - sql = dbConn.getAllItemsIdsForFeedSQLFilteredByTitle(idFeed, onlyUnreadItems, onlyStarredItems, sortDirection, searchString); + sql = dbConn.getAllItemsIdsForFeedSQLFilteredByTitle(idFeed, false, false, sortDirection, searchString); } else if(searchIn.equals(SEARCH_IN_BODY)) { - sql = dbConn.getAllItemsIdsForFeedSQLFilteredByBodySQL(idFeed, onlyUnreadItems, onlyStarredItems, sortDirection, searchString); + sql = dbConn.getAllItemsIdsForFeedSQLFilteredByBodySQL(idFeed, false, false, sortDirection, searchString); } return sql; } private static String getFolderSQLStatement(final long ID_FOLDER, - final boolean onlyUnreadItems, final DatabaseConnectionOrm.SORT_DIRECTION sortDirection, final String searchString, final DatabaseConnectionOrm dbConn, @@ -74,9 +64,9 @@ public class Search { String sql = ""; String searchIn = mPrefs.getString(SettingsActivity.SP_SEARCH_IN,"0"); if(searchIn.equals(SEARCH_IN_TITLE)) { - sql = dbConn.getAllItemsIdsForFolderSQLFilteredByTitle(ID_FOLDER, onlyUnreadItems, sortDirection, searchString); + sql = dbConn.getAllItemsIdsForFolderSQLSearch(ID_FOLDER, sortDirection, RssItemDao.Properties.Title.columnName, searchString); } else if(searchIn.equals(SEARCH_IN_BODY)) { - sql = dbConn.getAllItemsIdsForFolderSQLFilteredByBody(ID_FOLDER, onlyUnreadItems, sortDirection, searchString); + sql = dbConn.getAllItemsIdsForFolderSQLSearch(ID_FOLDER, sortDirection, RssItemDao.Properties.Body.columnName, searchString); } return sql; |