1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 08:11:17 +00:00

Improved handling for empty device IDs.

This commit is contained in:
Felix Ableitner 2016-01-23 17:32:52 +01:00
parent 34fead0623
commit 3d09d43bd4
3 changed files with 11 additions and 5 deletions

View file

@ -373,7 +373,7 @@ public class FolderFragment extends Fragment
inflater.inflate(R.layout.item_device_form, mDevicesContainer);
SwitchCompat deviceView = (SwitchCompat) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1);
deviceView.setChecked(mFolder.deviceIds.contains(device.deviceID));
deviceView.setText(device.name);
deviceView.setText(RestApi.getDeviceDisplayName(device));
deviceView.setTag(device);
deviceView.setOnCheckedChangeListener(mOnShareChangeListener);
}

View file

@ -8,6 +8,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
@ -1140,4 +1141,12 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
mRestartPostponed = true;
}
/**
* Returns the device name, or the first characters of the ID if the name is empty.
*/
public static String getDeviceDisplayName(Device device) {
return (TextUtils.isEmpty(device.name))
? device.deviceID.substring(0, 7)
: device.name;
}
}

View file

@ -54,10 +54,7 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
String deviceId = getItem(position).deviceID;
RestApi.Connection conn = mConnections.get(deviceId);
String displayName = (TextUtils.isEmpty(getItem(position).name))
? deviceId.substring(0, 7)
: getItem(position).name;
name.setText(displayName);
name.setText(RestApi.getDeviceDisplayName(getItem(position)));
Resources r = getContext().getResources();
if (conn != null && conn.connected) {
if (conn.completion == 100) {