Finish filters
This commit is contained in:
parent
3ca1e3b402
commit
a1aa96a2bd
|
@ -41,6 +41,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Spinner;
|
||||
|
@ -274,8 +275,10 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(OwnerStatusActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
dateIni = new StatusCacheDAO(OwnerStatusActivity.this, db).getSmallerDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
dateEnd = new StatusCacheDAO(OwnerStatusActivity.this, db).getGreaterDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
if( dateIni == null)
|
||||
dateIni = new StatusCacheDAO(OwnerStatusActivity.this, db).getSmallerDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
if( dateEnd == null)
|
||||
dateEnd = new StatusCacheDAO(OwnerStatusActivity.this, db).getGreaterDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
String dateInitString = Helper.shortDateToString(dateIni);
|
||||
String dateEndString = Helper.shortDateToString(dateEnd);
|
||||
|
||||
|
@ -286,7 +289,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
final CheckBox filter_visibility_public = dialogView.findViewById(R.id.filter_visibility_public);
|
||||
final CheckBox filter_visibility_unlisted = dialogView.findViewById(R.id.filter_visibility_unlisted);
|
||||
final CheckBox filter_visibility_private = dialogView.findViewById(R.id.filter_visibility_private);
|
||||
CheckBox filter_visibility_direct = dialogView.findViewById(R.id.filter_visibility_direct);
|
||||
final CheckBox filter_visibility_direct = dialogView.findViewById(R.id.filter_visibility_direct);
|
||||
|
||||
filter_visibility_public.setChecked(filterToots.isV_public());
|
||||
filter_visibility_unlisted.setChecked(filterToots.isV_unlisted());
|
||||
|
@ -303,11 +306,13 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
filter_media.setSelection(filterToots.getMedia().ordinal());
|
||||
filter_pinned.setSelection(filterToots.getPinned().ordinal());
|
||||
|
||||
final TextView filter_keywords = dialogView.findViewById(R.id.filter_keywords);
|
||||
final EditText filter_keywords = dialogView.findViewById(R.id.filter_keywords);
|
||||
|
||||
settings_time_from.setText(dateInitString);
|
||||
settings_time_to.setText(dateEndString);
|
||||
|
||||
if( filterToots.getFilter() != null)
|
||||
filter_keywords.setText(filterToots.getFilter());
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(dateIni);
|
||||
|
@ -349,12 +354,15 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
filterToots.setV_public(filter_visibility_public.isChecked());
|
||||
filterToots.setV_unlisted(filter_visibility_unlisted.isChecked());
|
||||
filterToots.setV_private(filter_visibility_private.isChecked());
|
||||
filterToots.setV_direct(filter_visibility_public.isChecked());
|
||||
filterToots.setV_direct(filter_visibility_direct.isChecked());
|
||||
|
||||
filterToots.setDateIni(Helper.dateToString(OwnerStatusActivity.this,dateIni));
|
||||
filterToots.setDateEnd(Helper.dateToString(OwnerStatusActivity.this,dateEnd));
|
||||
|
||||
filterToots.setFilter(filter_keywords.getText().toString());
|
||||
if( filter_keywords.getText() != null && filter_keywords.getText().toString().trim().length() > 0)
|
||||
filterToots.setFilter(filter_keywords.getText().toString());
|
||||
else
|
||||
filterToots.setFilter(null);
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
max_id = null;
|
||||
firstLoad = true;
|
||||
|
|
|
@ -170,32 +170,64 @@ public class StatusCacheDAO {
|
|||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
//That the basic selection for all toots
|
||||
String selection = Sqlite.COL_CACHED_ACTION + " = '" + cacheType+ "' AND " + Sqlite.COL_INSTANCE + " = '" + instance+ "' AND " + Sqlite.COL_USER_ID + " = '" + userId+ "'";
|
||||
StringBuilder selection = new StringBuilder(Sqlite.COL_CACHED_ACTION + " = '" + cacheType + "' AND " + Sqlite.COL_INSTANCE + " = '" + instance + "' AND " + Sqlite.COL_USER_ID + " = '" + userId + "'");
|
||||
if( max_id != null)
|
||||
selection += " AND " + Sqlite.COL_STATUS_ID + " < '" + max_id+ "'";
|
||||
selection.append(" AND " + Sqlite.COL_STATUS_ID + " < '").append(max_id).append("'");
|
||||
//BOOST
|
||||
if(filterToots.getBoosts() == FilterToots.typeFilter.NONE)
|
||||
selection += " AND (" + Sqlite.COL_REBLOG + " IS NULL OR "+ Sqlite.COL_REBLOG + " = 'null')";
|
||||
selection.append(" AND (" + Sqlite.COL_REBLOG + " IS NULL OR " + Sqlite.COL_REBLOG + " = 'null')");
|
||||
else if(filterToots.getBoosts() == FilterToots.typeFilter.ONLY)
|
||||
selection += " AND " + Sqlite.COL_REBLOG + " IS NOT NULL AND "+ Sqlite.COL_REBLOG + " <> 'null'";
|
||||
selection.append(" AND " + Sqlite.COL_REBLOG + " IS NOT NULL AND " + Sqlite.COL_REBLOG + " <> 'null'");
|
||||
//REPLIES
|
||||
if(filterToots.getReplies() == FilterToots.typeFilter.NONE)
|
||||
selection += " AND (" + Sqlite.COL_IN_REPLY_TO_ID + " IS NULL OR "+ Sqlite.COL_IN_REPLY_TO_ID + " = 'null')";
|
||||
selection.append(" AND (" + Sqlite.COL_IN_REPLY_TO_ID + " IS NULL OR " + Sqlite.COL_IN_REPLY_TO_ID + " = 'null')");
|
||||
else if(filterToots.getReplies() == FilterToots.typeFilter.ONLY)
|
||||
selection += " AND " + Sqlite.COL_IN_REPLY_TO_ID + " IS NOT NULL AND "+ Sqlite.COL_IN_REPLY_TO_ID + " <> 'null'";
|
||||
selection.append(" AND " + Sqlite.COL_IN_REPLY_TO_ID + " IS NOT NULL AND " + Sqlite.COL_IN_REPLY_TO_ID + " <> 'null'");
|
||||
//PINNED
|
||||
if(filterToots.getPinned() == FilterToots.typeFilter.NONE)
|
||||
selection += " AND " + Sqlite.COL_PINNED + " = 0";
|
||||
selection.append(" AND " + Sqlite.COL_PINNED + " = 0");
|
||||
else if(filterToots.getPinned() == FilterToots.typeFilter.ONLY)
|
||||
selection += " AND " + Sqlite.COL_PINNED + " = 1";
|
||||
selection.append(" AND " + Sqlite.COL_PINNED + " = 1");
|
||||
//PINNED
|
||||
if(filterToots.getMedia() == FilterToots.typeFilter.NONE)
|
||||
selection += " AND " + Sqlite.COL_MEDIA_ATTACHMENTS + " = '[]'";
|
||||
selection.append(" AND " + Sqlite.COL_MEDIA_ATTACHMENTS + " = '[]'");
|
||||
else if(filterToots.getMedia() == FilterToots.typeFilter.ONLY)
|
||||
selection += " AND " + Sqlite.COL_MEDIA_ATTACHMENTS + " <> '[]'";
|
||||
selection.append(" AND " + Sqlite.COL_MEDIA_ATTACHMENTS + " <> '[]'");
|
||||
|
||||
if( !filterToots.isV_direct())
|
||||
selection.append(" AND " + Sqlite.COL_VISIBILITY + " <> 'direct'");
|
||||
if( !filterToots.isV_private())
|
||||
selection.append(" AND " + Sqlite.COL_VISIBILITY + " <> 'private'");
|
||||
if( !filterToots.isV_public())
|
||||
selection.append(" AND " + Sqlite.COL_VISIBILITY + " <> 'public'");
|
||||
if( !filterToots.isV_unlisted())
|
||||
selection.append(" AND " + Sqlite.COL_VISIBILITY + " <> 'unlisted'");
|
||||
|
||||
if( filterToots.getDateIni() != null)
|
||||
selection.append(" AND " + Sqlite.COL_CREATED_AT + " >= '").append(filterToots.getDateIni()).append("'");
|
||||
|
||||
if( filterToots.getDateEnd() != null)
|
||||
selection.append(" AND " + Sqlite.COL_CREATED_AT + " <= '").append(filterToots.getDateEnd()).append("'");
|
||||
|
||||
if( filterToots.getFilter() != null ){
|
||||
String[] keywords = filterToots.getFilter().split(" ");
|
||||
selection.append(" AND (");
|
||||
int i = 0;
|
||||
for(String kw: keywords){
|
||||
|
||||
if( i == 0 && keywords.length == 1)
|
||||
selection.append(Sqlite.COL_CONTENT + " LIKE '%").append(kw).append("%'");
|
||||
else if( i == 0 && keywords.length > 1)
|
||||
selection.append(Sqlite.COL_CONTENT + " LIKE '%").append(kw).append("%' OR ");
|
||||
else if( i == keywords.length -1 )
|
||||
selection.append(Sqlite.COL_CONTENT + " LIKE '%").append(kw).append("%'");
|
||||
i++;
|
||||
}
|
||||
selection.append(")");
|
||||
}
|
||||
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, selection, null, null, null, Sqlite.COL_CREATED_AT + " DESC", "80");
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, selection.toString(), null, null, null, Sqlite.COL_CREATED_AT + " DESC", "80");
|
||||
return cursorToListStatuses(c);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -404,7 +404,7 @@
|
|||
<string name="v_public">Public</string>
|
||||
<string name="v_unlisted">Unlisted</string>
|
||||
<string name="v_private">Private</string>
|
||||
<string name="v_direct">Public</string>
|
||||
<string name="v_direct">Direct</string>
|
||||
<string name="v_keywords">Some keywords…</string>
|
||||
<string-array name="filter_select">
|
||||
<item>No</item>
|
||||
|
|
Loading…
Reference in New Issue