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
6e7b5305
Commit
6e7b5305
authored
Oct 28, 2024
by
Ishankha K.C
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
baby wet checker
parent
92ce955b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
1 deletion
+138
-1
app/src/main/java/com/kaluwa/enterprises/babycare/activities/DashboardActivity.java
...wa/enterprises/babycare/activities/DashboardActivity.java
+129
-1
app/src/main/java/com/kaluwa/enterprises/babycare/dto/BabyDto.java
...ain/java/com/kaluwa/enterprises/babycare/dto/BabyDto.java
+1
-0
app/src/main/java/com/kaluwa/enterprises/babycare/service/ActivityLogsApiService.java
.../enterprises/babycare/service/ActivityLogsApiService.java
+4
-0
app/src/main/java/com/kaluwa/enterprises/babycare/service/BabyApiService.java
...m/kaluwa/enterprises/babycare/service/BabyApiService.java
+4
-0
app/src/main/res/raw/wet_warning.mp3
app/src/main/res/raw/wet_warning.mp3
+0
-0
No files found.
app/src/main/java/com/kaluwa/enterprises/babycare/activities/DashboardActivity.java
View file @
6e7b5305
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
.
constants
.
LogTypes
.
C_WET
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
animationChanger
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
animationChanger
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.media.MediaPlayer
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.Gravity
;
import
android.view.Menu
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.MenuInflater
;
...
@@ -17,12 +23,35 @@ import androidx.appcompat.app.AppCompatActivity;
...
@@ -17,12 +23,35 @@ 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.dto.ActivityLogDto
;
import
com.kaluwa.enterprises.babycare.dto.BabyDto
;
import
com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto
;
import
com.kaluwa.enterprises.babycare.error.ErrorDto
;
import
com.kaluwa.enterprises.babycare.service.ActivityLogsApiService
;
import
com.kaluwa.enterprises.babycare.service.BabyApiService
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
DashboardActivity
extends
AppCompatActivity
{
public
class
DashboardActivity
extends
AppCompatActivity
{
LinearLayout
btn1
,
btn2
,
btn3
,
btn4
,
btn5
,
btn6
;
private
static
final
String
TAG
=
"DashboardActivity"
;
private
static
final
long
CHECK_INTERVAL_MS
=
5000
;
// 5 seconds interval
private
LinearLayout
btn1
,
btn2
,
btn3
,
btn4
,
btn5
,
btn6
;
private
AuthenticationDto
authDto
;
private
BabyApiService
babyApiService
;
private
Handler
handler
=
new
Handler
(
Looper
.
getMainLooper
());
private
MediaPlayer
warningSoundPlayer
;
private
boolean
isWarningPlaying
=
false
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -32,6 +61,15 @@ public class DashboardActivity extends AppCompatActivity {
...
@@ -32,6 +61,15 @@ public class DashboardActivity 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
();
}
babyApiService
=
ApiConfig
.
getInstance
().
getBabyApi
(
authDto
.
getTokenDto
().
getToken
());
btn1
=
findViewById
(
R
.
id
.
btn_camera
);
btn1
=
findViewById
(
R
.
id
.
btn_camera
);
btn2
=
findViewById
(
R
.
id
.
btn_vocal
);
btn2
=
findViewById
(
R
.
id
.
btn_vocal
);
btn3
=
findViewById
(
R
.
id
.
btn_notifications
);
btn3
=
findViewById
(
R
.
id
.
btn_notifications
);
...
@@ -69,6 +107,89 @@ public class DashboardActivity extends AppCompatActivity {
...
@@ -69,6 +107,89 @@ public class DashboardActivity extends AppCompatActivity {
startActivity
(
intent
);
startActivity
(
intent
);
animationChanger
(
this
);
animationChanger
(
this
);
});
});
// Start periodic check for wet status
startCheckingWetStatus
();
}
private
void
startCheckingWetStatus
()
{
handler
.
post
(
checkWetStatusRunnable
);
}
private
final
Runnable
checkWetStatusRunnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
// Call the API to get the list of babies and check wet status
babyApiService
.
getAllBabiesByUserId
(
authDto
.
getUserId
()).
enqueue
(
new
Callback
<
List
<
BabyDto
>>()
{
@Override
public
void
onResponse
(
Call
<
List
<
BabyDto
>>
call
,
Response
<
List
<
BabyDto
>>
response
)
{
if
(
response
.
isSuccessful
()
&&
response
.
body
()
!=
null
)
{
List
<
BabyDto
>
babies
=
response
.
body
();
boolean
anyBabyWet
=
false
;
for
(
BabyDto
baby
:
babies
)
{
if
(
baby
.
isWet
()
&&
!
baby
.
getDeviceUid
().
isEmpty
())
{
Log
.
i
(
TAG
,
"Baby "
+
baby
.
getFirstName
()
+
" is wet."
);
Toast
.
makeText
(
DashboardActivity
.
this
,
"Baby "
+
baby
.
getFirstName
()
+
" is wet."
,
Toast
.
LENGTH_SHORT
).
show
();
anyBabyWet
=
true
;
}
}
if
(
anyBabyWet
)
{
startWarningSound
();
}
else
{
stopWarningSound
();
}
}
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
(
DashboardActivity
.
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
(
DashboardActivity
.
this
,
"An unexpected error occurred"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"else-error: "
+
e
.
getMessage
());
}
}
}
@Override
public
void
onFailure
(
Call
<
List
<
BabyDto
>>
call
,
Throwable
t
)
{
Log
.
e
(
TAG
,
"API call failed: "
+
t
.
getMessage
());
}
});
// Schedule the next check
handler
.
postDelayed
(
this
,
CHECK_INTERVAL_MS
);
}
};
private
void
startWarningSound
()
{
if
(!
isWarningPlaying
)
{
if
(
warningSoundPlayer
==
null
)
{
warningSoundPlayer
=
MediaPlayer
.
create
(
this
,
R
.
raw
.
wet_warning
);
// Replace with your sound file
warningSoundPlayer
.
setLooping
(
true
);
// Set to loop
}
warningSoundPlayer
.
start
();
isWarningPlaying
=
true
;
}
}
private
void
stopWarningSound
()
{
if
(
isWarningPlaying
)
{
warningSoundPlayer
.
stop
();
warningSoundPlayer
.
release
();
warningSoundPlayer
=
null
;
isWarningPlaying
=
false
;
}
}
}
private
void
defineActionbar
()
{
private
void
defineActionbar
()
{
...
@@ -135,4 +256,11 @@ public class DashboardActivity extends AppCompatActivity {
...
@@ -135,4 +256,11 @@ public class DashboardActivity extends AppCompatActivity {
super
.
onBackPressed
();
super
.
onBackPressed
();
animationChanger
(
this
);
animationChanger
(
this
);
}
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
handler
.
removeCallbacks
(
checkWetStatusRunnable
);
// Stop status checking when activity is destroyed
stopWarningSound
();
// Ensure sound stops if activity is closed
}
}
}
\ No newline at end of file
app/src/main/java/com/kaluwa/enterprises/babycare/dto/BabyDto.java
View file @
6e7b5305
...
@@ -51,6 +51,7 @@ public class BabyDto {
...
@@ -51,6 +51,7 @@ public class BabyDto {
private
Long
userId
;
private
Long
userId
;
private
Long
documentId
;
private
Long
documentId
;
private
byte
[]
imageData
;
private
byte
[]
imageData
;
private
boolean
wet
;
@JsonIgnore
@JsonIgnore
private
boolean
sys_validated
;
private
boolean
sys_validated
;
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/service/ActivityLogsApiService.java
View file @
6e7b5305
...
@@ -8,6 +8,7 @@ import java.util.List;
...
@@ -8,6 +8,7 @@ import java.util.List;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.http.DELETE
;
import
retrofit2.http.DELETE
;
import
retrofit2.http.GET
;
import
retrofit2.http.GET
;
import
retrofit2.http.Query
;
public
interface
ActivityLogsApiService
{
public
interface
ActivityLogsApiService
{
...
@@ -17,4 +18,7 @@ public interface ActivityLogsApiService {
...
@@ -17,4 +18,7 @@ public interface ActivityLogsApiService {
@DELETE
(
"activity-logs"
)
@DELETE
(
"activity-logs"
)
Call
<
ResponseDto
>
deleteAllActivityLogs
();
Call
<
ResponseDto
>
deleteAllActivityLogs
();
@GET
(
"activity-logs"
)
Call
<
List
<
ActivityLogDto
>>
getTop5ActivityLogsByType
(
@Query
(
"activityLogType"
)
String
activityLogType
);
}
}
app/src/main/java/com/kaluwa/enterprises/babycare/service/BabyApiService.java
View file @
6e7b5305
...
@@ -10,6 +10,7 @@ import retrofit2.http.GET;
...
@@ -10,6 +10,7 @@ import retrofit2.http.GET;
import
retrofit2.http.POST
;
import
retrofit2.http.POST
;
import
retrofit2.http.PUT
;
import
retrofit2.http.PUT
;
import
retrofit2.http.Path
;
import
retrofit2.http.Path
;
import
retrofit2.http.Query
;
public
interface
BabyApiService
{
public
interface
BabyApiService
{
...
@@ -22,4 +23,7 @@ public interface BabyApiService {
...
@@ -22,4 +23,7 @@ public interface BabyApiService {
@PUT
(
"baby/{babyId}"
)
@PUT
(
"baby/{babyId}"
)
Call
<
BabyDto
>
updateBaby
(
@Path
(
"babyId"
)
Long
babyId
,
@Body
BabyDto
baby
);
Call
<
BabyDto
>
updateBaby
(
@Path
(
"babyId"
)
Long
babyId
,
@Body
BabyDto
baby
);
@GET
(
"baby"
)
Call
<
List
<
BabyDto
>>
getAllBabiesByUserId
(
@Query
(
"userId"
)
Long
userId
);
}
}
app/src/main/res/raw/wet_warning.mp3
0 → 100644
View file @
6e7b5305
File added
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