From b03f7d23e440616986e2611c318a21fe98818343 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sat, 25 Feb 2017 17:43:22 -0800 Subject: [PATCH] Added "deflate" message support to musikdroid. Also fixed a layout bug and a couple non-translated string resources. --- .../io/casey/musikcube/remote/SettingsActivity.java | 5 ++++- .../io/casey/musikcube/remote/WebSocketService.java | 11 +++++++++-- .../app/src/main/res/layout/activity_main.xml | 1 + .../app/src/main/res/layout/activity_settings.xml | 9 ++++++++- src/musikdroid/app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/SettingsActivity.java b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/SettingsActivity.java index eecd997cd..5501de75b 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/SettingsActivity.java +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/SettingsActivity.java @@ -14,7 +14,7 @@ import java.util.Locale; public class SettingsActivity extends AppCompatActivity { private EditText addressText, portText, passwordText; - private CheckBox albumArtCheckbox; + private CheckBox albumArtCheckbox, messageCompressionCheckbox; private SharedPreferences prefs; public static Intent getStartIntent(final Context context) { @@ -42,8 +42,10 @@ public class SettingsActivity extends AppCompatActivity { this.portText = (EditText) this.findViewById(R.id.port); this.passwordText = (EditText) this.findViewById(R.id.password); this.albumArtCheckbox = (CheckBox) findViewById(R.id.album_art_checkbox); + this.messageCompressionCheckbox = (CheckBox) findViewById(R.id.message_compression); this.albumArtCheckbox.setChecked(this.prefs.getBoolean("album_art_enabled", true)); + this.messageCompressionCheckbox.setChecked(this.prefs.getBoolean("message_compression_enabled", true)); this.findViewById(R.id.button_connect).setOnClickListener((View v) -> { final String addr = addressText.getText().toString(); @@ -55,6 +57,7 @@ public class SettingsActivity extends AppCompatActivity { .putInt("port", (port.length() > 0) ? Integer.valueOf(port) : 0) .putString("password", password) .putBoolean("album_art_enabled", albumArtCheckbox.isChecked()) + .putBoolean("message_compression_enabled", messageCompressionCheckbox.isChecked()) .apply(); WebSocketService.getInstance(this).disconnect(); diff --git a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/WebSocketService.java b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/WebSocketService.java index 4a5ec8d05..cda84eb24 100644 --- a/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/WebSocketService.java +++ b/src/musikdroid/app/src/main/java/io/casey/musikcube/remote/WebSocketService.java @@ -13,6 +13,7 @@ import android.os.Message; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; +import com.neovisionaries.ws.client.WebSocketExtension; import com.neovisionaries.ws.client.WebSocketFactory; import com.neovisionaries.ws.client.WebSocketFrame; @@ -23,6 +24,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; +import java.util.zip.Deflater; import static android.content.Context.CONNECTIVITY_SERVICE; @@ -409,8 +411,8 @@ public class WebSocketService { private WebSocketAdapter webSocketAdapter = new WebSocketAdapter() { @Override - public void onTextFrame(WebSocket websocket, WebSocketFrame frame) throws Exception { - final SocketMessage message = SocketMessage.create(frame.getPayloadText()); + public void onTextMessage(WebSocket websocket, String text) throws Exception { + final SocketMessage message = SocketMessage.create(text); if (message != null) { if (message.getName().equals(Messages.Request.Authenticate.toString())) { handler.sendMessage(Message.obtain( @@ -452,6 +454,11 @@ public class WebSocketService { socket = factory.createSocket(host, CONNECTION_TIMEOUT_MILLIS); socket.addListener(webSocketAdapter); + + if (prefs.getBoolean("message_compression_enabled", true)) { + socket.addExtension(WebSocketExtension.PERMESSAGE_DEFLATE); + } + socket.connect(); socket.setPingInterval(PING_INTERVAL_MILLIS); diff --git a/src/musikdroid/app/src/main/res/layout/activity_main.xml b/src/musikdroid/app/src/main/res/layout/activity_main.xml index bc4fcd8bc..32a43632e 100644 --- a/src/musikdroid/app/src/main/res/layout/activity_main.xml +++ b/src/musikdroid/app/src/main/res/layout/activity_main.xml @@ -127,6 +127,7 @@ android:id="@+id/track_artist" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:gravity="center" android:layout_gravity="center" android:layout_marginTop="2dp" android:textColor="@color/theme_yellow" diff --git a/src/musikdroid/app/src/main/res/layout/activity_settings.xml b/src/musikdroid/app/src/main/res/layout/activity_settings.xml index 3a0704c2b..e09c42cae 100644 --- a/src/musikdroid/app/src/main/res/layout/activity_settings.xml +++ b/src/musikdroid/app/src/main/res/layout/activity_settings.xml @@ -81,7 +81,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@color/theme_foreground" - android:text="enable album art (uses last.fm)"/> + android:text="@string/settings_enable_album_art"/> + + diff --git a/src/musikdroid/app/src/main/res/values/strings.xml b/src/musikdroid/app/src/main/res/values/strings.xml index 5030c040e..f53d28a5a 100644 --- a/src/musikdroid/app/src/main/res/values/strings.xml +++ b/src/musikdroid/app/src/main/res/values/strings.xml @@ -46,4 +46,6 @@ genres playlists <unknown> + enable album art (uses last.fm) + enable message compression