diff --git a/app/src/main/java/de/kuschku/libquassel/client/BufferManager.java b/app/src/main/java/de/kuschku/libquassel/client/BufferManager.java index 3b2c11994c5be4ffe13571023a79449e1224048f..8a9fdc02030bcc27c57ddafb441022eeac04cd8b 100644 --- a/app/src/main/java/de/kuschku/libquassel/client/BufferManager.java +++ b/app/src/main/java/de/kuschku/libquassel/client/BufferManager.java @@ -30,7 +30,11 @@ import java.util.Map; import de.kuschku.libquassel.localtypes.buffers.Buffer; import de.kuschku.libquassel.localtypes.buffers.Buffers; +import de.kuschku.libquassel.localtypes.buffers.ChannelBuffer; +import de.kuschku.libquassel.localtypes.buffers.QueryBuffer; import de.kuschku.libquassel.primitives.types.BufferInfo; +import de.kuschku.libquassel.syncables.types.interfaces.QIrcChannel; +import de.kuschku.libquassel.syncables.types.interfaces.QIrcUser; import static de.kuschku.util.AndroidAssert.assertNotNull; @@ -39,12 +43,16 @@ public class BufferManager { private final Map<Integer, Buffer> buffers = new HashMap<>(); private final Client client; + private final Map<String, Integer> buffersByNick = new HashMap<>(); + private final Map<String, Integer> buffersByChannel = new HashMap<>(); + public BufferManager(Client client) { this.client = client; } public void createBuffer(@NonNull Buffer buffer) { buffers.put(buffer.getInfo().id(), buffer); + updateBufferMapEntries(buffer, buffer.getInfo().name()); } public void removeBuffer(@IntRange(from = 0) int id) { @@ -80,4 +88,43 @@ public class BufferManager { public boolean exists(BufferInfo info) { return buffers.containsKey(info.id()); } + + public void renameBuffer(int bufferId, String newName) { + Buffer buffer = buffer(bufferId); + if (buffer != null) { + buffer.renameBuffer(newName); + } + } + + private void updateBufferMapEntries(Buffer buffer, String name) { + buffersByNick.remove(buffer.objectName()); + buffersByChannel.remove(buffer.objectName()); + if (buffer instanceof ChannelBuffer) { + buffersByChannel.put(buffer.objectName(name), buffer.getInfo().id()); + } else if (buffer instanceof QueryBuffer) { + buffersByNick.put(buffer.objectName(name), buffer.getInfo().id()); + } + } + + public ChannelBuffer channel(QIrcChannel channel) { + if (channel == null) + return null; + if (!buffersByChannel.containsKey(channel.getObjectName())) + return null; + Buffer buffer = buffer(buffersByChannel.get(channel.getObjectName())); + if (!(buffer instanceof ChannelBuffer)) + return null; + return (ChannelBuffer) buffer; + } + + public QueryBuffer user(QIrcUser user) { + if (user == null) + return null; + if (!buffersByNick.containsKey(user.getObjectName())) + return null; + Buffer buffer = buffer(buffersByNick.get(user.getObjectName())); + if (!(buffer instanceof QueryBuffer)) + return null; + return (QueryBuffer) buffer; + } } diff --git a/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/Buffer.java b/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/Buffer.java index 2bcfda022b58989e122ba14e5d29d1ff3a0a046c..ce73300dc1f70b1d871cd5a80f8ed63c8f84dcb5 100644 --- a/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/Buffer.java +++ b/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/Buffer.java @@ -39,4 +39,8 @@ public interface Buffer { BufferInfo.BufferStatus getStatus(); void renameBuffer(@NonNull String newName); + + String objectName(); + + String objectName(String name); } diff --git a/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/ChannelBuffer.java b/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/ChannelBuffer.java index 3a0451742c332843eab15458431df5d48775d42a..8fb9f4ca0bf2dffb5058606e1462615115be6171 100644 --- a/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/ChannelBuffer.java +++ b/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/ChannelBuffer.java @@ -67,6 +67,16 @@ public class ChannelBuffer implements Buffer { info.setName(newName); } + @Override + public String objectName() { + return objectName(info.name()); + } + + @Override + public String objectName(String name) { + return info.networkId() + "/" + name; + } + @Nullable public QIrcChannel getChannel() { return client.networkManager().network(info.networkId()).ircChannel(info.name()); diff --git a/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/QueryBuffer.java b/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/QueryBuffer.java index 0b862ab5c80d0bec18e3c74a698f7f6044403ba3..a87ddc8fda116f2ae4ca35706e2360f297e631ba 100644 --- a/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/QueryBuffer.java +++ b/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/QueryBuffer.java @@ -69,6 +69,16 @@ public class QueryBuffer implements Buffer { info.setName(newName); } + @Override + public String objectName() { + return objectName(info.name()); + } + + @Override + public String objectName(String name) { + return info.networkId() + "/" + name; + } + @Nullable public QIrcUser getUser() { return client.networkManager().network(info.networkId()).ircUser(info.name()); diff --git a/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/StatusBuffer.java b/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/StatusBuffer.java index cd172cf586b151c08f7b052a8ed6e09855d505e5..4bab97e2fd0ec163ca59b3e5845e3ccc8933ad66 100644 --- a/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/StatusBuffer.java +++ b/app/src/main/java/de/kuschku/libquassel/localtypes/buffers/StatusBuffer.java @@ -66,6 +66,16 @@ public class StatusBuffer implements Buffer { return getNetwork().isConnected() ? BufferInfo.BufferStatus.ONLINE : BufferInfo.BufferStatus.OFFLINE; } + @Override + public String objectName() { + return objectName(info.name()); + } + + @Override + public String objectName(String name) { + return info.networkId() + "/" + name; + } + @Override public void renameBuffer(@NonNull String newName) { this.info.setName(newName); diff --git a/app/src/main/java/de/kuschku/libquassel/syncables/types/impl/BufferSyncer.java b/app/src/main/java/de/kuschku/libquassel/syncables/types/impl/BufferSyncer.java index b6cdcfd23ddab3b63d8d9fa888b20408ef40b379..532883b2e9c75536295120b09db87310d138b103 100644 --- a/app/src/main/java/de/kuschku/libquassel/syncables/types/impl/BufferSyncer.java +++ b/app/src/main/java/de/kuschku/libquassel/syncables/types/impl/BufferSyncer.java @@ -28,7 +28,6 @@ import java.util.Map; import de.kuschku.libquassel.BusProvider; import de.kuschku.libquassel.client.Client; -import de.kuschku.libquassel.localtypes.buffers.Buffer; import de.kuschku.libquassel.message.Message; import de.kuschku.libquassel.primitives.types.QVariant; import de.kuschku.libquassel.syncables.serializers.BufferSyncerSerializer; @@ -112,9 +111,7 @@ public class BufferSyncer extends ABufferSyncer<BufferSyncer> { @Override public void _renameBuffer(int bufferId, @NonNull String newName) { - Buffer buffer = client.bufferManager().buffer(bufferId); - if (buffer != null) - buffer.renameBuffer(newName); + client.bufferManager().renameBuffer(bufferId, newName); _update(); } diff --git a/app/src/main/java/de/kuschku/libquassel/syncables/types/interfaces/QIrcChannel.java b/app/src/main/java/de/kuschku/libquassel/syncables/types/interfaces/QIrcChannel.java index 4daa26bca1448491034690e605b2f6599f2c4928..cabd2211274f06a208fb9a49ae9a68da667b78e0 100644 --- a/app/src/main/java/de/kuschku/libquassel/syncables/types/interfaces/QIrcChannel.java +++ b/app/src/main/java/de/kuschku/libquassel/syncables/types/interfaces/QIrcChannel.java @@ -146,4 +146,6 @@ public interface QIrcChannel { void _removeChannelMode(final char mode, final String value); void init(QNetwork network, Client client); + + String getObjectName(); } diff --git a/app/src/main/java/de/kuschku/libquassel/syncables/types/interfaces/QIrcUser.java b/app/src/main/java/de/kuschku/libquassel/syncables/types/interfaces/QIrcUser.java index e16222be7f27325f30f443b16caf438f0f8ea867..333f593f3bf74152fb7683785ab5777886a29e42 100644 --- a/app/src/main/java/de/kuschku/libquassel/syncables/types/interfaces/QIrcUser.java +++ b/app/src/main/java/de/kuschku/libquassel/syncables/types/interfaces/QIrcUser.java @@ -204,4 +204,6 @@ public interface QIrcUser { void _removeUserModes(final String modes); void init(QNetwork network, Client client); + + String getObjectName(); } diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/ChatActivity.java b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/ChatActivity.java index b8cda329ade58affe59ea98ef895443dead8f444..6059da4f8cb904f64cbcdf7ed03e354f6a7eda34 100644 --- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/ChatActivity.java +++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/ChatActivity.java @@ -83,6 +83,7 @@ import de.kuschku.libquassel.events.UnknownCertificateEvent; import de.kuschku.libquassel.localtypes.BacklogFilter; import de.kuschku.libquassel.localtypes.buffers.Buffer; import de.kuschku.libquassel.localtypes.buffers.ChannelBuffer; +import de.kuschku.libquassel.localtypes.buffers.QueryBuffer; import de.kuschku.libquassel.message.Message; import de.kuschku.libquassel.syncables.types.interfaces.QBufferViewConfig; import de.kuschku.libquassel.syncables.types.interfaces.QBufferViewManager; @@ -105,7 +106,6 @@ import de.kuschku.util.instancestateutil.Storable; import de.kuschku.util.instancestateutil.Store; import de.kuschku.util.observables.AutoScroller; import de.kuschku.util.observables.lists.ObservableSortedList; -import de.kuschku.util.ui.SpanFormatter; import static de.kuschku.util.AndroidAssert.assertNotNull; @@ -573,6 +573,7 @@ public class ChatActivity extends AppCompatActivity { } private void selectBuffer(@IntRange(from = -1) int bufferId) { + Log.d("libquassel", context.client().bufferManager().channel(context.client().networkManager().network(4).ircChannel("#quassel")).getChannel().topic()); if (bufferId == -1) { swipeView.setEnabled(false); @@ -594,6 +595,7 @@ public class ChatActivity extends AppCompatActivity { toolbar.setTitle(buffer.getName()); updateNoColor(buffer, formattingMenu.getMenu()); } + updateSubTitle(); } private void onConnectionEstablished() { @@ -758,7 +760,27 @@ public class ChatActivity extends AppCompatActivity { private void updateSubTitle() { if (context.client() != null) { - toolbar.setSubtitle(SpanFormatter.format("Lag: %.2f, %s", context.client().latency() / 1000.0F, context.client().connectionStatus())); + String subtitle; + if (context.client().connectionStatus() == ConnectionChangeEvent.Status.CONNECTED) { + if (status.bufferId >= 0) { + Buffer buffer = context.client().bufferManager().buffer(status.bufferId); + if (buffer != null) { + if (buffer instanceof QueryBuffer) + subtitle = ((QueryBuffer) buffer).getUser().realName(); + else if (buffer instanceof ChannelBuffer) + subtitle = ((ChannelBuffer) buffer).getChannel().topic(); + else + subtitle = ""; + } else { + subtitle = ""; + } + } else { + subtitle = ""; + } + } else { + subtitle = String.valueOf(context.client().connectionStatus()); + } + toolbar.setSubtitle(subtitle); } else { toolbar.setSubtitle(""); } diff --git a/app/src/main/res/menu/chat.xml b/app/src/main/res/menu/chat.xml index bdbe0caadbd38e70a71a938dc932b847c602e94b..e5cbf8eae2cf96727e43514a581e8b51551215fa 100644 --- a/app/src/main/res/menu/chat.xml +++ b/app/src/main/res/menu/chat.xml @@ -27,5 +27,5 @@ android:icon="@android:drawable/ic_menu_sort_by_size" android:orderInCategory="100" android:title="@string/labelHideEvents" - app:showAsAction="ifRoom" /> + app:showAsAction="never" /> </menu>