diff --git a/app/src/main/java/de/kuschku/quasseldroid/ui/chat/messages/MessageRenderer.kt b/app/src/main/java/de/kuschku/quasseldroid/ui/chat/messages/MessageRenderer.kt index 8c4e0f4b887e311826aa6269e1fe3cc3fa0ac55d..abfc89b57fba916107393808cf481fd3f2242c59 100644 --- a/app/src/main/java/de/kuschku/quasseldroid/ui/chat/messages/MessageRenderer.kt +++ b/app/src/main/java/de/kuschku/quasseldroid/ui/chat/messages/MessageRenderer.kt @@ -14,6 +14,7 @@ interface MessageRenderer { fun render(context: Context, message: QuasselDatabase.DatabaseMessage, markerLine: MsgId): FormattedMessage + fun init(viewHolder: QuasselMessageViewHolder, messageType: Message_Type?, hasHighlight: Boolean) { diff --git a/app/src/main/java/de/kuschku/quasseldroid/util/ui/SpanFormatter.java b/app/src/main/java/de/kuschku/quasseldroid/util/ui/SpanFormatter.java deleted file mode 100644 index b6e9122e6bc8bbbcf3cedd1343920ecb9b549d86..0000000000000000000000000000000000000000 --- a/app/src/main/java/de/kuschku/quasseldroid/util/ui/SpanFormatter.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * QuasselDroid - Quassel client for Android - * Copyright (C) 2016 Janne Koschinski - * Copyright (C) 2016 Ken Børge Viktil - * Copyright (C) 2016 Magnus Fjell - * Copyright (C) 2016 Martin Sandsmark <martin.sandsmark@kde.org> - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/* -* Copyright © 2014 George T. Steel -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -package de.kuschku.quasseldroid.util.ui; - -import android.support.annotation.NonNull; -import android.text.Spannable; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.SpannedString; - -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Provides {@link String#format} style functions that work with {@link Spanned} strings and preserve formatting. - * - * @author George T. Steel - */ -public class SpanFormatter { - private static final Pattern FORMAT_SEQUENCE = Pattern.compile("%([0-9]+\\$|<?)([^a-zA-z%]*)([[a-zA-Z%]&&[^tT]]|[tT][a-zA-Z])"); - - private SpanFormatter() { - } - - /** - * Version of {@link String#format(String, Object...)} that works on {@link Spanned} strings to preserve rich text formatting. - * Both the {@code format} as well as any {@code %s args} can be Spanned and will have their formatting preserved. - * Due to the way {@link Spannable}s work, any argument's spans will can only be included <b>once</b> in the result. - * Any duplicates will appear as text only. - * - * @param format the format string (see {@link java.util.Formatter#format}) - * @param args the list of arguments passed to the formatter. If there are - * more arguments than required by {@code format}, - * additional arguments are ignored. - * @return the formatted string (with spans). - */ - @NonNull - public static SpannedString format(@NonNull CharSequence format, Object... args) { - return format(Locale.getDefault(), format, args); - } - - /** - * Version of {@link String#format(Locale, String, Object...)} that works on {@link Spanned} strings to preserve rich text formatting. - * Both the {@code format} as well as any {@code %s args} can be Spanned and will have their formatting preserved. - * Due to the way {@link Spannable}s work, any argument's spans will can only be included <b>once</b> in the result. - * Any duplicates will appear as text only. - * - * @param locale the locale to apply; {@code null} value means no localization. - * @param format the format string (see {@link java.util.Formatter#format}) - * @param args the list of arguments passed to the formatter. - * @return the formatted string (with spans). - * @see String#format(Locale, String, Object...) - */ - @NonNull - public static SpannedString format(@NonNull Locale locale, @NonNull CharSequence format, Object... args) { - SpannableStringBuilder out = new SpannableStringBuilder(format); - - int i = 0; - int argAt = -1; - - while (i < out.length()) { - Matcher m = FORMAT_SEQUENCE.matcher(out); - if (!m.find(i)) break; - i = m.start(); - int exprEnd = m.end(); - - String argTerm = m.group(1); - String modTerm = m.group(2); - String typeTerm = m.group(3); - - CharSequence cookedArg; - - if (typeTerm.equals("%")) { - cookedArg = "%"; - } else { - int argIdx; - switch (argTerm) { - case "": - argIdx = ++argAt; - break; - case "<": - argIdx = argAt; - break; - default: - argIdx = Integer.parseInt(argTerm.substring(0, argTerm.length() - 1)) - 1; - break; - } - - Object argItem = args[argIdx]; - - if (typeTerm.equals("s") && argItem instanceof Spanned) { - cookedArg = (Spanned) argItem; - } else { - cookedArg = String.format(locale, "%" + modTerm + typeTerm, argItem); - } - } - - out.replace(i, exprEnd, cookedArg); - i += cookedArg.length(); - } - - return new SpannedString(out); - } -} diff --git a/app/src/main/java/de/kuschku/quasseldroid/util/ui/SpanFormatter.kt b/app/src/main/java/de/kuschku/quasseldroid/util/ui/SpanFormatter.kt new file mode 100644 index 0000000000000000000000000000000000000000..09ddf7b1f7cd064fd8f407f1d49a2b5d91ec492c --- /dev/null +++ b/app/src/main/java/de/kuschku/quasseldroid/util/ui/SpanFormatter.kt @@ -0,0 +1,103 @@ +/* + * Copyright © 2014 George T. Steel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.kuschku.quasseldroid.util.ui + +import android.text.Spannable +import android.text.SpannableStringBuilder +import android.text.Spanned +import android.text.SpannedString +import java.util.* +import java.util.regex.Pattern + +/** + * Provides [String.format] style functions that work with [Spanned] strings and preserve formatting. + * + * @author George T. Steel + */ +object SpanFormatter { + private val FORMAT_SEQUENCE = Pattern.compile("%([0-9]+\\$|<?)([^a-zA-z%]*)([[a-zA-Z%]&&[^tT]]|[tT][a-zA-Z])") + + /** + * Version of [String.format] that works on [Spanned] strings to preserve rich text formatting. + * Both the `format` as well as any `%s args` can be Spanned and will have their formatting preserved. + * Due to the way [Spannable]s work, any argument's spans will can only be included **once** in the result. + * Any duplicates will appear as text only. + * + * @param format the format string (see [java.util.Formatter.format]) + * @param args the list of arguments passed to the formatter. If there are + * more arguments than required by `format`, + * additional arguments are ignored. + * @return the formatted string (with spans). + */ + fun format(format: CharSequence, vararg args: Any): SpannedString { + return format(Locale.getDefault(), format, *args) + } + + /** + * Version of [String.format] that works on [Spanned] strings to preserve rich text formatting. + * Both the `format` as well as any `%s args` can be Spanned and will have their formatting preserved. + * Due to the way [Spannable]s work, any argument's spans will can only be included **once** in the result. + * Any duplicates will appear as text only. + * + * @param locale the locale to apply; `null` value means no localization. + * @param format the format string (see [java.util.Formatter.format]) + * @param args the list of arguments passed to the formatter. + * @return the formatted string (with spans). + * @see String.format + */ + fun format(locale: Locale, format: CharSequence, vararg args: Any): SpannedString { + val out = SpannableStringBuilder(format) + + var i = 0 + var argAt = -1 + + while (i < out.length) { + val m = FORMAT_SEQUENCE.matcher(out) + if (!m.find(i)) break + i = m.start() + val exprEnd = m.end() + + val argTerm = m.group(1) + val modTerm = m.group(2) + val typeTerm = m.group(3) + + val cookedArg: CharSequence + + if (typeTerm == "%") { + cookedArg = "%" + } else { + val argIdx = when (argTerm) { + "" -> ++argAt + "<" -> argAt + else -> Integer.parseInt(argTerm.substring(0, argTerm.length - 1)) - 1 + } + + val argItem = args[argIdx] + + cookedArg = if (typeTerm == "s" && argItem is Spanned) { + argItem + } else { + String.format(locale, "%$modTerm$typeTerm", argItem) + } + } + + out.replace(i, exprEnd, cookedArg) + i += cookedArg.length + } + + return SpannedString(out) + } +} diff --git a/app/src/main/res/layout-sw720dp-land/activity_main.xml b/app/src/main/res/layout-sw720dp-land/activity_main.xml index 82db79c8cd776279f932cde77857875dfbb5dafe..99c33c0d96417b917c576354ed525a745bf891c5 100644 --- a/app/src/main/res/layout-sw720dp-land/activity_main.xml +++ b/app/src/main/res/layout-sw720dp-land/activity_main.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> + <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" diff --git a/app/src/main/res/layout/widget_chatmessage_error.xml b/app/src/main/res/layout/widget_chatmessage_error.xml index cbcd73b12de21b16cdb4954b5db780a72c0c1931..2a0b20956750854e26052487adc122b60d798884 100644 --- a/app/src/main/res/layout/widget_chatmessage_error.xml +++ b/app/src/main/res/layout/widget_chatmessage_error.xml @@ -17,24 +17,24 @@ android:paddingStart="@dimen/message_horizontal" android:paddingTop="@dimen/message_vertical"> - <TextView - android:id="@+id/time" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/message_horizontal" - android:layout_marginRight="@dimen/message_horizontal" - android:textColor="?attr/colorForegroundSecondary" - android:typeface="monospace" - tools:text="[15:55]" /> + <TextView + android:id="@+id/time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="@dimen/message_horizontal" + android:layout_marginRight="@dimen/message_horizontal" + android:textColor="?attr/colorForegroundSecondary" + android:typeface="monospace" + tools:text="[15:55]" /> - <TextView - android:id="@+id/content" - android:layout_width="0dip" - android:layout_height="wrap_content" - android:layout_weight="1" - android:textColor="?attr/colorForegroundError" - android:textIsSelectable="true" - tools:text="everyone: deserves a chance to fly. No such channel" /> + <TextView + android:id="@+id/content" + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1" + android:textColor="?attr/colorForegroundError" + android:textIsSelectable="true" + tools:text="everyone: deserves a chance to fly. No such channel" /> </LinearLayout> <View diff --git a/app/src/main/res/layout/widget_chatmessage_info.xml b/app/src/main/res/layout/widget_chatmessage_info.xml index ba643efbbe7f4574df29c72f349322ba529e2e10..3d576e1e9e95c8aa63e6844cb2c7b8377b46e704 100644 --- a/app/src/main/res/layout/widget_chatmessage_info.xml +++ b/app/src/main/res/layout/widget_chatmessage_info.xml @@ -17,25 +17,25 @@ android:paddingStart="@dimen/message_horizontal" android:paddingTop="@dimen/message_vertical"> - <TextView - android:id="@+id/time" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/message_horizontal" - android:layout_marginRight="@dimen/message_horizontal" - android:fontFamily="monospace" - android:textColor="?attr/colorForegroundSecondary" - tools:text="[15:55]" /> + <TextView + android:id="@+id/time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="@dimen/message_horizontal" + android:layout_marginRight="@dimen/message_horizontal" + android:fontFamily="monospace" + android:textColor="?attr/colorForegroundSecondary" + tools:text="[15:55]" /> - <TextView - android:id="@+id/content" - android:layout_width="0dip" - android:layout_height="wrap_content" - android:layout_weight="1" - android:textColor="?attr/colorForegroundSecondary" - android:textIsSelectable="true" - android:textStyle="italic" - tools:text="Connecting to irc.freenode.net:6667..." /> + <TextView + android:id="@+id/content" + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1" + android:textColor="?attr/colorForegroundSecondary" + android:textIsSelectable="true" + android:textStyle="italic" + tools:text="Connecting to irc.freenode.net:6667..." /> </LinearLayout> <View diff --git a/app/src/main/res/layout/widget_chatmessage_notice.xml b/app/src/main/res/layout/widget_chatmessage_notice.xml index 6bcf8f7cbac80d5a68bda2e0104d5ba4e09d5d2b..bc904f147095501c36ce2a104e8ceb8c1e337751 100644 --- a/app/src/main/res/layout/widget_chatmessage_notice.xml +++ b/app/src/main/res/layout/widget_chatmessage_notice.xml @@ -17,24 +17,24 @@ android:paddingStart="@dimen/message_horizontal" android:paddingTop="@dimen/message_vertical"> - <TextView - android:id="@+id/time" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/message_horizontal" - android:layout_marginRight="@dimen/message_horizontal" - android:fontFamily="monospace" - android:textColor="?attr/colorForegroundNotice" - tools:text="[15:55]" /> + <TextView + android:id="@+id/time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="@dimen/message_horizontal" + android:layout_marginRight="@dimen/message_horizontal" + android:fontFamily="monospace" + android:textColor="?attr/colorForegroundNotice" + tools:text="[15:55]" /> - <TextView - android:id="@+id/content" - android:layout_width="0dip" - android:layout_height="wrap_content" - android:layout_weight="1" - android:textColor="?attr/colorForegroundNotice" - android:textIsSelectable="true" - tools:text="Connecting to irc.freenode.net:6667..." /> + <TextView + android:id="@+id/content" + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1" + android:textColor="?attr/colorForegroundNotice" + android:textIsSelectable="true" + tools:text="Connecting to irc.freenode.net:6667..." /> </LinearLayout> <View diff --git a/app/src/main/res/layout/widget_chatmessage_plain.xml b/app/src/main/res/layout/widget_chatmessage_plain.xml index 476865332c167682107583f55db2fd4f7e7ae74a..48c9be053ab66e6fd06fa2fa02dced2dc776e033 100644 --- a/app/src/main/res/layout/widget_chatmessage_plain.xml +++ b/app/src/main/res/layout/widget_chatmessage_plain.xml @@ -17,24 +17,24 @@ android:paddingStart="@dimen/message_horizontal" android:paddingTop="@dimen/message_vertical"> - <TextView - android:id="@+id/time" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/message_horizontal" - android:layout_marginRight="@dimen/message_horizontal" - android:textColor="?attr/colorForegroundSecondary" - android:typeface="monospace" - tools:text="[15:55]" /> + <TextView + android:id="@+id/time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="@dimen/message_horizontal" + android:layout_marginRight="@dimen/message_horizontal" + android:textColor="?attr/colorForegroundSecondary" + android:typeface="monospace" + tools:text="[15:55]" /> - <TextView - android:id="@+id/content" - android:layout_width="0dip" - android:layout_height="wrap_content" - android:layout_weight="1" - android:textColor="?attr/colorForeground" - android:textIsSelectable="true" - tools:text="justJanne: hiii" /> + <TextView + android:id="@+id/content" + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1" + android:textColor="?attr/colorForeground" + android:textIsSelectable="true" + tools:text="justJanne: hiii" /> </LinearLayout> <View diff --git a/app/src/main/res/layout/widget_chatmessage_server.xml b/app/src/main/res/layout/widget_chatmessage_server.xml index 00003711c80e2ea2d9ebcb280b9d0a7134959931..6d42e0c170e63b21e35949aba79af5c67b21b1d4 100644 --- a/app/src/main/res/layout/widget_chatmessage_server.xml +++ b/app/src/main/res/layout/widget_chatmessage_server.xml @@ -17,24 +17,24 @@ android:paddingStart="@dimen/message_horizontal" android:paddingTop="@dimen/message_vertical"> - <TextView - android:id="@+id/time" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginEnd="@dimen/message_horizontal" - android:layout_marginRight="@dimen/message_horizontal" - android:textColor="?attr/colorForegroundSecondary" - android:typeface="monospace" - tools:text="[15:55]" /> + <TextView + android:id="@+id/time" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="@dimen/message_horizontal" + android:layout_marginRight="@dimen/message_horizontal" + android:textColor="?attr/colorForegroundSecondary" + android:typeface="monospace" + tools:text="[15:55]" /> - <TextView - android:id="@+id/content" - android:layout_width="0dip" - android:layout_height="wrap_content" - android:layout_weight="1" - android:textColor="?attr/colorForegroundSecondary" - android:textIsSelectable="true" - tools:text="Connecting to irc.freenode.net:6667..." /> + <TextView + android:id="@+id/content" + android:layout_width="0dip" + android:layout_height="wrap_content" + android:layout_weight="1" + android:textColor="?attr/colorForegroundSecondary" + android:textIsSelectable="true" + tools:text="Connecting to irc.freenode.net:6667..." /> </LinearLayout> <View diff --git a/app/src/main/res/values/strings_preferences.xml b/app/src/main/res/values/strings_preferences.xml index 035ef82856ea7f232280caea76a6ef6d18fcf693..8993c6ae33ec996949ac8a407125fdd0bda6de28 100644 --- a/app/src/main/res/values/strings_preferences.xml +++ b/app/src/main/res/values/strings_preferences.xml @@ -112,7 +112,7 @@ <string name="preference_initial_amount_key" translatable="false">initial_amount</string> <string name="preference_initial_amount_title">Initial Amount</string> - <string name="preference_initial_amount_summary">Number of messages to load when opening a buffer for the first time</string> + <string name="preference_initial_amount_summary">Number of messages to load when opening a buffer for the first time</string> <string name="preference_connection_title">Connection</string> diff --git a/app/src/main/res/values/themes_quassel.xml b/app/src/main/res/values/themes_quassel.xml index f21e5ab138dd38da1d711246252a650d84e58d48..49784f16cab7161632a1aac9e206349751ed2677 100644 --- a/app/src/main/res/values/themes_quassel.xml +++ b/app/src/main/res/values/themes_quassel.xml @@ -2,6 +2,7 @@ <resources> <color name="quassel_light_background">#fafafa</color> + <style name="Theme.ChatTheme.Quassel_Light" parent="Theme.ChatTheme.Light"> <item name="senderColor0">#cc0000</item> <item name="senderColor1">#006cad</item> @@ -44,6 +45,7 @@ </style> <color name="quassel_dark_background">#303030</color> + <style name="Theme.ChatTheme.Quassel_Dark" parent="Theme.ChatTheme"> <item name="senderColor0">#cc0000</item> <item name="senderColor1">#006cad</item> diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index bb1902278765e3e8a24425ad6e3d8b31cf342952..aa6a895532d3436eebea84f07762dacc45ce33d5 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -85,11 +85,11 @@ android:summary="@string/preference_page_size_summary" android:title="@string/preference_page_size_title" /> <EditTextPreference - android:defaultValue="20" - android:inputType="number" - android:key="@string/preference_initial_amount_key" - android:summary="@string/preference_initial_amount_summary" - android:title="@string/preference_initial_amount_title" /> + android:defaultValue="20" + android:inputType="number" + android:key="@string/preference_initial_amount_key" + android:summary="@string/preference_initial_amount_summary" + android:title="@string/preference_initial_amount_title" /> </PreferenceCategory> <PreferenceCategory android:title="@string/preference_connection_title"> diff --git a/lib/src/main/java/de/kuschku/libquassel/protocol/QVariant.kt b/lib/src/main/java/de/kuschku/libquassel/protocol/QVariant.kt index b0eeac79123bf06a9133d23ca78b392ddcd8bc6e..22cd81d6da973409f7f24559b2f07a02323f5e0f 100644 --- a/lib/src/main/java/de/kuschku/libquassel/protocol/QVariant.kt +++ b/lib/src/main/java/de/kuschku/libquassel/protocol/QVariant.kt @@ -14,8 +14,7 @@ class QVariant<T>(val data: T?, val type: MetaType<T>) { } } -inline fun <reified U> QVariant_?.value(): U? - = this?.value<U?>(null) +inline fun <reified U> QVariant_?.value(): U? = this?.value<U?>(null) inline fun <reified U> QVariant_?.value(defValue: U): U = this?.data as? U ?: defValue diff --git a/lib/src/main/java/de/kuschku/libquassel/protocol/primitive/serializer/BoolSerializer.kt b/lib/src/main/java/de/kuschku/libquassel/protocol/primitive/serializer/BoolSerializer.kt index 85785e8dbbda7d2b0d78768fd2500929c5abe808..3daf6f868eaf82257c702aa515d352983928a2ed 100644 --- a/lib/src/main/java/de/kuschku/libquassel/protocol/primitive/serializer/BoolSerializer.kt +++ b/lib/src/main/java/de/kuschku/libquassel/protocol/primitive/serializer/BoolSerializer.kt @@ -14,6 +14,6 @@ object BoolSerializer : Serializer<Boolean> { }.toByte() ) - override fun deserialize(buffer: ByteBuffer, features: Quassel_Features) - = buffer.get() != 0x00.toByte() + override fun deserialize(buffer: ByteBuffer, + features: Quassel_Features) = buffer.get() != 0x00.toByte() } diff --git a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/BufferSyncer.kt b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/BufferSyncer.kt index 003897236a2dbac9b57e48622eaf6d08a9b9b1d0..a6497e25dc8fce11f70c391b759e6a1398780e4d 100644 --- a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/BufferSyncer.kt +++ b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/BufferSyncer.kt @@ -14,32 +14,33 @@ class BufferSyncer constructor( private val session: ISession ) : SyncableObject(proxy, "BufferSyncer"), IBufferSyncer { fun lastSeenMsg(buffer: BufferId): MsgId = _lastSeenMsg[buffer] ?: 0 - fun liveLastSeenMsg(buffer: BufferId): Observable<MsgId> - = live_lastSeenMsg.map { markerLine(buffer) }.distinctUntilChanged() + fun liveLastSeenMsg(buffer: BufferId): Observable<MsgId> = live_lastSeenMsg.map { + markerLine(buffer) + }.distinctUntilChanged() fun liveLastSeenMsgs(): Observable<Map<BufferId, MsgId>> = live_lastSeenMsg fun markerLine(buffer: BufferId): MsgId = _markerLines[buffer] ?: 0 - fun liveMarkerLine(buffer: BufferId): Observable<MsgId> - = live_markerLines.map { markerLine(buffer) }.distinctUntilChanged() + fun liveMarkerLine( + buffer: BufferId): Observable<MsgId> = live_markerLines.map { markerLine(buffer) }.distinctUntilChanged() fun liveMarkerLines(): Observable<Map<BufferId, MsgId>> = live_markerLines fun activity(buffer: BufferId): Message_Types = _bufferActivities[buffer] ?: Message_Types.of() - fun liveActivity(buffer: BufferId): Observable<Message_Types> - = live_bufferActivities.map { activity(buffer) }.distinctUntilChanged() + fun liveActivity( + buffer: BufferId): Observable<Message_Types> = live_bufferActivities.map { activity(buffer) }.distinctUntilChanged() fun liveActivities(): Observable<Map<BufferId, Message_Types>> = live_bufferActivities fun highlightCount(buffer: BufferId): Int = _highlightCounts[buffer] ?: 0 - fun liveHighlightCount(buffer: BufferId): Observable<Int> - = live_highlightCounts.map { highlightCount(buffer) }.distinctUntilChanged() + fun liveHighlightCount( + buffer: BufferId): Observable<Int> = live_highlightCounts.map { highlightCount(buffer) }.distinctUntilChanged() fun liveHighlightCounts(): Observable<Map<BufferId, Int>> = live_highlightCounts fun bufferInfo(bufferId: BufferId) = _bufferInfos[bufferId] - fun liveBufferInfo(bufferId: BufferId) - = live_bufferInfos.map { bufferInfo(bufferId) }.distinctUntilChanged() + fun liveBufferInfo( + bufferId: BufferId) = live_bufferInfos.map { bufferInfo(bufferId) }.distinctUntilChanged() fun bufferInfos(): Collection<BufferInfo> = _bufferInfos.values fun liveBufferInfos(): Observable<Map<BufferId, BufferInfo>> = live_bufferInfos @@ -207,22 +208,17 @@ class BufferSyncer constructor( } private val _lastSeenMsg: MutableMap<BufferId, MsgId> = mutableMapOf() - private val live_lastSeenMsg - = BehaviorSubject.createDefault(mapOf<BufferId, MsgId>()) + private val live_lastSeenMsg = BehaviorSubject.createDefault(mapOf<BufferId, MsgId>()) private val _markerLines: MutableMap<BufferId, MsgId> = mutableMapOf() - private val live_markerLines - = BehaviorSubject.createDefault(mapOf<BufferId, MsgId>()) + private val live_markerLines = BehaviorSubject.createDefault(mapOf<BufferId, MsgId>()) private val _bufferActivities: MutableMap<BufferId, Message_Types> = mutableMapOf() - private val live_bufferActivities - = BehaviorSubject.createDefault(mapOf<BufferId, Message_Types>()) + private val live_bufferActivities = BehaviorSubject.createDefault(mapOf<BufferId, Message_Types>()) private val _highlightCounts: MutableMap<BufferId, Int> = mutableMapOf() - private val live_highlightCounts - = BehaviorSubject.createDefault(mapOf<BufferId, Int>()) + private val live_highlightCounts = BehaviorSubject.createDefault(mapOf<BufferId, Int>()) private val _bufferInfos = mutableMapOf<BufferId, BufferInfo>() - private val live_bufferInfos - = BehaviorSubject.createDefault(mapOf<BufferId, BufferInfo>()) + private val live_bufferInfos = BehaviorSubject.createDefault(mapOf<BufferId, BufferInfo>()) } diff --git a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/BufferViewManager.kt b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/BufferViewManager.kt index ee717379d914746423ac8f7b96db97b8a933ac77..bf56136b46c27632a0afa8eb89237e88f110a28f 100644 --- a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/BufferViewManager.kt +++ b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/BufferViewManager.kt @@ -60,11 +60,10 @@ class BufferViewManager constructor( live_bufferViewConfigs.onNext(_bufferViewConfigs.keys) } - private val _bufferViewConfigs: MutableMap<Int, BufferViewConfig> - = mutableMapOf() + private val _bufferViewConfigs: MutableMap<Int, BufferViewConfig> = mutableMapOf() - private val live_bufferViewConfigs: BehaviorSubject<Set<Int>> - = BehaviorSubject.createDefault<Set<Int>>(emptySet()) + private val live_bufferViewConfigs: BehaviorSubject<Set<Int>> = BehaviorSubject.createDefault<Set<Int>>( + emptySet()) fun handleBuffer(info: BufferInfo, bufferSyncer: BufferSyncer) { for (bufferViewConfig in bufferViewConfigs()) { diff --git a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IrcChannel.kt b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IrcChannel.kt index b7ff9e364b810c1fe0d6a120f8a342dcd8b2a2bb..2b1ef93133657b706a66173dc88c9771df7ae9a2 100644 --- a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IrcChannel.kt +++ b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IrcChannel.kt @@ -123,6 +123,7 @@ class IrcChannel( fun liveUserModes(ircUser: IrcUser) = live_userModes.map { _userModes.getOr(ircUser, "") } + fun userModes(nick: String) = network().ircUser(nick)?.let { userModes(it) } ?: "" fun liveUserModes(nick: String) = network().ircUser(nick)?.let { userModes(it) } ?: "" diff --git a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IrcUser.kt b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IrcUser.kt index 84fa55d9ce29dab56a5980e6855a0b3e6204ca89..fda29f35977ece92397e3e30916ccecddd872503 100644 --- a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IrcUser.kt +++ b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/IrcUser.kt @@ -84,6 +84,7 @@ class IrcUser( _idleTime = Instant.EPOCH return _idleTime } + fun loginTime() = _loginTime fun ircOperator() = _ircOperator fun lastAwayMessage() = _lastAwayMessage diff --git a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/Network.kt b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/Network.kt index 5b981d535bc1285e800c321fa60096401e1e7f8d..a4649b29954cd4148c25fc3fd312512c516121e3 100644 --- a/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/Network.kt +++ b/lib/src/main/java/de/kuschku/libquassel/quassel/syncables/Network.kt @@ -69,21 +69,17 @@ class Network constructor( fun isConnected() = _connected fun connectionState() = _connectionState - fun prefixToMode(prefix: Char): Char? - = prefixModes().elementAtOrNull(prefixes().indexOf(prefix)) + fun prefixToMode(prefix: Char): Char? = prefixModes().elementAtOrNull(prefixes().indexOf(prefix)) - fun prefixesToModes(prefixes: String): String - = prefixes.mapNotNull { + fun prefixesToModes(prefixes: String): String = prefixes.mapNotNull { prefixes().indexOf(it) }.sorted().mapNotNull { prefixModes().elementAtOrNull(it) }.joinToString("") - fun modeToPrefix(mode: Char): Char? - = prefixes().elementAtOrNull(prefixModes().indexOf(mode)) + fun modeToPrefix(mode: Char): Char? = prefixes().elementAtOrNull(prefixModes().indexOf(mode)) - fun modesToPrefixes(modes: String): String - = modes.mapNotNull { + fun modesToPrefixes(modes: String): String = modes.mapNotNull { prefixModes().indexOf(it) }.sorted().mapNotNull { prefixes().elementAtOrNull(it) diff --git a/lib/src/main/java/de/kuschku/libquassel/session/ProtocolHandler.kt b/lib/src/main/java/de/kuschku/libquassel/session/ProtocolHandler.kt index 428cbdfb05df6bba395e0a5f6b4c3b35557e48b8..b04a2ae3a4b696ef8ab2392fd914c2c4946e0161 100644 --- a/lib/src/main/java/de/kuschku/libquassel/session/ProtocolHandler.kt +++ b/lib/src/main/java/de/kuschku/libquassel/session/ProtocolHandler.kt @@ -134,15 +134,14 @@ abstract class ProtocolHandler : SignalProxy, AuthHandler, Closeable { return true } - override fun shouldSync(type: String, instance: String, slot: String): Boolean - = type != currentCallClass || slot != currentCallSlot || instance != currentCallInstance + override fun shouldSync(type: String, instance: String, + slot: String): Boolean = type != currentCallClass || slot != currentCallSlot || instance != currentCallInstance override fun callSync(type: String, instance: String, slot: String, params: List<QVariant_>) { dispatch(SignalProxyMessage.SyncMessage(type, instance, slot, params)) } - override fun shouldRpc(slot: String): Boolean - = slot != currentCallSlot + override fun shouldRpc(slot: String): Boolean = slot != currentCallSlot override fun callRpc(slot: String, params: List<QVariant_>) { dispatch(SignalProxyMessage.RpcCall(slot, params)) diff --git a/lib/src/main/java/de/kuschku/libquassel/util/Flag.kt b/lib/src/main/java/de/kuschku/libquassel/util/Flag.kt index f2a29ec538b1ee8d649305134e0627de8cd0d328..9ab52790363b8a82c754c01d9105246661cd52bd 100644 --- a/lib/src/main/java/de/kuschku/libquassel/util/Flag.kt +++ b/lib/src/main/java/de/kuschku/libquassel/util/Flag.kt @@ -46,14 +46,13 @@ data class Flags<E>( } companion object { - inline fun <reified T> of(int: Int): Flags<T> where T : Flag<T>, T : Enum<T> = Flags( - int, enumValues() - ) - - inline fun <reified T> of( - vararg flags: Flag<T>): Flags<T> where T : Flag<T>, T : Enum<T> = Flags( - flags.map(Flag<T>::bit).distinct().sum(), enumValues() - ) + inline fun <reified T> of(int: Int): Flags<T> + where T : Flag<T>, T : Enum<T> = Flags(int, enumValues()) + + inline fun <reified T> of(vararg flags: Flag<T>): Flags<T> + where T : Flag<T>, T : Enum<T> = + Flags(flags.map(Flag<T>::bit).distinct().sum(), enumValues() + ) } interface Factory<E> where E : Flag<E>, E : Enum<E> { diff --git a/lib/src/main/java/de/kuschku/libquassel/util/LongFlag.kt b/lib/src/main/java/de/kuschku/libquassel/util/LongFlag.kt index a2807b50c964aed581bccc6d326cd6a61bfd3423..b30a6cd1d4e807ad281792e46a425f8788c9f577 100644 --- a/lib/src/main/java/de/kuschku/libquassel/util/LongFlag.kt +++ b/lib/src/main/java/de/kuschku/libquassel/util/LongFlag.kt @@ -46,12 +46,12 @@ data class LongFlags<E>( } companion object { - inline fun <reified T> of( - int: Long): LongFlags<T> where T : LongFlag<T>, T : Enum<T> = LongFlags(int, enumValues()) + inline fun <reified T> of(int: Long): LongFlags<T> + where T : LongFlag<T>, T : Enum<T> = LongFlags(int, enumValues()) - inline fun <reified T> of( - vararg flags: LongFlag<T>): LongFlags<T> where T : LongFlag<T>, T : Enum<T> = LongFlags( - flags.map(LongFlag<T>::bit).distinct().sum(), enumValues() + inline fun <reified T> of(vararg flags: LongFlag<T>): LongFlags<T> + where T : LongFlag<T>, T : Enum<T> = + LongFlags(flags.map(LongFlag<T>::bit).distinct().sum(), enumValues() ) } diff --git a/lib/src/main/java/de/kuschku/libquassel/util/ShortFlag.kt b/lib/src/main/java/de/kuschku/libquassel/util/ShortFlag.kt index 8f22a03bdabbc49fcc06dfd6af6a0e0cf2ed1785..fd15fda6d95f22275f2c4dd1cda4b35e46d9f79c 100644 --- a/lib/src/main/java/de/kuschku/libquassel/util/ShortFlag.kt +++ b/lib/src/main/java/de/kuschku/libquassel/util/ShortFlag.kt @@ -51,12 +51,12 @@ data class ShortFlags<E>( } companion object { - inline fun <reified T> ofBitMask(int: Short): ShortFlags<T> where T : ShortFlag<T>, T : Enum<T> - = ShortFlags(int, enumValues()) + inline fun <reified T> of(int: Short): ShortFlags<T> + where T : ShortFlag<T>, T : Enum<T> = ShortFlags(int, enumValues()) - inline fun <reified T> of( - vararg flags: ShortFlag<T>): ShortFlags<T> where T : ShortFlag<T>, T : Enum<T> - = ShortFlags(flags.map(ShortFlag<T>::bit).distinct().sum().toShort(), enumValues()) + inline fun <reified T> of(vararg flags: ShortFlag<T>): ShortFlags<T> + where T : ShortFlag<T>, T : Enum<T> = + ShortFlags(flags.map(ShortFlag<T>::bit).distinct().sum().toShort(), enumValues()) } interface Factory<E> where E : ShortFlag<E>, E : Enum<E> { diff --git a/lib/src/main/java/de/kuschku/libquassel/util/helpers/MapHelper.kt b/lib/src/main/java/de/kuschku/libquassel/util/helpers/MapHelper.kt index 78b1e1ab22f9f4090458fa8ff3d941fda00872f1..471d163478f74bc441746ff7610d5f0994dd9fa8 100644 --- a/lib/src/main/java/de/kuschku/libquassel/util/helpers/MapHelper.kt +++ b/lib/src/main/java/de/kuschku/libquassel/util/helpers/MapHelper.kt @@ -1,4 +1,3 @@ package de.kuschku.libquassel.util.helpers -fun <K, V> Map<K, V>.getOr(key: K, defValue: V) - = this[key] ?: defValue +fun <K, V> Map<K, V>.getOr(key: K, defValue: V) = this[key] ?: defValue diff --git a/lib/src/main/java/de/kuschku/libquassel/util/helpers/MathHelper.kt b/lib/src/main/java/de/kuschku/libquassel/util/helpers/MathHelper.kt index 692bd6fd42cf0ea2ae233df328acd0071415787b..bedb3827a980c885716a997c5fcc901ccb70a844 100644 --- a/lib/src/main/java/de/kuschku/libquassel/util/helpers/MathHelper.kt +++ b/lib/src/main/java/de/kuschku/libquassel/util/helpers/MathHelper.kt @@ -1,2 +1,2 @@ -inline fun Int.clamp(lowerBound: Int, upperBound: Int): Int - = maxOf(lowerBound, minOf(this, upperBound)) +inline fun Int.clamp(lowerBound: Int, upperBound: Int): Int = maxOf(lowerBound, + minOf(this, upperBound)) diff --git a/lib/src/main/java/de/kuschku/libquassel/util/helpers/ObservableHelper.kt b/lib/src/main/java/de/kuschku/libquassel/util/helpers/ObservableHelper.kt index 137c42e1bcc7659d2eeb27dd1946f8b2cc980423..656e6fa4c5695d2efe3355fb36ca8aa1342ff99a 100644 --- a/lib/src/main/java/de/kuschku/libquassel/util/helpers/ObservableHelper.kt +++ b/lib/src/main/java/de/kuschku/libquassel/util/helpers/ObservableHelper.kt @@ -16,13 +16,15 @@ fun <T, U> Observable<Optional<T>>.mapMap(mapper: (T) -> U): Observable<Optional it.map(mapper) } -fun <T, U> Observable<Optional<T>>.mapMapNullable(mapper: (T) -> U?): Observable<Optional<U>> = map { +fun <T, U> Observable<Optional<T>>.mapMapNullable( + mapper: (T) -> U?): Observable<Optional<U>> = map { it.flatMap { Optional.ofNullable(mapper(it)) } } -fun <T, U> Observable<Optional<T>>.mapSwitchMap(mapper: (T) -> Observable<U>): Observable<Optional<U>> = switchMap { +fun <T, U> Observable<Optional<T>>.mapSwitchMap( + mapper: (T) -> Observable<U>): Observable<Optional<U>> = switchMap { if (it.isPresent()) { it.map(mapper).get().map { Optional.of(it) } } else { @@ -30,7 +32,8 @@ fun <T, U> Observable<Optional<T>>.mapSwitchMap(mapper: (T) -> Observable<U>): O } } -fun <T, U> Observable<Optional<T>>.mapSwitchMapEmpty(mapper: (T) -> Observable<U>): Observable<U> = switchMap { +fun <T, U> Observable<Optional<T>>.mapSwitchMapEmpty( + mapper: (T) -> Observable<U>): Observable<U> = switchMap { if (it.isPresent()) { it.map(mapper).get() } else { @@ -38,7 +41,8 @@ fun <T, U> Observable<Optional<T>>.mapSwitchMapEmpty(mapper: (T) -> Observable<U } } -fun <T, U> Observable<Optional<T>>.flatMapSwitchMap(mapper: (T) -> Observable<Optional<U>>): Observable<Optional<U>> = switchMap { +fun <T, U> Observable<Optional<T>>.flatMapSwitchMap( + mapper: (T) -> Observable<Optional<U>>): Observable<Optional<U>> = switchMap { it.map(mapper).orElse(Observable.just(Optional.empty())) } diff --git a/lib/src/main/java/de/kuschku/libquassel/util/irc/IrcCaseMappers.kt b/lib/src/main/java/de/kuschku/libquassel/util/irc/IrcCaseMappers.kt index c7cbc1521d72ad59301b3fcb84741b1e6edaa274..d0c05235473ca32d9d96759c88f1828ba606c5a1 100644 --- a/lib/src/main/java/de/kuschku/libquassel/util/irc/IrcCaseMappers.kt +++ b/lib/src/main/java/de/kuschku/libquassel/util/irc/IrcCaseMappers.kt @@ -44,8 +44,7 @@ object IrcCaseMappers { } } - operator fun get(caseMapping: String) - = if (caseMapping.equals("rfc1459", ignoreCase = true)) { + operator fun get(caseMapping: String) = if (caseMapping.equals("rfc1459", ignoreCase = true)) { irc } else { unicode