Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tagavari committed Jan 7, 2022
2 parents 695dbaa + 38c0aff commit 159cc7d
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ android {
applicationId "me.tagavari.airmessage"
minSdkVersion 23
targetSdkVersion 31
versionName "3.3.6"
versionCode 130
versionName "3.3.7"
versionCode 131

resConfigs "en", "fr", "ja"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class Conversations extends AppCompatCompositeActivity {

//Creating the view model and info bar values
private ActivityViewModel viewModel;
private PluginMessageBar.InfoBar infoBarConnection, infoBarContacts, infoBarServerUpdate, infoBarSecurityUpdate;
private PluginMessageBar.InfoBar infoBarConnection, infoBarContacts, infoBarServerUpdate, infoBarServerUpdateRequired, infoBarSecurityUpdate;

//Creating the menu values
private MenuItem menuItemMarkAllRead = null;
Expand Down Expand Up @@ -306,6 +306,8 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
infoBarContacts = pluginMessageBar.create(R.drawable.contacts, getResources().getString(R.string.message_permissiondetails_contacts_listing));
infoBarContacts.setButton(R.string.action_enable, view -> requestPermissions(new String[]{android.Manifest.permission.READ_CONTACTS}, permissionRequestContacts));
infoBarServerUpdate = pluginMessageBar.create(R.drawable.update, getResources().getString(R.string.message_serverupdate));
infoBarServerUpdateRequired = pluginMessageBar.create(R.drawable.sync_problem, getResources().getString(R.string.message_serverupdaterequired));
infoBarServerUpdateRequired.setButton(R.string.action_details, view -> showServerUpdateRequiredDialog());
infoBarSecurityUpdate = pluginMessageBar.create(R.drawable.lock_alert, getResources().getString(R.string.message_securityupdate));
infoBarSecurityUpdate.setButton(R.string.action_resolve, view -> GoogleApiAvailability.getInstance().showErrorDialogFragment(this, viewModel.playServicesErrorCode.getValue(), activityResultPlayServices));

Expand Down Expand Up @@ -548,7 +550,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
String proxyType;

if(pluginCS.isServiceBound()) {
currentCommunicationsVersion = pluginCS.getConnectionManager().getCommunicationsVersion();
List<Integer> communicationsVersion = pluginCS.getConnectionManager().getCommunicationsVersion();
currentCommunicationsVersion = communicationsVersion != null ? communicationsVersion.stream().map(String::valueOf).collect(Collectors.joining(".")) : "(none)";
serverSystemVersion = StringHelper.defaultEmptyString(pluginCS.getConnectionManager().getServerSystemVersion(), "(none)");
serverSoftwareVersion = StringHelper.defaultEmptyString(pluginCS.getConnectionManager().getServerSoftwareVersion(), "(none)");
} else {
Expand Down Expand Up @@ -710,9 +713,20 @@ private void updateUI(int state) {
* Updates the activity based on a new connection event
*/
private void updateStateConnection(ReduxEventConnection event) {
//Prompting the user to sync their messages
if(event.getState() == ConnectionState.connected) {
//Prompting the user to sync their messages
promptSync();

//Showing the server update required bar if the user's server is too old
if(pluginCS.isServiceBound()) {
List<Integer> version = pluginCS.getConnectionManager().getCommunicationsVersion();
if(version != null && VersionHelper.INSTANCE.compareVersions(version, Arrays.asList(5, 4)) < 0) {
infoBarServerUpdateRequired.show();
}
}
} else {
//Dismissing the server update required bar
infoBarServerUpdateRequired.hide();
}

//Updating the connection warning banner
Expand Down Expand Up @@ -801,6 +815,18 @@ private void hideServerWarning() {
infoBarConnection.hide();
}

/**
* Shows a dialog that warns the user to update their server
*/
private void showServerUpdateRequiredDialog() {
new MaterialAlertDialogBuilder(this)
.setTitle(R.string.message_serverupdaterequired)
.setMessage(R.string.message_serverupdaterequired_desc)
.setPositiveButton(android.R.string.ok, (dialog, which) -> dialog.dismiss())
.create()
.show();
}

/**
* Updates the conversation list in response to a messaging event
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.File;
import java.util.Collection;
import java.util.List;

public abstract class CommunicationsManager<Packet> {
//Creating the handler
Expand Down Expand Up @@ -221,7 +222,7 @@ public void onHandshake(String installationID, String deviceName, String systemV
/**
* Gets the active communications version
*/
public abstract String getCommunicationsVersion();
public abstract List<Integer> getCommunicationsVersion();

/**
* Gets the handler for this communications manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ private <S, T> Observable<S> queueObservableIDRequest(short requestID, Throwable
* Gets the human-readable version of the active communications protocol, or NULL if no protocol is active
*/
@Nullable
public String getCommunicationsVersion() {
public List<Integer> getCommunicationsVersion() {
if(communicationsManager != null) return communicationsManager.getCommunicationsVersion();
else return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class ClientComm4 extends CommunicationsManager<HeaderPacket> {
private static final int communicationsVersion = 4;
Expand Down Expand Up @@ -255,8 +258,12 @@ public boolean requiresPersistence() {
}

@Override
public String getCommunicationsVersion() {
return communicationsVersion + "." + (protocolManagerVer != -1 ? protocolManagerVer : "X");
public List<Integer> getCommunicationsVersion() {
if(protocolManagerVer == -1) {
return Collections.singletonList(communicationsVersion);
} else {
return Arrays.asList(communicationsVersion, protocolManagerVer);
}
}

String getPassword() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class ClientComm5 extends CommunicationsManager<EncryptedPacket> {
private static final String TAG = ClientComm5.class.getSimpleName();
Expand Down Expand Up @@ -284,8 +287,12 @@ public boolean requiresPersistence() {
}

@Override
public String getCommunicationsVersion() {
return communicationsVersion + "." + (protocolManagerVer != -1 ? protocolManagerVer : "X");
public List<Integer> getCommunicationsVersion() {
if(protocolManagerVer == -1) {
return Collections.singletonList(communicationsVersion);
} else {
return Arrays.asList(communicationsVersion, protocolManagerVer);
}
}

String getPassword() {
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/me/tagavari/airmessage/helper/VersionHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.tagavari.airmessage.helper

object VersionHelper {
/* Compares 2 version lists and returns which one is larger
-1: version 1 is smaller
0: versions are equal
1: version 1 is greater
*/
fun compareVersions(version1: List<Int>, version2: List<Int>): Int {
//Iterate over the arrays
for(i in 0 until version1.size.coerceAtLeast(version2.size)) {
//Compare the version values
val code1 = if(i >= version1.size) 0 else version1[i]
val code2 = if(i >= version2.size) 0 else version2[i]
val comparison = code1.compareTo(code2)

//Return if the value is not 0
if(comparison != 0) return comparison
}

//Return 0 (the loop finished, meaning that there was no difference)
return 0
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/sync_problem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M3,12c0,2.21 0.91,4.2 2.36,5.64L3,20h6v-6l-2.24,2.24C5.68,15.15 5,13.66 5,12c0,-2.61 1.67,-4.83 4,-5.65L9,4.26C5.55,5.15 3,8.27 3,12zM11,17h2v-2h-2v2zM21,4h-6v6l2.24,-2.24C18.32,8.85 19,10.34 19,12c0,2.61 -1.67,4.83 -4,5.65v2.09c3.45,-0.89 6,-4.01 6,-7.74 0,-2.21 -0.91,-4.2 -2.36,-5.64L21,4zM11,13h2L13,7h-2v6z"/>
</vector>
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,6 @@
<string name="action_updatepassword">Mise à jour du mot de passe du serveur</string>
<string name="message_decrypterrornotify">Un message illisible a été reçu</string>
<string name="message_decrypterrornotify_desc">Un message a été reçu qui n\'a pas pu être décrypté</string>
<string name="message_serverupdaterequired">Votre serveur doit être mis à jour</string>
<string name="message_serverupdaterequired_desc">Vous exécutez une version non prise en charge d\'AirMessage Server.\n\nLes versions non prises en charge d\'AirMessage Server peuvent présenter des problèmes de sécurité ou de stabilité et commenceront à refuser les connexions à partir de la fin janvier.\n\nVeuillez installer la dernière version d\'AirMessage Server depuis airmessage.org sur votre Mac.</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,6 @@
<string name="action_updatepassword">サーバーのパスワードの更新</string>
<string name="message_decrypterrornotify">読めないメッセージを受信しました</string>
<string name="message_decrypterrornotify_desc">復号化できなかったメッセージを受信しました</string>
<string name="message_serverupdaterequired">サーバーを更新する必要があります</string>
<string name="message_serverupdaterequired_desc">サポートされていないバージョンの AirMessage Server が動作しています。\n\nAirMessage Server の未サポートバージョンは、セキュリティや安定性に問題がある可能性があり、1月下旬に接続拒否を開始する予定です。\n\nお使いの Mac に airmessage.org から最新版の AirMessage Server をインストールしてください。</string>
</resources>
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@
<string name="message_serverupdate">A server update is available</string>
<string name="message_securityupdate">AirMessage can\'t check for security updates</string>
<string name="message_searchnoresults">No results</string>


<string name="message_serverupdaterequired">Your server needs to be updated</string>
<string name="message_serverupdaterequired_desc">You\'re running an unsupported version of AirMessage Server.\n\nUnsupported versions of AirMessage Server may contain security or stability issues, and will start refusing connections late January.\n\nPlease install the latest version of AirMessage Server from airmessage.org on your Mac.</string>

<string name="message_eventtype_chatrename_change">%1$s named the conversation \"%2$s\"</string>
<string name="message_eventtype_chatrename_change_you">You named the conversation \"%s\"</string>
<string name="message_eventtype_chatrename_remove">%s removed the conversation name</string>
Expand Down

0 comments on commit 159cc7d

Please sign in to comment.