Arcturus-Community/src/main/java/com/eu/habbo/habbohotel/navigation/SearchResultList.java

79 lines
2.7 KiB
Java
Raw Normal View History

2018-07-06 15:30:00 +02:00
package com.eu.habbo.habbohotel.navigation;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomState;
import com.eu.habbo.messages.ISerialize;
import com.eu.habbo.messages.ServerMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
2019-05-26 20:14:53 +02:00
public class SearchResultList implements ISerialize, Comparable<SearchResultList> {
2018-07-06 15:30:00 +02:00
public final int order;
public final String code;
public final String query;
public final SearchAction action;
public final ListMode mode;
public final DisplayMode hidden;
public final List<Room> rooms;
public final boolean filter;
public final boolean showInvisible;
2018-11-17 14:28:00 +01:00
public final DisplayOrder displayOrder;
public final int categoryOrder;
2018-07-06 15:30:00 +02:00
2019-05-26 20:14:53 +02:00
public SearchResultList(int order, String code, String query, SearchAction action, ListMode mode, DisplayMode hidden, List<Room> rooms, boolean filter, boolean showInvisible, DisplayOrder displayOrder, int categoryOrder) {
2018-07-06 15:30:00 +02:00
this.order = order;
this.code = code;
this.query = query;
this.action = action;
this.mode = mode;
this.rooms = rooms;
this.hidden = hidden;
this.filter = filter;
this.showInvisible = showInvisible;
2018-11-17 14:28:00 +01:00
this.displayOrder = displayOrder;
this.categoryOrder = categoryOrder;
2018-07-06 15:30:00 +02:00
}
@Override
2019-05-26 20:14:53 +02:00
public void serialize(ServerMessage message) {
2018-07-06 15:30:00 +02:00
message.appendString(this.code); //Search Code
message.appendString(this.query); //Text
message.appendInt(this.action.type); //Action Allowed (0 (Nothing), 1 (More Results), 2 (Go Back))
message.appendBoolean(this.hidden.equals(DisplayMode.COLLAPSED)); //Closed
message.appendInt(this.mode.type); //Display Mode (0 (List), 1 (Thumbnails), 2 (Thumbnail no choice))
2019-05-26 20:14:53 +02:00
synchronized (this.rooms) {
if (!this.showInvisible) {
2018-09-28 21:25:00 +02:00
List<Room> toRemove = new ArrayList<>();
2019-05-26 20:14:53 +02:00
for (Room room : this.rooms) {
if (room.getState() == RoomState.INVISIBLE) {
2018-07-06 15:30:00 +02:00
toRemove.add(room);
}
}
this.rooms.removeAll(toRemove);
}
message.appendInt(this.rooms.size());
Collections.sort(this.rooms);
2019-05-26 20:14:53 +02:00
for (Room room : this.rooms) {
2018-07-06 15:30:00 +02:00
room.serialize(message);
}
}
}
@Override
2019-05-26 20:14:53 +02:00
public int compareTo(SearchResultList o) {
if (this.displayOrder == DisplayOrder.ACTIVITY) {
if (this.code.equalsIgnoreCase("popular")) {
2018-11-17 14:28:00 +01:00
return -1;
}
2018-07-06 15:30:00 +02:00
2018-11-17 14:28:00 +01:00
return this.rooms.size() - o.rooms.size();
}
return this.categoryOrder - o.categoryOrder;
2018-07-06 15:30:00 +02:00
}
}