Benutzeroberflaeche #2

Manually merged
Tinzch67102 merged 36 commits from Benutzeroberflaeche into master 2023-06-23 16:21:00 +00:00
8 changed files with 100 additions and 8 deletions
Showing only changes of commit 1094b0f75d - Show all commits

View File

@ -70,7 +70,6 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
@Override
public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices);
Toast.makeText(AccelerometerActivity.this, "onChanged", Toast.LENGTH_LONG).show();
}
});
@ -81,6 +80,18 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
}
});
mAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
}
}
});
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {

View File

@ -62,7 +62,6 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices);
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_LONG).show();
}
});
@ -73,6 +72,18 @@ public class MainActivity extends AppCompatActivity {
}
});
mMainActivityViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
}
}
});
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -89,7 +100,6 @@ public class MainActivity extends AppCompatActivity {
else {
mMainActivityViewModel.accessRequestCamera(MainActivity.this);
}
}
});
accelerometerButton.setOnClickListener(new View.OnClickListener() {

View File

@ -62,7 +62,6 @@ public class VideodetectionActivity extends AppCompatActivity {
@Override
public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices);
Toast.makeText(VideodetectionActivity.this, "onChanged", Toast.LENGTH_LONG).show();
}
});
@ -73,6 +72,18 @@ public class VideodetectionActivity extends AppCompatActivity {
}
});
mVideoDetectionViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(VideodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
}
}
});
mVideoDetectionViewModel.getVideoAlarmDetectedValue().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {

View File

@ -17,10 +17,12 @@ public class DeviceRepository {
private final int maxAlarmHistoryListSize = 20;
private final String delimiter = ", ";
private final String SensorStatusKey = "An";
private final String sensorStatusKey = "An";
private String localDeviceUUID;
private static DeviceRepository deviceRepositoryInstance;
private WiFiCommunication mWiFiCommunication;
private boolean startAlarmRecordingValue;
private MutableLiveData<Boolean> startAlarmRecording = new MutableLiveData<>();
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>();
private HashMap<String, Device> connectedDevicesList = new HashMap<>();
@ -29,6 +31,7 @@ public class DeviceRepository {
private DeviceRepository() {
setLocalDeviceUUID();
startAlarmRecordingValue = false;
}
public static synchronized DeviceRepository getInstance() {
@ -52,11 +55,21 @@ public class DeviceRepository {
return alarmHistoryList;
}
public MutableLiveData<Boolean> getStartAlarmRecording() {
setMutableLiveDataStartAlarmRecording();
return startAlarmRecording;
}
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
if (sensorStatus) {
setAlarmHistoryDeviceList(newDevice);
}
boolean newStartAlarmRecordingValue = checkDeviceStatus();
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
startAlarmRecordingValue = newStartAlarmRecordingValue;
setMutableLiveDataStartAlarmRecording();
}
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
setMutableLiveDataDeviceList();
}
@ -124,6 +137,11 @@ public class DeviceRepository {
setAlarmHistoryDeviceList(device);
}
device.setSensorStatus(sensorStatus);
boolean newStartAlarmRecordingValue = checkDeviceStatus();
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
startAlarmRecordingValue = newStartAlarmRecordingValue;
setMutableLiveDataStartAlarmRecording();
}
addToConnectedDeviceList(checkedDeviceID, device);
setMutableLiveDataDeviceList();
}
@ -177,6 +195,11 @@ public class DeviceRepository {
setAlarmHistoryDeviceList(device);
}
device.setSensorStatus(sensorStatus);
boolean newStartAlarmRecordingValue = checkDeviceStatus();
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
startAlarmRecordingValue = newStartAlarmRecordingValue;
setMutableLiveDataStartAlarmRecording();
}
addToConnectedDeviceList(checkedDeviceID, device);
setMutableLiveDataDeviceList();
@ -245,6 +268,10 @@ public class DeviceRepository {
alarmHistoryList.setValue(alarmHistoryDeviceList);
}
private void setMutableLiveDataStartAlarmRecording() {
startAlarmRecording.setValue(startAlarmRecordingValue);
}
private void addToConnectedDeviceList(String key, Device device) {
connectedDevicesList.put(key, device);
if (key.equals(checkDeviceID(localDeviceUUID))) {
@ -272,7 +299,7 @@ public class DeviceRepository {
}
private boolean convertSensorStatus(String status) {
return status.equals(SensorStatusKey);
return status.equals(sensorStatusKey);
}
private void setAlarmHistoryDeviceList(Device device) {
@ -283,4 +310,13 @@ public class DeviceRepository {
alarmHistoryDeviceList.add(0, alarmHistoryDevice);
setMutableLiveDataAlarmHistoryList();
}
private boolean checkDeviceStatus() {
for (Device device : connectedDevicesList.values()) {
if (device.getSensorStatus()) {
return true;
}
}
return false;
}
}

View File

@ -17,6 +17,7 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>();
private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private DeviceRepository mDeviceRepository;
private ArrayList<Float> Gesamt_be;
int arraySize = 500;
@ -32,6 +33,7 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
mDeviceRepository = DeviceRepository.getInstance();
mDeviceList = mDeviceRepository.getConnectedDeviceList();
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
}
initGesamtBE();
mMovementDetected.setValue(false);
@ -96,6 +98,11 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
return mAlarmHistoryList;
}
@Override
public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);

View File

@ -20,8 +20,9 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private DeviceRepository mDeviceRepository;
private static final int RECHTEANFORDERUNG_KAMERA = 10;
private static final int RIGHTS_REQUEST_CAMERA = 10;
@Override
public void init() {
@ -37,6 +38,7 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
mDeviceList = mDeviceRepository.getConnectedDeviceList();
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
}
public boolean isCameraAccessAllowed(Context context) {
@ -44,7 +46,7 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
}
public void accessRequestCamera(Activity activity) {
ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.CAMERA}, RECHTEANFORDERUNG_KAMERA);
ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.CAMERA}, RIGHTS_REQUEST_CAMERA);
}
@Override
@ -57,6 +59,11 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
return mAlarmHistoryList;
}
@Override
public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);

View File

@ -19,6 +19,7 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<Boolean> mVideoAlarmDetected;
private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private DeviceRepository mDeviceRepository;
private CameraSensor mCameraSensor;
@ -41,6 +42,9 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
if (mAlarmHistoryList == null) {
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
}
if (mStartAlarmRecording == null) {
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
}
if (mVideoAlarmDetected == null) {
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue();
}
@ -64,6 +68,11 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
return mAlarmHistoryList;
}
@Override
public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);

View File

@ -10,6 +10,7 @@ public interface ViewModelInterface {
void init();
LiveData<List<Device>> getConnectedDeviceList();
LiveData<List<Device>> getAlarmHistoryList();
LiveData<Boolean> getStartAlarmRecording();
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage);
void setTimeStamp(String deviceID, String timeStamp);
String getTimeStamp(String deviceID);