1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 19:31:30 +00:00

Moved all model classes to seperate package

This commit is contained in:
Felix Ableitner 2016-10-15 16:27:49 +09:00
parent e74c5b8c47
commit e7e0e061a1
14 changed files with 116 additions and 83 deletions

View file

@ -24,6 +24,8 @@ import com.google.zxing.integration.android.IntentResult;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.SettingsActivity;
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.SyncthingService;
import com.nutomic.syncthingandroid.util.Compression;
@ -59,7 +61,7 @@ public class DeviceFragment extends Fragment implements
private SyncthingService mSyncthingService;
private RestApi.Device mDevice;
private Device mDevice;
private View mIdContainer;
@ -157,7 +159,7 @@ public class DeviceFragment extends Fragment implements
if (mIsCreateMode) {
if (savedInstanceState != null) {
mDevice = (RestApi.Device) savedInstanceState.getSerializable("device");
mDevice = (Device) savedInstanceState.getSerializable("device");
}
if (mDevice == null) {
initDevice();
@ -244,7 +246,7 @@ public class DeviceFragment extends Fragment implements
* version/address changes.
*/
@Override
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
public void onReceiveConnections(Map<String, Connection> connections) {
boolean viewsExist = mSyncthingVersionView != null && mCurrentAddressView != null;
if (viewsExist && connections.containsKey(mDevice.deviceID)) {
mCurrentAddressView.setVisibility(VISIBLE);
@ -262,9 +264,9 @@ public class DeviceFragment extends Fragment implements
}
if (!mIsCreateMode) {
List<RestApi.Device> devices = mSyncthingService.getApi().getDevices(false);
List<Device> devices = mSyncthingService.getApi().getDevices(false);
mDevice = null;
for (RestApi.Device device : devices) {
for (Device device : devices) {
if (device.deviceID.equals(
getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID))) {
mDevice = device;
@ -365,7 +367,7 @@ public class DeviceFragment extends Fragment implements
}
private void initDevice() {
mDevice = new RestApi.Device();
mDevice = new Device();
mDevice.name = "";
mDevice.deviceID = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
mDevice.addresses = DYNAMIC_ADDRESS;

View file

@ -13,6 +13,7 @@ import android.widget.ListView;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.SettingsActivity;
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
import com.nutomic.syncthingandroid.model.Device;
import com.nutomic.syncthingandroid.syncthing.RestApi;
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
import com.nutomic.syncthingandroid.util.DevicesAdapter;
@ -29,7 +30,7 @@ import java.util.TimerTask;
public class DeviceListFragment extends ListFragment implements SyncthingService.OnApiChangeListener,
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;
@ -97,7 +98,7 @@ public class DeviceListFragment extends ListFragment implements SyncthingService
// Prevent scroll position reset due to list update from clear().
mAdapter.setNotifyOnChange(false);
mAdapter.clear();
List<RestApi.Device> devices = activity.getApi().getDevices(false);
List<Device> devices = activity.getApi().getDevices(false);
Collections.sort(devices, DEVICES_COMPARATOR);
mAdapter.addAll(devices);
mAdapter.updateConnections(activity.getApi());

View file

@ -13,6 +13,9 @@ import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.MainActivity;
import com.nutomic.syncthingandroid.activities.SettingsActivity;
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.SyncthingService;
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}.
*/
@Override
public void onReceiveSystemInfo(RestApi.SystemInfo info) {
public void onReceiveSystemInfo(SystemInfo info) {
if (getActivity() == null)
return;
@ -176,7 +179,7 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
* Populates views with status received via {@link RestApi#getSystemInfo}.
*/
@Override
public void onReceiveSystemVersion(RestApi.SystemVersion info) {
public void onReceiveSystemVersion(SystemVersion info) {
if (getActivity() == null)
return;
@ -187,8 +190,8 @@ public class DrawerFragment extends Fragment implements RestApi.OnReceiveSystemI
* Populates views with status received via {@link RestApi#getConnections}.
*/
@Override
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
RestApi.Connection c = connections.get(RestApi.TOTAL_STATS);
public void onReceiveConnections(Map<String, Connection> connections) {
Connection c = connections.get(RestApi.TOTAL_STATS);
mDownload.setText(Util.readableTransferRate(mActivity, c.inBits));
mUpload.setText(Util.readableTransferRate(mActivity, c.outBits));
}

View file

@ -23,11 +23,13 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.common.collect.ImmutableList;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.FolderPickerActivity;
import com.nutomic.syncthingandroid.activities.SettingsActivity;
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
import com.nutomic.syncthingandroid.fragments.dialog.KeepVersionsDialogFragment;
import com.nutomic.syncthingandroid.model.Device;
import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.syncthing.RestApi;
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
@ -102,7 +104,7 @@ public class FolderFragment extends Fragment
break;
case R.id.device_toggle:
List<String> devicesList = mFolder.getDevices();
RestApi.Device device = (RestApi.Device) view.getTag();
Device device = (Device) view.getTag();
if (isChecked) {
devicesList.add(device.deviceID);
} else {
@ -269,13 +271,13 @@ public class FolderFragment extends Fragment
mIdView.setText(mFolder.id);
mPathView.setText(mFolder.path);
mFolderMasterView.setChecked(mFolder.type.equals("readonly"));
List<RestApi.Device> devicesList = mSyncthingService.getApi().getDevices(false);
List<Device> devicesList = mSyncthingService.getApi().getDevices(false);
mDevicesContainer.removeAllViews();
if (devicesList.isEmpty()) {
addEmptyDeviceListView();
} else {
for (RestApi.Device n : devicesList) {
for (Device n : devicesList) {
addDeviceViewAndSetListener(n, LayoutInflater.from(getActivity()));
}
}
@ -360,8 +362,13 @@ public class FolderFragment extends Fragment
mFolder.setDevices(new ArrayList<>());
mFolder.versioning = new Folder.Versioning();
String deviceId = getActivity().getIntent().getStringExtra(EXTRA_DEVICE_ID);
//if (deviceId != null)
// TODO mFolder.devices.add(deviceId);
if (deviceId != null) {
List<String> devices = ImmutableList.<String>builder()
.addAll(mFolder.getDevices())
.add(deviceId)
.build();
mFolder.setDevices(devices);
}
}
private void prepareEditMode() {
@ -383,7 +390,7 @@ public class FolderFragment extends Fragment
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);
SwitchCompat deviceView = (SwitchCompat) mDevicesContainer.getChildAt(mDevicesContainer.getChildCount()-1);
deviceView.setChecked(mFolder.getDevices().contains(device.deviceID));

View file

@ -17,6 +17,7 @@ import android.widget.Toast;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.SyncthingActivity;
import com.nutomic.syncthingandroid.model.Device;
import com.nutomic.syncthingandroid.preferences.WifiSsidPreference;
import com.nutomic.syncthingandroid.syncthing.RestApi;
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
@ -233,8 +234,8 @@ public class SettingsFragment extends PreferenceFragment
} else if (preference.equals(mSyncOnlyWifi)) {
mSyncOnlyOnSSIDs.setEnabled((Boolean) o);
} else if (preference.getKey().equals(DEVICE_NAME_KEY)) {
RestApi.Device old = mSyncthingService.getApi().getLocalDevice();
RestApi.Device updated = new RestApi.Device();
Device old = mSyncthingService.getApi().getLocalDevice();
Device updated = new Device();
updated.addresses = old.addresses;
updated.compression = old.compression;
updated.deviceID = old.deviceID;

View file

@ -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;
}

View 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;
}

View 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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -18,6 +18,7 @@ import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.SettingsActivity;
import com.nutomic.syncthingandroid.fragments.DeviceFragment;
import com.nutomic.syncthingandroid.fragments.FolderFragment;
import com.nutomic.syncthingandroid.model.Device;
import java.io.File;
import java.util.concurrent.TimeUnit;
@ -125,7 +126,7 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene
pi = PendingIntent.getActivity(mContext, requestCode, intent, 0);
String deviceName = null;
for (RestApi.Device d : mApi.getDevices(false)) {
for (Device d : mApi.getDevices(false)) {
if (d.deviceID.equals(deviceId))
deviceName = RestApi.getDeviceDisplayName(d);
}

View file

@ -19,7 +19,12 @@ import com.nutomic.syncthingandroid.BuildConfig;
import com.nutomic.syncthingandroid.activities.RestartActivity;
import com.nutomic.syncthingandroid.http.GetTask;
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.Model;
import com.nutomic.syncthingandroid.model.SystemInfo;
import com.nutomic.syncthingandroid.model.SystemVersion;
import com.nutomic.syncthingandroid.util.FolderObserver;
import org.json.JSONArray;
@ -70,61 +75,6 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
private static final List<Integer> USAGE_REPORTING_DECIDED =
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 {
void onConfigChanged();
}

View file

@ -11,6 +11,8 @@ import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.model.Connection;
import com.nutomic.syncthingandroid.model.Device;
import com.nutomic.syncthingandroid.syncthing.RestApi;
import java.util.HashMap;
@ -19,10 +21,10 @@ import java.util.Map;
/**
* Generates item views for device items.
*/
public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
public class DevicesAdapter extends ArrayAdapter<Device>
implements RestApi.OnReceiveConnectionsListener {
private Map<String, RestApi.Connection> mConnections =
private Map<String, Connection> mConnections =
new HashMap<>();
public DevicesAdapter(Context context) {
@ -44,7 +46,7 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
TextView upload = (TextView) convertView.findViewById(R.id.upload);
String deviceId = getItem(position).deviceID;
RestApi.Connection conn = mConnections.get(deviceId);
Connection conn = mConnections.get(deviceId);
name.setText(RestApi.getDeviceDisplayName(getItem(position)));
Resources r = getContext().getResources();
@ -80,7 +82,7 @@ public class DevicesAdapter extends ArrayAdapter<RestApi.Device>
}
@Override
public void onReceiveConnections(Map<String, RestApi.Connection> connections) {
public void onReceiveConnections(Map<String, Connection> connections) {
mConnections = connections;
notifyDataSetChanged();
}

View file

@ -13,6 +13,7 @@ import android.widget.TextView;
import com.nutomic.syncthingandroid.BuildConfig;
import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.model.Model;
import com.nutomic.syncthingandroid.syncthing.RestApi;
import java.util.HashMap;
@ -26,7 +27,7 @@ import static android.view.View.VISIBLE;
public class FoldersAdapter extends ArrayAdapter<Folder>
implements RestApi.OnReceiveModelListener {
private final HashMap<String, RestApi.Model> mModels = new HashMap<>();
private final HashMap<String, Model> mModels = new HashMap<>();
private final LayoutInflater mInflater;
public FoldersAdapter(Context context) {
@ -48,7 +49,7 @@ public class FoldersAdapter extends ArrayAdapter<Folder>
TextView invalid = (TextView) convertView.findViewById(R.id.invalid);
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);
state.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green));
directory.setText(folder.path);
@ -103,7 +104,7 @@ public class FoldersAdapter extends ArrayAdapter<Folder>
}
@Override
public void onReceiveModel(String folderId, RestApi.Model model) {
public void onReceiveModel(String folderId, Model model) {
mModels.put(folderId, model);
notifyDataSetChanged();
}