Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
baby-monitoring-android-app
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
R24-145
baby-monitoring-android-app
Commits
92ce955b
Commit
92ce955b
authored
Oct 28, 2024
by
Ishankha K.C
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
integrate device controller
parent
9ef3abdd
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
824 additions
and
22 deletions
+824
-22
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+3
-0
app/src/main/java/com/kaluwa/enterprises/babycare/activities/BabyDevControlListActivity.java
...rises/babycare/activities/BabyDevControlListActivity.java
+240
-0
app/src/main/java/com/kaluwa/enterprises/babycare/activities/DashboardActivity.java
...wa/enterprises/babycare/activities/DashboardActivity.java
+1
-1
app/src/main/java/com/kaluwa/enterprises/babycare/activities/DeviceControlsActivity.java
...terprises/babycare/activities/DeviceControlsActivity.java
+147
-0
app/src/main/java/com/kaluwa/enterprises/babycare/activities/LiveFeedActivity.java
...uwa/enterprises/babycare/activities/LiveFeedActivity.java
+47
-20
app/src/main/java/com/kaluwa/enterprises/babycare/adapter/BabyDevControlListAdapter.java
...terprises/babycare/adapter/BabyDevControlListAdapter.java
+128
-0
app/src/main/java/com/kaluwa/enterprises/babycare/config/ApiConfig.java
...ava/com/kaluwa/enterprises/babycare/config/ApiConfig.java
+6
-0
app/src/main/java/com/kaluwa/enterprises/babycare/config/TokenSaver.java
...va/com/kaluwa/enterprises/babycare/config/TokenSaver.java
+30
-0
app/src/main/java/com/kaluwa/enterprises/babycare/constants/LogTypes.java
...a/com/kaluwa/enterprises/babycare/constants/LogTypes.java
+11
-0
app/src/main/java/com/kaluwa/enterprises/babycare/dto/SwingRequestDto.java
.../com/kaluwa/enterprises/babycare/dto/SwingRequestDto.java
+13
-0
app/src/main/java/com/kaluwa/enterprises/babycare/service/DeviceApiService.java
...kaluwa/enterprises/babycare/service/DeviceApiService.java
+19
-0
app/src/main/res/layout/activity_baby_dev_control_list.xml
app/src/main/res/layout/activity_baby_dev_control_list.xml
+104
-0
app/src/main/res/layout/dialog_configure_contact_info.xml
app/src/main/res/layout/dialog_configure_contact_info.xml
+1
-1
app/src/main/res/layout/dialog_swing_control_layout.xml
app/src/main/res/layout/dialog_swing_control_layout.xml
+74
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
92ce955b
...
@@ -18,6 +18,9 @@
...
@@ -18,6 +18,9 @@
android:supportsRtl=
"true"
android:supportsRtl=
"true"
android:theme=
"@style/Theme.BabyCare"
android:theme=
"@style/Theme.BabyCare"
tools:targetApi=
"31"
>
tools:targetApi=
"31"
>
<activity
android:name=
".activities.BabyDevControlListActivity"
android:exported=
"false"
/>
<activity
<activity
android:name=
".activities.BabyCamListActivity"
android:name=
".activities.BabyCamListActivity"
android:exported=
"false"
/>
android:exported=
"false"
/>
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/activities/BabyDevControlListActivity.java
0 → 100644
View file @
92ce955b
This diff is collapsed.
Click to expand it.
app/src/main/java/com/kaluwa/enterprises/babycare/activities/DashboardActivity.java
View file @
92ce955b
...
@@ -55,7 +55,7 @@ public class DashboardActivity extends AppCompatActivity {
...
@@ -55,7 +55,7 @@ public class DashboardActivity extends AppCompatActivity {
animationChanger
(
this
);
animationChanger
(
this
);
});
});
btn4
.
setOnClickListener
(
v
->
{
btn4
.
setOnClickListener
(
v
->
{
Intent
intent
=
new
Intent
(
this
,
DeviceControls
Activity
.
class
);
Intent
intent
=
new
Intent
(
this
,
BabyDevControlList
Activity
.
class
);
startActivity
(
intent
);
startActivity
(
intent
);
animationChanger
(
this
);
animationChanger
(
this
);
});
});
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/activities/DeviceControlsActivity.java
View file @
92ce955b
package
com.kaluwa.enterprises.babycare.activities
;
package
com.kaluwa.enterprises.babycare.activities
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
config
.
TokenSaver
.
clearToken
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
config
.
TokenSaver
.
clearToken
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
config
.
TokenSaver
.
getToken
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
animationChanger
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
animationChanger
;
import
android.app.AlertDialog
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.Gravity
;
import
android.view.LayoutInflater
;
import
android.view.Menu
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.MenuInflater
;
import
android.view.MenuItem
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.widget.ArrayAdapter
;
import
android.widget.LinearLayout
;
import
android.widget.Spinner
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
android.widget.ToggleButton
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.widget.PopupMenu
;
import
androidx.appcompat.widget.PopupMenu
;
import
androidx.appcompat.widget.Toolbar
;
import
androidx.appcompat.widget.Toolbar
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.google.gson.Gson
;
import
com.kaluwa.enterprises.babycare.MainActivity
;
import
com.kaluwa.enterprises.babycare.MainActivity
;
import
com.kaluwa.enterprises.babycare.R
;
import
com.kaluwa.enterprises.babycare.R
;
import
com.kaluwa.enterprises.babycare.config.ApiConfig
;
import
com.kaluwa.enterprises.babycare.config.TokenSaver
;
import
com.kaluwa.enterprises.babycare.dto.SwingRequestDto
;
import
com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto
;
import
com.kaluwa.enterprises.babycare.dto.responseDto.ResponseDto
;
import
com.kaluwa.enterprises.babycare.error.ErrorDto
;
import
com.kaluwa.enterprises.babycare.service.BabyApiService
;
import
com.kaluwa.enterprises.babycare.service.DeviceApiService
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
DeviceControlsActivity
extends
AppCompatActivity
{
public
class
DeviceControlsActivity
extends
AppCompatActivity
{
private
final
static
String
TAG
=
"DeviceControlsActivity"
;
private
AuthenticationDto
authDto
;
private
DeviceApiService
deviceApiService
;
private
String
deviceUid
=
""
;
private
LinearLayout
btnSwing
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
...
@@ -28,6 +58,123 @@ public class DeviceControlsActivity extends AppCompatActivity {
...
@@ -28,6 +58,123 @@ public class DeviceControlsActivity extends AppCompatActivity {
// define actionbar
// define actionbar
defineActionbar
();
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
();
}
deviceApiService
=
ApiConfig
.
getInstance
().
getDeviceApi
(
authDto
.
getTokenDto
().
getToken
());
// get extra
if
(
getIntent
().
hasExtra
(
"deviceUid"
))
{
deviceUid
=
getIntent
().
getStringExtra
(
"deviceUid"
);
}
// initialize views
btnSwing
=
findViewById
(
R
.
id
.
btnSwing
);
// set click listeners
onClickers
();
}
private
void
onClickers
()
{
btnSwing
.
setOnClickListener
(
v
->
{
// open swing dialog
showCradleSwingDialog
();
});
}
private
void
showCradleSwingDialog
()
{
// Inflate the dialog layout
LayoutInflater
inflater
=
getLayoutInflater
();
View
dialogView
=
inflater
.
inflate
(
R
.
layout
.
dialog_swing_control_layout
,
null
);
// Find views in the dialog layout
Spinner
speedControlSpinner
=
dialogView
.
findViewById
(
R
.
id
.
scl_spinner_speed_control
);
ToggleButton
toggleButton
=
dialogView
.
findViewById
(
R
.
id
.
scl_toggle_swing
);
// Set up the speed options for the spinner
String
[]
speedOptions
=
{
"Low"
,
"Medium"
,
"High"
};
ArrayAdapter
<
String
>
adapter
=
new
ArrayAdapter
<>(
this
,
android
.
R
.
layout
.
simple_spinner_item
,
speedOptions
);
adapter
.
setDropDownViewResource
(
android
.
R
.
layout
.
simple_spinner_dropdown_item
);
speedControlSpinner
.
setAdapter
(
adapter
);
// Load and set previous swing status if available
boolean
previousSwingStatus
=
TokenSaver
.
getSwingStatus
(
this
);
toggleButton
.
setChecked
(
previousSwingStatus
);
// Load and set previously selected speed
String
previousSpeed
=
TokenSaver
.
getSpeed
(
this
);
int
speedIndex
=
adapter
.
getPosition
(
previousSpeed
);
speedControlSpinner
.
setSelection
(
speedIndex
);
// Set the previous speed selection
// Create the dialog
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setView
(
dialogView
)
.
setTitle
(
"Cradle Swing Control"
)
// Set dialog title
.
setPositiveButton
(
"OK"
,
(
dialog
,
which
)
->
{
// Handle OK button click
// Retrieve selected speed and toggle state
String
selectedSpeed
=
speedControlSpinner
.
getSelectedItem
().
toString
();
boolean
isSwingOn
=
toggleButton
.
isChecked
();
// Save the swing status and speed
TokenSaver
.
setSwingStatus
(
this
,
isSwingOn
);
TokenSaver
.
setSpeed
(
this
,
selectedSpeed
);
// call api to enable swing
Call
<
ResponseDto
>
callSwing
=
deviceApiService
.
swingDevice
(
deviceUid
,
new
SwingRequestDto
(
isSwingOn
,
selectedSpeed
));
callSwing
.
enqueue
(
new
Callback
<
ResponseDto
>()
{
@Override
public
void
onResponse
(
Call
<
ResponseDto
>
call
,
Response
<
ResponseDto
>
response
)
{
if
(
response
.
isSuccessful
())
{
ResponseDto
responseDto
=
response
.
body
();
if
(
responseDto
!=
null
)
{
Toast
.
makeText
(
DeviceControlsActivity
.
this
,
responseDto
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
Toast
.
makeText
(
DeviceControlsActivity
.
this
,
"An unexpected error occurred"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
else
{
try
{
Gson
gson
=
new
Gson
();
assert
response
.
errorBody
()
!=
null
;
String
errorBodyString
=
response
.
errorBody
().
string
();
// Check if the error body is in JSON format
if
(
errorBodyString
.
startsWith
(
"{"
))
{
ErrorDto
errorDto
=
gson
.
fromJson
(
errorBodyString
,
ErrorDto
.
class
);
Toast
.
makeText
(
DeviceControlsActivity
.
this
,
errorDto
.
getMessage
(),
Toast
.
LENGTH_LONG
).
show
();
}
else
{
// If the error body is not in JSON format, display a generic error message
Log
.
e
(
TAG
,
errorBodyString
);
Toast
.
makeText
(
DeviceControlsActivity
.
this
,
"An unexpected error occurred"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"else-error: "
+
e
.
getMessage
());
Toast
.
makeText
(
DeviceControlsActivity
.
this
,
e
.
getMessage
(),
Toast
.
LENGTH_LONG
).
show
();
}
}
}
@Override
public
void
onFailure
(
Call
<
ResponseDto
>
call
,
Throwable
throwable
)
{
Log
.
e
(
TAG
,
throwable
.
getMessage
());
Toast
.
makeText
(
DeviceControlsActivity
.
this
,
"Error to Failure"
,
Toast
.
LENGTH_LONG
).
show
();
}
});
// Log or send to the backend
Log
.
d
(
"CradleSwingControl"
,
"Selected Speed: "
+
selectedSpeed
+
", Swing On: "
+
isSwingOn
);
})
.
setNegativeButton
(
"Cancel"
,
(
dialog
,
which
)
->
dialog
.
dismiss
());
// Handle Cancel button
// Show the dialog
AlertDialog
dialog
=
builder
.
create
();
dialog
.
show
();
}
}
private
void
defineActionbar
()
{
private
void
defineActionbar
()
{
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/activities/LiveFeedActivity.java
View file @
92ce955b
...
@@ -31,10 +31,15 @@ import androidx.appcompat.widget.PopupMenu;
...
@@ -31,10 +31,15 @@ import androidx.appcompat.widget.PopupMenu;
import
androidx.appcompat.widget.Toolbar
;
import
androidx.appcompat.widget.Toolbar
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.google.gson.Gson
;
import
com.kaluwa.enterprises.babycare.MainActivity
;
import
com.kaluwa.enterprises.babycare.MainActivity
;
import
com.kaluwa.enterprises.babycare.R
;
import
com.kaluwa.enterprises.babycare.R
;
import
com.kaluwa.enterprises.babycare.config.ApiConfig
;
import
com.kaluwa.enterprises.babycare.config.BabyEmotionWebSocketListener
;
import
com.kaluwa.enterprises.babycare.config.BabyEmotionWebSocketListener
;
import
com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto
;
import
com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto
;
import
com.kaluwa.enterprises.babycare.dto.responseDto.ResponseDto
;
import
com.kaluwa.enterprises.babycare.error.ErrorDto
;
import
com.kaluwa.enterprises.babycare.service.DeviceApiService
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -44,6 +49,9 @@ import java.net.URL;
...
@@ -44,6 +49,9 @@ import java.net.URL;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Request
;
import
okhttp3.WebSocket
;
import
okhttp3.WebSocket
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
LiveFeedActivity
extends
AppCompatActivity
{
public
class
LiveFeedActivity
extends
AppCompatActivity
{
...
@@ -59,6 +67,7 @@ public class LiveFeedActivity extends AppCompatActivity {
...
@@ -59,6 +67,7 @@ public class LiveFeedActivity extends AppCompatActivity {
private
String
deviceUid
=
""
;
private
String
deviceUid
=
""
;
private
AuthenticationDto
authDto
;
private
AuthenticationDto
authDto
;
private
DeviceApiService
deviceApiService
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -73,6 +82,7 @@ public class LiveFeedActivity extends AppCompatActivity {
...
@@ -73,6 +82,7 @@ public class LiveFeedActivity extends AppCompatActivity {
Log
.
e
(
TAG
,
"Error: "
+
e
.
getMessage
());
Log
.
e
(
TAG
,
"Error: "
+
e
.
getMessage
());
Toast
.
makeText
(
this
,
"Error getting token, Please refresh"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
this
,
"Error getting token, Please refresh"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
deviceApiService
=
ApiConfig
.
getInstance
().
getDeviceApi
(
authDto
.
getTokenDto
().
getToken
());
// get extra
// get extra
if
(
getIntent
().
hasExtra
(
"deviceUid"
))
{
if
(
getIntent
().
hasExtra
(
"deviceUid"
))
{
...
@@ -105,30 +115,47 @@ public class LiveFeedActivity extends AppCompatActivity {
...
@@ -105,30 +115,47 @@ public class LiveFeedActivity extends AppCompatActivity {
String
url
=
isFlashOn
?
LIVE_FEED_URL
+
"/flashlight/off"
:
LIVE_FEED_URL
+
"/flashlight/on"
;
String
url
=
isFlashOn
?
LIVE_FEED_URL
+
"/flashlight/off"
:
LIVE_FEED_URL
+
"/flashlight/on"
;
int
iconResId
=
isFlashOn
?
R
.
drawable
.
ico_flash_off
:
R
.
drawable
.
ico_flash_on
;
// Icons for flash on/off
int
iconResId
=
isFlashOn
?
R
.
drawable
.
ico_flash_off
:
R
.
drawable
.
ico_flash_on
;
// Icons for flash on/off
// Call the API in a background thread
String
isFlashOnStatus
=
isFlashOn
?
"off"
:
"on"
;
new
Thread
(()
->
{
try
{
Call
<
ResponseDto
>
callToggle
=
deviceApiService
.
toggleFlashlight
(
deviceUid
,
isFlashOnStatus
);
URL
apiUrl
=
new
URL
(
url
);
callToggle
.
enqueue
(
new
Callback
<
ResponseDto
>()
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
apiUrl
.
openConnection
();
@Override
connection
.
setRequestMethod
(
"GET"
);
public
void
onResponse
(
Call
<
ResponseDto
>
call
,
Response
<
ResponseDto
>
response
)
{
connection
.
connect
();
if
(
response
.
isSuccessful
())
{
ResponseDto
responseDto
=
response
.
body
();
int
responseCode
=
connection
.
getResponseCode
();
if
(
responseDto
!=
null
)
{
if
(
responseCode
==
200
)
{
Toast
.
makeText
(
LiveFeedActivity
.
this
,
responseDto
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
// Successfully called the API, update the ImageView and flash status on the main thread
}
runOnUiThread
(()
->
{
lfFlashBtn
.
setImageResource
(
iconResId
);
// Update the ImageView icon
lfFlashBtn
.
setImageResource
(
iconResId
);
// Update the ImageView icon
isFlashOn
=
!
isFlashOn
;
// Toggle the flash status
isFlashOn
=
!
isFlashOn
;
// Toggle the flash status
});
}
else
{
}
else
{
Log
.
e
(
TAG
,
"Failed to call API: "
+
responseCode
);
try
{
Gson
gson
=
new
Gson
();
assert
response
.
errorBody
()
!=
null
;
String
errorBodyString
=
response
.
errorBody
().
string
();
// Check if the error body is in JSON format
if
(
errorBodyString
.
startsWith
(
"{"
))
{
ErrorDto
errorDto
=
gson
.
fromJson
(
errorBodyString
,
ErrorDto
.
class
);
Toast
.
makeText
(
LiveFeedActivity
.
this
,
errorDto
.
getMessage
(),
Toast
.
LENGTH_LONG
).
show
();
}
else
{
// If the error body is not in JSON format, display a generic error message
Log
.
e
(
TAG
,
errorBodyString
);
Toast
.
makeText
(
LiveFeedActivity
.
this
,
"An unexpected error occurred"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"else-error: "
+
e
.
getMessage
());
Toast
.
makeText
(
LiveFeedActivity
.
this
,
e
.
getMessage
(),
Toast
.
LENGTH_LONG
).
show
();
}
}
}
}
connection
.
disconnect
();
@Override
}
catch
(
IOException
e
)
{
public
void
onFailure
(
Call
<
ResponseDto
>
call
,
Throwable
throwable
)
{
Log
.
e
(
TAG
,
"Error calling flashlight API"
,
e
);
Log
.
e
(
TAG
,
throwable
.
getMessage
());
Toast
.
makeText
(
LiveFeedActivity
.
this
,
"Error to Failure"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
})
.
start
()
;
});
}
}
});
});
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/adapter/BabyDevControlListAdapter.java
0 → 100644
View file @
92ce955b
package
com.kaluwa.enterprises.babycare.adapter
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
animationChanger
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
babyAgeCalculate
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
convertByteArrayToBitmap
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.constraintlayout.widget.ConstraintLayout
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.google.android.material.imageview.ShapeableImageView
;
import
com.kaluwa.enterprises.babycare.R
;
import
com.kaluwa.enterprises.babycare.activities.BabyDevControlListActivity
;
import
com.kaluwa.enterprises.babycare.activities.DeviceControlsActivity
;
import
com.kaluwa.enterprises.babycare.activities.LiveFeedActivity
;
import
com.kaluwa.enterprises.babycare.dto.BabyDto
;
import
java.time.LocalDate
;
import
java.util.List
;
@SuppressLint
(
"LongLogTag"
)
public
class
BabyDevControlListAdapter
extends
RecyclerView
.
Adapter
<
BabyDevControlListAdapter
.
BabyDevControlListItemHolder
>
{
private
final
static
String
TAG
=
"BabyDevControlListAdapter"
;
private
Context
context
;
private
List
<
BabyDto
>
babyList
;
public
BabyDevControlListAdapter
(
Context
context
,
List
<
BabyDto
>
babyList
)
{
this
.
context
=
context
;
this
.
babyList
=
babyList
;
}
@NonNull
@Override
public
BabyDevControlListAdapter
.
BabyDevControlListItemHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
View
view
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
baby_rv_item
,
parent
,
false
);
return
new
BabyDevControlListAdapter
.
BabyDevControlListItemHolder
(
view
);
}
@Override
public
void
onBindViewHolder
(
@NonNull
BabyDevControlListAdapter
.
BabyDevControlListItemHolder
holder
,
int
position
)
{
BabyDto
babyDto
=
babyList
.
get
(
position
);
String
firstname
=
babyDto
.
getFirstName
();
String
lastname
=
babyDto
.
getLastName
();
LocalDate
dob
=
babyDto
.
getDob
();
String
sex
=
babyDto
.
getSex
();
String
notes
=
babyDto
.
getNotes
();
Boolean
isActive
=
babyDto
.
getIsActive
();
byte
[]
imageData
=
babyDto
.
getImageData
();
if
(
lastname
!=
null
)
{
holder
.
tvBabyName
.
setText
(
firstname
+
" "
+
lastname
);
}
else
{
holder
.
tvBabyName
.
setText
(
firstname
);
}
String
age
=
babyAgeCalculate
(
dob
);
holder
.
tvBabyAge
.
setText
(
age
!=
null
?
age
:
"Not Available"
);
holder
.
tvBabySex
.
setText
(
sex
);
if
(!
TextUtils
.
isEmpty
(
notes
))
{
holder
.
tvBabyDDespContent
.
setText
(
notes
);
}
else
{
holder
.
tvBabyDDespTitle
.
setText
(
"Status >"
);
holder
.
tvBabyDDespContent
.
setTextColor
(
isActive
?
context
.
getResources
().
getColor
(
R
.
color
.
success_green
)
:
context
.
getResources
().
getColor
(
R
.
color
.
cancel_red
));
holder
.
tvBabyDDespContent
.
setText
(
isActive
?
"Active"
:
"Inactive"
);
}
if
(
imageData
!=
null
)
{
try
{
Bitmap
bitmap
=
convertByteArrayToBitmap
(
imageData
);
holder
.
ivBabyImage
.
setImageBitmap
(
bitmap
);
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Error occurred: "
+
e
.
getMessage
());
Toast
.
makeText
(
context
,
e
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
}
// Handle item click
holder
.
clBabyItem
.
setOnClickListener
(
v
->
{
// Open live feed activity
if
(
babyDto
.
getDeviceUid
()
==
null
||
babyDto
.
getDeviceUid
().
isEmpty
())
{
Toast
.
makeText
(
context
,
"No device is associated with this baby."
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
Toast
.
makeText
(
context
,
"Opening device controls for "
+
babyDto
.
getFirstName
(),
Toast
.
LENGTH_SHORT
).
show
();
Intent
intent
=
new
Intent
(
context
,
DeviceControlsActivity
.
class
);
intent
.
putExtra
(
"deviceUid"
,
babyDto
.
getDeviceUid
());
context
.
startActivity
(
intent
);
animationChanger
((
Activity
)
context
);
}
});
}
@Override
public
int
getItemCount
()
{
return
babyList
.
size
();
}
public
class
BabyDevControlListItemHolder
extends
RecyclerView
.
ViewHolder
{
public
ConstraintLayout
clBabyItem
;
public
TextView
tvBabyName
,
tvBabyAge
,
tvBabySex
,
tvBabyDDespTitle
,
tvBabyDDespContent
;
public
ShapeableImageView
ivBabyImage
;
public
BabyDevControlListItemHolder
(
@NonNull
View
view
)
{
super
(
view
);
clBabyItem
=
view
.
findViewById
(
R
.
id
.
baby_item
);
tvBabyName
=
view
.
findViewById
(
R
.
id
.
baby_item_name
);
tvBabyAge
=
view
.
findViewById
(
R
.
id
.
baby_item_tv_age_content
);
tvBabySex
=
view
.
findViewById
(
R
.
id
.
baby_item_tv_sex_content
);
tvBabyDDespTitle
=
view
.
findViewById
(
R
.
id
.
baby_item_tv_desp_title
);
tvBabyDDespContent
=
view
.
findViewById
(
R
.
id
.
baby_item_tv_desp_content
);
ivBabyImage
=
view
.
findViewById
(
R
.
id
.
baby_item_iv_image
);
}
}
}
app/src/main/java/com/kaluwa/enterprises/babycare/config/ApiConfig.java
View file @
92ce955b
...
@@ -10,6 +10,7 @@ import com.kaluwa.enterprises.babycare.service.ActivityLogsApiService;
...
@@ -10,6 +10,7 @@ import com.kaluwa.enterprises.babycare.service.ActivityLogsApiService;
import
com.kaluwa.enterprises.babycare.service.AuthApiService
;
import
com.kaluwa.enterprises.babycare.service.AuthApiService
;
import
com.kaluwa.enterprises.babycare.service.BabyApiService
;
import
com.kaluwa.enterprises.babycare.service.BabyApiService
;
import
com.kaluwa.enterprises.babycare.service.ContactInfoService
;
import
com.kaluwa.enterprises.babycare.service.ContactInfoService
;
import
com.kaluwa.enterprises.babycare.service.DeviceApiService
;
import
com.kaluwa.enterprises.babycare.service.DocumentApiService
;
import
com.kaluwa.enterprises.babycare.service.DocumentApiService
;
import
com.kaluwa.enterprises.babycare.service.UserApiService
;
import
com.kaluwa.enterprises.babycare.service.UserApiService
;
...
@@ -89,4 +90,9 @@ public class ApiConfig {
...
@@ -89,4 +90,9 @@ public class ApiConfig {
AUTH_TOKEN
=
JWTToken
;
AUTH_TOKEN
=
JWTToken
;
return
retrofitOther
.
create
(
ContactInfoService
.
class
);
return
retrofitOther
.
create
(
ContactInfoService
.
class
);
}
}
public
DeviceApiService
getDeviceApi
(
String
JWTToken
)
{
AUTH_TOKEN
=
JWTToken
;
return
retrofitOther
.
create
(
DeviceApiService
.
class
);
}
}
}
app/src/main/java/com/kaluwa/enterprises/babycare/config/TokenSaver.java
View file @
92ce955b
...
@@ -10,6 +10,8 @@ import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
...
@@ -10,6 +10,8 @@ import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
public
class
TokenSaver
{
public
class
TokenSaver
{
private
final
static
String
SHARED_PREF_NAME
=
"net.kaluwa.SHARED_PREF_NAME"
;
private
final
static
String
SHARED_PREF_NAME
=
"net.kaluwa.SHARED_PREF_NAME"
;
private
final
static
String
TOKEN_KEY
=
"net.kaluwa.TOKEN_KEY"
;
private
final
static
String
TOKEN_KEY
=
"net.kaluwa.TOKEN_KEY"
;
private
final
static
String
SWING_STATUS_KEY
=
"net.kaluwa.SWING_STATUS_KEY"
;
private
final
static
String
SPEED_KEY
=
"net.kaluwa.SPEED_KEY"
;
private
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
public
static
AuthenticationDto
getToken
(
Context
c
)
throws
JsonProcessingException
{
public
static
AuthenticationDto
getToken
(
Context
c
)
throws
JsonProcessingException
{
...
@@ -38,4 +40,32 @@ public class TokenSaver {
...
@@ -38,4 +40,32 @@ public class TokenSaver {
editor
.
remove
(
TOKEN_KEY
);
editor
.
remove
(
TOKEN_KEY
);
editor
.
apply
();
editor
.
apply
();
}
}
// New method to save swing status
public
static
void
setSwingStatus
(
Context
c
,
boolean
swingStatus
)
{
SharedPreferences
prefs
=
c
.
getSharedPreferences
(
SHARED_PREF_NAME
,
Context
.
MODE_PRIVATE
);
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putBoolean
(
SWING_STATUS_KEY
,
swingStatus
);
editor
.
apply
();
}
// New method to get swing status
public
static
boolean
getSwingStatus
(
Context
c
)
{
SharedPreferences
prefs
=
c
.
getSharedPreferences
(
SHARED_PREF_NAME
,
Context
.
MODE_PRIVATE
);
return
prefs
.
getBoolean
(
SWING_STATUS_KEY
,
false
);
// Default to false if not found
}
// New method to save the selected speed
public
static
void
setSpeed
(
Context
c
,
String
speed
)
{
SharedPreferences
prefs
=
c
.
getSharedPreferences
(
SHARED_PREF_NAME
,
Context
.
MODE_PRIVATE
);
SharedPreferences
.
Editor
editor
=
prefs
.
edit
();
editor
.
putString
(
SPEED_KEY
,
speed
);
editor
.
apply
();
}
// New method to get the selected speed
public
static
String
getSpeed
(
Context
c
)
{
SharedPreferences
prefs
=
c
.
getSharedPreferences
(
SHARED_PREF_NAME
,
Context
.
MODE_PRIVATE
);
return
prefs
.
getString
(
SPEED_KEY
,
"Medium"
);
// Default to "Medium" if not found
}
}
}
app/src/main/java/com/kaluwa/enterprises/babycare/constants/LogTypes.java
0 → 100644
View file @
92ce955b
package
com.kaluwa.enterprises.babycare.constants
;
public
class
LogTypes
{
public
static
final
String
EMOTION
=
"EMOTION"
;
public
static
final
String
FLASH_LIGHT
=
"FLASH_LIGHT"
;
public
static
final
String
C_SWING
=
"C_SWING"
;
public
static
final
String
C_MOTION
=
"C_MOTION"
;
public
static
final
String
C_WET
=
"C_WET"
;
}
app/src/main/java/com/kaluwa/enterprises/babycare/dto/SwingRequestDto.java
0 → 100644
View file @
92ce955b
package
com.kaluwa.enterprises.babycare.dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
SwingRequestDto
{
private
boolean
start
;
private
String
speed
;
// LOW, MEDIUM, HIGH
}
app/src/main/java/com/kaluwa/enterprises/babycare/service/DeviceApiService.java
0 → 100644
View file @
92ce955b
package
com.kaluwa.enterprises.babycare.service
;
import
com.kaluwa.enterprises.babycare.dto.SwingRequestDto
;
import
com.kaluwa.enterprises.babycare.dto.responseDto.ResponseDto
;
import
retrofit2.Call
;
import
retrofit2.http.Body
;
import
retrofit2.http.GET
;
import
retrofit2.http.POST
;
import
retrofit2.http.Path
;
public
interface
DeviceApiService
{
@GET
(
"device/flashlight/{deviceUid}/{status}"
)
Call
<
ResponseDto
>
toggleFlashlight
(
@Path
(
"deviceUid"
)
String
deviceUid
,
@Path
(
"status"
)
String
status
);
@POST
(
"device/swing/{deviceUid}"
)
Call
<
ResponseDto
>
swingDevice
(
@Path
(
"deviceUid"
)
String
deviceUid
,
@Body
SwingRequestDto
swingRequest
);
}
app/src/main/res/layout/activity_baby_dev_control_list.xml
0 → 100644
View file @
92ce955b
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/swipeContainer"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".activities.BabyDevControlListActivity"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<include
layout=
"@layout/appbar"
/>
<ImageView
android:id=
"@+id/background"
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/b_care_action_bar"
app:layout_constraintBottom_toBottomOf=
"parent"
android:src=
"@drawable/background"
android:contentDescription=
"background-image"
android:scaleType=
"centerCrop"
android:alpha=
"0.4"
/>
<RelativeLayout
android:id=
"@+id/rl_header"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@drawable/rl_background"
android:backgroundTint=
"#62178F"
app:layout_constraintTop_toTopOf=
"@+id/background"
app:layout_constraintStart_toStartOf=
"@id/background"
app:layout_constraintEnd_toEndOf=
"@id/background"
android:padding=
"8dp"
>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"Baby Device List"
android:textAlignment=
"center"
android:textColor=
"@color/white"
android:textAllCaps=
"true"
android:fontFamily=
"@font/inknut_antiqua_regular"
android:textSize=
"20sp"
android:gravity=
"center"
/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/bdcl_baby_dash_rv"
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
app:layout_constraintTop_toBottomOf=
"@id/rl_header"
app:layout_constraintBottom_toBottomOf=
"@id/background"
app:layout_constraintEnd_toEndOf=
"@id/background"
app:layout_constraintStart_toStartOf=
"@id/background"
android:scrollbars=
"none"
android:paddingTop=
"6dp"
android:paddingStart=
"15dp"
android:paddingEnd=
"15dp"
android:paddingBottom=
"6dp"
/>
<TextView
android:id=
"@+id/no_content_message"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"No content available"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
android:textStyle=
"bold"
android:visibility=
"gone"
/>
<View
android:id=
"@+id/overlay"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"#99D5C5DF"
android:visibility=
"gone"
android:clickable=
"true"
android:focusable=
"true"
/>
<com.github.ybq.android.spinkit.SpinKitView
android:id=
"@+id/progress_bar"
style=
"@style/SpinKitView.Large.DoubleBounce"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
app:SpinKit_Color=
"@color/purple"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
android:visibility=
"gone"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
\ No newline at end of file
app/src/main/res/layout/dialog_configure_contact_info.xml
View file @
92ce955b
...
@@ -24,8 +24,8 @@
...
@@ -24,8 +24,8 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Contact Information"
android:text=
"Contact Information"
android:textColor=
"@color/purple"
android:textColor=
"@color/purple"
android:textStyle=
"bold"
android:fontFamily=
"@font/jeju_gothic_regular"
android:fontFamily=
"@font/jeju_gothic_regular"
android:textStyle=
"bold"
android:textSize=
"18sp"
/>
android:textSize=
"18sp"
/>
<View
<View
...
...
app/src/main/res/layout/dialog_swing_control_layout.xml
0 → 100644
View file @
92ce955b
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
android:padding=
"16dp"
android:background=
"@android:color/white"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:background=
"@drawable/borders"
android:padding=
"24dp"
android:elevation=
"4dp"
android:layout_marginBottom=
"16dp"
>
<!-- Speed Control Spinner -->
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Select Speed"
android:textSize=
"20sp"
android:textStyle=
"bold"
android:textColor=
"@color/purple"
android:fontFamily=
"@font/jeju_gothic_regular"
android:layout_marginBottom=
"8dp"
/>
<Spinner
android:id=
"@+id/scl_spinner_speed_control"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@android:color/white"
android:padding=
"12dp"
android:layout_marginBottom=
"16dp"
/>
<View
android:layout_width=
"match_parent"
android:layout_height=
"1dp"
android:background=
"@color/dark_purple"
/>
<!-- Toggle Button -->
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Toggle Cradle Swing"
android:textSize=
"20sp"
android:textStyle=
"bold"
android:textColor=
"@color/purple"
android:fontFamily=
"@font/jeju_gothic_regular"
android:layout_marginTop=
"16dp"
android:layout_marginBottom=
"8dp"
/>
<ToggleButton
android:id=
"@+id/scl_toggle_swing"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textOn=
"Swing ON"
android:textOff=
"Swing OFF"
android:layout_gravity=
"center"
android:padding=
"16dp"
android:textSize=
"16sp"
android:layout_marginBottom=
"16dp"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Use the switch to control the cradle swing."
android:textSize=
"14sp"
android:layout_gravity=
"center"
android:layout_marginTop=
"8dp"
/>
</LinearLayout>
</LinearLayout>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment