1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

Fixed some crashes

This commit is contained in:
Felix Ableitner 2016-11-28 00:16:22 +09:00
parent d2323b5c1d
commit 9209a8fb6c
2 changed files with 10 additions and 9 deletions

View file

@ -348,9 +348,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
for (Map.Entry<String, Connections.Connection> e : connections.connections.entrySet()) { for (Map.Entry<String, Connections.Connection> e : connections.connections.entrySet()) {
e.getValue().completion = getDeviceCompletion(e.getKey()); e.getValue().completion = getDeviceCompletion(e.getKey());
Connections.Connection prev = mPreviousConnections Connections.Connection prev =
.transform(c -> c.connections.get(e.getKey())) (mPreviousConnections.isPresent() && mPreviousConnections.get().connections.containsKey(e.getKey()))
.or(new Connections.Connection()); ? mPreviousConnections.get().connections.get(e.getKey())
: new Connections.Connection();
e.getValue().setTransferRate(prev, msElapsed); e.getValue().setTransferRate(prev, msElapsed);
} }
Connections.Connection prev = Connections.Connection prev =

View file

@ -43,21 +43,21 @@ public class DevicesAdapter extends ArrayAdapter<Device> {
TextView upload = (TextView) convertView.findViewById(R.id.upload); TextView upload = (TextView) convertView.findViewById(R.id.upload);
String deviceId = getItem(position).deviceID; String deviceId = getItem(position).deviceID;
Optional<Connections.Connection> conn = mConnections.transform(a -> a.connections.get(deviceId));
name.setText(getItem(position).getDisplayName()); name.setText(getItem(position).getDisplayName());
Resources r = getContext().getResources(); Resources r = getContext().getResources();
if (conn.isPresent() && conn.get().connected) { if (mConnections.isPresent() && mConnections.get().connections.containsKey(deviceId)) {
if (conn.get().completion == 100) { Connections.Connection conn = mConnections.get().connections.get(deviceId);
if (conn.completion == 100) {
status.setText(r.getString(R.string.device_up_to_date)); status.setText(r.getString(R.string.device_up_to_date));
status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green)); status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green));
} }
else { else {
status.setText(r.getString(R.string.device_syncing, conn.get().completion)); status.setText(r.getString(R.string.device_syncing, conn.completion));
status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_blue)); status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_blue));
} }
download.setText(Util.readableTransferRate(getContext(), conn.get().inBits)); download.setText(Util.readableTransferRate(getContext(), conn.inBits));
upload.setText(Util.readableTransferRate(getContext(), conn.get().outBits)); upload.setText(Util.readableTransferRate(getContext(), conn.outBits));
} }
else { else {
download.setText(Util.readableTransferRate(getContext(), 0)); download.setText(Util.readableTransferRate(getContext(), 0));