Commit d73d445b authored by Ishankha K.C's avatar Ishankha K.C

connect multiple devices to android application

parent 9d4716df
......@@ -2,6 +2,7 @@ package com.kaluwa.enterprises.babycare.activities;
import static com.kaluwa.enterprises.babycare.config.BabyEmotionWebSocketListener.NORMAL_CLOSURE_STATUS;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.clearToken;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.getToken;
import static com.kaluwa.enterprises.babycare.constants.Configs.EMOTIONAL_VIDEO_PROCESS_WS_URL;
import static com.kaluwa.enterprises.babycare.constants.Configs.LIVE_FEED_URL;
import static com.kaluwa.enterprises.babycare.constants.Configs.REFRESH_INTERVAL;
......@@ -29,9 +30,11 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.kaluwa.enterprises.babycare.MainActivity;
import com.kaluwa.enterprises.babycare.R;
import com.kaluwa.enterprises.babycare.config.BabyEmotionWebSocketListener;
import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import java.io.IOException;
import java.io.InputStream;
......@@ -53,6 +56,9 @@ public class LiveFeedActivity extends AppCompatActivity {
private Handler handler = new Handler();
private Runnable updateRunnable;
private WebSocket webSocket;
private String deviceUid = "8563efa6";
private AuthenticationDto authDto;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -60,6 +66,16 @@ public class LiveFeedActivity extends AppCompatActivity {
setContentView(R.layout.activity_live_feed);
// define actionbar
defineActionbar();
// initialize user api service
try {
authDto = getToken(getApplicationContext());
} catch (JsonProcessingException e) {
Log.e(TAG, "Error: "+e.getMessage());
Toast.makeText(this, "Error getting token, Please refresh", Toast.LENGTH_SHORT).show();
}
// Replace the device UID in the URLs
LIVE_FEED_URL = LIVE_FEED_URL.replace("{device_uid}", deviceUid);
ivLiveFeed = findViewById(R.id.ivLiveFeed);
lfFlashBtn = findViewById(R.id.lfFlashBtn);
......@@ -232,8 +248,19 @@ public class LiveFeedActivity extends AppCompatActivity {
}
private void connectWebSocket() {
EMOTIONAL_VIDEO_PROCESS_WS_URL = EMOTIONAL_VIDEO_PROCESS_WS_URL.replace("{device_uid}", deviceUid);
Log.d(TAG, "Connecting to WebSocket: " + EMOTIONAL_VIDEO_PROCESS_WS_URL);
// Create OkHttpClient instance
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(EMOTIONAL_VIDEO_PROCESS_WS_URL).build();
// Build request with Authorization header for Bearer token
Request request = new Request.Builder()
.url(EMOTIONAL_VIDEO_PROCESS_WS_URL)
.addHeader("Authorization", "Bearer " + authDto.getTokenDto().getToken())
.build();
// Create WebSocket with the request
webSocket = client.newWebSocket(request, new BabyEmotionWebSocketListener(this, tvLlStatusValue));
}
......
......@@ -4,8 +4,8 @@ public class Configs {
public static final String URL = "192.168.1.2:8080/api/v1/baby-care/";
public static final String BASE_URL = "http://"+URL;
public static final String LIVE_FEED_URL = "http://192.168.1.7";
public static final String EMOTIONAL_VIDEO_PROCESS_WS_URL = "ws://"+URL+"emotional/video-process";
public static String LIVE_FEED_URL = "http://192.168.1.7/{device_uid}";
public static String EMOTIONAL_VIDEO_PROCESS_WS_URL = "ws://"+URL+"emotional/video-process/{device_uid}";
public static final int REFRESH_INTERVAL = 100; // Refresh every 100 ms
......
......@@ -35,7 +35,7 @@ import java.time.LocalDate;
public class AddBabyDialog extends AppCompatDialogFragment {
BabyDialogInterface babyDialogInterface;
private EditText etFirstname, etLastname, dateDob, etSex, etWeight, etHeight, etBloodType, etEyeColor, etHairColor, etAllergies, etMediConditions, etMedication, etVaccinateRecs, etDocName, etDocContact, etHealthInsuranceInfo, dateFirstSmile, dateFirstTooth, dateFirstWord, dateFirstStep, etFavFoods, etDisFoods, etPEmergConName, etPEmergRelation, etPEmergConNumber, etSEmergConName, etSEmergRelation, etSEmergConNumber, etNotes;
private EditText etFirstname, etLastname, dateDob, etSex, et_device_uid, etWeight, etHeight, etBloodType, etEyeColor, etHairColor, etAllergies, etMediConditions, etMedication, etVaccinateRecs, etDocName, etDocContact, etHealthInsuranceInfo, dateFirstSmile, dateFirstTooth, dateFirstWord, dateFirstStep, etFavFoods, etDisFoods, etPEmergConName, etPEmergRelation, etPEmergConNumber, etSEmergConName, etSEmergRelation, etSEmergConNumber, etNotes;
private ImageButton ibPhoto;
private SwitchCompat switchStatus;
private View overlay;
......@@ -113,12 +113,13 @@ public class AddBabyDialog extends AppCompatDialogFragment {
private BabyDto validateObjects() {
BabyDto baby = new BabyDto();
baby.setSys_validated(false);
String firstname, lastname, dob, sex, weight, height, bType, eyeColor, hairColor, allergies, medicalConditions, medications, vaccinateRecs, docName, docContact, healthInsuInfo, firstSmile, firstTooth, firstWord, firstStep, favFoods, disFoods, pEmergeConName, pEmergeRelationship, pEmergeContact, sEmergeConName, sEmergeRelationship, sEmergeContact, notes;
String firstname, lastname, dob, sex, device_uid, weight, height, bType, eyeColor, hairColor, allergies, medicalConditions, medications, vaccinateRecs, docName, docContact, healthInsuInfo, firstSmile, firstTooth, firstWord, firstStep, favFoods, disFoods, pEmergeConName, pEmergeRelationship, pEmergeContact, sEmergeConName, sEmergeRelationship, sEmergeContact, notes;
firstname = etFirstname.getText().toString();
lastname = etLastname.getText().toString();
dob = dateDob.getText().toString();
sex = etSex.getText().toString();
device_uid = et_device_uid.getText().toString();
weight = etWeight.getText().toString();
height = etHeight.getText().toString();
bType = etBloodType.getText().toString();
......@@ -159,6 +160,7 @@ public class AddBabyDialog extends AppCompatDialogFragment {
baby.setLastName(lastname);
baby.setDob(LocalDate.parse(dob, getDateTimeFormatter()));
baby.setSex(sex);
baby.setDeviceUid(device_uid);
baby.setIsActive(switchStatus.isChecked());
if (!TextUtils.isEmpty(weight)) {
baby.setWeight(Float.parseFloat(weight));
......@@ -215,6 +217,7 @@ public class AddBabyDialog extends AppCompatDialogFragment {
etLastname = view.findViewById(R.id.abv_et_last_name);
dateDob = view.findViewById(R.id.abv_et_dob);
etSex = view.findViewById(R.id.abv_et_sex);
et_device_uid = view.findViewById(R.id.abv_et_device_uid);
etWeight = view.findViewById(R.id.abv_et_weight);
etHeight = view.findViewById(R.id.abv_et_height);
etBloodType = view.findViewById(R.id.abv_dd_blood_type);
......
......@@ -72,7 +72,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
private static final String TAG = "EditBabyDialogTAG";
EditBabyDialogInterface babyDialogInterface;
private EditText etFirstname, etLastname, dateDob, etSex, etWeight, etHeight, etBloodType, etEyeColor, etHairColor, etAllergies, etMediConditions, etMedication, etVaccinateRecs, etDocName, etDocContact, etHealthInsuranceInfo, dateFirstSmile, dateFirstTooth, dateFirstWord, dateFirstStep, etFavFoods, etDisFoods, etPEmergConName, etPEmergRelation, etPEmergConNumber, etSEmergConName, etSEmergRelation, etSEmergConNumber, etNotes;
private EditText etFirstname, etLastname, dateDob, etSex, et_device_uid, etWeight, etHeight, etBloodType, etEyeColor, etHairColor, etAllergies, etMediConditions, etMedication, etVaccinateRecs, etDocName, etDocContact, etHealthInsuranceInfo, dateFirstSmile, dateFirstTooth, dateFirstWord, dateFirstStep, etFavFoods, etDisFoods, etPEmergConName, etPEmergRelation, etPEmergConNumber, etSEmergConName, etSEmergRelation, etSEmergConNumber, etNotes;
private ShapeableImageView ibPhoto;
private SwitchCompat switchStatus;
private View overlay;
......@@ -333,6 +333,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
etLastname.setText(babyDto.getLastName());
dateDob.setText(babyDto.getDob() != null ? babyDto.getDob().toString() : "");
etSex.setText(babyDto.getSex());
et_device_uid.setText(babyDto.getDeviceUid());
etWeight.setText(babyDto.getWeight() != null && babyDto.getWeight() != 0 ? String.valueOf(babyDto.getWeight()) : "");
etHeight.setText(babyDto.getHeight() != null && babyDto.getHeight() != 0 ? String.valueOf(babyDto.getHeight()) : "");
etBloodType.setText(babyDto.getBloodType());
......@@ -374,12 +375,13 @@ public class EditBabyDialog extends AppCompatDialogFragment {
BabyDto baby = new BabyDto();
baby.setBabyId(babyDto.getBabyId());
baby.setSys_validated(false);
String firstname, lastname, dob, sex, weight, height, bType, eyeColor, hairColor, allergies, medicalConditions, medications, vaccinateRecs, docName, docContact, healthInsuInfo, firstSmile, firstTooth, firstWord, firstStep, favFoods, disFoods, pEmergeConName, pEmergeRelationship, pEmergeContact, sEmergeConName, sEmergeRelationship, sEmergeContact, notes, uniqKey;
String firstname, lastname, dob, sex, device_uid, weight, height, bType, eyeColor, hairColor, allergies, medicalConditions, medications, vaccinateRecs, docName, docContact, healthInsuInfo, firstSmile, firstTooth, firstWord, firstStep, favFoods, disFoods, pEmergeConName, pEmergeRelationship, pEmergeContact, sEmergeConName, sEmergeRelationship, sEmergeContact, notes, uniqKey;
firstname = etFirstname.getText().toString();
lastname = etLastname.getText().toString();
dob = dateDob.getText().toString();
sex = etSex.getText().toString();
device_uid = et_device_uid.getText().toString();
weight = etWeight.getText().toString();
height = etHeight.getText().toString();
bType = etBloodType.getText().toString();
......@@ -420,6 +422,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
baby.setLastName(lastname);
baby.setDob(LocalDate.parse(dob, getDateTimeFormatter()));
baby.setSex(sex);
baby.setDeviceUid(device_uid);
baby.setIsActive(switchStatus.isChecked());
if (!TextUtils.isEmpty(weight)) {
baby.setWeight(Float.parseFloat(weight));
......@@ -477,6 +480,7 @@ public class EditBabyDialog extends AppCompatDialogFragment {
etLastname = view.findViewById(R.id.ebv_et_last_name);
dateDob = view.findViewById(R.id.ebv_et_dob);
etSex = view.findViewById(R.id.ebv_et_sex);
et_device_uid = view.findViewById(R.id.ebv_et_device_uid);
etWeight = view.findViewById(R.id.ebv_et_weight);
etHeight = view.findViewById(R.id.ebv_et_height);
etBloodType = view.findViewById(R.id.ebv_dd_blood_type);
......
......@@ -18,6 +18,7 @@ public class BabyDto {
private String lastName;
private LocalDate dob;
private String sex;
private String deviceUid;
private String status;
private Boolean isActive;
private Float weight;
......
......@@ -77,6 +77,15 @@
android:textSize="16sp"
android:fontFamily="@font/kanit_regular"/>
<EditText
android:id="@+id/abv_et_device_uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/device_unique_id"
android:inputType="text"
android:textSize="16sp"
android:fontFamily="@font/kanit_regular"/>
<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
......
......@@ -116,6 +116,15 @@
android:textSize="16sp"
android:fontFamily="@font/kanit_regular"/>
<EditText
android:id="@+id/ebv_et_device_uid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/device_unique_id"
android:inputType="text"
android:textSize="16sp"
android:fontFamily="@font/kanit_regular"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
......@@ -24,4 +24,5 @@
<string name="about">A child is a human being between the stages of birth and puberty, or between the developmental periods of infancy and puberty. It may also refer to an unborn human being. The legal definition of a child generally refers to a minor, which is a person younger than the age of majority.</string>
<string name="version">Version 0.1</string>
<string name="contact_name">Contact Name<font color="#FF0000"> *</font></string>
<string name="device_unique_id">Device Unique ID</string>
</resources>
\ No newline at end of file
......@@ -23,4 +23,5 @@
<string name="about">A child is a human being between the stages of birth and puberty, or between the developmental periods of infancy and puberty. It may also refer to an unborn human being. The legal definition of a child generally refers to a minor, which is a person younger than the age of majority.</string>
<string name="version">Version 0.1</string>
<string name="contact_name">Contact Name<font color="#FF0000"> *</font></string>
<string name="device_unique_id">Device Unique ID</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment