Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 03de63f

Browse files
kunall17niftynei
authored andcommitted
Setup the date filter for fetching messages
1 parent 626a970 commit 03de63f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

app/src/main/java/com/zulip/android/widget/ZulipRemoteViewsFactory.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.text.format.DateUtils;
56
import android.util.Log;
67
import android.widget.RemoteViews;
78
import android.widget.RemoteViewsService;
@@ -32,10 +33,31 @@ public ZulipRemoteViewsFactory(Context applicationContext, Intent intent) {
3233
public void onCreate() {
3334

3435
}
36+
37+
private String setupWhere() {
38+
switch (from) {
39+
//These values present in R.arrays.from_values
40+
case "today":
41+
return "timestamp BETWEEN DATE('now') AND DATE('now', '+1 day')";
42+
case "yesterday":
43+
return "DATE(timestamp) >= DATE('now', '-1 days')";
44+
case "week":
45+
return "DATE(timestamp) >= DATE('now', 'weekday 0', '-7 days')";
46+
case "all":
47+
default:
48+
return "";
49+
}
50+
}
51+
3552
@Override
3653
public void onDataSetChanged() {
3754
Log.i("ZULIP_WIDGET", "onDataSetChanged() = Data reloaded");
3855
QueryBuilder<Message, Object> queryBuilder = ZulipApp.get().getDao(Message.class).queryBuilder();
56+
String filter;
57+
filter = setupWhere();
58+
if (!filter.equals("")) {
59+
queryBuilder.where().raw(filter);
60+
}
3961

4062
try {
4163
messageList = queryBuilder.query();

0 commit comments

Comments
 (0)