Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
badaix committed Apr 9, 2024
1 parent 372f023 commit 0c12b33
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 60 deletions.
8 changes: 4 additions & 4 deletions Snapcast/src/main/java/de/badaix/snapcast/ClientItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class ClientItem extends LinearLayout implements SeekBar.OnSeekBarChangeL

private static final String TAG = "ClientItem";

private TextView title;
private SeekBar volumeSeekBar;
private ImageButton ibMute;
private ImageButton ibOverflow;
private final TextView title;
private final SeekBar volumeSeekBar;
private final ImageButton ibMute;
private final ImageButton ibOverflow;
private Client client;
private ClientItemListener listener = null;

Expand Down
12 changes: 6 additions & 6 deletions Snapcast/src/main/java/de/badaix/snapcast/GroupItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public class GroupItem extends LinearLayout implements SeekBar.OnSeekBarChangeLi
private static final String TAG = "GroupItem";

// private TextView title;
private SeekBar volumeSeekBar;
private ImageButton ibMute;
private ImageButton ibSettings;
private LinearLayout llClient;
private final SeekBar volumeSeekBar;
private final ImageButton ibMute;
private final ImageButton ibSettings;
private final LinearLayout llClient;
private Group group;
private ServerStatus server;
private final ServerStatus server;
private TextView tvStreamName = null;
private GroupItemListener listener = null;
private LinearLayout llVolume;
private final LinearLayout llVolume;
private boolean hideOffline = false;
private Vector<ClientItem> clientItems = null;
private Vector<Integer> clientVolumes = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onCreate(Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
Log.d(TAG, "onCreateView: " + this.toString());
Log.d(TAG, "onCreateView: " + this);
View view = inflater.inflate(R.layout.fragment_group_list, container, false);
ListView lvGroup = (ListView) view.findViewById(R.id.lvGroup);
groupAdapter = new GroupAdapter(getContext(), groupItemListener);
Expand All @@ -90,7 +90,7 @@ public void onAttach(Context context) {
if (context instanceof GroupItem.GroupItemListener) {
groupItemListener = (GroupItem.GroupItemListener) context;
} else {
throw new RuntimeException(context.toString()
throw new RuntimeException(context
+ " must implement GroupItemListener");
}
updateGui();
Expand All @@ -115,8 +115,8 @@ public void setHideOffline(boolean hide) {
}

public class GroupAdapter extends ArrayAdapter<Group> {
private Context context;
private GroupItem.GroupItemListener listener;
private final Context context;
private final GroupItem.GroupItemListener listener;
private boolean hideOffline = false;
private ServerStatus serverStatus = new ServerStatus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void askNotificationPermission() {
/**
* Defines callbacks for service binding, passed to bindService()
*/
private ServiceConnection mConnection = new ServiceConnection() {
private final ServiceConnection mConnection = new ServiceConnection() {

@Override
public void onServiceConnected(ComponentName className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public class SnapclientService extends Service {
private java.lang.Process process = null;
private PowerManager.WakeLock wakeLock = null;
private WifiManager.WifiLock wifiWakeLock = null;
private Thread reader = null;
private final Thread reader = null;
private boolean running = false;
private SnapclientListener listener = null;
private boolean logReceived;
private Handler restartHandler = new Handler();
private final Handler restartHandler = new Handler();
private Runnable restartRunnable = null;
private String host = null;
private int port = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum RPCEvent {

private TcpClient tcpClient;
private long msgId;
private RemoteControlListener listener;
private final RemoteControlListener listener;
private String host;
private int port;
private final HashMap<Long, String> pendingRequests;
Expand Down Expand Up @@ -352,7 +352,7 @@ public enum ClientEvent {
disconnected("Client.OnDisconnect"),
updated("Client.OnUpdate");
//deleted("Client.OnDelete");
private String text;
private final String text;

ClientEvent(String text) {
this.text = text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class TcpClient {
private BufferedReader mBufferIn;
private Thread readerThread = null;
private Socket socket = null;
private BlockingQueue<String> messages = new LinkedBlockingQueue<>();
private final BlockingQueue<String> messages = new LinkedBlockingQueue<>();

/**
* Constructor of the class. OnMessagedReceived listens for the messages
Expand Down Expand Up @@ -136,8 +136,8 @@ public void run() {
}

private class ReaderRunnable implements Runnable {
private String host;
private int port;
private final String host;
private final int port;

ReaderRunnable(final String host, final int port) {
this.host = host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Objects;

/**
* Created by johannes on 06.01.16.
*/
Expand Down Expand Up @@ -134,12 +136,12 @@ public boolean equals(Object o) {

Client that = (Client) o;

if (host != null ? !host.equals(that.host) : that.host != null) return false;
if (snapclient != null ? !snapclient.equals(that.snapclient) : that.snapclient != null)
if (!Objects.equals(host, that.host)) return false;
if (!Objects.equals(snapclient, that.snapclient))
return false;
if (config != null ? !config.equals(that.config) : that.config != null) return false;
if (!Objects.equals(config, that.config)) return false;
if (connected != that.connected) return false;
if (clientId != null ? !clientId.equals(that.clientId) : that.clientId != null)
if (!Objects.equals(clientId, that.clientId))
return false;
return (deleted == that.deleted);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Objects;

/**
* Created by johannes on 06.01.16.
*/
Expand Down Expand Up @@ -105,9 +107,9 @@ public boolean equals(Object o) {
ClientConfig that = (ClientConfig) o;

if (latency != that.latency) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (!Objects.equals(name, that.name)) return false;
if (instance != that.instance) return false;
return !(volume != null ? !volume.equals(that.volume) : that.volume != null);
return !(!Objects.equals(volume, that.volume));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;


/**
Expand All @@ -39,7 +40,7 @@ public class Group implements JsonSerialisable, Comparable<Group> {
private String id = "";
private String streamId = "";
private boolean muted = false;
private ArrayList<Client> clients = new ArrayList<Client>();
private final ArrayList<Client> clients = new ArrayList<Client>();

public Group(JSONObject json) {
fromJson(json);
Expand Down Expand Up @@ -185,12 +186,12 @@ public boolean equals(Object o) {

Group group = (Group) o;

if (name != null ? !name.equals(group.name) : group.name != null) return false;
if (id != null ? !id.equals(group.id) : group.id != null) return false;
if (!Objects.equals(name, group.name)) return false;
if (!Objects.equals(id, group.id)) return false;
if (muted != group.muted) return false;
if (streamId != null ? !streamId.equals(group.streamId) : group.streamId != null)
if (!Objects.equals(streamId, group.streamId))
return false;
return clients != null ? clients.equals(group.clients) : group.clients == null;
return Objects.equals(clients, group.clients);

}

Expand Down
12 changes: 7 additions & 5 deletions Snapcast/src/main/java/de/badaix/snapcast/control/json/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Objects;

/**
* Created by johannes on 06.01.16.
*/
Expand Down Expand Up @@ -99,11 +101,11 @@ public boolean equals(Object o) {

Host that = (Host) o;

if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (mac != null ? !mac.equals(that.mac) : that.mac != null) return false;
if (os != null ? !os.equals(that.os) : that.os != null) return false;
if (arch != null ? !arch.equals(that.arch) : that.arch != null) return false;
return !(ip != null ? !ip.equals(that.ip) : that.ip != null);
if (!Objects.equals(name, that.name)) return false;
if (!Objects.equals(mac, that.mac)) return false;
if (!Objects.equals(os, that.os)) return false;
if (!Objects.equals(arch, that.arch)) return false;
return !(!Objects.equals(ip, that.ip));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Created by johannes on 08.01.16.
*/
public interface JsonSerialisable {
public void fromJson(JSONObject json);
void fromJson(JSONObject json);

public JSONObject toJson();
JSONObject toJson();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Objects;

/**
* Created by johannes on 02.03.16.
*/
Expand Down Expand Up @@ -85,8 +87,8 @@ public boolean equals(Object o) {

Server server = (Server) o;

if (host != null ? !host.equals(server.host) : server.host != null) return false;
return snapserver != null ? snapserver.equals(server.snapserver) : server.snapserver == null;
if (!Objects.equals(host, server.host)) return false;
return Objects.equals(snapserver, server.snapserver);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* Created by johannes on 06.01.16.
*/
public class ServerStatus implements JsonSerialisable {
private ArrayList<Group> groups = new ArrayList<Group>();
private ArrayList<Stream> streams = new ArrayList<Stream>();
private final ArrayList<Group> groups = new ArrayList<Group>();
private final ArrayList<Stream> streams = new ArrayList<Stream>();
private Server server = null;

public ServerStatus(JSONObject json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Objects;

/**
* Created by johannes on 06.01.16.
*/
Expand Down Expand Up @@ -84,8 +86,8 @@ public boolean equals(Object o) {

Snapcast that = (Snapcast) o;

if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (version != null ? !version.equals(that.version) : that.version != null) return false;
if (!Objects.equals(name, that.name)) return false;
if (!Objects.equals(version, that.version)) return false;
return (protocolVersion == that.protocolVersion);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Objects;

/**
* Created by johannes on 06.01.16.
*/
Expand Down Expand Up @@ -70,9 +72,9 @@ public boolean equals(Object o) {

Stream stream = (Stream) o;

if (uri != null ? !uri.equals(stream.uri) : stream.uri != null) return false;
if (id != null ? !id.equals(stream.id) : stream.id != null) return false;
return !(status != null ? !status.equals(stream.status) : stream.status != null);
if (!Objects.equals(uri, stream.uri)) return false;
if (!Objects.equals(id, stream.id)) return false;
return !(!Objects.equals(status, stream.status));
}

@Override
Expand Down Expand Up @@ -122,7 +124,7 @@ public enum Status {
playing("playing"),
disabled("disabled");

private String status;
private final String status;

Status(String status) {
this.status = status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* Created by johannes on 06.01.16.
Expand Down Expand Up @@ -85,13 +86,13 @@ public boolean equals(Object o) {

StreamUri stream = (StreamUri) o;

if (raw != null ? !raw.equals(stream.raw) : stream.raw != null) return false;
if (scheme != null ? !scheme.equals(stream.scheme) : stream.scheme != null) return false;
if (host != null ? !host.equals(stream.host) : stream.host != null) return false;
if (path != null ? !path.equals(stream.path) : stream.path != null) return false;
if (fragment != null ? !fragment.equals(stream.fragment) : stream.fragment != null)
if (!Objects.equals(raw, stream.raw)) return false;
if (!Objects.equals(scheme, stream.scheme)) return false;
if (!Objects.equals(host, stream.host)) return false;
if (!Objects.equals(path, stream.path)) return false;
if (!Objects.equals(fragment, stream.fragment))
return false;
return !(query != null ? !query.equals(stream.query) : stream.query != null);
return !(!Objects.equals(query, stream.query));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ public void startListening(String serviceType, String serviceName, NsdHelperList

public void stopListening() {
if (mDiscoveryListener != null) {
try {
mNsdManager.stopServiceDiscovery(mDiscoveryListener);
} finally {
}
mNsdManager.stopServiceDiscovery(mDiscoveryListener);
mDiscoveryListener = null;
}
if (multicastLock != null) {
Expand Down

0 comments on commit 0c12b33

Please sign in to comment.