Skip to content
Snippets Groups Projects
Commit a27d02c3 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fixed several minor issues, improved performance of daychange updating

parent 07505def
No related branches found
No related tags found
No related merge requests found
......@@ -23,11 +23,16 @@ package de.kuschku.libquassel.localtypes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.format.DateUtils;
import android.util.Log;
import org.joda.time.DateTime;
import org.joda.time.DateTimeUtils;
import org.joda.time.LocalDate;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import de.greenrobot.event.EventBus;
......@@ -35,6 +40,7 @@ import de.kuschku.libquassel.client.Client;
import de.kuschku.libquassel.message.Message;
import de.kuschku.libquassel.primitives.types.BufferInfo;
import de.kuschku.libquassel.syncables.types.interfaces.QNetwork;
import de.kuschku.util.backports.Objects;
import de.kuschku.util.observables.callbacks.UICallback;
import de.kuschku.util.observables.lists.ObservableComparableSortedList;
......@@ -54,8 +60,6 @@ public class BacklogFilter implements UICallback {
private final EventBus bus = new EventBus();
@Nullable
private CharSequence searchQuery;
@Nullable
private DateTime earliestMessage;
public BacklogFilter(@NonNull Client client, int bufferId, @NonNull ObservableComparableSortedList<Message> unfiltered, @NonNull ObservableComparableSortedList<Message> filtered) {
this.client = client;
......@@ -64,6 +68,7 @@ public class BacklogFilter implements UICallback {
this.filtered = filtered;
this.bus.register(this);
setFiltersInternal(client.metaDataManager().hiddendata(client.coreId(), bufferId));
updateDayChangeMessages();
}
@Override
......@@ -73,11 +78,45 @@ public class BacklogFilter implements UICallback {
}
private void updateDayChangeMessages() {
DateTime now = DateTime.now().withMillisOfDay(0);
while (now.isAfter(earliestMessage)) {
LocalDate date = null;
Message lastMessage = null;
for (Message message : filtered) {
if (Objects.equals(date, message.getLocalDate()))
continue;
date = message.getLocalDate();
if (message.type == Message.Type.DayChange) {
if (lastMessage != null && lastMessage.type == Message.Type.DayChange) {
bus.post(new MessageRemoveEvent(lastMessage));
}
lastMessage = message;
continue;
}
lastMessage = message;
date = message.getLocalDate();
DateTime time = message.time.withMillisOfDay(0);
bus.post(new MessageInsertEvent(Message.create(
(int) DateTimeUtils.toJulianDay(now.getMillis()),
now,
(int) DateTimeUtils.toJulianDay(time.getMillis()),
time,
Message.Type.DayChange,
new Message.Flags(false, false, false, false, false),
BufferInfo.create(
bufferId,
-1,
BufferInfo.Type.INVALID,
-1,
null
),
"",
""
)));
}
DateTime time = DateTime.now();
if (!Objects.equals(date, time.toLocalDate())) {
time = time.withMillisOfDay(0);
bus.post(new MessageInsertEvent(Message.create(
(int) DateTimeUtils.toJulianDay(time.getMillis()),
time,
Message.Type.DayChange,
new Message.Flags(false, false, false, false, false),
BufferInfo.create(
......@@ -90,7 +129,6 @@ public class BacklogFilter implements UICallback {
"",
""
)));
now = now.minusDays(1);
}
}
......@@ -141,17 +179,19 @@ public class BacklogFilter implements UICallback {
public void onEventAsync(@NonNull MessageFilterEvent event) {
if (!filterItem(event.msg)) bus.post(new MessageInsertEvent(event.msg));
if (event.msg.time.isBefore(earliestMessage)) earliestMessage = event.msg.time;
updateDayChangeMessages();
}
public void onEventMainThread(@NonNull MessageInsertEvent event) {
filtered.add(event.msg);
client.bufferSyncer().addActivity(event.msg);
if (event.msg.type != Message.Type.DayChange)
updateDayChangeMessages();
}
public void onEventMainThread(@NonNull MessageRemoveEvent event) {
filtered.remove(event.msg);
if (event.msg.type != Message.Type.DayChange)
updateDayChangeMessages();
}
@Override
......
......@@ -32,6 +32,7 @@ import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import java.io.Serializable;
import java.util.Comparator;
......@@ -63,6 +64,14 @@ public class Message extends BaseModel implements ContentComparable<Message> {
@Column
public String content;
public LocalDate date;
public LocalDate getLocalDate() {
if (date == null)
date = time.toLocalDate();
return date;
}
public static Message create(int id, DateTime time, Type type, Flags flags, BufferInfo bufferInfo, String sender, String content) {
Message message = new Message();
message.id = id;
......@@ -91,11 +100,18 @@ public class Message extends BaseModel implements ContentComparable<Message> {
@Override
public boolean areContentsTheSame(@Nullable Message message) {
return this == message;
return message != null && this.id == message.id && this.sender.equals(message.sender) && this.type == message.type && this.time.equals(message.time) && this.content.equals(message.content) && this.flags == message.flags;
}
@Override
public boolean areItemsTheSame(@NonNull Message other) {
if (this.type == Type.DayChange && other.type == Type.DayChange)
return this.bufferInfo.id == other.bufferInfo.id && this.time.equals(other.time);
else if (this.type == Type.DayChange)
return false;
else if (other.type == Type.DayChange)
return false;
else
return this.id == other.id;
}
......
......@@ -35,10 +35,6 @@
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
......@@ -46,6 +42,10 @@
android:layout_height="wrap_content"
android:theme="?attr/actionBarTheme">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/chatListToolbar"
android:layout_width="match_parent"
......@@ -61,8 +61,6 @@
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ViewStub
android:id="@+id/cab_stub"
android:layout_width="match_parent"
......@@ -70,6 +68,8 @@
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/chatList"
android:layout_width="match_parent"
......
......@@ -54,10 +54,6 @@
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
......@@ -65,6 +61,10 @@
android:layout_height="wrap_content"
android:theme="?attr/actionBarTheme">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/chatListToolbar"
android:layout_width="match_parent"
......@@ -82,8 +82,6 @@
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ViewStub
android:id="@+id/cab_stub"
android:layout_width="match_parent"
......@@ -91,6 +89,8 @@
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/chatList"
android:layout_width="match_parent"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment