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
430da406
Commit
430da406
authored
May 19, 2024
by
Chamod Ishankha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complete user profile without image upload
parent
227c13db
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
142 additions
and
7 deletions
+142
-7
app/src/main/java/com/kaluwa/enterprises/babycare/activities/UserProfileActivity.java
.../enterprises/babycare/activities/UserProfileActivity.java
+29
-3
app/src/main/java/com/kaluwa/enterprises/babycare/dto/UserDto.java
...ain/java/com/kaluwa/enterprises/babycare/dto/UserDto.java
+3
-0
app/src/main/java/com/kaluwa/enterprises/babycare/utils/Utils.java
...ain/java/com/kaluwa/enterprises/babycare/utils/Utils.java
+104
-0
app/src/main/res/anim/fade_in.xml
app/src/main/res/anim/fade_in.xml
+1
-1
app/src/main/res/anim/fade_out.xml
app/src/main/res/anim/fade_out.xml
+1
-1
app/src/main/res/layout/activity_user_profile.xml
app/src/main/res/layout/activity_user_profile.xml
+4
-2
No files found.
app/src/main/java/com/kaluwa/enterprises/babycare/activities/UserProfileActivity.java
View file @
430da406
package
com.kaluwa.enterprises.babycare.activities
;
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
.
getToken
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
animationChanger
;
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
.
mobileNumberValidation
;
import
static
com
.
kaluwa
.
enterprises
.
babycare
.
utils
.
Utils
.
setUpDOBPicker
;
import
android.annotation.SuppressLint
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
...
...
@@ -35,7 +38,11 @@ import com.kaluwa.enterprises.babycare.dto.AuthenticationDto;
import
com.kaluwa.enterprises.babycare.dto.UserDto
;
import
com.kaluwa.enterprises.babycare.error.ErrorDto
;
import
com.kaluwa.enterprises.babycare.service.UserApiService
;
import
com.kaluwa.enterprises.babycare.utils.Utils
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.concurrent.atomic.AtomicBoolean
;
...
...
@@ -46,7 +53,7 @@ import retrofit2.Response;
public
class
UserProfileActivity
extends
AppCompatActivity
{
private
final
static
String
TAG
=
"UserProfileActivity"
;
private
EditText
etFirstName
,
etLastName
,
etType
,
etEmail
,
etMobile
;
private
EditText
etFirstName
,
etLastName
,
etType
,
etEmail
,
etMobile
,
etDob
;
private
Button
btnEdit
,
btnCancel
;
private
SpinKitView
progressBar
;
private
View
overlay
;
...
...
@@ -78,11 +85,13 @@ public class UserProfileActivity extends AppCompatActivity {
etType
=
findViewById
(
R
.
id
.
up_et_type
);
etEmail
=
findViewById
(
R
.
id
.
up_et_email
);
etMobile
=
findViewById
(
R
.
id
.
up_et_mobile
);
etDob
=
findViewById
(
R
.
id
.
up_et_dob
);
// buttons
btnEdit
=
findViewById
(
R
.
id
.
l_btn_edit
);
btnCancel
=
findViewById
(
R
.
id
.
l_btn_cancel
);
// disable all edit texts
// call custom date-picker
disableET
();
AtomicBoolean
enableEdit
=
new
AtomicBoolean
(
false
);
btnCancel
.
setOnClickListener
(
v
->
{
...
...
@@ -91,6 +100,7 @@ public class UserProfileActivity extends AppCompatActivity {
btnCancel
.
setVisibility
(
View
.
GONE
);
btnEdit
.
setText
(
R
.
string
.
edit_btn_value
);
btnEdit
.
setBackgroundResource
(
R
.
drawable
.
positive_btn_background
);
etDob
.
setOnClickListener
(
null
);
});
btnEdit
.
setOnClickListener
(
v
->
{
if
(!
enableEdit
.
get
())
{
...
...
@@ -99,6 +109,7 @@ public class UserProfileActivity extends AppCompatActivity {
btnCancel
.
setVisibility
(
View
.
VISIBLE
);
btnEdit
.
setText
(
R
.
string
.
update_btn_value
);
btnEdit
.
setBackgroundResource
(
R
.
drawable
.
green_btn_background
);
setUpDOBPicker
(
etDob
,
this
);
}
else
{
// validate text
UserDto
user
=
validate
();
...
...
@@ -122,6 +133,7 @@ public class UserProfileActivity extends AppCompatActivity {
btnCancel
.
setVisibility
(
View
.
GONE
);
btnEdit
.
setText
(
R
.
string
.
edit_btn_value
);
btnEdit
.
setBackgroundResource
(
R
.
drawable
.
positive_btn_background
);
etDob
.
setOnClickListener
(
null
);
Toast
.
makeText
(
UserProfileActivity
.
this
,
"User details successfully updated."
,
Toast
.
LENGTH_SHORT
).
show
();
loader
(
overlay
,
progressBar
,
false
);
}
else
{
...
...
@@ -140,7 +152,7 @@ public class UserProfileActivity extends AppCompatActivity {
Toast
.
makeText
(
UserProfileActivity
.
this
,
"An unexpected error occurred"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
e
.
getMessage
());
Log
.
e
(
TAG
,
"else-error: "
+
e
.
getMessage
());
Toast
.
makeText
(
UserProfileActivity
.
this
,
e
.
getMessage
(),
Toast
.
LENGTH_LONG
).
show
();
}
loader
(
overlay
,
progressBar
,
false
);
...
...
@@ -155,6 +167,7 @@ public class UserProfileActivity extends AppCompatActivity {
});
}
@SuppressLint
(
"NewApi"
)
private
UserDto
validate
()
{
UserDto
userDto
=
new
UserDto
();
String
firstName
,
lastName
,
mobileNumber
;
...
...
@@ -180,6 +193,10 @@ public class UserProfileActivity extends AppCompatActivity {
userDto
.
setFirstName
(
firstName
);
userDto
.
setLastName
(
lastName
);
userDto
.
setPhone
(
mobileNumber
);
if
(!
TextUtils
.
isEmpty
(
etDob
.
getText
().
toString
()))
{
LocalDate
dob
=
LocalDate
.
parse
(
etDob
.
getText
().
toString
(),
DateTimeFormatter
.
ofPattern
(
DATE_FORMAT
));
userDto
.
setDob
(
dob
.
toString
());
}
}
return
userDto
;
...
...
@@ -189,6 +206,7 @@ public class UserProfileActivity extends AppCompatActivity {
loader
(
overlay
,
progressBar
,
true
);
Call
<
UserDto
>
call
=
userApiService
.
getUserById
(
authDto
.
getUserId
());
call
.
enqueue
(
new
Callback
<
UserDto
>()
{
@SuppressLint
(
"NewApi"
)
@Override
public
void
onResponse
(
Call
<
UserDto
>
call
,
Response
<
UserDto
>
response
)
{
if
(
response
.
isSuccessful
())
{
...
...
@@ -198,6 +216,12 @@ public class UserProfileActivity extends AppCompatActivity {
etType
.
setText
(!
Objects
.
equals
(
user
.
getRole
(),
"USER"
)
?
user
.
getRole
():
"PARENT"
);
etEmail
.
setText
(
user
.
getEmail
());
etMobile
.
setText
(
user
.
getPhone
());
if
(
user
.
getDob
()
!=
null
)
{
LocalDate
localDate
=
Utils
.
getLocalDate
(
user
.
getDob
());
if
(
localDate
!=
null
)
{
etDob
.
setText
(
localDate
.
format
(
DateTimeFormatter
.
ofPattern
(
DATE_FORMAT
)));
}
}
loader
(
overlay
,
progressBar
,
false
);
}
else
{
try
{
...
...
@@ -224,7 +248,8 @@ public class UserProfileActivity extends AppCompatActivity {
@Override
public
void
onFailure
(
Call
<
UserDto
>
call
,
Throwable
t
)
{
Toast
.
makeText
(
UserProfileActivity
.
this
,
"Error to Failure"
,
Toast
.
LENGTH_LONG
).
show
();
Log
.
e
(
TAG
,
t
.
getMessage
());
Toast
.
makeText
(
UserProfileActivity
.
this
,
"Load data Error to Failure"
,
Toast
.
LENGTH_LONG
).
show
();
loader
(
overlay
,
progressBar
,
false
);
}
});
...
...
@@ -236,6 +261,7 @@ public class UserProfileActivity extends AppCompatActivity {
disableEditText
(
etType
,
false
,
this
);
disableEditText
(
etEmail
,
false
,
this
);
disableEditText
(
etMobile
,
false
,
this
);
disableEditText
(
etDob
,
false
,
this
);
}
private
void
enableET
()
{
...
...
app/src/main/java/com/kaluwa/enterprises/babycare/dto/UserDto.java
View file @
430da406
package
com.kaluwa.enterprises.babycare.dto
;
import
java.time.LocalDate
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
...
...
@@ -15,4 +17,5 @@ public class UserDto {
private
String
phone
;
private
String
role
;
private
String
status
;
private
Object
dob
;
}
\ No newline at end of file
app/src/main/java/com/kaluwa/enterprises/babycare/utils/Utils.java
View file @
430da406
package
com.kaluwa.enterprises.babycare.utils
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.app.DatePickerDialog
;
import
android.content.Context
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.EditText
;
import
com.github.ybq.android.spinkit.SpinKitView
;
import
com.kaluwa.enterprises.babycare.R
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDate
;
import
java.util.Calendar
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Objects
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
Utils
{
private
static
final
String
TAG
=
"Utils"
;
public
static
final
String
DATE_FORMAT
=
"dd/M/yyyy"
;
public
static
void
loader
(
View
overlay
,
SpinKitView
spinKitView
,
boolean
status
)
{
if
(
status
)
{
overlay
.
setVisibility
(
View
.
VISIBLE
);
...
...
@@ -52,4 +66,94 @@ public class Utils {
}
}
public
static
void
setUpDOBPicker
(
EditText
editText
,
Context
context
)
{
editText
.
setOnClickListener
(
v
->
{
final
Calendar
calendar
=
Calendar
.
getInstance
();
// Check if EditText is not empty and parse the date
if
(!
TextUtils
.
isEmpty
(
editText
.
getText
().
toString
()))
{
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
DATE_FORMAT
,
Locale
.
getDefault
());
calendar
.
setTime
(
Objects
.
requireNonNull
(
sdf
.
parse
(
editText
.
getText
().
toString
())));
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
int
day
=
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
);
int
month
=
calendar
.
get
(
Calendar
.
MONTH
);
int
year
=
calendar
.
get
(
Calendar
.
YEAR
);
// Calculate the date 18 years ago from today
Calendar
maxDate
=
Calendar
.
getInstance
();
maxDate
.
add
(
Calendar
.
YEAR
,
-
18
);
// Date Picker Dialog
DatePickerDialog
datePicker
=
new
DatePickerDialog
(
context
,
(
view
,
selectedYear
,
selectedMonth
,
selectedDayOfMonth
)
->
{
editText
.
setText
(
selectedDayOfMonth
+
"/"
+
(
selectedMonth
+
1
)
+
"/"
+
selectedYear
);
},
year
,
month
,
day
);
// Set the maximum date (18 years ago)
datePicker
.
getDatePicker
().
setMaxDate
(
maxDate
.
getTimeInMillis
());
// Show the date picker
datePicker
.
show
();
});
}
public
static
void
setUpDatePicker
(
EditText
editText
,
Context
context
)
{
editText
.
setOnClickListener
(
v
->
{
final
Calendar
calendar
=
Calendar
.
getInstance
();
// Check if EditText is not empty and parse the date
if
(!
TextUtils
.
isEmpty
(
editText
.
getText
().
toString
()))
{
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
DATE_FORMAT
,
Locale
.
getDefault
());
calendar
.
setTime
(
Objects
.
requireNonNull
(
sdf
.
parse
(
editText
.
getText
().
toString
())));
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
}
int
day
=
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
);
int
month
=
calendar
.
get
(
Calendar
.
MONTH
);
int
year
=
calendar
.
get
(
Calendar
.
YEAR
);
// Date Picker Dialog
DatePickerDialog
datePicker
=
new
DatePickerDialog
(
context
,
(
view
,
selectedYear
,
selectedMonth
,
selectedDayOfMonth
)
->
{
editText
.
setText
(
selectedDayOfMonth
+
"/"
+
(
selectedMonth
+
1
)
+
"/"
+
selectedYear
);
},
year
,
month
,
day
);
// Show the date picker
datePicker
.
show
();
});
}
@SuppressLint
(
"NewApi"
)
public
static
LocalDate
getLocalDate
(
Object
dob
)
{
LocalDate
localDate
=
null
;
if
(
dob
instanceof
LocalDate
)
{
localDate
=
(
LocalDate
)
dob
;
}
else
if
(
dob
instanceof
List
)
{
// dob is a List, convert it to LocalDate
List
dobList
=
(
List
)
dob
;
if
(
dobList
.
size
()
==
3
)
{
try
{
int
year
=
((
Double
)
dobList
.
get
(
0
)).
intValue
();
int
month
=
((
Double
)
dobList
.
get
(
1
)).
intValue
();
int
day
=
((
Double
)
dobList
.
get
(
2
)).
intValue
();
localDate
=
LocalDate
.
of
(
year
,
month
,
day
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
else
{
Log
.
e
(
TAG
,
"Unsupported date format"
);
}
}
else
{
// Handle other unexpected types if necessary
Log
.
e
(
TAG
,
"Unsupported date format"
);
}
return
localDate
;
}
}
app/src/main/res/anim/fade_in.xml
View file @
430da406
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:duration=
"
5
00"
android:duration=
"
3
00"
android:fromAlpha=
"0.0"
android:toAlpha=
"1.0"
/>
app/src/main/res/anim/fade_out.xml
View file @
430da406
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:duration=
"
5
00"
android:duration=
"
3
00"
android:fromAlpha=
"1.0"
android:toAlpha=
"0.0"
/>
app/src/main/res/layout/activity_user_profile.xml
View file @
430da406
...
...
@@ -140,11 +140,13 @@
android:id=
"@+id/up_et_dob"
android:layout_width=
"match_parent"
android:layout_height=
"45dp"
android:inputType=
"
text
"
android:inputType=
"
date
"
android:background=
"@drawable/et_background"
android:padding=
"8dp"
android:fontFamily=
"@font/acme_regular"
android:textColor=
"@color/purple"
/>
android:textColor=
"@color/purple"
android:hint=
"Select your Date of birth (dd/mm/yyyy)*"
android:focusable=
"false"
/>
</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