From cfaf6162e608ea1ddf5ef07aa54c544ec08982b5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 5 Mar 2023 15:23:46 +0100 Subject: [PATCH] use Java 17 --- app/build.gradle | 6 +- .../1.json | 8 +- .../android/database/entity/ChatEntity.java | 2 +- .../im/conversations/android/ui/Intents.java | 6 +- .../settings/InterfaceSettingsFragment.java | 3 +- .../android/xmpp/manager/AxolotlManager.java | 3 +- .../xmpp/manager/MultiUserChatManager.java | 3 +- .../android/xmpp/processor/BindProcessor.java | 24 +- .../android/xmpp/EntityCapabilitiesTest.java | 250 +++++++++--------- .../android/xmpp/PubSubTest.java | 52 ++-- .../android/xmpp/TimestampTest.java | 14 +- .../android/xmpp/XmlElementReaderTest.java | 21 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 14 files changed, 208 insertions(+), 188 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fd2b088ff..fc1efb7d1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,8 +30,8 @@ android { } compileOptions { coreLibraryDesugaringEnabled true - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } buildFeatures { dataBinding true @@ -65,7 +65,7 @@ android { spotless { java { target '**/*.java' - googleJavaFormat('1.8').aosp().reflowLongStrings() + googleJavaFormat().aosp().reflowLongStrings() } } diff --git a/app/schemas/im.conversations.android.database.ConversationsDatabase/1.json b/app/schemas/im.conversations.android.database.ConversationsDatabase/1.json index e9bbad705..84b16426b 100644 --- a/app/schemas/im.conversations.android.database.ConversationsDatabase/1.json +++ b/app/schemas/im.conversations.android.database.ConversationsDatabase/1.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 1, - "identityHash": "9620a1b63d595091a2b463e89b504eb7", + "identityHash": "414be5ac9e68ecf9063dddbcc1cf993a", "entities": [ { "tableName": "account", @@ -1009,7 +1009,7 @@ }, { "tableName": "chat", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `accountId` INTEGER NOT NULL, `address` TEXT NOT NULL, `type` TEXT, `archived` INTEGER NOT NULL, `mucState` TEXT, `errorCondition` TEXT, FOREIGN KEY(`accountId`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `accountId` INTEGER NOT NULL, `address` TEXT NOT NULL, `type` TEXT NOT NULL, `archived` INTEGER NOT NULL, `mucState` TEXT, `errorCondition` TEXT, FOREIGN KEY(`accountId`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", "fields": [ { "fieldPath": "id", @@ -1033,7 +1033,7 @@ "fieldPath": "type", "columnName": "type", "affinity": "TEXT", - "notNull": false + "notNull": true }, { "fieldPath": "archived", @@ -2594,7 +2594,7 @@ "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '9620a1b63d595091a2b463e89b504eb7')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '414be5ac9e68ecf9063dddbcc1cf993a')" ] } } \ No newline at end of file diff --git a/app/src/main/java/im/conversations/android/database/entity/ChatEntity.java b/app/src/main/java/im/conversations/android/database/entity/ChatEntity.java index 7ea15b065..2f1f29988 100644 --- a/app/src/main/java/im/conversations/android/database/entity/ChatEntity.java +++ b/app/src/main/java/im/conversations/android/database/entity/ChatEntity.java @@ -31,7 +31,7 @@ public class ChatEntity { @NonNull public String address; - public ChatType type; + @NonNull public ChatType type; public boolean archived; diff --git a/app/src/main/java/im/conversations/android/ui/Intents.java b/app/src/main/java/im/conversations/android/ui/Intents.java index fc2aae3fc..7304e8df0 100644 --- a/app/src/main/java/im/conversations/android/ui/Intents.java +++ b/app/src/main/java/im/conversations/android/ui/Intents.java @@ -19,15 +19,13 @@ public final class Intents { private Intents() {} public static Intent of(final ChatFilter chatFilter) { - if (chatFilter instanceof AccountIdentifier) { - final var account = (AccountIdentifier) chatFilter; + if (chatFilter instanceof final AccountIdentifier account) { final var intent = new Intent(ACTION_FILTER_CHATS_BY_ACCOUNT); intent.putExtra(EXTRA_ACCOUNT_ID, account.id); intent.putExtra(EXTRA_ACCOUNT_ADDRESS, account.address.toString()); return intent; } - if (chatFilter instanceof GroupIdentifier) { - final var group = (GroupIdentifier) chatFilter; + if (chatFilter instanceof final GroupIdentifier group) { final var intent = new Intent(ACTION_FILTER_CHATS_BY_GROUP); intent.putExtra(EXTRA_GROUP_ID, group.id); intent.putExtra(EXTRA_GROUP_NAME, group.name); diff --git a/app/src/main/java/im/conversations/android/ui/fragment/settings/InterfaceSettingsFragment.java b/app/src/main/java/im/conversations/android/ui/fragment/settings/InterfaceSettingsFragment.java index 7e225fa34..7c49bc1b5 100644 --- a/app/src/main/java/im/conversations/android/ui/fragment/settings/InterfaceSettingsFragment.java +++ b/app/src/main/java/im/conversations/android/ui/fragment/settings/InterfaceSettingsFragment.java @@ -21,8 +21,7 @@ public class InterfaceSettingsFragment extends PreferenceFragmentCompat { } themePreference.setOnPreferenceChangeListener( (preference, newValue) -> { - if (newValue instanceof String) { - final String theme = (String) newValue; + if (newValue instanceof final String theme) { final int desiredNightMode = Conversations.getDesiredNightMode(theme); requireSettingsActivity().setDesiredNightMode(desiredNightMode); } diff --git a/app/src/main/java/im/conversations/android/xmpp/manager/AxolotlManager.java b/app/src/main/java/im/conversations/android/xmpp/manager/AxolotlManager.java index 11089c4cf..5087d60d8 100644 --- a/app/src/main/java/im/conversations/android/xmpp/manager/AxolotlManager.java +++ b/app/src/main/java/im/conversations/android/xmpp/manager/AxolotlManager.java @@ -109,8 +109,7 @@ public class AxolotlManager extends AbstractManager implements AxolotlService.Po if (throwable instanceof TimeoutException) { return; } - if (throwable instanceof IqErrorException) { - final var iqErrorException = (IqErrorException) throwable; + if (throwable instanceof final IqErrorException iqErrorException) { final var error = iqErrorException.getError(); final var condition = error == null ? null : error.getCondition(); if (condition != null) { diff --git a/app/src/main/java/im/conversations/android/xmpp/manager/MultiUserChatManager.java b/app/src/main/java/im/conversations/android/xmpp/manager/MultiUserChatManager.java index 11bae2029..ed5a2fb90 100644 --- a/app/src/main/java/im/conversations/android/xmpp/manager/MultiUserChatManager.java +++ b/app/src/main/java/im/conversations/android/xmpp/manager/MultiUserChatManager.java @@ -179,8 +179,7 @@ public class MultiUserChatManager extends AbstractManager { @Override public void onFailure(@NonNull final Throwable throwable) { final String errorCondition; - if (throwable instanceof IqErrorException) { - final var iqErrorException = (IqErrorException) throwable; + if (throwable instanceof final IqErrorException iqErrorException) { final Error error = iqErrorException.getError(); final Condition condition = error == null ? null : error.getCondition(); errorCondition = condition == null ? null : condition.getName(); diff --git a/app/src/main/java/im/conversations/android/xmpp/processor/BindProcessor.java b/app/src/main/java/im/conversations/android/xmpp/processor/BindProcessor.java index 3a1a8f0c2..53f4450ee 100644 --- a/app/src/main/java/im/conversations/android/xmpp/processor/BindProcessor.java +++ b/app/src/main/java/im/conversations/android/xmpp/processor/BindProcessor.java @@ -1,6 +1,9 @@ package im.conversations.android.xmpp.processor; import android.content.Context; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.MoreExecutors; import im.conversations.android.xml.Namespace; import im.conversations.android.xmpp.Entity; import im.conversations.android.xmpp.XmppConnection; @@ -8,9 +11,11 @@ import im.conversations.android.xmpp.manager.AxolotlManager; import im.conversations.android.xmpp.manager.BlockingManager; import im.conversations.android.xmpp.manager.BookmarkManager; import im.conversations.android.xmpp.manager.DiscoManager; +import im.conversations.android.xmpp.manager.HttpUploadManager; import im.conversations.android.xmpp.manager.PresenceManager; import im.conversations.android.xmpp.manager.RosterManager; import java.util.function.Consumer; +import okhttp3.MediaType; import org.jxmpp.jid.Jid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +33,6 @@ public class BindProcessor extends XmppConnection.Delegate implements Consumer { database.chatDao().resetMucStates(); @@ -53,5 +57,23 @@ public class BindProcessor extends XmppConnection.Delegate implements Consumer() { + @Override + public void onSuccess(HttpUploadManager.Slot result) { + LOGGER.info("requested slot {}", result); + } + + @Override + public void onFailure(Throwable t) { + LOGGER.info("could not request slot", t); + } + }, + MoreExecutors.directExecutor()); } } diff --git a/app/src/test/java/im/conversations/android/xmpp/EntityCapabilitiesTest.java b/app/src/test/java/im/conversations/android/xmpp/EntityCapabilitiesTest.java index 5f786835c..02fa09b45 100644 --- a/app/src/test/java/im/conversations/android/xmpp/EntityCapabilitiesTest.java +++ b/app/src/test/java/im/conversations/android/xmpp/EntityCapabilitiesTest.java @@ -23,15 +23,15 @@ public class EntityCapabilitiesTest { @Test public void entityCaps() throws IOException { final String xml = - "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " "; + """ + + + + + + + """; final Element element = XmlElementReader.read(xml.getBytes(StandardCharsets.UTF_8)); assertThat(element, instanceOf(InfoQuery.class)); final InfoQuery info = (InfoQuery) element; @@ -42,36 +42,37 @@ public class EntityCapabilitiesTest { @Test public void entityCapsComplexExample() throws IOException { final String xml = - "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " urn:xmpp:dataforms:softwareinfo\n" - + " \n" - + " \n" - + " ipv4\n" - + " ipv6\n" - + " \n" - + " \n" - + " Mac\n" - + " \n" - + " \n" - + " 10.5.1\n" - + " \n" - + " \n" - + " Psi\n" - + " \n" - + " \n" - + " 0.11\n" - + " \n" - + " \n" - + " "; + """ + + + + + + + + + + urn:xmpp:dataforms:softwareinfo + + + ipv4 + ipv6 + + + Mac + + + 10.5.1 + + + Psi + + + 0.11 + + + """; final Element element = XmlElementReader.read(xml.getBytes(StandardCharsets.UTF_8)); assertThat(element, instanceOf(InfoQuery.class)); final InfoQuery info = (InfoQuery) element; @@ -82,26 +83,27 @@ public class EntityCapabilitiesTest { @Test public void caps2() throws IOException { final String xml = - "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + ""; + """ + + + + + + + + + + + + + + + + + + + + """; final Element element = XmlElementReader.read(xml.getBytes(StandardCharsets.UTF_8)); assertThat(element, instanceOf(InfoQuery.class)); final InfoQuery info = (InfoQuery) element; @@ -112,72 +114,70 @@ public class EntityCapabilitiesTest { @Test public void caps2complex() throws IOException { final String xml = - "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " urn:xmpp:dataforms:softwareinfo\n" - + " \n" - + " \n" - + " Tkabber\n" - + " \n" - + " \n" - + " 0.11.1-svn-20111216-mod (Tcl/Tk 8.6b2)\n" - + " \n" - + " \n" - + " Windows\n" - + " \n" - + " \n" - + " XP\n" - + " \n" - + " \n" - + ""; + """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + urn:xmpp:dataforms:softwareinfo + + + Tkabber + + + 0.11.1-svn-20111216-mod (Tcl/Tk 8.6b2) + + + Windows + + + XP + + + """; final Element element = XmlElementReader.read(xml.getBytes(StandardCharsets.UTF_8)); assertThat(element, instanceOf(InfoQuery.class)); final InfoQuery info = (InfoQuery) element; diff --git a/app/src/test/java/im/conversations/android/xmpp/PubSubTest.java b/app/src/test/java/im/conversations/android/xmpp/PubSubTest.java index 4b0e5406d..cd386a744 100644 --- a/app/src/test/java/im/conversations/android/xmpp/PubSubTest.java +++ b/app/src/test/java/im/conversations/android/xmpp/PubSubTest.java @@ -23,32 +23,32 @@ public class PubSubTest { @Test public void parseBookmarkResult() throws IOException { final String xml = - "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " JC\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " JC\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + ""; + """ + + + + + + JC + + + + + JC + + + + + + + + """; final Element element = XmlElementReader.read(xml.getBytes(StandardCharsets.UTF_8)); assertThat(element, instanceOf(Iq.class)); final Iq iq = (Iq) element; diff --git a/app/src/test/java/im/conversations/android/xmpp/TimestampTest.java b/app/src/test/java/im/conversations/android/xmpp/TimestampTest.java index fc945ac34..d47237579 100644 --- a/app/src/test/java/im/conversations/android/xmpp/TimestampTest.java +++ b/app/src/test/java/im/conversations/android/xmpp/TimestampTest.java @@ -21,9 +21,10 @@ public class TimestampTest { @Test public void testZuluNoMillis() throws IOException { final String xml = - ""; + """ + """; final Element element = XmlElementReader.read(xml.getBytes(StandardCharsets.UTF_8)); assertThat(element, instanceOf(Delay.class)); final Delay delay = (Delay) element; @@ -33,9 +34,10 @@ public class TimestampTest { @Test public void testZuluWithMillis() throws IOException { final String xml = - ""; + """ + """; final Element element = XmlElementReader.read(xml.getBytes(StandardCharsets.UTF_8)); assertThat(element, instanceOf(Delay.class)); final Delay delay = (Delay) element; diff --git a/app/src/test/java/im/conversations/android/xmpp/XmlElementReaderTest.java b/app/src/test/java/im/conversations/android/xmpp/XmlElementReaderTest.java index a324824bc..1f87ebe1c 100644 --- a/app/src/test/java/im/conversations/android/xmpp/XmlElementReaderTest.java +++ b/app/src/test/java/im/conversations/android/xmpp/XmlElementReaderTest.java @@ -37,16 +37,17 @@ public class XmlElementReaderTest { public void readMessageError() throws IOException { final String xml = - "\n" - + " Wherefore art thou, Romeo?\n" - + " \n" - + " \n" - + " \n" - + ""; + """ + + Wherefore art thou, Romeo? + + + + """; final Element element = XmlElementReader.read(xml.getBytes(StandardCharsets.UTF_8)); assertThat(element, instanceOf(Message.class)); final Message message = (Message) element; diff --git a/build.gradle b/build.gradle index 8375d1f71..7d6870180 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.4.2' classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navVersion" - classpath "com.diffplug.spotless:spotless-plugin-gradle:6.13.0" + classpath "com.diffplug.spotless:spotless-plugin-gradle:6.16.0" } } allprojects { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9114c060e..6ea1cebff 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-rc-2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip