import java.util.Date; | import java.util.Date; | ||||
import java.util.List; | import java.util.List; | ||||
public class AccelerometerViewModel extends ViewModel { | |||||
public class AccelerometerViewModel extends ViewModel implements ViewModelInterface { | |||||
private MutableLiveData<List<Device>> mDeviceList; | private MutableLiveData<List<Device>> mDeviceList; | ||||
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>(); | private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>(); | ||||
float thresholdValue; | float thresholdValue; | ||||
boolean startMeasuring; | boolean startMeasuring; | ||||
@Override | |||||
public void init() { | public void init() { | ||||
if (mDeviceList == null) { | if (mDeviceList == null) { | ||||
mDeviceRepository = DeviceRepository.getInstance(); | mDeviceRepository = DeviceRepository.getInstance(); | ||||
return mMovementDetected; | return mMovementDetected; | ||||
} | } | ||||
@Override | |||||
public LiveData<List<Device>> getConnectedDeviceList() { | public LiveData<List<Device>> getConnectedDeviceList() { | ||||
return mDeviceList; | return mDeviceList; | ||||
} | } | ||||
@Override | |||||
public LiveData<List<Device>> getAlarmHistoryList() { | public LiveData<List<Device>> getAlarmHistoryList() { | ||||
return mAlarmHistoryList; | return mAlarmHistoryList; | ||||
} | } | ||||
@Override | |||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | ||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); | mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); | ||||
} | } | ||||
@Override | |||||
public void setTimeStamp(String deviceID, String timeStamp) { | public void setTimeStamp(String deviceID, String timeStamp) { | ||||
mDeviceRepository.setTimeStamp(deviceID, timeStamp); | mDeviceRepository.setTimeStamp(deviceID, timeStamp); | ||||
} | } | ||||
@Override | |||||
public String getTimeStamp(String deviceID) { | public String getTimeStamp(String deviceID) { | ||||
return mDeviceRepository.getTimeStamp(deviceID); | return mDeviceRepository.getTimeStamp(deviceID); | ||||
} | } | ||||
@Override | |||||
public void setDeviceID(String deviceID, String newDeviceID) { | public void setDeviceID(String deviceID, String newDeviceID) { | ||||
mDeviceRepository.setDeviceID(deviceID, newDeviceID); | mDeviceRepository.setDeviceID(deviceID, newDeviceID); | ||||
} | } | ||||
@Override | |||||
public String getDeviceID(String deviceID) { | public String getDeviceID(String deviceID) { | ||||
return mDeviceRepository.getDeviceID(deviceID); | return mDeviceRepository.getDeviceID(deviceID); | ||||
} | } | ||||
@Override | |||||
public void setSensorStatus(String deviceID, boolean sensorStatus) { | public void setSensorStatus(String deviceID, boolean sensorStatus) { | ||||
mDeviceRepository.setSensorStatus(deviceID, sensorStatus); | mDeviceRepository.setSensorStatus(deviceID, sensorStatus); | ||||
} | } | ||||
@Override | |||||
public boolean getSensorStatus(String deviceID) { | public boolean getSensorStatus(String deviceID) { | ||||
return mDeviceRepository.getSensorStatus(deviceID); | return mDeviceRepository.getSensorStatus(deviceID); | ||||
} | } | ||||
@Override | |||||
public void setSensorType(String deviceID, String sensorType) { | public void setSensorType(String deviceID, String sensorType) { | ||||
mDeviceRepository.setSensorType(deviceID, sensorType); | mDeviceRepository.setSensorType(deviceID, sensorType); | ||||
} | } | ||||
@Override | |||||
public String getSensorType(String deviceID) { | public String getSensorType(String deviceID) { | ||||
return mDeviceRepository.getSensorType(deviceID); | return mDeviceRepository.getSensorType(deviceID); | ||||
} | } | ||||
@Override | |||||
public void setSensorMassage(String deviceID, int sensorMessage) { | public void setSensorMassage(String deviceID, int sensorMessage) { | ||||
mDeviceRepository.setSensorMassage(deviceID, sensorMessage); | mDeviceRepository.setSensorMassage(deviceID, sensorMessage); | ||||
} | } | ||||
@Override | |||||
public int getSensorMassage(String deviceID) { | public int getSensorMassage(String deviceID) { | ||||
return mDeviceRepository.getSensorMassage(deviceID); | return mDeviceRepository.getSensorMassage(deviceID); | ||||
} | } | ||||
@Override | |||||
public String getLocalDeviceUUID() { | public String getLocalDeviceUUID() { | ||||
return mDeviceRepository.getLocalDeviceUUID(); | return mDeviceRepository.getLocalDeviceUUID(); | ||||
} | } |
import java.util.List; | import java.util.List; | ||||
public class MainActivityViewModel extends ViewModel { | |||||
public class MainActivityViewModel extends ViewModel implements ViewModelInterface { | |||||
private MutableLiveData<List<Device>> mDeviceList; | private MutableLiveData<List<Device>> mDeviceList; | ||||
private MutableLiveData<List<Device>> mAlarmHistoryList; | private MutableLiveData<List<Device>> mAlarmHistoryList; | ||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
@Override | |||||
public void init() { | public void init() { | ||||
WiFiCommunication mWiFiCommunication; | WiFiCommunication mWiFiCommunication; | ||||
if(mDeviceList != null) { | if(mDeviceList != null) { | ||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | ||||
} | } | ||||
@Override | |||||
public LiveData<List<Device>> getConnectedDeviceList() { | public LiveData<List<Device>> getConnectedDeviceList() { | ||||
return mDeviceList; | return mDeviceList; | ||||
} | } | ||||
@Override | |||||
public LiveData<List<Device>> getAlarmHistoryList() { | public LiveData<List<Device>> getAlarmHistoryList() { | ||||
return mAlarmHistoryList; | return mAlarmHistoryList; | ||||
} | } | ||||
@Override | |||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | ||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); | mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); | ||||
} | } | ||||
@Override | |||||
public void setTimeStamp(String deviceID, String timeStamp) { | public void setTimeStamp(String deviceID, String timeStamp) { | ||||
mDeviceRepository.setTimeStamp(deviceID, timeStamp); | mDeviceRepository.setTimeStamp(deviceID, timeStamp); | ||||
} | } | ||||
@Override | |||||
public String getTimeStamp(String deviceID) { | public String getTimeStamp(String deviceID) { | ||||
return mDeviceRepository.getTimeStamp(deviceID); | return mDeviceRepository.getTimeStamp(deviceID); | ||||
} | } | ||||
@Override | |||||
public void setDeviceID(String deviceID, String newDeviceID) { | public void setDeviceID(String deviceID, String newDeviceID) { | ||||
mDeviceRepository.setDeviceID(deviceID, newDeviceID); | mDeviceRepository.setDeviceID(deviceID, newDeviceID); | ||||
} | } | ||||
@Override | |||||
public String getDeviceID(String deviceID) { | public String getDeviceID(String deviceID) { | ||||
return mDeviceRepository.getDeviceID(deviceID); | return mDeviceRepository.getDeviceID(deviceID); | ||||
} | } | ||||
@Override | |||||
public void setSensorStatus(String deviceID, boolean sensorStatus) { | public void setSensorStatus(String deviceID, boolean sensorStatus) { | ||||
mDeviceRepository.setSensorStatus(deviceID, sensorStatus); | mDeviceRepository.setSensorStatus(deviceID, sensorStatus); | ||||
} | } | ||||
@Override | |||||
public boolean getSensorStatus(String deviceID) { | public boolean getSensorStatus(String deviceID) { | ||||
return mDeviceRepository.getSensorStatus(deviceID); | return mDeviceRepository.getSensorStatus(deviceID); | ||||
} | } | ||||
@Override | |||||
public void setSensorType(String deviceID, String sensorType) { | public void setSensorType(String deviceID, String sensorType) { | ||||
mDeviceRepository.setSensorType(deviceID, sensorType); | mDeviceRepository.setSensorType(deviceID, sensorType); | ||||
} | } | ||||
@Override | |||||
public String getSensorType(String deviceID) { | public String getSensorType(String deviceID) { | ||||
return mDeviceRepository.getSensorType(deviceID); | return mDeviceRepository.getSensorType(deviceID); | ||||
} | } | ||||
@Override | |||||
public void setSensorMassage(String deviceID, int sensorMessage) { | public void setSensorMassage(String deviceID, int sensorMessage) { | ||||
mDeviceRepository.setSensorMassage(deviceID, sensorMessage); | mDeviceRepository.setSensorMassage(deviceID, sensorMessage); | ||||
} | } | ||||
@Override | |||||
public int getSensorMassage(String deviceID) { | public int getSensorMassage(String deviceID) { | ||||
return mDeviceRepository.getSensorMassage(deviceID); | return mDeviceRepository.getSensorMassage(deviceID); | ||||
} | } | ||||
@Override | |||||
public String getLocalDeviceUUID() { | public String getLocalDeviceUUID() { | ||||
return mDeviceRepository.getLocalDeviceUUID(); | return mDeviceRepository.getLocalDeviceUUID(); | ||||
} | } |
package com.example.greenwatch.viewmodels; | |||||
import androidx.lifecycle.LiveData; | |||||
import com.example.greenwatch.models.Device; | |||||
import java.util.List; | |||||
public interface ViewModelInterface { | |||||
void init(); | |||||
LiveData<List<Device>> getConnectedDeviceList(); | |||||
LiveData<List<Device>> getAlarmHistoryList(); | |||||
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage); | |||||
void setTimeStamp(String deviceID, String timeStamp); | |||||
String getTimeStamp(String deviceID); | |||||
void setDeviceID(String deviceID, String newDeviceID); | |||||
String getDeviceID(String deviceID); | |||||
void setSensorStatus(String deviceID, boolean sensorStatus); | |||||
boolean getSensorStatus(String deviceID); | |||||
void setSensorType(String deviceID, String sensorType); | |||||
String getSensorType(String deviceID); | |||||
void setSensorMassage(String deviceID, int sensorMessage); | |||||
int getSensorMassage(String deviceID); | |||||
String getLocalDeviceUUID(); | |||||
} |