Added "deflate" message support to musikdroid. Also fixed a layout bug and

a couple non-translated string resources.
This commit is contained in:
casey langen 2017-02-25 17:43:22 -08:00
parent d9f6b74e6a
commit b03f7d23e4
5 changed files with 24 additions and 4 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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"

View File

@ -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"/>
<CheckBox
android:id="@+id/message_compression"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/theme_foreground"
android:text="@string/settings_enable_message_compression"/>
</LinearLayout>

View File

@ -46,4 +46,6 @@
<string name="menu_genres">genres</string>
<string name="menu_playlists">playlists</string>
<string name="unknown_value">&lt;unknown&gt;</string>
<string name="settings_enable_album_art">enable album art (uses last.fm)</string>
<string name="settings_enable_message_compression">enable message compression</string>
</resources>