mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 12:51:16 +00:00
Merge branch 'Zillode-fix-npe-device-edit'
This commit is contained in:
commit
fb2b6a21c4
3 changed files with 29 additions and 6 deletions
|
@ -57,8 +57,8 @@ public class DevicesAdapterTest extends AndroidTestCase {
|
||||||
|
|
||||||
assertEquals(getContext().getString(R.string.device_up_to_date),
|
assertEquals(getContext().getString(R.string.device_up_to_date),
|
||||||
((TextView) v.findViewById(R.id.status)).getText().toString());
|
((TextView) v.findViewById(R.id.status)).getText().toString());
|
||||||
assertEquals("1 Mb/s", ((TextView) v.findViewById(R.id.download)).getText().toString());
|
assertEquals("1 Mib/s", ((TextView) v.findViewById(R.id.download)).getText().toString());
|
||||||
assertEquals("1 Gb/s", ((TextView) v.findViewById(R.id.upload)).getText().toString());
|
assertEquals("1 Gib/s", ((TextView) v.findViewById(R.id.upload)).getText().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.support.v4.preference.PreferenceFragment;
|
import android.support.v4.preference.PreferenceFragment;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -36,6 +37,8 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
|
|
||||||
public static final String EXTRA_NODE_ID = "device_id";
|
public static final String EXTRA_NODE_ID = "device_id";
|
||||||
|
|
||||||
|
private static final String TAG = "DeviceSettingsFragment";
|
||||||
|
|
||||||
private static final int SCAN_QR_REQUEST_CODE = 235;
|
private static final int SCAN_QR_REQUEST_CODE = 235;
|
||||||
|
|
||||||
private SyncthingService mSyncthingService;
|
private SyncthingService mSyncthingService;
|
||||||
|
@ -93,7 +96,8 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
if (mIsCreate) {
|
if (mIsCreate) {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mDevice = (RestApi.Device) savedInstanceState.getSerializable("device");
|
mDevice = (RestApi.Device) savedInstanceState.getSerializable("device");
|
||||||
} else {
|
}
|
||||||
|
if (mDevice == null) {
|
||||||
mDevice = new RestApi.Device();
|
mDevice = new RestApi.Device();
|
||||||
mDevice.Name = "";
|
mDevice.Name = "";
|
||||||
mDevice.DeviceID = "";
|
mDevice.DeviceID = "";
|
||||||
|
@ -131,17 +135,25 @@ public class DeviceSettingsFragment extends PreferenceFragment implements
|
||||||
if (mIsCreate) {
|
if (mIsCreate) {
|
||||||
getActivity().setTitle(R.string.add_device);
|
getActivity().setTitle(R.string.add_device);
|
||||||
} else {
|
} else {
|
||||||
|
RestApi.Device device = null;
|
||||||
getActivity().setTitle(R.string.edit_device);
|
getActivity().setTitle(R.string.edit_device);
|
||||||
List<RestApi.Device> devices = mSyncthingService.getApi().getDevices(false);
|
List<RestApi.Device> devices = mSyncthingService.getApi().getDevices(false);
|
||||||
for (int i = 0; i < devices.size(); i++) {
|
for (int i = 0; i < devices.size(); i++) {
|
||||||
if (devices.get(i).DeviceID.equals(
|
if (devices.get(i).DeviceID.equals(
|
||||||
getActivity().getIntent().getStringExtra(EXTRA_NODE_ID))) {
|
getActivity().getIntent().getStringExtra(EXTRA_NODE_ID))) {
|
||||||
mDevice = devices.get(i);
|
device = devices.get(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (device == null) {
|
||||||
|
Log.w(TAG, "Device not found in API update");
|
||||||
|
getActivity().finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mDevice = device;
|
||||||
mDeviceId.setOnPreferenceClickListener(this);
|
mDeviceId.setOnPreferenceClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSyncthingService.getApi().getConnections(DeviceSettingsFragment.this);
|
mSyncthingService.getApi().getConnections(DeviceSettingsFragment.this);
|
||||||
|
|
||||||
mDeviceId.setSummary(mDevice.DeviceID);
|
mDeviceId.setSummary(mDevice.DeviceID);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import android.preference.EditTextPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.support.v4.preference.PreferenceFragment;
|
import android.support.v4.preference.PreferenceFragment;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -43,6 +44,8 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
*/
|
*/
|
||||||
public static final String EXTRA_REPO_ID = "folder_id";
|
public static final String EXTRA_REPO_ID = "folder_id";
|
||||||
|
|
||||||
|
private static final String TAG = "FolderSettingsFragment";
|
||||||
|
|
||||||
private static final String KEY_NODE_SHARED = "device_shared";
|
private static final String KEY_NODE_SHARED = "device_shared";
|
||||||
|
|
||||||
private SyncthingService mSyncthingService;
|
private SyncthingService mSyncthingService;
|
||||||
|
@ -98,7 +101,8 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
if (mIsCreate) {
|
if (mIsCreate) {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mFolder = (RestApi.Folder) savedInstanceState.getSerializable("folder");
|
mFolder = (RestApi.Folder) savedInstanceState.getSerializable("folder");
|
||||||
} else {
|
}
|
||||||
|
if (mFolder == null) {
|
||||||
mFolder = new RestApi.Folder();
|
mFolder = new RestApi.Folder();
|
||||||
mFolder.ID = "";
|
mFolder.ID = "";
|
||||||
mFolder.Path = "";
|
mFolder.Path = "";
|
||||||
|
@ -131,15 +135,22 @@ public class FolderSettingsFragment extends PreferenceFragment
|
||||||
if (mIsCreate) {
|
if (mIsCreate) {
|
||||||
getActivity().setTitle(R.string.create_folder);
|
getActivity().setTitle(R.string.create_folder);
|
||||||
} else {
|
} else {
|
||||||
|
RestApi.Folder folder = null;
|
||||||
getActivity().setTitle(R.string.edit_folder);
|
getActivity().setTitle(R.string.edit_folder);
|
||||||
List<RestApi.Folder> folders = mSyncthingService.getApi().getFolders();
|
List<RestApi.Folder> folders = mSyncthingService.getApi().getFolders();
|
||||||
for (int i = 0; i < folders.size(); i++) {
|
for (int i = 0; i < folders.size(); i++) {
|
||||||
if (folders.get(i).ID.equals(
|
if (folders.get(i).ID.equals(
|
||||||
getActivity().getIntent().getStringExtra(EXTRA_REPO_ID))) {
|
getActivity().getIntent().getStringExtra(EXTRA_REPO_ID))) {
|
||||||
mFolder = folders.get(i);
|
folder = folders.get(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (folder == null) {
|
||||||
|
Log.w(TAG, "Folder not found in API update");
|
||||||
|
getActivity().finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mFolder = folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
mFolderId.setText(mFolder.ID);
|
mFolderId.setText(mFolder.ID);
|
||||||
|
|
Loading…
Reference in a new issue