Added alarm history to project and renaming
This commit is contained in:
parent
792c650400
commit
032ab2788d
@ -3,6 +3,8 @@ package com.example.greenwatch;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
@ -14,6 +16,8 @@ import android.widget.Button;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
|
||||||
|
import com.example.greenwatch.adapters.DeviceListAdapter;
|
||||||
import com.example.greenwatch.models.Device;
|
import com.example.greenwatch.models.Device;
|
||||||
import com.example.greenwatch.viewmodels.AccelerometerViewModel;
|
import com.example.greenwatch.viewmodels.AccelerometerViewModel;
|
||||||
|
|
||||||
@ -39,6 +43,20 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
|||||||
accelerometerWarningTV = (TextView) findViewById(R.id.tvAccelerometerWarning);
|
accelerometerWarningTV = (TextView) findViewById(R.id.tvAccelerometerWarning);
|
||||||
backToMainActivityButton = (Button) findViewById(R.id.accelerometerBackToMainActivity);
|
backToMainActivityButton = (Button) findViewById(R.id.accelerometerBackToMainActivity);
|
||||||
|
|
||||||
|
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
|
||||||
|
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
recyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
|
||||||
|
recyclerView.setAdapter(deviceListAdapter);
|
||||||
|
|
||||||
|
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
|
||||||
|
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
alarmHistoryListRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
|
||||||
|
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
|
||||||
|
|
||||||
backToMainActivityButton.setOnClickListener(new View.OnClickListener() {
|
backToMainActivityButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -51,34 +69,26 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
|||||||
mAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
mAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(List<Device> devices) {
|
public void onChanged(List<Device> devices) {
|
||||||
StringBuilder sb = new StringBuilder();
|
deviceListAdapter.setDevices(devices);
|
||||||
sb.append("Time Stamp: ");
|
|
||||||
sb.append(mAccelerometerViewModel.getTimeStamp(mAccelerometerViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("DeviceID: ");
|
|
||||||
sb.append(mAccelerometerViewModel.getDeviceID(mAccelerometerViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Status: ");
|
|
||||||
sb.append(mAccelerometerViewModel.getSensorStatus(mAccelerometerViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Type: ");
|
|
||||||
sb.append(mAccelerometerViewModel.getSensorType(mAccelerometerViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Massage: ");
|
|
||||||
sb.append(mAccelerometerViewModel.getSensorMassage(mAccelerometerViewModel.getLocalDeviceUUID()));
|
|
||||||
accelerometerStatusMessage.setText(sb);
|
|
||||||
Toast.makeText(AccelerometerActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
Toast.makeText(AccelerometerActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mAccelerometerViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
alarmHistoryListAdapter.setAlarmHistoryList(devices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() {
|
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(Boolean aBoolean) {
|
public void onChanged(Boolean aBoolean) {
|
||||||
if (aBoolean) {
|
if (aBoolean) {
|
||||||
mAccelerometerViewModel.setDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10);
|
mAccelerometerViewModel.updateDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mAccelerometerViewModel.setDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), false, "Accelerometer", 0);
|
mAccelerometerViewModel.updateDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), false, "Accelerometer", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,9 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
|
||||||
import com.example.greenwatch.adapters.DeviceListAdapter;
|
import com.example.greenwatch.adapters.DeviceListAdapter;
|
||||||
import com.example.greenwatch.models.Device;
|
import com.example.greenwatch.models.Device;
|
||||||
import com.example.greenwatch.viewmodels.MainActivityViewModel;
|
import com.example.greenwatch.viewmodels.MainActivityViewModel;
|
||||||
@ -21,7 +21,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private TextView tvstatusmessage;
|
|
||||||
private Button audiodetectionButton;
|
private Button audiodetectionButton;
|
||||||
private Button videodetectionButton;
|
private Button videodetectionButton;
|
||||||
private Button accelerometerButton;
|
private Button accelerometerButton;
|
||||||
@ -35,7 +34,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
tvstatusmessage = (TextView) findViewById(R.id.tvStatusmessage);
|
|
||||||
audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton);
|
audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton);
|
||||||
videodetectionButton = (Button) findViewById(R.id.videodetectionButton);
|
videodetectionButton = (Button) findViewById(R.id.videodetectionButton);
|
||||||
accelerometerButton = (Button) findViewById(R.id.accelerometerButton);
|
accelerometerButton = (Button) findViewById(R.id.accelerometerButton);
|
||||||
@ -43,12 +41,19 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
videodetectionAndAccelerometerButton = (Button) findViewById(R.id.videodetectionAndAccelerometerButton);
|
videodetectionAndAccelerometerButton = (Button) findViewById(R.id.videodetectionAndAccelerometerButton);
|
||||||
connectionButton = (Button) findViewById(R.id.connectionButton);
|
connectionButton = (Button) findViewById(R.id.connectionButton);
|
||||||
|
|
||||||
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
|
RecyclerView deviceListRecyclerView = findViewById(R.id.deviceListRecyclerView);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
deviceListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
recyclerView.setHasFixedSize(true);
|
deviceListRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
|
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
|
||||||
recyclerView.setAdapter(deviceListAdapter);
|
deviceListRecyclerView.setAdapter(deviceListAdapter);
|
||||||
|
|
||||||
|
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
|
||||||
|
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
alarmHistoryListRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
|
||||||
|
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
|
||||||
|
|
||||||
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
|
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
|
||||||
mMainActivityViewModel.init();
|
mMainActivityViewModel.init();
|
||||||
@ -56,31 +61,22 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onChanged(List<Device> devices) {
|
public void onChanged(List<Device> devices) {
|
||||||
deviceListAdapter.setDevices(devices);
|
deviceListAdapter.setDevices(devices);
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("Time Stamp: ");
|
|
||||||
sb.append(mMainActivityViewModel.getTimeStamp(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("DeviceID: ");
|
|
||||||
sb.append(mMainActivityViewModel.getDeviceID(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Status: ");
|
|
||||||
sb.append(mMainActivityViewModel.getSensorStatus(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Type: ");
|
|
||||||
sb.append(mMainActivityViewModel.getSensorType(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
sb.append(";\n");
|
|
||||||
sb.append("Sensor Massage: ");
|
|
||||||
sb.append(mMainActivityViewModel.getSensorMassage(mMainActivityViewModel.getLocalDeviceUUID()));
|
|
||||||
tvstatusmessage.setText(sb);
|
|
||||||
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mMainActivityViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
alarmHistoryListAdapter.setAlarmHistoryList(devices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
|
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//openAudiodetectionActivity();
|
//openAudiodetectionActivity();
|
||||||
mMainActivityViewModel.setDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", false, "Audio", 10);
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", false, "Audio", 10);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@ -140,12 +136,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public void openVideodetectionAndAccelerometerActivity(){
|
public void openVideodetectionAndAccelerometerActivity(){
|
||||||
//Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
//Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
||||||
//startActivity(intent);
|
//startActivity(intent);
|
||||||
mMainActivityViewModel.setDevice(mMainActivityViewModel.getLocalDeviceUUID(), "24:00", false, "Video", 0);
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "24:00", false, "Video", 0);
|
||||||
}
|
}
|
||||||
public void openConnectionActivity(){
|
public void openConnectionActivity(){
|
||||||
//Intent intent = new Intent(this, ConnectionActivity.class);
|
//Intent intent = new Intent(this, ConnectionActivity.class);
|
||||||
//startActivity(intent);
|
//startActivity(intent);
|
||||||
mMainActivityViewModel.setDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", true, "Audio", 10);
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", true, "Audio", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package com.example.greenwatch.adapters;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.example.greenwatch.R;
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AlarmHistoryListAdapter extends RecyclerView.Adapter<AlarmHistoryListAdapter.AlarmHistoryListHolder> {
|
||||||
|
private List<Device> alarmHistoryList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public AlarmHistoryListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View itemView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.alarm_history_item, parent, false);
|
||||||
|
return new AlarmHistoryListHolder(itemView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull AlarmHistoryListHolder holder, int position) {
|
||||||
|
Device currentDevice = alarmHistoryList.get(position);
|
||||||
|
holder.textViewSensorType.setText(holder.itemView.getContext().getString(R.string.sensor_type_placeholder, currentDevice.getSensorType()));
|
||||||
|
holder.textViewDeviceID.setText(holder.itemView.getContext().getString(R.string.deviceID_placeholder, currentDevice.getDeviceID()));
|
||||||
|
holder.textViewTimeStamp.setText(holder.itemView.getContext().getString(R.string.sensor_time_stamp_placeholder, currentDevice.getTimeStamp()));
|
||||||
|
holder.textViewSensorMessage.setText(holder.itemView.getContext().getString(R.string.sensor_message_placeholder, currentDevice.getSensorMassage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return alarmHistoryList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlarmHistoryList(List<Device> alarmHistoryList) {
|
||||||
|
this.alarmHistoryList = alarmHistoryList;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
class AlarmHistoryListHolder extends RecyclerView.ViewHolder {
|
||||||
|
private TextView textViewSensorType;
|
||||||
|
private TextView textViewDeviceID;
|
||||||
|
private TextView textViewTimeStamp;
|
||||||
|
private TextView textViewSensorMessage;
|
||||||
|
|
||||||
|
public AlarmHistoryListHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
textViewSensorType = (TextView) itemView.findViewById(R.id.tvAlarmHistoryDeviceSensorType);
|
||||||
|
textViewDeviceID = (TextView) itemView.findViewById(R.id.tvAlarmHistoryDeviceID);
|
||||||
|
textViewTimeStamp = (TextView) itemView.findViewById(R.id.tvAlarmHistoryDeviceTimeStamp);
|
||||||
|
textViewSensorMessage = (TextView) itemView.findViewById(R.id.tvAlarmHistoryDeviceSensorMassage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,21 +6,26 @@ import androidx.lifecycle.MutableLiveData;
|
|||||||
import com.example.greenwatch.models.Device;
|
import com.example.greenwatch.models.Device;
|
||||||
import com.example.greenwatch.communication.WiFiCommunication;
|
import com.example.greenwatch.communication.WiFiCommunication;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DeviceRepository {
|
public class DeviceRepository {
|
||||||
|
|
||||||
|
private final int maxAlarmHistoryListSize = 20;
|
||||||
private final String delimiter = ", ";
|
private final String delimiter = ", ";
|
||||||
private final String SensorStatusKey = "An";
|
private final String SensorStatusKey = "An";
|
||||||
private String localDeviceUUID;
|
private String localDeviceUUID;
|
||||||
private static DeviceRepository deviceRepositoryInstance;
|
private static DeviceRepository deviceRepositoryInstance;
|
||||||
private WiFiCommunication mWiFiCommunication;
|
private WiFiCommunication mWiFiCommunication;
|
||||||
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
|
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
|
||||||
|
private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>();
|
||||||
private HashMap<String, Device> connectedDevicesList = new HashMap<>();
|
private HashMap<String, Device> connectedDevicesList = new HashMap<>();
|
||||||
private HashMap<String, String> deviceIDMapper = new HashMap<>();
|
private HashMap<String, String> deviceIDMapper = new HashMap<>();
|
||||||
|
private List<Device> alarmHistoryDeviceList = new ArrayList<>();
|
||||||
|
|
||||||
private DeviceRepository() {
|
private DeviceRepository() {
|
||||||
setLocalDeviceUUID();
|
setLocalDeviceUUID();
|
||||||
@ -38,15 +43,42 @@ public class DeviceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<Device>> getConnectedDeviceList() {
|
public MutableLiveData<List<Device>> getConnectedDeviceList() {
|
||||||
setMutableLiveDataValue();
|
setMutableLiveDataDeviceList();
|
||||||
return deviceList;
|
return deviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<List<Device>> getAlarmHistoryDeviceList() {
|
||||||
|
setMutableLiveDataAlarmHistoryList();
|
||||||
|
return alarmHistoryList;
|
||||||
|
}
|
||||||
|
|
||||||
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
|
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
|
||||||
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
setDeviceIDMapper(deviceID);
|
if (sensorStatus) {
|
||||||
|
setAlarmHistoryDeviceList(newDevice);
|
||||||
|
}
|
||||||
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
|
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
|
||||||
setMutableLiveDataValue();
|
setMutableLiveDataDeviceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getNewReceivedMessage(String newMessage) {
|
||||||
|
String[] messageString = messageStringSplitter(newMessage);
|
||||||
|
String timeStamp = messageString[0];
|
||||||
|
String deviceID = messageString[1];
|
||||||
|
boolean sensorStatus = convertSensorStatus(messageString[2]);
|
||||||
|
String sensorType = messageString[3];
|
||||||
|
int sensorMassage = Integer.valueOf(messageString[4]);
|
||||||
|
|
||||||
|
if (deviceID.equals(checkDeviceID(localDeviceUUID))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!connectedDevicesList.containsKey(deviceID)) {
|
||||||
|
createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String messageStringBuilder(String deviceID) {
|
private String messageStringBuilder(String deviceID) {
|
||||||
@ -62,7 +94,6 @@ public class DeviceRepository {
|
|||||||
.append(device.getSensorType())
|
.append(device.getSensorType())
|
||||||
.append(delimiter)
|
.append(delimiter)
|
||||||
.append(device.getSensorMassage());
|
.append(device.getSensorMassage());
|
||||||
return message.toString();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
message.append("")
|
message.append("")
|
||||||
@ -74,8 +105,8 @@ public class DeviceRepository {
|
|||||||
.append("")
|
.append("")
|
||||||
.append(delimiter)
|
.append(delimiter)
|
||||||
.append("");
|
.append("");
|
||||||
return message.toString();
|
|
||||||
}
|
}
|
||||||
|
return message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocalDeviceUUID() {
|
public String getLocalDeviceUUID() {
|
||||||
@ -87,11 +118,14 @@ public class DeviceRepository {
|
|||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
if(device != null) {
|
if(device != null) {
|
||||||
device.setTimeStamp(timeStamp);
|
device.setTimeStamp(timeStamp);
|
||||||
device.setSensorStatus(sensorStatus);
|
|
||||||
device.setSensorType(sensorType);
|
device.setSensorType(sensorType);
|
||||||
device.setSensorMassage(sensorMassage);
|
device.setSensorMassage(sensorMassage);
|
||||||
|
if (!device.getSensorStatus() && sensorStatus) {
|
||||||
|
setAlarmHistoryDeviceList(device);
|
||||||
|
}
|
||||||
|
device.setSensorStatus(sensorStatus);
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
setMutableLiveDataValue();
|
setMutableLiveDataDeviceList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +135,7 @@ public class DeviceRepository {
|
|||||||
if(device != null) {
|
if(device != null) {
|
||||||
device.setTimeStamp(timeStamp);
|
device.setTimeStamp(timeStamp);
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
setMutableLiveDataValue();
|
setMutableLiveDataDeviceList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +156,7 @@ public class DeviceRepository {
|
|||||||
setDeviceIDMapper(newDeviceID);
|
setDeviceIDMapper(newDeviceID);
|
||||||
connectedDevicesList.remove(checkedDeviceID);
|
connectedDevicesList.remove(checkedDeviceID);
|
||||||
addToConnectedDeviceList(newDeviceID, device);
|
addToConnectedDeviceList(newDeviceID, device);
|
||||||
setMutableLiveDataValue();
|
setMutableLiveDataDeviceList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,9 +173,13 @@ public class DeviceRepository {
|
|||||||
String checkedDeviceID = checkDeviceID(deviceID);
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
Device device = connectedDevicesList.get(checkedDeviceID);
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
if(device != null) {
|
if(device != null) {
|
||||||
|
if (!device.getSensorStatus() && sensorStatus) {
|
||||||
|
setAlarmHistoryDeviceList(device);
|
||||||
|
}
|
||||||
device.setSensorStatus(sensorStatus);
|
device.setSensorStatus(sensorStatus);
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
setMutableLiveDataValue();
|
setMutableLiveDataDeviceList();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +198,7 @@ public class DeviceRepository {
|
|||||||
if(device != null) {
|
if(device != null) {
|
||||||
device.setSensorType(sensorType);
|
device.setSensorType(sensorType);
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
setMutableLiveDataValue();
|
setMutableLiveDataDeviceList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +217,7 @@ public class DeviceRepository {
|
|||||||
if(device != null) {
|
if(device != null) {
|
||||||
device.setSensorMassage(sensorMessage);
|
device.setSensorMassage(sensorMessage);
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
setMutableLiveDataValue();
|
setMutableLiveDataDeviceList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,11 +230,21 @@ public class DeviceRepository {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMutableLiveDataValue() {
|
public String getSystemTimeStamp() {
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
Date date = new Date(System.currentTimeMillis());
|
||||||
|
return formatter.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMutableLiveDataDeviceList() {
|
||||||
List<Device> list = new ArrayList<>(connectedDevicesList.values());
|
List<Device> list = new ArrayList<>(connectedDevicesList.values());
|
||||||
deviceList.setValue(list);
|
deviceList.setValue(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setMutableLiveDataAlarmHistoryList() {
|
||||||
|
alarmHistoryList.setValue(alarmHistoryDeviceList);
|
||||||
|
}
|
||||||
|
|
||||||
private void addToConnectedDeviceList(String key, Device device) {
|
private void addToConnectedDeviceList(String key, Device device) {
|
||||||
connectedDevicesList.put(key, device);
|
connectedDevicesList.put(key, device);
|
||||||
if (key.equals(checkDeviceID(localDeviceUUID))) {
|
if (key.equals(checkDeviceID(localDeviceUUID))) {
|
||||||
@ -223,27 +271,16 @@ public class DeviceRepository {
|
|||||||
return message.split(delimiter);
|
return message.split(delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getNewReceivedMessage(String newMessage) {
|
|
||||||
String[] messageString = messageStringSplitter(newMessage);
|
|
||||||
String timeStamp = messageString[0];
|
|
||||||
String deviceID = messageString[1];
|
|
||||||
boolean sensorStatus = convertSensorStatus(messageString[2]);
|
|
||||||
String sensorType = messageString[3];
|
|
||||||
int sensorMassage = Integer.valueOf(messageString[4]);
|
|
||||||
|
|
||||||
if (deviceID.equals(checkDeviceID(localDeviceUUID))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!connectedDevicesList.containsKey(deviceID)) {
|
|
||||||
createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean convertSensorStatus(String status) {
|
private boolean convertSensorStatus(String status) {
|
||||||
return status.equals(SensorStatusKey);
|
return status.equals(SensorStatusKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setAlarmHistoryDeviceList(Device device) {
|
||||||
|
if (alarmHistoryDeviceList.size() == maxAlarmHistoryListSize) {
|
||||||
|
alarmHistoryDeviceList.remove(alarmHistoryDeviceList.size() -1);
|
||||||
|
}
|
||||||
|
Device alarmHistoryDevice = new Device(device.getTimeStamp(), device.getDeviceID(), device.getSensorStatus(), device.getSensorType(), device.getSensorMassage());
|
||||||
|
alarmHistoryDeviceList.add(0, alarmHistoryDevice);
|
||||||
|
setMutableLiveDataAlarmHistoryList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ public class AccelerometerViewModel extends ViewModel {
|
|||||||
|
|
||||||
private MutableLiveData<List<Device>> mDeviceList;
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>();
|
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>();
|
||||||
|
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||||
private DeviceRepository mDeviceRepository;
|
private DeviceRepository mDeviceRepository;
|
||||||
private ArrayList<Float> Gesamt_be;
|
private ArrayList<Float> Gesamt_be;
|
||||||
int arraySize = 500;
|
int arraySize = 500;
|
||||||
@ -29,6 +30,7 @@ public class AccelerometerViewModel extends ViewModel {
|
|||||||
if (mDeviceList == null) {
|
if (mDeviceList == null) {
|
||||||
mDeviceRepository = DeviceRepository.getInstance();
|
mDeviceRepository = DeviceRepository.getInstance();
|
||||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
|
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||||
}
|
}
|
||||||
initGesamtBE();
|
initGesamtBE();
|
||||||
mMovementDetected.setValue(false);
|
mMovementDetected.setValue(false);
|
||||||
@ -80,9 +82,7 @@ public class AccelerometerViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getSystemTimeStamp() {
|
public String getSystemTimeStamp() {
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
return mDeviceRepository.getSystemTimeStamp();
|
||||||
Date date = new Date(System.currentTimeMillis());
|
|
||||||
return formatter.format(date);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<Boolean> getMovementDetectedValue() {
|
public LiveData<Boolean> getMovementDetectedValue() {
|
||||||
@ -93,7 +93,11 @@ public class AccelerometerViewModel extends ViewModel {
|
|||||||
return mDeviceList;
|
return mDeviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
public LiveData<List<Device>> getAlarmHistoryList() {
|
||||||
|
return mAlarmHistoryList;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||||||
public class MainActivityViewModel extends ViewModel {
|
public class MainActivityViewModel extends ViewModel {
|
||||||
|
|
||||||
private MutableLiveData<List<Device>> mDeviceList;
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
|
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||||
private DeviceRepository mDeviceRepository;
|
private DeviceRepository mDeviceRepository;
|
||||||
|
|
||||||
|
|
||||||
@ -26,15 +27,21 @@ public class MainActivityViewModel extends ViewModel {
|
|||||||
mWiFiCommunication = WiFiCommunication.getInstance();
|
mWiFiCommunication = WiFiCommunication.getInstance();
|
||||||
mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
|
mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
|
||||||
mWiFiCommunication.setDeviceRepository(mDeviceRepository);
|
mWiFiCommunication.setDeviceRepository(mDeviceRepository);
|
||||||
mDeviceRepository.createNewDevice("", mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
||||||
|
mDeviceRepository.createNewDevice("00:00", "1234", true, "Test", 21);
|
||||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
|
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Device>> getConnectedDeviceList() {
|
public LiveData<List<Device>> getConnectedDeviceList() {
|
||||||
return mDeviceList;
|
return mDeviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
public LiveData<List<Device>> getAlarmHistoryList() {
|
||||||
|
return mAlarmHistoryList;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,4 +36,27 @@
|
|||||||
android:text="Back to MainActivity">
|
android:text="Back to MainActivity">
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/deviceListRecyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:listitem="@layout/device_item"
|
||||||
|
android:layout_weight="1">
|
||||||
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/alarmHistoryListRecyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:listitem="@layout/alarm_history_item"
|
||||||
|
android:layout_weight="1">
|
||||||
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -8,19 +8,19 @@
|
|||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<TextView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/tvStatusmessage"
|
android:id="@+id/alarmHistoryListRecyclerView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:text="Hello World!"
|
android:layout_weight="3"
|
||||||
android:layout_weight="4">
|
tools:listitem="@layout/alarm_history_item">
|
||||||
</TextView>
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/deviceListRecyclerView"
|
android:id="@+id/deviceListRecyclerView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="2"
|
android:layout_weight="3"
|
||||||
tools:listitem="@layout/device_item">
|
tools:listitem="@layout/device_item">
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
|
51
app/src/main/res/layout/alarm_history_item.xml
Normal file
51
app/src/main/res/layout/alarm_history_item.xml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="8dp">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAlarmHistoryDeviceSensorType"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/sensor_type_placeholder"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:ellipsize="end">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAlarmHistoryDeviceID"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvAlarmHistoryDeviceSensorType"
|
||||||
|
android:text="@string/deviceID_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAlarmHistoryDeviceTimeStamp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvAlarmHistoryDeviceID"
|
||||||
|
android:text="@string/sensor_time_stamp_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAlarmHistoryDeviceSensorMassage"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvAlarmHistoryDeviceTimeStamp"
|
||||||
|
android:text="@string/sensor_message_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
Loading…
x
Reference in New Issue
Block a user