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

Commit 6e72c07

Browse files
committed
Added @-mentions option in people drawer.
Fix:#351 and Fix:#39
1 parent ee447f7 commit 6e72c07

File tree

6 files changed

+130
-5
lines changed

6 files changed

+130
-5
lines changed

app/src/main/java/com/zulip/android/activities/RefreshableCursorAdapter.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,20 @@ public void onClick(View v) {
6666
}
6767
});
6868
return;
69+
} else if (position == 1) {
70+
tileHolder.tvName.setText(R.string.mentions);
71+
tileHolder.ivDot.setVisibility(View.VISIBLE);
72+
tileHolder.ivDot.setBackgroundResource(R.drawable.ic_mentions);
73+
holder.itemView.setOnClickListener(new View.OnClickListener() {
74+
@Override
75+
public void onClick(View v) {
76+
onPeopleSelect(Constants.MENTIONS);
77+
}
78+
});
79+
return;
6980
}
70-
position = tileHolder.getLayoutPosition() - 1;
81+
//first two are narrow to all private message and mentions
82+
position = tileHolder.getLayoutPosition() - 2;
7183
tileHolder.tvName.setText(mList.get(position).getPerson().getName());
7284
//app is passed as parameter from ZulipActivity
7385
//presence of all persons are in ZulipApp
@@ -118,14 +130,15 @@ public void onClick(View v) {
118130

119131
@Override
120132
public int getItemCount() {
121-
return mList.size() + 1;
133+
//first two are narrow to all private message and mentions
134+
return mList.size() + 2;
122135
}
123136

124137
@Override
125138
public long getHeaderId(int position) {
126-
if (position == 0)
139+
if (position == 0 || position == 1)
127140
return FloatingHeaderDecoration.NO_HEADER_ID;
128-
return (long) mList.get(position - 1).getGroupId();
141+
return (long) mList.get(position - 2).getGroupId();
129142
}
130143

131144
@Override
@@ -136,7 +149,8 @@ public HeaderHolder onCreateHeaderViewHolder(ViewGroup parent) {
136149

137150
@Override
138151
public void onBindHeaderViewHolder(HeaderHolder headerHolder, int position) {
139-
headerHolder.tvHeading.setText(mList.get(position - 1).getGroupName());
152+
//first two are narrow to all private message and mentions
153+
headerHolder.tvHeading.setText(mList.get(position - 2).getGroupName());
140154
}
141155

142156
private static class TileHolder extends RecyclerView.ViewHolder {

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
import com.zulip.android.filters.NarrowFilter;
8787
import com.zulip.android.filters.NarrowFilterAllPMs;
8888
import com.zulip.android.filters.NarrowFilterByDate;
89+
import com.zulip.android.filters.NarrowFilterMentioned;
8990
import com.zulip.android.filters.NarrowFilterPM;
9091
import com.zulip.android.filters.NarrowFilterSearch;
9192
import com.zulip.android.filters.NarrowFilterStar;
@@ -722,6 +723,8 @@ protected void onPeopleSelect(int id) {
722723
resetPeopleSearch();
723724
if (id == Constants.ALL_PEOPLE_ID) {
724725
openAllPrivateMessages();
726+
} else if (id == Constants.MENTIONS) {
727+
doNarrow(new NarrowFilterMentioned());
725728
} else {
726729
Person person = Person.getById(app, id);
727730
narrowPMWith(person);
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.zulip.android.filters;
2+
3+
import android.os.Parcel;
4+
import android.support.v4.content.ContextCompat;
5+
import android.text.TextUtils;
6+
7+
import com.j256.ormlite.stmt.SelectArg;
8+
import com.j256.ormlite.stmt.Where;
9+
import com.zulip.android.R;
10+
import com.zulip.android.ZulipApp;
11+
import com.zulip.android.models.Message;
12+
import com.zulip.android.models.MessageType;
13+
import com.zulip.android.models.Person;
14+
import com.zulip.android.models.Stream;
15+
16+
import org.json.JSONArray;
17+
import org.json.JSONException;
18+
19+
import java.sql.SQLException;
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.List;
23+
24+
public class NarrowFilterMentioned implements NarrowFilter {
25+
public static final Creator<NarrowFilterMentioned> CREATOR = new Creator<NarrowFilterMentioned>() {
26+
public NarrowFilterMentioned createFromParcel(Parcel in) {
27+
return new NarrowFilterMentioned();
28+
}
29+
30+
public NarrowFilterMentioned[] newArray(int size) {
31+
return new NarrowFilterMentioned[size];
32+
}
33+
};
34+
35+
private String name;
36+
37+
public NarrowFilterMentioned() {
38+
name = ZulipApp.get().getYou().getName();
39+
}
40+
41+
public int describeContents() {
42+
return 0;
43+
}
44+
45+
public void writeToParcel(Parcel dest, int flags) {
46+
dest.writeString(this.name);
47+
}
48+
49+
@Override
50+
public Where<Message, Object> modWhere(Where<Message, Object> where)
51+
throws SQLException {
52+
53+
where.like(Message.CONTENT_FIELD, name);
54+
return where;
55+
}
56+
57+
@Override
58+
public boolean matches(Message msg) {
59+
return msg.getContent().contains(name);
60+
}
61+
62+
@Override
63+
public String getTitle() {
64+
return ZulipApp.get().getString(R.string.mentions);
65+
}
66+
67+
@Override
68+
public String getSubtitle() {
69+
return null;
70+
}
71+
72+
@Override
73+
public Stream getComposeStream() {
74+
return null;
75+
}
76+
77+
@Override
78+
public String getComposePMRecipient() {
79+
return "";
80+
}
81+
82+
@Override
83+
public String getJsonFilter() throws JSONException {
84+
return (new JSONArray()).put(new JSONArray(Arrays.asList("is", "mentioned"))).toString();
85+
}
86+
87+
@Override
88+
public boolean equals(NarrowFilter filter) {
89+
if (filter instanceof NarrowFilterMentioned) {
90+
NarrowFilterMentioned filterPM = (NarrowFilterMentioned) filter;
91+
return this.getTitle().equals(filterPM.getTitle());
92+
} else {
93+
return false;
94+
}
95+
}
96+
97+
@Override
98+
public String toString() {
99+
try {
100+
return getJsonFilter();
101+
} catch (JSONException e) {
102+
return null;
103+
}
104+
}
105+
}

app/src/main/java/com/zulip/android/util/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ public class Constants {
2222
public static final int PEOPLE_DRAWER_OTHERS_GROUP_ID = 2;
2323
// row number which is used to differentiate the 'All private messages' in people drawer
2424
public static final int ALL_PEOPLE_ID = -1;
25+
// row number which is used to differentiate the '@-mentions' in people drawer
26+
public static int MENTIONS = -2;
2527
}
390 Bytes
Loading

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,5 @@
166166
<string name="people_drawer_active_label">Active</string>
167167
<string name="people_drawer_recent_pm_label">Recent Private Messages</string>
168168
<string name="people_drawer_others_label">New Private Message</string>
169+
<string name="mentions">\@-mentions</string>
169170
</resources>

0 commit comments

Comments
 (0)