Commit b704af6f authored by Tiago Cunha's avatar Tiago Cunha Committed by GitHub

Merge pull request #241 from RocketChat/feature/show-favorites-grouping

Show favorites grouping on room list
parents 99cacc3a 6d01ed69
......@@ -27,6 +27,7 @@ import chat.rocket.android.helper.AbsoluteUrlHelper;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.layouthelper.chatroom.roomlist.ChannelRoomListHeader;
import chat.rocket.android.layouthelper.chatroom.roomlist.DirectMessageRoomListHeader;
import chat.rocket.android.layouthelper.chatroom.roomlist.FavoriteRoomListHeader;
import chat.rocket.android.layouthelper.chatroom.roomlist.RoomListAdapter;
import chat.rocket.android.layouthelper.chatroom.roomlist.RoomListHeader;
import chat.rocket.android.layouthelper.chatroom.roomlist.UnreadRoomListHeader;
......@@ -179,6 +180,10 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
));
}
roomListHeaders.add(new FavoriteRoomListHeader(
getString(R.string.fragment_sidebar_main_favorite_title)
));
roomListHeaders.add(new ChannelRoomListHeader(
getString(R.string.fragment_sidebar_main_channels_title),
() -> showAddRoomDialog(AddChannelDialogFragment.create(hostname))
......
package chat.rocket.android.layouthelper.chatroom.roomlist;
import android.support.annotation.NonNull;
import java.util.List;
import chat.rocket.core.models.Room;
public class FavoriteRoomListHeader implements RoomListHeader {
private final String title;
public FavoriteRoomListHeader(String title) {
this.title = title;
}
@Override
public String getTitle() {
return title;
}
@Override
public boolean owns(Room room) {
return room.isFavorite();
}
@Override
public boolean shouldShow(@NonNull List<Room> roomList) {
for (int i = 0, size = roomList.size(); i < size; i++) {
if (roomList.get(i).isFavorite()) {
return true;
}
}
return false;
}
@Override
public ClickListener getClickListener() {
return null;
}
}
<resources>
<string name="app_name">Rocket.Chat+</string>
<string name="fragment_sidebar_main_favorite_title">FAVORITES</string>
<string name="fragment_sidebar_main_channels_title">CHANNELS</string>
<string name="fragment_sidebar_main_direct_messages_title">DIRECT MESSAGES</string>
<string name="user_status_online">Online</string>
......
package chat.rocket.persistence.realm;
import io.realm.DynamicRealm;
import io.realm.RealmMigration;
import io.realm.RealmObjectSchema;
import io.realm.RealmSchema;
public class Migration implements RealmMigration {
@Override
public void migrate(DynamicRealm dynamicRealm, long oldVersion, long newVersion) {
RealmSchema schema = dynamicRealm.getSchema();
if (oldVersion == 0) {
RealmObjectSchema roomSchema = schema.get("RealmRoom");
roomSchema.addField("f", boolean.class);
oldVersion++;
}
}
}
......@@ -15,7 +15,8 @@ public class RocketChatPersistenceRealm {
new RealmConfiguration.Builder()
.name("rocket.chat.persistence.realm")
.modules(new RocketChatLibraryModule())
.deleteRealmIfMigrationNeeded()
.schemaVersion(1)
.migration(new Migration())
.build());
}
}
......@@ -24,6 +24,7 @@ public class RealmRoom extends RealmObject {
public static final String UNREAD = "unread";
public static final String UPDATED_AT = "_updatedAt";
public static final String LAST_SEEN = "ls";
public static final String FAVORITE = "f";
public static final String TYPE_CHANNEL = "c";
public static final String TYPE_PRIVATE = "p";
......@@ -39,6 +40,7 @@ public class RealmRoom extends RealmObject {
private int unread;
private long _updatedAt;
private long ls; //last seen.
private boolean f;
public static JSONObject customizeJson(JSONObject roomSubscriptionJson) throws JSONException {
if (!roomSubscriptionJson.isNull(LAST_SEEN)) {
......@@ -128,6 +130,14 @@ public class RealmRoom extends RealmObject {
this.ls = ls;
}
public boolean isFavorite() {
return f;
}
public void setFavorite(boolean f) {
this.f = f;
}
public Room asRoom() {
return Room.builder()
.setId(_id)
......@@ -139,6 +149,7 @@ public class RealmRoom extends RealmObject {
.setUnread(unread)
.setUpdatedAt(_updatedAt)
.setLastSeen(ls)
.setFavorite(f)
.build();
}
}
......@@ -27,6 +27,8 @@ public abstract class Room {
public abstract long getLastSeen();
public abstract boolean isFavorite();
public boolean isChannel() {
return TYPE_CHANNEL.equals(getType());
}
......@@ -64,6 +66,8 @@ public abstract class Room {
public abstract Builder setLastSeen(long lastSeen);
public abstract Builder setFavorite(boolean favorite);
public abstract Room build();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment