Browse Source

Added alarm history to project and renaming

DoNotMerge_Runnable_Test_Branch
Christian Tinz 1 year ago
parent
commit
032ab2788d

+ 28
- 18
app/src/main/java/com/example/greenwatch/AccelerometerActivity.java View File

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


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) {
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();
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);
deviceListAdapter.setDevices(devices);
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);
} }


} }

+ 22
- 26
app/src/main/java/com/example/greenwatch/MainActivity.java View File

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;


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;
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);
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.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
RecyclerView deviceListRecyclerView = findViewById(R.id.deviceListRecyclerView);
deviceListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
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();
@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() {
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);
} }


} }

+ 62
- 0
app/src/main/java/com/example/greenwatch/adapters/AlarmHistoryListAdapter.java View File

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

+ 70
- 33
app/src/main/java/com/example/greenwatch/repositories/DeviceRepository.java View File

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();
} }


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) {
.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("")
.append("") .append("")
.append(delimiter) .append(delimiter)
.append(""); .append("");
return message.toString();
} }
return message.toString();
} }


public String getLocalDeviceUUID() { public String getLocalDeviceUUID() {
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();
} }
} }


if(device != null) { if(device != null) {
device.setTimeStamp(timeStamp); device.setTimeStamp(timeStamp);
addToConnectedDeviceList(checkedDeviceID, device); addToConnectedDeviceList(checkedDeviceID, device);
setMutableLiveDataValue();
setMutableLiveDataDeviceList();
} }
} }


setDeviceIDMapper(newDeviceID); setDeviceIDMapper(newDeviceID);
connectedDevicesList.remove(checkedDeviceID); connectedDevicesList.remove(checkedDeviceID);
addToConnectedDeviceList(newDeviceID, device); addToConnectedDeviceList(newDeviceID, device);
setMutableLiveDataValue();
setMutableLiveDataDeviceList();
} }
} }


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();

} }
} }


if(device != null) { if(device != null) {
device.setSensorType(sensorType); device.setSensorType(sensorType);
addToConnectedDeviceList(checkedDeviceID, device); addToConnectedDeviceList(checkedDeviceID, device);
setMutableLiveDataValue();
setMutableLiveDataDeviceList();
} }
} }


if(device != null) { if(device != null) {
device.setSensorMassage(sensorMessage); device.setSensorMassage(sensorMessage);
addToConnectedDeviceList(checkedDeviceID, device); addToConnectedDeviceList(checkedDeviceID, device);
setMutableLiveDataValue();
setMutableLiveDataDeviceList();
} }
} }


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))) {
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();
}
} }

+ 8
- 4
app/src/main/java/com/example/greenwatch/viewmodels/AccelerometerViewModel.java View File



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


public String getSystemTimeStamp() { public String getSystemTimeStamp() {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
return formatter.format(date);
return mDeviceRepository.getSystemTimeStamp();
} }


public LiveData<Boolean> getMovementDetectedValue() { public LiveData<Boolean> getMovementDetectedValue() {
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);
} }



+ 9
- 2
app/src/main/java/com/example/greenwatch/viewmodels/MainActivityViewModel.java View File

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;




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



+ 23
- 0
app/src/main/res/layout/activity_accelerometer.xml View File

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>

+ 6
- 6
app/src/main/res/layout/activity_main.xml View File

android:padding="10dp" android:padding="10dp"
tools:context=".MainActivity"> tools:context=".MainActivity">


<TextView
android:id="@+id/tvStatusmessage"
<androidx.recyclerview.widget.RecyclerView
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="4">
</TextView>
android:layout_weight="3"
tools:listitem="@layout/alarm_history_item">
</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
- 0
app/src/main/res/layout/alarm_history_item.xml View File

<?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…
Cancel
Save