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