This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 244
Fixes #155 : Modified widget to use NarrowFilter #411
Open
rhari991
wants to merge
1
commit into
zulip:master
Choose a base branch
from
rhari991:where-change-in-widget
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,14 @@ | |
import com.j256.ormlite.stmt.QueryBuilder; | ||
import com.zulip.android.R; | ||
import com.zulip.android.ZulipApp; | ||
import com.zulip.android.filters.NarrowFilter; | ||
import com.zulip.android.filters.NarrowFilterByDate; | ||
import com.zulip.android.models.Message; | ||
import com.zulip.android.models.MessageType; | ||
import com.zulip.android.util.ZLog; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Calendar; | ||
import java.util.List; | ||
|
||
import static com.zulip.android.widget.WidgetPreferenceFragment.FROM_PREFERENCE; | ||
|
@@ -34,32 +37,35 @@ public void onCreate() { | |
|
||
} | ||
|
||
private String setupWhere() { | ||
private Calendar getMinDate() { | ||
Calendar calendar = Calendar.getInstance(); | ||
switch (from) { | ||
//These values present in R.arrays.from_values | ||
case "today": | ||
return "timestamp BETWEEN DATE('now') AND DATE('now', '+1 day')"; | ||
break; | ||
case "yesterday": | ||
return "DATE(timestamp) >= DATE('now', '-1 days')"; | ||
calendar.add(Calendar.DATE, -1); | ||
break; | ||
case "week": | ||
return "DATE(timestamp) >= DATE('now', 'weekday 0', '-7 days')"; | ||
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); | ||
break; | ||
case "all": | ||
default: | ||
return ""; | ||
calendar = null; | ||
} | ||
return calendar; | ||
} | ||
|
||
@Override | ||
public void onDataSetChanged() { | ||
Log.i("ZULIP_WIDGET", "onDataSetChanged() = Data reloaded"); | ||
QueryBuilder<Message, Object> queryBuilder = ZulipApp.get().getDao(Message.class).queryBuilder(); | ||
String filter; | ||
filter = setupWhere(); | ||
if (!filter.equals("")) { | ||
queryBuilder.where().raw(filter); | ||
} | ||
|
||
try { | ||
Log.i("ZULIP_WIDGET", "onDataSetChanged() = Data reloaded"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a TAG filed in the class and use that as a parameter of Log.d |
||
QueryBuilder<Message, Object> queryBuilder = ZulipApp.get().getDao(Message.class).queryBuilder(); | ||
Calendar minDate = getMinDate(); | ||
if (minDate != null) { | ||
NarrowFilter minDateFilter = new NarrowFilterByDate(minDate.getTime(), true); | ||
minDateFilter.modWhere(queryBuilder.where()); | ||
} | ||
messageList = queryBuilder.query(); | ||
} catch (SQLException e) { | ||
ZLog.logException(e); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you removing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Calendar.getInstance() method returns a Calendar object with the current date, so in case the minimum date is today, there is no need to modify it.