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
2858c3fb
Commit
2858c3fb
authored
May 20, 2024
by
Chamod Ishankha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start to show baby list
parent
ccd159e2
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
662 additions
and
20 deletions
+662
-20
.idea/inspectionProfiles/Project_Default.xml
.idea/inspectionProfiles/Project_Default.xml
+1
-1
app/build.gradle.kts
app/build.gradle.kts
+1
-0
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+4
-2
app/src/main/java/com/kaluwa/enterprises/babycare/activities/BabyDashboardActivity.java
...nterprises/babycare/activities/BabyDashboardActivity.java
+182
-0
app/src/main/java/com/kaluwa/enterprises/babycare/activities/DashboardActivity.java
...wa/enterprises/babycare/activities/DashboardActivity.java
+30
-0
app/src/main/java/com/kaluwa/enterprises/babycare/activities/UserProfileActivity.java
.../enterprises/babycare/activities/UserProfileActivity.java
+13
-17
app/src/main/java/com/kaluwa/enterprises/babycare/adapter/BabyDashboardAdapter.java
...wa/enterprises/babycare/adapter/BabyDashboardAdapter.java
+97
-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/dto/BabyDto.java
...ain/java/com/kaluwa/enterprises/babycare/dto/BabyDto.java
+24
-0
app/src/main/java/com/kaluwa/enterprises/babycare/service/BabyApiService.java
...m/kaluwa/enterprises/babycare/service/BabyApiService.java
+4
-0
app/src/main/java/com/kaluwa/enterprises/babycare/utils/Utils.java
...ain/java/com/kaluwa/enterprises/babycare/utils/Utils.java
+42
-0
app/src/main/res/drawable/ic_add_32.xml
app/src/main/res/drawable/ic_add_32.xml
+12
-0
app/src/main/res/layout/activity_baby_dashboard.xml
app/src/main/res/layout/activity_baby_dashboard.xml
+116
-0
app/src/main/res/layout/baby_rv_item.xml
app/src/main/res/layout/baby_rv_item.xml
+128
-0
gradle/libs.versions.toml
gradle/libs.versions.toml
+2
-0
No files found.
.idea/inspectionProfiles/Project_Default.xml
View file @
2858c3fb
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<profile
version=
"1.0"
>
<profile
version=
"1.0"
>
<option
name=
"myName"
value=
"Project Default"
/>
<option
name=
"myName"
value=
"Project Default"
/>
<inspection_tool
class=
"AutoCloseableResource"
enabled=
"true"
level=
"WARNING"
enabled_by_default=
"true"
>
<inspection_tool
class=
"AutoCloseableResource"
enabled=
"true"
level=
"WARNING"
enabled_by_default=
"true"
>
<option
name=
"METHOD_MATCHER_CONFIG"
value=
"java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,retrofit2.Response,errorBody"
/>
<option
name=
"METHOD_MATCHER_CONFIG"
value=
"java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,retrofit2.Response,errorBody
|body
"
/>
</inspection_tool>
</inspection_tool>
</profile>
</profile>
</component>
</component>
\ No newline at end of file
app/build.gradle.kts
View file @
2858c3fb
...
@@ -44,6 +44,7 @@ dependencies {
...
@@ -44,6 +44,7 @@ dependencies {
implementation
(
libs
.
convertor
.
gson
)
implementation
(
libs
.
convertor
.
gson
)
implementation
(
libs
.
jackson
.
databind
)
implementation
(
libs
.
jackson
.
databind
)
implementation
(
libs
.
ucrop
)
implementation
(
libs
.
ucrop
)
implementation
(
libs
.
swiperefreshlayout
)
testImplementation
(
libs
.
junit
)
testImplementation
(
libs
.
junit
)
androidTestImplementation
(
libs
.
ext
.
junit
)
androidTestImplementation
(
libs
.
ext
.
junit
)
androidTestImplementation
(
libs
.
espresso
.
core
)
androidTestImplementation
(
libs
.
espresso
.
core
)
...
...
app/src/main/AndroidManifest.xml
View file @
2858c3fb
...
@@ -17,11 +17,13 @@
...
@@ -17,11 +17,13 @@
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.BabyDashboardActivity"
android:exported=
"false"
/>
<activity
<activity
android:name=
"com.yalantis.ucrop.UCropActivity"
android:name=
"com.yalantis.ucrop.UCropActivity"
android:screenOrientation=
"fullSensor"
android:screenOrientation=
"fullSensor"
android:theme=
"@style/Theme.AppCompat.Light.NoActionBar"
/>
android:theme=
"@style/Theme.AppCompat.Light.NoActionBar"
/>
<activity
<activity
android:name=
".activities.UserProfileActivity"
android:name=
".activities.UserProfileActivity"
android:exported=
"false"
/>
android:exported=
"false"
/>
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/activities/BabyDashboardActivity.java
0 → 100644
View file @
2858c3fb
package
com.kaluwa.enterprises.babycare.activities
;
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
android.annotation.SuppressLint
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.activity.EdgeToEdge
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.widget.PopupMenu
;
import
androidx.appcompat.widget.Toolbar
;
import
androidx.core.graphics.Insets
;
import
androidx.core.view.ViewCompat
;
import
androidx.core.view.WindowInsetsCompat
;
import
androidx.recyclerview.widget.LinearLayoutManager
;
import
androidx.recyclerview.widget.RecyclerView
;
import
androidx.swiperefreshlayout.widget.SwipeRefreshLayout
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.github.ybq.android.spinkit.SpinKitView
;
import
com.google.android.material.floatingactionbutton.FloatingActionButton
;
import
com.kaluwa.enterprises.babycare.MainActivity
;
import
com.kaluwa.enterprises.babycare.R
;
import
com.kaluwa.enterprises.babycare.adapter.BabyDashboardAdapter
;
import
com.kaluwa.enterprises.babycare.config.ApiConfig
;
import
com.kaluwa.enterprises.babycare.dto.BabyDto
;
import
com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto
;
import
com.kaluwa.enterprises.babycare.service.BabyApiService
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
BabyDashboardActivity
extends
AppCompatActivity
{
private
final
static
String
TAG
=
"BabyDashboardActivity"
;
private
SwipeRefreshLayout
swipeContainer
;
private
AuthenticationDto
authDto
;
private
RecyclerView
recyclerView
;
private
FloatingActionButton
floatingAddButton
;
private
TextView
tvNoContent
;
private
View
overlay
;
private
SpinKitView
progressbar
;
private
BabyApiService
babyApiService
;
@SuppressLint
(
"NewApi"
)
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_baby_dashboard
);
// define actionbar
defineActionbar
();
swipeToRefresh
();
// 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
());
// assign ids here
recyclerView
=
findViewById
(
R
.
id
.
baby_dash_rv
);
floatingAddButton
=
findViewById
(
R
.
id
.
fab_baby_add
);
tvNoContent
=
findViewById
(
R
.
id
.
no_content_message
);
overlay
=
findViewById
(
R
.
id
.
overlay
);
progressbar
=
findViewById
(
R
.
id
.
progress_bar
);
List
<
BabyDto
>
babyDtoList
=
new
ArrayList
<>();
BabyDto
baby1
=
new
BabyDto
();
baby1
.
setFirstName
(
"Chamod"
);
baby1
.
setLastName
(
"Ishankha"
);
baby1
.
setDob
(
LocalDate
.
parse
(
"2000/07/23"
,
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/dd"
)));
baby1
.
setGender
(
"Male"
);
baby1
.
setActive
(
true
);
BabyDto
baby2
=
new
BabyDto
();
baby2
.
setFirstName
(
"Yohani"
);
baby2
.
setLastName
(
"Madusha"
);
baby2
.
setDob
(
LocalDate
.
parse
(
"2000/11/01"
,
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/dd"
)));
baby2
.
setGender
(
"Female"
);
baby2
.
setActive
(
false
);
baby2
.
setDescription
(
"My little cute daughter, Love you my darling."
);
babyDtoList
.
add
(
baby1
);
babyDtoList
.
add
(
baby2
);
if
(
babyDtoList
.
isEmpty
())
{
tvNoContent
.
setVisibility
(
View
.
VISIBLE
);
}
BabyDashboardAdapter
adapter
=
new
BabyDashboardAdapter
(
this
,
babyDtoList
);
recyclerView
.
setAdapter
(
adapter
);
recyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
this
));
}
private
void
defineActionbar
()
{
Toolbar
toolbar
=
findViewById
(
R
.
id
.
b_care_action_bar
);
setSupportActionBar
(
toolbar
);
if
(
getSupportActionBar
()
!=
null
)
{
getSupportActionBar
().
setDisplayShowTitleEnabled
(
false
);
}
toolbar
.
setNavigationIcon
(
R
.
drawable
.
ico_menu_32
);
toolbar
.
setNavigationOnClickListener
(
v
->
{
// Initializing the popup menu and giving the reference as current context
PopupMenu
popupMenu
=
new
PopupMenu
(
this
,
toolbar
);
popupMenu
.
setGravity
(
Gravity
.
BOTTOM
);
popupMenu
.
getMenuInflater
().
inflate
(
R
.
menu
.
menu_main
,
popupMenu
.
getMenu
());
popupMenu
.
setOnMenuItemClickListener
(
item
->
{
int
id
=
item
.
getItemId
();
if
(
id
==
R
.
id
.
mm_device_setting
)
{
Toast
.
makeText
(
this
,
"You Clicked "
+
item
.
getTitle
(),
Toast
.
LENGTH_SHORT
).
show
();
}
else
if
(
id
==
R
.
id
.
mm_app_setting
)
{
Toast
.
makeText
(
this
,
"You Clicked "
+
item
.
getTitle
(),
Toast
.
LENGTH_SHORT
).
show
();
}
else
if
(
id
==
R
.
id
.
mm_logout
)
{
clearToken
(
getApplicationContext
());
Toast
.
makeText
(
this
,
"Logout successful."
,
Toast
.
LENGTH_SHORT
).
show
();
Intent
intent
=
new
Intent
(
this
,
MainActivity
.
class
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_CLEAR_TOP
|
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
startActivity
(
intent
);
finish
();
animationChanger
(
this
);
}
return
true
;
});
popupMenu
.
show
();
});
}
private
void
swipeToRefresh
()
{
// Look up for the swipe container
swipeContainer
=
findViewById
(
R
.
id
.
swipeContainer
);
// Setup Refresh Listener which triggers new data loading
swipeContainer
.
setOnRefreshListener
(()
->
{
// Code to refresh goes here. Make sure to call swipeContainer.setRefresh(false) once the refreshed.
startActivity
(
getIntent
());
finish
();
overridePendingTransition
(
0
,
0
);
swipeContainer
.
setRefreshing
(
false
);
});
// Configure refresh colors
swipeContainer
.
setColorSchemeResources
(
android
.
R
.
color
.
holo_blue_bright
,
android
.
R
.
color
.
holo_green_light
,
android
.
R
.
color
.
holo_orange_light
,
android
.
R
.
color
.
holo_red_light
);
}
@Override
public
boolean
onCreateOptionsMenu
(
Menu
menu
)
{
MenuInflater
inflater
=
getMenuInflater
();
inflater
.
inflate
(
R
.
menu
.
user_action_menu
,
menu
);
return
true
;
}
@Override
public
boolean
onOptionsItemSelected
(
@NonNull
MenuItem
item
)
{
int
id
=
item
.
getItemId
();
if
(
id
==
R
.
id
.
user
)
{
Intent
intent
=
new
Intent
(
this
,
UserProfileActivity
.
class
);
startActivity
(
intent
);
animationChanger
(
this
);
}
else
{
Toast
.
makeText
(
this
,
"No item."
,
Toast
.
LENGTH_SHORT
).
show
();
}
return
super
.
onOptionsItemSelected
(
item
);
}
@Override
public
void
onBackPressed
()
{
super
.
onBackPressed
();
animationChanger
(
this
);
}
}
\ No newline at end of file
app/src/main/java/com/kaluwa/enterprises/babycare/activities/DashboardActivity.java
View file @
2858c3fb
...
@@ -9,6 +9,7 @@ import android.view.Gravity;
...
@@ -9,6 +9,7 @@ import android.view.Gravity;
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.widget.LinearLayout
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.NonNull
;
...
@@ -22,6 +23,8 @@ import com.kaluwa.enterprises.babycare.activities.auth.LoginActivity;
...
@@ -22,6 +23,8 @@ import com.kaluwa.enterprises.babycare.activities.auth.LoginActivity;
public
class
DashboardActivity
extends
AppCompatActivity
{
public
class
DashboardActivity
extends
AppCompatActivity
{
LinearLayout
btn1
,
btn2
,
btn3
,
btn4
,
btn5
,
btn6
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
...
@@ -29,6 +32,33 @@ public class DashboardActivity extends AppCompatActivity {
...
@@ -29,6 +32,33 @@ public class DashboardActivity extends AppCompatActivity {
// define actionbar
// define actionbar
defineActionbar
();
defineActionbar
();
btn1
=
findViewById
(
R
.
id
.
btn_camera
);
btn2
=
findViewById
(
R
.
id
.
btn_vocal
);
btn3
=
findViewById
(
R
.
id
.
btn_notifications
);
btn4
=
findViewById
(
R
.
id
.
btn_device_controls
);
btn5
=
findViewById
(
R
.
id
.
btn_about_baby
);
btn6
=
findViewById
(
R
.
id
.
btn_settings
);
btn1
.
setOnClickListener
(
v
->
{
});
btn2
.
setOnClickListener
(
v
->
{
});
btn3
.
setOnClickListener
(
v
->
{
});
btn4
.
setOnClickListener
(
v
->
{
});
btn5
.
setOnClickListener
(
v
->
{
Intent
intent
=
new
Intent
(
this
,
BabyDashboardActivity
.
class
);
startActivity
(
intent
);
});
btn6
.
setOnClickListener
(
v
->
{
});
}
}
private
void
defineActionbar
()
{
private
void
defineActionbar
()
{
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/activities/UserProfileActivity.java
View file @
2858c3fb
...
@@ -4,6 +4,7 @@ import static com.kaluwa.enterprises.babycare.utils.Utils.DATE_FORMAT;
...
@@ -4,6 +4,7 @@ import static com.kaluwa.enterprises.babycare.utils.Utils.DATE_FORMAT;
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
.
config
.
TokenSaver
.
getToken
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
animationChanger
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
animationChanger
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
convertByteArrayToBitmap
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
disableEditText
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
disableEditText
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
loader
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
loader
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
mobileNumberValidation
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
mobileNumberValidation
;
...
@@ -248,7 +249,18 @@ public class UserProfileActivity extends AppCompatActivity {
...
@@ -248,7 +249,18 @@ public class UserProfileActivity extends AppCompatActivity {
@Override
@Override
public
void
onResponse
(
Call
<
ResponseBody
>
call
,
Response
<
ResponseBody
>
response
)
{
public
void
onResponse
(
Call
<
ResponseBody
>
call
,
Response
<
ResponseBody
>
response
)
{
if
(
response
.
isSuccessful
())
{
if
(
response
.
isSuccessful
())
{
setByteArrayToImageView
(
response
.
body
());
try
{
if
(
response
.
body
()
!=
null
)
{
InputStream
inputStream
=
response
.
body
().
byteStream
();
Bitmap
bitmap
=
convertByteArrayToBitmap
(
inputStream
);
ivProfilePicture
.
setImageBitmap
(
bitmap
);
}
else
{
Log
.
e
(
TAG
,
"Response body is null"
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Error occurred: "
+
e
.
getMessage
());
Toast
.
makeText
(
UserProfileActivity
.
this
,
e
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
loader
(
overlay
,
progressBar
,
false
);
loader
(
overlay
,
progressBar
,
false
);
}
else
{
}
else
{
try
{
try
{
...
@@ -281,22 +293,6 @@ public class UserProfileActivity extends AppCompatActivity {
...
@@ -281,22 +293,6 @@ public class UserProfileActivity extends AppCompatActivity {
});
});
}
}
private
void
setByteArrayToImageView
(
ResponseBody
responseBody
)
{
if
(
responseBody
!=
null
)
{
try
{
InputStream
inputStream
=
responseBody
.
byteStream
();
Bitmap
bitmap
=
BitmapFactory
.
decodeStream
(
inputStream
);
ivProfilePicture
.
setImageBitmap
(
bitmap
);
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Error decoding image byte array: "
+
e
.
getMessage
());
Toast
.
makeText
(
UserProfileActivity
.
this
,
"Error decoding image byte array"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
else
{
Log
.
e
(
TAG
,
"Response body is null"
);
Toast
.
makeText
(
UserProfileActivity
.
this
,
"Response body is null"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
private
void
startCrop
(
@NonNull
Uri
uri
)
{
private
void
startCrop
(
@NonNull
Uri
uri
)
{
// Generate a unique destination file name based on current time
// Generate a unique destination file name based on current time
String
destinationFileName
=
"CroppedImage_"
+
System
.
currentTimeMillis
()
+
".jpg"
;
String
destinationFileName
=
"CroppedImage_"
+
System
.
currentTimeMillis
()
+
".jpg"
;
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/adapter/BabyDashboardAdapter.java
0 → 100644
View file @
2858c3fb
package
com.kaluwa.enterprises.babycare.adapter
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
calculateAge
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
convertByteArrayToBitmap
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.Color
;
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.UserProfileActivity
;
import
com.kaluwa.enterprises.babycare.dto.BabyDto
;
import
java.io.InputStream
;
import
java.util.List
;
public
class
BabyDashboardAdapter
extends
RecyclerView
.
Adapter
<
BabyDashboardAdapter
.
BabyDashboardItemHolder
>
{
private
final
static
String
TAG
=
"BabyDashboardAdapter"
;
private
Context
context
;
private
List
<
BabyDto
>
babyList
;
public
BabyDashboardAdapter
(
Context
context
,
List
<
BabyDto
>
babyList
)
{
this
.
context
=
context
;
this
.
babyList
=
babyList
;
}
@NonNull
@Override
public
BabyDashboardAdapter
.
BabyDashboardItemHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
View
view
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
baby_rv_item
,
parent
,
false
);
return
new
BabyDashboardAdapter
.
BabyDashboardItemHolder
(
view
);
}
@SuppressLint
(
"SetTextI18n"
)
@Override
public
void
onBindViewHolder
(
@NonNull
BabyDashboardAdapter
.
BabyDashboardItemHolder
holder
,
int
position
)
{
BabyDto
babyDto
=
babyList
.
get
(
position
);
holder
.
tvBabyName
.
setText
(
babyDto
.
getFirstName
()
+
" "
+
babyDto
.
getLastName
());
Double
age
=
calculateAge
(
babyDto
.
getDob
(),
"byMonths"
);
holder
.
tvBabyAge
.
setText
(
age
!=
null
?
age
+
" months"
:
"Not Available"
);
holder
.
tvBabySex
.
setText
(
babyDto
.
getGender
());
if
(!
TextUtils
.
isEmpty
(
babyDto
.
getDescription
()))
{
holder
.
tvBabyDDespContent
.
setText
(
babyDto
.
getDescription
());
}
else
{
holder
.
tvBabyDDespTitle
.
setText
(
"Status >"
);
holder
.
tvBabyDDespContent
.
setTextColor
(
babyDto
.
isActive
()
?
context
.
getResources
().
getColor
(
R
.
color
.
success_green
)
:
context
.
getResources
().
getColor
(
R
.
color
.
cancel_red
));
holder
.
tvBabyDDespContent
.
setText
(
babyDto
.
isActive
()
?
"Active"
:
"Inactive"
);
}
if
(
babyDto
.
getImageData
()
!=
null
)
{
try
{
InputStream
inputStream
=
babyDto
.
getImageData
();
Bitmap
bitmap
=
convertByteArrayToBitmap
(
inputStream
);
holder
.
ivBabyImage
.
setImageBitmap
(
bitmap
);
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Error occurred: "
+
e
.
getMessage
());
Toast
.
makeText
(
context
,
e
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
}
}
@Override
public
int
getItemCount
()
{
return
babyList
.
size
();
}
public
static
class
BabyDashboardItemHolder
extends
RecyclerView
.
ViewHolder
{
public
ConstraintLayout
clBabyItem
;
public
TextView
tvBabyName
,
tvBabyAge
,
tvBabySex
,
tvBabyDDespTitle
,
tvBabyDDespContent
;
public
ShapeableImageView
ivBabyImage
;
public
BabyDashboardItemHolder
(
@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 @
2858c3fb
...
@@ -3,6 +3,7 @@ package com.kaluwa.enterprises.babycare.config;
...
@@ -3,6 +3,7 @@ package com.kaluwa.enterprises.babycare.config;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
config
.
TokenSaver
.
getToken
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
config
.
TokenSaver
.
getToken
;
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.UserApiService
;
import
com.kaluwa.enterprises.babycare.service.UserApiService
;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
...
@@ -56,4 +57,9 @@ public class ApiConfig {
...
@@ -56,4 +57,9 @@ public class ApiConfig {
AUTH_TOKEN
=
JWTToken
;
AUTH_TOKEN
=
JWTToken
;
return
retrofitOther
.
create
(
UserApiService
.
class
);
return
retrofitOther
.
create
(
UserApiService
.
class
);
}
}
public
BabyApiService
getBabyApi
(
String
JWTToken
)
{
AUTH_TOKEN
=
JWTToken
;
return
retrofitOther
.
create
(
BabyApiService
.
class
);
}
}
}
app/src/main/java/com/kaluwa/enterprises/babycare/dto/BabyDto.java
0 → 100644
View file @
2858c3fb
package
com.kaluwa.enterprises.babycare.dto
;
import
java.io.InputStream
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
BabyDto
{
private
String
firstName
;
private
String
lastName
;
private
Object
dob
;
private
String
gender
;
private
String
description
;
private
String
status
;
private
boolean
isActive
;
private
UserDto
user
;
private
Long
userId
;
private
InputStream
imageData
;
}
app/src/main/java/com/kaluwa/enterprises/babycare/service/BabyApiService.java
0 → 100644
View file @
2858c3fb
package
com.kaluwa.enterprises.babycare.service
;
public
interface
BabyApiService
{
}
app/src/main/java/com/kaluwa/enterprises/babycare/utils/Utils.java
View file @
2858c3fb
...
@@ -4,17 +4,23 @@ import android.annotation.SuppressLint;
...
@@ -4,17 +4,23 @@ import android.annotation.SuppressLint;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.app.DatePickerDialog
;
import
android.app.DatePickerDialog
;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.EditText
;
import
android.widget.EditText
;
import
android.widget.Toast
;
import
com.github.ybq.android.spinkit.SpinKitView
;
import
com.github.ybq.android.spinkit.SpinKitView
;
import
com.kaluwa.enterprises.babycare.R
;
import
com.kaluwa.enterprises.babycare.R
;
import
com.kaluwa.enterprises.babycare.activities.UserProfileActivity
;
import
java.io.InputStream
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.time.Period
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Locale
;
...
@@ -22,6 +28,8 @@ import java.util.Objects;
...
@@ -22,6 +28,8 @@ import java.util.Objects;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
okhttp3.ResponseBody
;
public
class
Utils
{
public
class
Utils
{
private
static
final
String
TAG
=
"Utils"
;
private
static
final
String
TAG
=
"Utils"
;
...
@@ -157,4 +165,38 @@ public class Utils {
...
@@ -157,4 +165,38 @@ public class Utils {
return
localDate
;
return
localDate
;
}
}
@SuppressLint
(
"NewApi"
)
public
static
Double
calculateAge
(
Object
dobObj
,
String
condition
)
{
LocalDate
dob
=
getLocalDate
(
dobObj
);
if
(
dob
==
null
)
{
Log
.
e
(
TAG
,
"Invalid date of birth"
);
return
null
;
}
LocalDate
currentDate
=
LocalDate
.
now
();
Period
period
=
Period
.
between
(
dob
,
currentDate
);
Double
age
=
null
;
if
(
condition
.
equalsIgnoreCase
(
"byYears"
))
{
age
=
(
double
)
period
.
getYears
();
age
=
Math
.
round
(
age
*
10.0
)
/
10.0
;
}
else
if
(
condition
.
equalsIgnoreCase
(
"byMonths"
))
{
age
=
period
.
getYears
()
*
12
+
period
.
getMonths
()
+
(
period
.
getDays
()
/
30.0
);
age
=
Math
.
round
(
age
*
10.0
)
/
10.0
;
}
else
{
Log
.
e
(
TAG
,
"Unsupported Condition"
);
}
return
age
;
}
public
static
Bitmap
convertByteArrayToBitmap
(
InputStream
stream
)
{
try
{
return
BitmapFactory
.
decodeStream
(
stream
);
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Error decoding image byte array: "
+
e
.
getMessage
());
throw
new
RuntimeException
(
"Error decoding image byte array"
);
}
}
}
}
app/src/main/res/drawable/ic_add_32.xml
0 → 100644
View file @
2858c3fb
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:width=
"48dp"
android:height=
"48dp"
android:tint=
"#FFFFFF"
android:viewportWidth=
"24"
android:viewportHeight=
"24"
>
<path
android:fillColor=
"@android:color/white"
android:pathData=
"M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"
/>
</vector>
app/src/main/res/layout/activity_baby_dashboard.xml
0 → 100644
View file @
2858c3fb
<?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.BabyDashboardActivity"
>
<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 Dash"
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/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"
/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id=
"@+id/fab_baby_add"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"@dimen/fab_margin"
android:contentDescription=
"add_own_baby_details"
android:src=
"@drawable/ic_add_32"
app:backgroundTint=
"@color/purple"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:maxImageSize=
"38dp"
/>
<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>
app/src/main/res/layout/baby_rv_item.xml
0 → 100644
View file @
2858c3fb
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
app:cardCornerRadius=
"20dp"
app:cardElevation=
"8dp"
android:layout_marginTop=
"3dp"
android:layout_marginBottom=
"3dp"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/baby_item"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:padding=
"15dp"
android:background=
"@color/white"
>
<TextView
android:id=
"@+id/baby_item_name"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Baby's Name"
android:fontFamily=
"@font/jeju_gothic_regular"
android:textStyle=
"bold"
android:textColor=
"@color/black"
android:textSize=
"20sp"
android:maxLines=
"1"
android:ellipsize=
"end"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<LinearLayout
android:id=
"@+id/title_box"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"4dp"
android:orientation=
"vertical"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/baby_item_name"
>
<TextView
android:id=
"@+id/baby_item_tv_age_title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:fontFamily=
"@font/acme_regular"
android:text=
"Age >"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/baby_item_tv_sex_title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"4dp"
android:fontFamily=
"@font/acme_regular"
android:text=
"Sex >"
android:textSize=
"16sp"
/>
<TextView
android:id=
"@+id/baby_item_tv_desp_title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"4dp"
android:fontFamily=
"@font/acme_regular"
android:text=
"Description >"
android:textSize=
"16sp"
/>
</LinearLayout>
<LinearLayout
android:id=
"@+id/content_box"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"6dp"
android:layout_marginTop=
"4dp"
android:orientation=
"vertical"
app:layout_constraintEnd_toStartOf=
"@+id/baby_item_iv_image"
app:layout_constraintStart_toEndOf=
"@+id/title_box"
app:layout_constraintTop_toBottomOf=
"@id/baby_item_name"
>
<TextView
android:id=
"@+id/baby_item_tv_age_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:fontFamily=
"@font/acme_regular"
android:text=
"Value"
android:textColor=
"@color/purple"
android:textSize=
"16sp"
android:textStyle=
"bold"
/>
<TextView
android:id=
"@+id/baby_item_tv_sex_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"4dp"
android:fontFamily=
"@font/acme_regular"
android:text=
"Value"
android:textColor=
"@color/purple"
android:textSize=
"16sp"
android:textStyle=
"bold"
/>
<TextView
android:id=
"@+id/baby_item_tv_desp_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"4dp"
android:ellipsize=
"end"
android:fontFamily=
"@font/acme_regular"
android:maxLines=
"2"
android:text=
"Value"
android:textColor=
"@color/purple"
android:textSize=
"16sp"
android:textStyle=
"bold"
/>
</LinearLayout>
<com.google.android.material.imageview.ShapeableImageView
android:id=
"@+id/baby_item_iv_image"
android:layout_width=
"120dp"
android:layout_height=
"120dp"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
android:src=
"@drawable/foreground"
app:shapeAppearanceOverlay=
"@style/RoundImage"
android:scaleType=
"centerCrop"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
\ No newline at end of file
gradle/libs.versions.toml
View file @
2858c3fb
...
@@ -13,6 +13,7 @@ projectLombok = "1.18.32"
...
@@ -13,6 +13,7 @@ projectLombok = "1.18.32"
retrofit2
=
"2.11.0"
retrofit2
=
"2.11.0"
jacksonDatabind
=
"2.17.1"
jacksonDatabind
=
"2.17.1"
materialVersion
=
"1.13.0-alpha02"
materialVersion
=
"1.13.0-alpha02"
swiperefreshlayout
=
"1.2.0-alpha01"
[libraries]
[libraries]
junit
=
{
group
=
"junit"
,
name
=
"junit"
,
version.ref
=
"junit"
}
junit
=
{
group
=
"junit"
,
name
=
"junit"
,
version.ref
=
"junit"
}
...
@@ -30,6 +31,7 @@ retrofit2 = { group = "com.squareup.retrofit2", name = "retrofit", version = "2.
...
@@ -30,6 +31,7 @@ retrofit2 = { group = "com.squareup.retrofit2", name = "retrofit", version = "2.
convertor-gson
=
{
group
=
"com.squareup.retrofit2"
,
name
=
"converter-gson"
,
version.ref
=
"retrofit2"
}
convertor-gson
=
{
group
=
"com.squareup.retrofit2"
,
name
=
"converter-gson"
,
version.ref
=
"retrofit2"
}
jackson-databind
=
{
group
=
"com.fasterxml.jackson.core"
,
name
=
"jackson-databind"
,
version.ref
=
"jacksonDatabind"
}
jackson-databind
=
{
group
=
"com.fasterxml.jackson.core"
,
name
=
"jackson-databind"
,
version.ref
=
"jacksonDatabind"
}
ucrop
=
{
group
=
"com.github.yalantis"
,
name
=
"ucrop"
,
version
=
"2.2.9"
}
ucrop
=
{
group
=
"com.github.yalantis"
,
name
=
"ucrop"
,
version
=
"2.2.9"
}
swiperefreshlayout
=
{
group
=
"androidx.swiperefreshlayout"
,
name
=
"swiperefreshlayout"
,
version.ref
=
"swiperefreshlayout"
}
[plugins]
[plugins]
androidApplication
=
{
id
=
"com.android.application"
,
version.ref
=
"agp"
}
androidApplication
=
{
id
=
"com.android.application"
,
version.ref
=
"agp"
}
...
...
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