mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-24 11:51:30 +00:00
Moved all model classes to seperate package
This commit is contained in:
parent
e74c5b8c47
commit
e7e0e061a1
14 changed files with 116 additions and 83 deletions
|
@ -24,6 +24,8 @@ import com.google.zxing.integration.android.IntentResult;
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
||||||
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
||||||
|
import com.nutomic.syncthingandroid.model.Connection;
|
||||||
|
import com.nutomic.syncthingandroid.model.Device;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
import com.nutomic.syncthingandroid.util.Compression;
|
import com.nutomic.syncthingandroid.util.Compression;
|
||||||
|
@ -59,7 +61,7 @@ public class DeviceFragment extends Fragment implements
|
||||||
|
|
||||||
private SyncthingService mSyncthingService;
|
private SyncthingService mSyncthingService;
|
||||||
|
|
||||||
private RestApi.Device mDevice;
|
private Device mDevice;
|
||||||
|
|
||||||
private View mIdContainer;
|
private View mIdContainer;
|
||||||
|
|
||||||
|
@ -157,7 +159,7 @@ public class DeviceFragment extends Fragment implements
|
||||||
|
|
||||||
if (mIsCreateMode) {
|
if (mIsCreateMode) {
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mDevice = (RestApi.Device) savedInstanceState.getSerializable("device");
|
mDevice = (Device) savedInstanceState.getSerializable("device");
|
||||||
}
|
}
|
||||||
if (mDevice == null) {
|
if (mDevice == null) {
|
||||||
initDevice();
|
initDevice();
|
||||||
|
@ -244,7 +246,7 @@ public class DeviceFragment extends Fragment implements
|
||||||
* version/address changes.
|
* version/address changes.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
|
public void onReceiveConnections(Map<String, Connection> connections) {
|
||||||
boolean viewsExist = mSyncthingVersionView != null && mCurrentAddressView != null;
|
boolean viewsExist = mSyncthingVersionView != null && mCurrentAddressView != null;
|
||||||
if (viewsExist && connections.containsKey(mDevice.deviceID)) {
|
if (viewsExist && connections.containsKey(mDevice.deviceID)) {
|
||||||
mCurrentAddressView.setVisibility(VISIBLE);
|
mCurrentAddressView.setVisibility(VISIBLE);
|
||||||
|
@ -262,9 +264,9 @@ public class DeviceFragment extends Fragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mIsCreateMode) {
|
if (!mIsCreateMode) {
|
||||||
List<RestApi.Device> devices = mSyncthingService.getApi().getDevices(false);
|
List<Device> devices = mSyncthingService.getApi().getDevices(false);
|
||||||
mDevice = null;
|
mDevice = null;
|
||||||
for (RestApi.Device device : devices) {
|
for (Device device : devices) {
|
||||||
if (device.deviceID.equals(
|
if (device.deviceID.equals(
|
||||||
getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID))) {
|
getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID))) {
|
||||||
mDevice = device;
|
mDevice = device;
|
||||||
|
@ -365,7 +367,7 @@ public class DeviceFragment extends Fragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDevice() {
|
private void initDevice() {
|
||||||
mDevice = new RestApi.Device();
|
mDevice = new Device();
|
||||||
mDevice.name = "";
|
mDevice.name = "";
|
||||||
mDevice.deviceID = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
mDevice.deviceID = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
||||||
mDevice.addresses = DYNAMIC_ADDRESS;
|
mDevice.addresses = DYNAMIC_ADDRESS;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import android.widget.ListView;
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
||||||
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
||||||
|
import com.nutomic.syncthingandroid.model.Device;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
import com.nutomic.syncthingandroid.util.DevicesAdapter;
|
import com.nutomic.syncthingandroid.util.DevicesAdapter;
|
||||||
|
@ -29,7 +30,7 @@ import java.util.TimerTask;
|
||||||
public class DeviceListFragment extends ListFragment implements SyncthingService.OnApiChangeListener,
|
public class DeviceListFragment extends ListFragment implements SyncthingService.OnApiChangeListener,
|
||||||
ListView.OnItemClickListener {
|
ListView.OnItemClickListener {
|
||||||
|
|
||||||
private final static Comparator<RestApi.Device> DEVICES_COMPARATOR = (lhs, rhs) -> lhs.name.compareTo(rhs.name);
|
private final static Comparator<Device> DEVICES_COMPARATOR = (lhs, rhs) -> lhs.name.compareTo(rhs.name);
|
||||||
|
|
||||||
private DevicesAdapter mAdapter;
|
private DevicesAdapter mAdapter;
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
|
||||||
// Prevent scroll position reset due to list update from clear().
|
// Prevent scroll position reset due to list update from clear().
|
||||||
mAdapter.setNotifyOnChange(false);
|
mAdapter.setNotifyOnChange(false);
|
||||||
mAdapter.clear();
|
mAdapter.clear();
|
||||||
List<RestApi.Device> devices = activity.getApi().getDevices(false);
|
List<Device> devices = activity.getApi().getDevices(false);
|
||||||
Collections.sort(devices, DEVICES_COMPARATOR);
|
Collections.sort(devices, DEVICES_COMPARATOR);
|
||||||
mAdapter.addAll(devices);
|
mAdapter.addAll(devices);
|
||||||
mAdapter.updateConnections(activity.getApi());
|
mAdapter.updateConnections(activity.getApi());
|
||||||
|
|
|
@ -13,6 +13,9 @@ import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.activities.MainActivity;
|
import com.nutomic.syncthingandroid.activities.MainActivity;
|
||||||
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
||||||
import com.nutomic.syncthingandroid.activities.WebGuiActivity;
|
import com.nutomic.syncthingandroid.activities.WebGuiActivity;
|
||||||
|
import com.nutomic.syncthingandroid.model.Connection;
|
||||||
|
import com.nutomic.syncthingandroid.model.SystemInfo;
|
||||||
|
import com.nutomic.syncthingandroid.model.SystemVersion;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
import com.nutomic.syncthingandroid.util.Util;
|
import com.nutomic.syncthingandroid.util.Util;
|
||||||
|
@ -152,7 +155,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
|
||||||
* Populates views with status received via {@link RestApi#getSystemInfo}.
|
* Populates views with status received via {@link RestApi#getSystemInfo}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveSystemInfo(RestApi.SystemInfo info) {
|
public void onReceiveSystemInfo(SystemInfo info) {
|
||||||
if (getActivity() == null)
|
if (getActivity() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -176,7 +179,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
|
||||||
* Populates views with status received via {@link RestApi#getSystemInfo}.
|
* Populates views with status received via {@link RestApi#getSystemInfo}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveSystemVersion(RestApi.SystemVersion info) {
|
public void onReceiveSystemVersion(SystemVersion info) {
|
||||||
if (getActivity() == null)
|
if (getActivity() == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -187,8 +190,8 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
|
||||||
* Populates views with status received via {@link RestApi#getConnections}.
|
* Populates views with status received via {@link RestApi#getConnections}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
|
public void onReceiveConnections(Map<String, Connection> connections) {
|
||||||
RestApi.Connection c = connections.get(RestApi.TOTAL_STATS);
|
Connection c = connections.get(RestApi.TOTAL_STATS);
|
||||||
mDownload.setText(Util.readableTransferRate(mActivity, c.inBits));
|
mDownload.setText(Util.readableTransferRate(mActivity, c.inBits));
|
||||||
mUpload.setText(Util.readableTransferRate(mActivity, c.outBits));
|
mUpload.setText(Util.readableTransferRate(mActivity, c.outBits));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,13 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.activities.FolderPickerActivity;
|
import com.nutomic.syncthingandroid.activities.FolderPickerActivity;
|
||||||
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
||||||
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
||||||
import com.nutomic.syncthingandroid.fragments.dialog.KeepVersionsDialogFragment;
|
import com.nutomic.syncthingandroid.fragments.dialog.KeepVersionsDialogFragment;
|
||||||
|
import com.nutomic.syncthingandroid.model.Device;
|
||||||
import com.nutomic.syncthingandroid.model.Folder;
|
import com.nutomic.syncthingandroid.model.Folder;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
|
@ -102,7 +104,7 @@ public class FolderFragment extends Fragment
|
||||||
break;
|
break;
|
||||||
case R.id.device_toggle:
|
case R.id.device_toggle:
|
||||||
List<String> devicesList = mFolder.getDevices();
|
List<String> devicesList = mFolder.getDevices();
|
||||||
RestApi.Device device = (RestApi.Device) view.getTag();
|
Device device = (Device) view.getTag();
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
devicesList.add(device.deviceID);
|
devicesList.add(device.deviceID);
|
||||||
} else {
|
} else {
|
||||||
|
@ -269,13 +271,13 @@ public class FolderFragment extends Fragment
|
||||||
mIdView.setText(mFolder.id);
|
mIdView.setText(mFolder.id);
|
||||||
mPathView.setText(mFolder.path);
|
mPathView.setText(mFolder.path);
|
||||||
mFolderMasterView.setChecked(mFolder.type.equals("readonly"));
|
mFolderMasterView.setChecked(mFolder.type.equals("readonly"));
|
||||||
List<RestApi.Device> devicesList = mSyncthingService.getApi().getDevices(false);
|
List<Device> devicesList = mSyncthingService.getApi().getDevices(false);
|
||||||
|
|
||||||
mDevicesContainer.removeAllViews();
|
mDevicesContainer.removeAllViews();
|
||||||
if (devicesList.isEmpty()) {
|
if (devicesList.isEmpty()) {
|
||||||
addEmptyDeviceListView();
|
addEmptyDeviceListView();
|
||||||
} else {
|
} else {
|
||||||
for (RestApi.Device n : devicesList) {
|
for (Device n : devicesList) {
|
||||||
addDeviceViewAndSetListener(n, LayoutInflater.from(getActivity()));
|
addDeviceViewAndSetListener(n, LayoutInflater.from(getActivity()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,8 +362,13 @@ public class FolderFragment extends Fragment
|
||||||
mFolder.setDevices(new ArrayList<>());
|
mFolder.setDevices(new ArrayList<>());
|
||||||
mFolder.versioning = new Folder.Versioning();
|
mFolder.versioning = new Folder.Versioning();
|
||||||
String deviceId = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
String deviceId = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
||||||
//if (deviceId != null)
|
if (deviceId != null) {
|
||||||
// TODO mFolder.devices.add(deviceId);
|
List<String> devices = ImmutableList.<String>builder()
|
||||||
|
.addAll(mFolder.getDevices())
|
||||||
|
.add(deviceId)
|
||||||
|
.build();
|
||||||
|
mFolder.setDevices(devices);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareEditMode() {
|
private void prepareEditMode() {
|
||||||
|
@ -383,7 +390,7 @@ public class FolderFragment extends Fragment
|
||||||
mDevicesContainer.addView(emptyView, params);
|
mDevicesContainer.addView(emptyView, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDeviceViewAndSetListener(RestApi.Device device, LayoutInflater inflater) {
|
private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) {
|
||||||
inflater.inflate(R.layout.item_device_form, mDevicesContainer);
|
inflater.inflate(R.layout.item_device_form, mDevicesContainer);
|
||||||
SwitchCompat deviceView = (SwitchCompat) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1);
|
SwitchCompat deviceView = (SwitchCompat) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1);
|
||||||
deviceView.setChecked(mFolder.getDevices().contains(device.deviceID));
|
deviceView.setChecked(mFolder.getDevices().contains(device.deviceID));
|
||||||
|
|
|
@ -17,6 +17,7 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
|
||||||
|
import com.nutomic.syncthingandroid.model.Device;
|
||||||
import com.nutomic.syncthingandroid.preferences.WifiSsidPreference;
|
import com.nutomic.syncthingandroid.preferences.WifiSsidPreference;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
|
@ -233,8 +234,8 @@ public class SettingsFragment extends PreferenceFragment
|
||||||
} else if (preference.equals(mSyncOnlyWifi)) {
|
} else if (preference.equals(mSyncOnlyWifi)) {
|
||||||
mSyncOnlyOnSSIDs.setEnabled((Boolean) o);
|
mSyncOnlyOnSSIDs.setEnabled((Boolean) o);
|
||||||
} else if (preference.getKey().equals(DEVICE_NAME_KEY)) {
|
} else if (preference.getKey().equals(DEVICE_NAME_KEY)) {
|
||||||
RestApi.Device old = mSyncthingService.getApi().getLocalDevice();
|
Device old = mSyncthingService.getApi().getLocalDevice();
|
||||||
RestApi.Device updated = new RestApi.Device();
|
Device updated = new Device();
|
||||||
updated.addresses = old.addresses;
|
updated.addresses = old.addresses;
|
||||||
updated.compression = old.compression;
|
updated.compression = old.compression;
|
||||||
updated.deviceID = old.deviceID;
|
updated.deviceID = old.deviceID;
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.nutomic.syncthingandroid.model;
|
||||||
|
|
||||||
|
public class Connection {
|
||||||
|
public String at;
|
||||||
|
public long inBytesTotal;
|
||||||
|
public long outBytesTotal;
|
||||||
|
public long inBits;
|
||||||
|
public long outBits;
|
||||||
|
public String address;
|
||||||
|
public String clientVersion;
|
||||||
|
public int completion;
|
||||||
|
public boolean connected;
|
||||||
|
}
|
12
src/main/java/com/nutomic/syncthingandroid/model/Device.java
Normal file
12
src/main/java/com/nutomic/syncthingandroid/model/Device.java
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package com.nutomic.syncthingandroid.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Device implements Serializable {
|
||||||
|
public List<String> addresses;
|
||||||
|
public String name;
|
||||||
|
public String deviceID;
|
||||||
|
public String compression;
|
||||||
|
public boolean introducer;
|
||||||
|
}
|
17
src/main/java/com/nutomic/syncthingandroid/model/Model.java
Normal file
17
src/main/java/com/nutomic/syncthingandroid/model/Model.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package com.nutomic.syncthingandroid.model;
|
||||||
|
|
||||||
|
public class Model {
|
||||||
|
public long globalBytes;
|
||||||
|
public long globalDeleted;
|
||||||
|
public long globalFiles;
|
||||||
|
public long localBytes;
|
||||||
|
public long localDeleted;
|
||||||
|
public long localFiles;
|
||||||
|
public long inSyncBytes;
|
||||||
|
public long inSyncFiles;
|
||||||
|
public long needBytes;
|
||||||
|
public long needFiles;
|
||||||
|
public long needDeletes;
|
||||||
|
public String state;
|
||||||
|
public String invalid;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.nutomic.syncthingandroid.model;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SystemInfo {
|
||||||
|
public long alloc;
|
||||||
|
public double cpuPercent;
|
||||||
|
public int goroutines;
|
||||||
|
public String myID;
|
||||||
|
public long sys;
|
||||||
|
public boolean discoveryEnabled;
|
||||||
|
public int discoveryMethods;
|
||||||
|
public Map<String, String> discoveryErrors;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.nutomic.syncthingandroid.model;
|
||||||
|
|
||||||
|
public class SystemVersion {
|
||||||
|
public String arch;
|
||||||
|
public String codename;
|
||||||
|
public String longVersion;
|
||||||
|
public String os;
|
||||||
|
public String version;
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
import com.nutomic.syncthingandroid.activities.SettingsActivity;
|
||||||
import com.nutomic.syncthingandroid.fragments.DeviceFragment;
|
import com.nutomic.syncthingandroid.fragments.DeviceFragment;
|
||||||
import com.nutomic.syncthingandroid.fragments.FolderFragment;
|
import com.nutomic.syncthingandroid.fragments.FolderFragment;
|
||||||
|
import com.nutomic.syncthingandroid.model.Device;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -125,7 +126,7 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene
|
||||||
pi = PendingIntent.getActivity(mContext, requestCode, intent, 0);
|
pi = PendingIntent.getActivity(mContext, requestCode, intent, 0);
|
||||||
|
|
||||||
String deviceName = null;
|
String deviceName = null;
|
||||||
for (RestApi.Device d : mApi.getDevices(false)) {
|
for (Device d : mApi.getDevices(false)) {
|
||||||
if (d.deviceID.equals(deviceId))
|
if (d.deviceID.equals(deviceId))
|
||||||
deviceName = RestApi.getDeviceDisplayName(d);
|
deviceName = RestApi.getDeviceDisplayName(d);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,12 @@ import com.nutomic.syncthingandroid.BuildConfig;
|
||||||
import com.nutomic.syncthingandroid.activities.RestartActivity;
|
import com.nutomic.syncthingandroid.activities.RestartActivity;
|
||||||
import com.nutomic.syncthingandroid.http.GetTask;
|
import com.nutomic.syncthingandroid.http.GetTask;
|
||||||
import com.nutomic.syncthingandroid.http.PostTask;
|
import com.nutomic.syncthingandroid.http.PostTask;
|
||||||
|
import com.nutomic.syncthingandroid.model.Connection;
|
||||||
|
import com.nutomic.syncthingandroid.model.Device;
|
||||||
import com.nutomic.syncthingandroid.model.Folder;
|
import com.nutomic.syncthingandroid.model.Folder;
|
||||||
|
import com.nutomic.syncthingandroid.model.Model;
|
||||||
|
import com.nutomic.syncthingandroid.model.SystemInfo;
|
||||||
|
import com.nutomic.syncthingandroid.model.SystemVersion;
|
||||||
import com.nutomic.syncthingandroid.util.FolderObserver;
|
import com.nutomic.syncthingandroid.util.FolderObserver;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
@ -70,61 +75,6 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
|
||||||
private static final List<Integer> USAGE_REPORTING_DECIDED =
|
private static final List<Integer> USAGE_REPORTING_DECIDED =
|
||||||
Arrays.asList(USAGE_REPORTING_ACCEPTED, USAGE_REPORTING_DENIED);
|
Arrays.asList(USAGE_REPORTING_ACCEPTED, USAGE_REPORTING_DENIED);
|
||||||
|
|
||||||
public static class Device implements Serializable {
|
|
||||||
public List<String> addresses;
|
|
||||||
public String name;
|
|
||||||
public String deviceID;
|
|
||||||
public String compression;
|
|
||||||
public boolean introducer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SystemInfo {
|
|
||||||
public long alloc;
|
|
||||||
public double cpuPercent;
|
|
||||||
public int goroutines;
|
|
||||||
public String myID;
|
|
||||||
public long sys;
|
|
||||||
public boolean discoveryEnabled;
|
|
||||||
public int discoveryMethods;
|
|
||||||
public Map<String, String> discoveryErrors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SystemVersion {
|
|
||||||
public String arch;
|
|
||||||
public String codename;
|
|
||||||
public String longVersion;
|
|
||||||
public String os;
|
|
||||||
public String version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Connection {
|
|
||||||
public String at;
|
|
||||||
public long inBytesTotal;
|
|
||||||
public long outBytesTotal;
|
|
||||||
public long inBits;
|
|
||||||
public long outBits;
|
|
||||||
public String address;
|
|
||||||
public String clientVersion;
|
|
||||||
public int completion;
|
|
||||||
public boolean connected;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Model {
|
|
||||||
public long globalBytes;
|
|
||||||
public long globalDeleted;
|
|
||||||
public long globalFiles;
|
|
||||||
public long localBytes;
|
|
||||||
public long localDeleted;
|
|
||||||
public long localFiles;
|
|
||||||
public long inSyncBytes;
|
|
||||||
public long inSyncFiles;
|
|
||||||
public long needBytes;
|
|
||||||
public long needFiles;
|
|
||||||
public long needDeletes;
|
|
||||||
public String state;
|
|
||||||
public String invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface OnConfigChangedListener {
|
public interface OnConfigChangedListener {
|
||||||
void onConfigChanged();
|
void onConfigChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
|
import com.nutomic.syncthingandroid.model.Connection;
|
||||||
|
import com.nutomic.syncthingandroid.model.Device;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -19,10 +21,10 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* Generates item views for device items.
|
* Generates item views for device items.
|
||||||
*/
|
*/
|
||||||
public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
|
public class DevicesAdapter extends ArrayAdapter<Device>
|
||||||
implements RestApi.OnReceiveConnectionsListener {
|
implements RestApi.OnReceiveConnectionsListener {
|
||||||
|
|
||||||
private Map<String, RestApi.Connection> mConnections =
|
private Map<String, Connection> mConnections =
|
||||||
new HashMap<>();
|
new HashMap<>();
|
||||||
|
|
||||||
public DevicesAdapter(Context context) {
|
public DevicesAdapter(Context context) {
|
||||||
|
@ -44,7 +46,7 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.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;
|
||||||
RestApi.Connection conn = mConnections.get(deviceId);
|
Connection conn = mConnections.get(deviceId);
|
||||||
|
|
||||||
name.setText(RestApi.getDeviceDisplayName(getItem(position)));
|
name.setText(RestApi.getDeviceDisplayName(getItem(position)));
|
||||||
Resources r = getContext().getResources();
|
Resources r = getContext().getResources();
|
||||||
|
@ -80,7 +82,7 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
|
public void onReceiveConnections(Map<String, Connection> connections) {
|
||||||
mConnections = connections;
|
mConnections = connections;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import android.widget.TextView;
|
||||||
import com.nutomic.syncthingandroid.BuildConfig;
|
import com.nutomic.syncthingandroid.BuildConfig;
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.model.Folder;
|
import com.nutomic.syncthingandroid.model.Folder;
|
||||||
|
import com.nutomic.syncthingandroid.model.Model;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -26,7 +27,7 @@ import static android.view.View.VISIBLE;
|
||||||
public class FoldersAdapter extends ArrayAdapter<Folder>
|
public class FoldersAdapter extends ArrayAdapter<Folder>
|
||||||
implements RestApi.OnReceiveModelListener {
|
implements RestApi.OnReceiveModelListener {
|
||||||
|
|
||||||
private final HashMap<String, RestApi.Model> mModels = new HashMap<>();
|
private final HashMap<String, Model> mModels = new HashMap<>();
|
||||||
private final LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
public FoldersAdapter(Context context) {
|
public FoldersAdapter(Context context) {
|
||||||
|
@ -48,7 +49,7 @@ public class FoldersAdapter extends ArrayAdapter<Folder>
|
||||||
TextView invalid = (TextView) convertView.findViewById(R.id.invalid);
|
TextView invalid = (TextView) convertView.findViewById(R.id.invalid);
|
||||||
|
|
||||||
Folder folder = getItem(position);
|
Folder folder = getItem(position);
|
||||||
RestApi.Model model = mModels.get(folder.id);
|
Model model = mModels.get(folder.id);
|
||||||
label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label);
|
label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label);
|
||||||
state.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green));
|
state.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green));
|
||||||
directory.setText(folder.path);
|
directory.setText(folder.path);
|
||||||
|
@ -103,7 +104,7 @@ public class FoldersAdapter extends ArrayAdapter<Folder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceiveModel(String folderId, RestApi.Model model) {
|
public void onReceiveModel(String folderId, Model model) {
|
||||||
mModels.put(folderId, model);
|
mModels.put(folderId, model);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue