Commit ccd159e2 authored by Chamod Ishankha's avatar Chamod Ishankha

complete user profile with image upload option

parent 1ca662d8
...@@ -43,6 +43,7 @@ dependencies { ...@@ -43,6 +43,7 @@ dependencies {
implementation(libs.retrofit2) implementation(libs.retrofit2)
implementation(libs.convertor.gson) implementation(libs.convertor.gson)
implementation(libs.jackson.databind) implementation(libs.jackson.databind)
implementation(libs.ucrop)
testImplementation(libs.junit) testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit) androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core) androidTestImplementation(libs.espresso.core)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<application <application
android:allowBackup="true" android:allowBackup="true"
...@@ -16,6 +17,11 @@ ...@@ -16,6 +17,11 @@
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="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="fullSensor"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<activity <activity
android:name=".activities.UserProfileActivity" android:name=".activities.UserProfileActivity"
android:exported="false" /> android:exported="false" />
......
...@@ -7,26 +7,15 @@ import android.content.Intent; ...@@ -7,26 +7,15 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.View;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.kaluwa.enterprises.babycare.activities.DashboardActivity; import com.kaluwa.enterprises.babycare.activities.DashboardActivity;
import com.kaluwa.enterprises.babycare.activities.auth.LoginActivity; import com.kaluwa.enterprises.babycare.activities.auth.LoginActivity;
import com.kaluwa.enterprises.babycare.config.TokenSaver; import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import com.kaluwa.enterprises.babycare.databinding.ActivityMainBinding;
import com.kaluwa.enterprises.babycare.dto.AuthenticationDto;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
......
package com.kaluwa.enterprises.babycare.activities.auth; package com.kaluwa.enterprises.babycare.activities.auth;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.getToken;
import static com.kaluwa.enterprises.babycare.config.TokenSaver.setToken; import static com.kaluwa.enterprises.babycare.config.TokenSaver.setToken;
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.emailAddressValidation; import static com.kaluwa.enterprises.babycare.utils.Utils.emailAddressValidation;
...@@ -16,29 +15,19 @@ import android.widget.EditText; ...@@ -16,29 +15,19 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.ybq.android.spinkit.SpinKitView; import com.github.ybq.android.spinkit.SpinKitView;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.kaluwa.enterprises.babycare.R; import com.kaluwa.enterprises.babycare.R;
import com.kaluwa.enterprises.babycare.activities.DashboardActivity; import com.kaluwa.enterprises.babycare.activities.DashboardActivity;
import com.kaluwa.enterprises.babycare.activities.UserProfileActivity;
import com.kaluwa.enterprises.babycare.config.ApiConfig; import com.kaluwa.enterprises.babycare.config.ApiConfig;
import com.kaluwa.enterprises.babycare.dto.AuthenticationDto; import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import com.kaluwa.enterprises.babycare.dto.LoginRequest; import com.kaluwa.enterprises.babycare.dto.LoginRequest;
import com.kaluwa.enterprises.babycare.dto.UserDto;
import com.kaluwa.enterprises.babycare.error.ErrorDto; import com.kaluwa.enterprises.babycare.error.ErrorDto;
import com.kaluwa.enterprises.babycare.service.AuthApiService; import com.kaluwa.enterprises.babycare.service.AuthApiService;
import java.io.IOException;
import java.util.Objects;
import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
......
...@@ -11,7 +11,7 @@ import retrofit2.Retrofit; ...@@ -11,7 +11,7 @@ import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
public class ApiConfig { public class ApiConfig {
private static final String BASE_URL = "http://192.168.1.6:8080/api/v1/baby-care/"; private static final String BASE_URL = "http://192.168.1.2:8080/api/v1/baby-care/";
private static ApiConfig instance; private static ApiConfig instance;
private static Retrofit retrofitAuth = null; private static Retrofit retrofitAuth = null;
private static Retrofit retrofitOther = null; private static Retrofit retrofitOther = null;
......
...@@ -5,7 +5,7 @@ import android.content.SharedPreferences; ...@@ -5,7 +5,7 @@ import android.content.SharedPreferences;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.kaluwa.enterprises.babycare.dto.AuthenticationDto; 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";
......
package com.kaluwa.enterprises.babycare.dto; package com.kaluwa.enterprises.babycare.dto.responseDto;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
......
package com.kaluwa.enterprises.babycare.dto.responseDto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseDto {
private Long id;
private String message;
}
package com.kaluwa.enterprises.babycare.dto; package com.kaluwa.enterprises.babycare.dto.responseDto;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
......
package com.kaluwa.enterprises.babycare.service; package com.kaluwa.enterprises.babycare.service;
import com.kaluwa.enterprises.babycare.dto.AuthenticationDto; import com.kaluwa.enterprises.babycare.dto.responseDto.AuthenticationDto;
import com.kaluwa.enterprises.babycare.dto.LoginRequest; import com.kaluwa.enterprises.babycare.dto.LoginRequest;
import com.kaluwa.enterprises.babycare.dto.RegisterRequest; import com.kaluwa.enterprises.babycare.dto.RegisterRequest;
import com.kaluwa.enterprises.babycare.dto.UserDto; import com.kaluwa.enterprises.babycare.dto.UserDto;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.POST; import retrofit2.http.POST;
......
package com.kaluwa.enterprises.babycare.service; package com.kaluwa.enterprises.babycare.service;
import com.kaluwa.enterprises.babycare.dto.UserDto; import com.kaluwa.enterprises.babycare.dto.UserDto;
import com.kaluwa.enterprises.babycare.dto.responseDto.ResponseDto;
import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.PUT; import retrofit2.http.PUT;
import retrofit2.http.Part;
import retrofit2.http.Path; import retrofit2.http.Path;
public interface UserApiService { public interface UserApiService {
...@@ -16,4 +21,11 @@ public interface UserApiService { ...@@ -16,4 +21,11 @@ public interface UserApiService {
@PUT("user/{userId}") @PUT("user/{userId}")
Call<UserDto> updateUserById(@Path("userId") Long userId, @Body UserDto user); Call<UserDto> updateUserById(@Path("userId") Long userId, @Body UserDto user);
@Multipart
@PUT("user/image/{userId}")
Call<ResponseDto> uploadUserImage(@Path("userId") Long userId, @Part MultipartBody.Part image);
@GET("user/image/{userId}")
Call<ResponseBody> getImage(@Path("userId") Long userId);
} }
...@@ -26,6 +26,7 @@ public class Utils { ...@@ -26,6 +26,7 @@ public class Utils {
private static final String TAG = "Utils"; private static final String TAG = "Utils";
public static final String DATE_FORMAT = "dd/M/yyyy"; public static final String DATE_FORMAT = "dd/M/yyyy";
public static final int PICK_IMAGE_REQUEST = 1;
public static void loader(View overlay, SpinKitView spinKitView, boolean status) { public static void loader(View overlay, SpinKitView spinKitView, boolean status) {
if (status) { if (status) {
......
...@@ -32,15 +32,17 @@ ...@@ -32,15 +32,17 @@
app:layout_constraintStart_toStartOf="@id/background" app:layout_constraintStart_toStartOf="@id/background"
app:layout_constraintTop_toTopOf="@+id/background"> app:layout_constraintTop_toTopOf="@+id/background">
<ImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/forground_img" android:id="@+id/up_iv_profile_image"
android:layout_width="160dp" android:layout_width="160dp"
android:layout_height="160dp" android:layout_height="160dp"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:layout_marginBottom="20dp" android:layout_marginBottom="20dp"
android:contentDescription="foreground-image" android:contentDescription="user-profile-image"
android:src="@drawable/icon_alt_user_pic_32" /> android:src="@drawable/icon_alt_user_pic_32"
app:shapeAppearanceOverlay="@style/RoundImage"
android:scaleType="centerCrop"/>
</RelativeLayout> </RelativeLayout>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RoundImage" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RoundImage" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
</resources>
\ No newline at end of file
...@@ -4,32 +4,32 @@ junit = "4.13.2" ...@@ -4,32 +4,32 @@ junit = "4.13.2"
junitVersion = "1.1.5" junitVersion = "1.1.5"
espressoCore = "3.5.1" espressoCore = "3.5.1"
appcompat = "1.6.1" appcompat = "1.6.1"
material = "1.12.0"
constraintlayout = "2.1.4" constraintlayout = "2.1.4"
navigationFragment = "2.7.7" navigationFragment = "2.7.7"
navigationUi = "2.7.7" navigationUi = "2.7.7"
activity = "1.9.0" activity = "1.9.0"
androidSpinkit = "1.4.0" androidSpinkit = "1.4.0"
projectLombok = "1.18.32" projectLombok = "1.18.32"
retrofit2 = "2.9.0" retrofit2 = "2.11.0"
retrofit2Convertor = "2.9.0"
jacksonDatabind = "2.17.1" jacksonDatabind = "2.17.1"
materialVersion = "1.13.0-alpha02"
[libraries] [libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" } junit = { group = "junit", name = "junit", version.ref = "junit" }
ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" } material = { group = "com.google.android.material", name = "material", version.ref = "materialVersion" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" } constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment", version.ref = "navigationFragment" } navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment", version.ref = "navigationFragment" }
navigation-ui = { group = "androidx.navigation", name = "navigation-ui", version.ref = "navigationUi" } navigation-ui = { group = "androidx.navigation", name = "navigation-ui", version.ref = "navigationUi" }
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" } activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
android-spinkit = { group = "com.github.ybq", name = "Android-SpinKit", version.ref = "androidSpinkit" } android-spinkit = { group = "com.github.ybq", name = "Android-SpinKit", version.ref = "androidSpinkit" }
projectlombok = { group = "org.projectlombok", name = "lombok", version.ref = "projectLombok"} projectlombok = { group = "org.projectlombok", name = "lombok", version.ref = "projectLombok"}
retrofit2 = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit2" } retrofit2 = { group = "com.squareup.retrofit2", name = "retrofit", version = "2.11.0" }
convertor-gson = { group = "com.squareup.retrofit2", name = "converter-gson", version.ref = "retrofit2Convertor" } 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" }
[plugins] [plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" } androidApplication = { id = "com.android.application", version.ref = "agp" }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment