diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 9396d43..5397393 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -7,11 +7,11 @@
-
+
-
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..05f39b4
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 19da391..e39a5de 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -50,6 +50,7 @@
+
@@ -67,10 +68,11 @@
+
-
+
diff --git a/app/build.gradle b/app/build.gradle
index 6522f31..c9f990c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "fu.prm391.sampl.project"
- minSdk 29
+ minSdk 28
targetSdk 32
versionCode 1
versionName "1.0"
@@ -45,7 +45,11 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment:2.4.1'
implementation 'androidx.navigation:navigation-ui:2.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
+ implementation 'com.google.android.gms:play-services-cast-framework:20.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+
+
+ implementation 'com.github.dhaval2404:imagepicker:2.1'
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 7dcb227..1f5ea84 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,8 +3,13 @@
package="fu.prm391.sampl.project">
+
+
+
+
+
diff --git a/app/src/main/java/fu/prm391/sampl/project/model/product/get_product_by_id/ProductResponse.java b/app/src/main/java/fu/prm391/sampl/project/model/product/get_product_by_id/ProductResponse.java
index 6e5a72a..34986d9 100644
--- a/app/src/main/java/fu/prm391/sampl/project/model/product/get_product_by_id/ProductResponse.java
+++ b/app/src/main/java/fu/prm391/sampl/project/model/product/get_product_by_id/ProductResponse.java
@@ -2,9 +2,6 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
-
-import java.util.List;
-
import fu.prm391.sampl.project.model.product.Product;
public class ProductResponse {
diff --git a/app/src/main/java/fu/prm391/sampl/project/model/user/UpdateUserInfoRequest.java b/app/src/main/java/fu/prm391/sampl/project/model/user/UpdateUserInfoRequest.java
new file mode 100644
index 0000000..d56e4f5
--- /dev/null
+++ b/app/src/main/java/fu/prm391/sampl/project/model/user/UpdateUserInfoRequest.java
@@ -0,0 +1,74 @@
+package fu.prm391.sampl.project.model.user;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+
+public class UpdateUserInfoRequest {
+ @SerializedName("firstName")
+ @Expose
+ private String firstName;
+ @SerializedName("lastName")
+ @Expose
+ private String lastName;
+ @SerializedName("gender")
+ @Expose
+ private int gender;
+ @SerializedName("phone")
+ @Expose
+ private String phone;
+ @SerializedName("image")
+ @Expose
+ private String image;
+
+ public UpdateUserInfoRequest() {
+ }
+
+ public UpdateUserInfoRequest(String firstName, String lastName, int gender, String phone, String image) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.gender = gender;
+ this.phone = phone;
+ this.image = image;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public int getGender() {
+ return gender;
+ }
+
+ public void setGender(int gender) {
+ this.gender = gender;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public String getImage() {
+ return image;
+ }
+
+ public void setImage(String image) {
+ this.image = image;
+ }
+
+}
diff --git a/app/src/main/java/fu/prm391/sampl/project/model/user/UpdateUserInfoResponse.java b/app/src/main/java/fu/prm391/sampl/project/model/user/UpdateUserInfoResponse.java
new file mode 100644
index 0000000..602939f
--- /dev/null
+++ b/app/src/main/java/fu/prm391/sampl/project/model/user/UpdateUserInfoResponse.java
@@ -0,0 +1,19 @@
+package fu.prm391.sampl.project.model.user;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+
+public class UpdateUserInfoResponse {
+
+ @SerializedName("message")
+ @Expose
+ private String message;
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
diff --git a/app/src/main/java/fu/prm391/sampl/project/model/user/User.java b/app/src/main/java/fu/prm391/sampl/project/model/user/User.java
index 98abc96..fdd8b13 100644
--- a/app/src/main/java/fu/prm391/sampl/project/model/user/User.java
+++ b/app/src/main/java/fu/prm391/sampl/project/model/user/User.java
@@ -3,7 +3,9 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
-public class User {
+import java.io.Serializable;
+
+public class User implements Serializable {
@SerializedName("id")
@Expose
private int id;
diff --git a/app/src/main/java/fu/prm391/sampl/project/remote/service/ProductService.java b/app/src/main/java/fu/prm391/sampl/project/remote/service/ProductService.java
index fc4bc77..064b9fe 100644
--- a/app/src/main/java/fu/prm391/sampl/project/remote/service/ProductService.java
+++ b/app/src/main/java/fu/prm391/sampl/project/remote/service/ProductService.java
@@ -2,6 +2,7 @@
import fu.prm391.sampl.project.model.product.get_list_product.ProductListResponse;
import fu.prm391.sampl.project.model.product.get_product_by_id.ProductResponse;
+
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
diff --git a/app/src/main/java/fu/prm391/sampl/project/remote/service/UserService.java b/app/src/main/java/fu/prm391/sampl/project/remote/service/UserService.java
index 6c6f283..8ddea92 100644
--- a/app/src/main/java/fu/prm391/sampl/project/remote/service/UserService.java
+++ b/app/src/main/java/fu/prm391/sampl/project/remote/service/UserService.java
@@ -1,5 +1,6 @@
package fu.prm391.sampl.project.remote.service;
-
+import fu.prm391.sampl.project.model.user.UpdateUserInfoRequest;
+import fu.prm391.sampl.project.model.user.UpdateUserInfoResponse;
import fu.prm391.sampl.project.model.user.forgot_password.ForgotPassRequest;
import fu.prm391.sampl.project.model.user.forgot_password.ForgotPassResponse;
import fu.prm391.sampl.project.model.user.login.LoginRequest;
@@ -15,6 +16,7 @@
import retrofit2.http.Header;
import retrofit2.http.PATCH;
import retrofit2.http.POST;
+import retrofit2.http.PUT;
public interface UserService {
@@ -32,4 +34,8 @@ public interface UserService {
@GET("user/get-user-info")
Call getUserInformation(@Header("Authorization") String token);
+
+ @PUT("user/update-information")
+ Call updateUserInformation(@Header("Authorization") String token,
+ @Body UpdateUserInfoRequest updateUserInfoRequest);
}
diff --git a/app/src/main/java/fu/prm391/sampl/project/view/fragment/Home.java b/app/src/main/java/fu/prm391/sampl/project/view/fragment/Home.java
index d4bb53b..a4abd3c 100644
--- a/app/src/main/java/fu/prm391/sampl/project/view/fragment/Home.java
+++ b/app/src/main/java/fu/prm391/sampl/project/view/fragment/Home.java
@@ -97,8 +97,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return view;
}
-
-
private void getTop4Category(View view) {
recyclerViewTop4Category = view.findViewById(R.id.recyclerViewTop4Cate);
Call categoryResponseCall = ApiClient.getCategoryService().getTop4Categories();
diff --git a/app/src/main/java/fu/prm391/sampl/project/view/fragment/Profiles.java b/app/src/main/java/fu/prm391/sampl/project/view/fragment/Profiles.java
index 96800da..0ab27b2 100644
--- a/app/src/main/java/fu/prm391/sampl/project/view/fragment/Profiles.java
+++ b/app/src/main/java/fu/prm391/sampl/project/view/fragment/Profiles.java
@@ -4,6 +4,10 @@
import android.content.Intent;
import android.os.Bundle;
+import androidx.activity.result.ActivityResult;
+import androidx.activity.result.ActivityResultCallback;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
@@ -22,8 +26,11 @@
import fu.prm391.sampl.project.model.user.User;
import fu.prm391.sampl.project.model.user.UserResponse;
import fu.prm391.sampl.project.remote.ApiClient;
+import fu.prm391.sampl.project.view.MainActivity;
import fu.prm391.sampl.project.view.account.Login;
import fu.prm391.sampl.project.view.order.MyOrderHistory;
+import fu.prm391.sampl.project.view.address.ProfileShippingAddress;
+import fu.prm391.sampl.project.view.profiles.EditProfiles;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@@ -44,10 +51,11 @@ public class Profiles extends Fragment {
private String mParam1;
private String mParam2;
- private View viewLogOut, viewMyHistoryOrders;
+ private View viewLogOut, viewMyHistoryOrders, viewShippingAddress;
private Button btnVerifyProfiles, btnEditProfiles;
private TextView labelVerified, profilesName, emailProfiles;
private ImageView verifyImage, imageProfiles;
+ private String token = "";
public Profiles() {
// Required empty public constructor
@@ -80,12 +88,14 @@ public void onCreate(Bundle savedInstanceState) {
}
}
+
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_profiles, container, false);
+ token = PreferencesHelpers.loadStringData(getContext(), "token");
- String token = PreferencesHelpers.loadStringData(getContext(), "token");
if (token == "") {
startActivity(new Intent(getContext(), Login.class));
getActivity().finish();
@@ -96,31 +106,82 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
emailProfiles = view.findViewById(R.id.txtEmailProfiles);
profilesName = view.findViewById(R.id.txtNameProfiles);
imageProfiles = view.findViewById(R.id.imageProfiles);
-
- // verify Profile Action
btnVerifyProfiles = view.findViewById(R.id.btnVerifyProfiles);
- btnVerifyProfiles.setOnClickListener(new View.OnClickListener() {
+ btnEditProfiles = view.findViewById(R.id.btnEditProfiles);
+ viewShippingAddress = view.findViewById(R.id.viewShippingAddressProfiles);
+ viewLogOut = view.findViewById(R.id.viewLogoutProfile);
+
+ // set invisible when api have not called
+ profilesName.setVisibility(View.INVISIBLE);
+ emailProfiles.setVisibility(View.INVISIBLE);
+ labelVerified.setVisibility(View.INVISIBLE);
+ verifyImage.setVisibility(View.INVISIBLE);
+ btnVerifyProfiles.setVisibility(View.INVISIBLE);
+ btnEditProfiles.setVisibility(View.INVISIBLE);
+
+ // call Api
+ callApiProfiles();
+
+ // action change page to shipping Address
+ viewShippingAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- // verify Profile Action
+ Intent intent = new Intent(getContext(), ProfileShippingAddress.class);
+ startActivity(intent);
}
});
- // edit profile action
- btnEditProfiles = view.findViewById(R.id.btnEditProfiles);
- btnEditProfiles.setOnClickListener(new View.OnClickListener() {
+ viewMyHistoryOrders = view.findViewById(R.id.viewMyOrdersHistoryProfiles);
+ viewMyHistoryOrders.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ startActivity(new Intent(getContext(), MyOrderHistory.class));
+ }
+ });
+
+ // logOut action
+ viewLogOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- // edit profile action
+ MaterialAlertDialogBuilder materialAlert = new MaterialAlertDialogBuilder(getContext(), R.style.ThemeOverlay_App_MaterialAlertDialog);
+ materialAlert.setTitle("ALERT");
+ materialAlert.setMessage("Are you Sure want to Logout");
+ materialAlert.setPositiveButton("Logout", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ // move to home navigation
+ BottomNavigationView bottomNavigationView;
+ bottomNavigationView = getActivity().findViewById(R.id.bottomNavigationView);
+ bottomNavigationView.setSelectedItemId(R.id.home2);
+ // delete token
+ PreferencesHelpers.removeSinglePreference(getContext(), "token");
+ }
+ });
+ materialAlert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ }
+ });
+ materialAlert.show();
}
});
+ return view;
+ }
+ private void callApiProfiles() {
Call userResponseCall = ApiClient.getUserService().getUserInformation("Bearer " + token);
userResponseCall.enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) {
if (response.isSuccessful()) {
User user = response.body().getData();
+ // set visible when api call successful
+ profilesName.setVisibility(View.VISIBLE);
+ emailProfiles.setVisibility(View.VISIBLE);
+ labelVerified.setVisibility(View.VISIBLE);
+ verifyImage.setVisibility(View.VISIBLE);
+ btnVerifyProfiles.setVisibility(View.VISIBLE);
+ btnEditProfiles.setVisibility(View.VISIBLE);
// check username
if (user.getFirstName() == null && user.getLastName() == null) {
profilesName.setText("Unknown");
@@ -149,6 +210,24 @@ public void onResponse(Call call, Response response)
labelVerified.setText("UnVerified");
btnVerifyProfiles.setVisibility(View.VISIBLE);
}
+
+ // verify Profile Action
+ btnVerifyProfiles.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ // verify Profile Action
+ }
+ });
+
+ // edit profile action
+ btnEditProfiles.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent intent = new Intent(getContext(), EditProfiles.class);
+ intent.putExtra("userInfo", user);
+ startActivity(intent);
+ }
+ });
}
}
@@ -156,44 +235,11 @@ public void onResponse(Call call, Response response)
public void onFailure(Call call, Throwable t) {
}
});
+ }
- viewMyHistoryOrders = view.findViewById(R.id.viewMyOrdersHistoryProfiles);
- viewMyHistoryOrders.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(getContext(), MyOrderHistory.class));
- }
- });
-
- // logout
- viewLogOut = view.findViewById(R.id.viewLogoutProfile);
- viewLogOut.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- MaterialAlertDialogBuilder materialAlert = new MaterialAlertDialogBuilder(getContext(), R.style.ThemeOverlay_App_MaterialAlertDialog);
- materialAlert.setTitle("ALERT");
- materialAlert.setMessage("Are you Sure want to Logout");
- materialAlert.setPositiveButton("Logout", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- // move to home navigation
- BottomNavigationView bottomNavigationView;
- bottomNavigationView = getActivity().findViewById(R.id.bottomNavigationView);
- bottomNavigationView.setSelectedItemId(R.id.home2);
- // delete token
- PreferencesHelpers.removeSinglePreference(getContext(), "token");
- }
- });
- materialAlert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
-
- }
- });
- materialAlert.show();
- }
- });
- return view;
-
+ @Override
+ public void onResume() {
+ super.onResume();
+ callApiProfiles();
}
}
\ No newline at end of file
diff --git a/app/src/main/java/fu/prm391/sampl/project/view/product/NewArrivalProduct.java b/app/src/main/java/fu/prm391/sampl/project/view/product/NewArrivalProduct.java
index dde88b6..9799539 100644
--- a/app/src/main/java/fu/prm391/sampl/project/view/product/NewArrivalProduct.java
+++ b/app/src/main/java/fu/prm391/sampl/project/view/product/NewArrivalProduct.java
@@ -28,6 +28,7 @@ public class NewArrivalProduct extends AppCompatActivity {
private RecyclerView recyclerView;
private ImageView imageViewBack;
private ConstraintLayout loadingConstraintLayout;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/app/src/main/java/fu/prm391/sampl/project/view/product/TrendingProduct.java b/app/src/main/java/fu/prm391/sampl/project/view/product/TrendingProduct.java
index d1a9567..a3e0072 100644
--- a/app/src/main/java/fu/prm391/sampl/project/view/product/TrendingProduct.java
+++ b/app/src/main/java/fu/prm391/sampl/project/view/product/TrendingProduct.java
@@ -28,6 +28,7 @@ public class TrendingProduct extends AppCompatActivity {
private ImageView imageViewBack;
private RecyclerView recyclerView;
private ConstraintLayout loadingConstraintLayout;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/app/src/main/java/fu/prm391/sampl/project/view/profiles/EditProfiles.java b/app/src/main/java/fu/prm391/sampl/project/view/profiles/EditProfiles.java
new file mode 100644
index 0000000..a3a4ec6
--- /dev/null
+++ b/app/src/main/java/fu/prm391/sampl/project/view/profiles/EditProfiles.java
@@ -0,0 +1,219 @@
+package fu.prm391.sampl.project.view.profiles;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.annotation.SuppressLint;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Base64;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.github.dhaval2404.imagepicker.ImagePicker;
+
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.squareup.picasso.Picasso;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import fu.prm391.sampl.project.R;
+import fu.prm391.sampl.project.helper.PreferencesHelpers;
+import fu.prm391.sampl.project.model.user.UpdateUserInfoRequest;
+import fu.prm391.sampl.project.model.user.UpdateUserInfoResponse;
+import fu.prm391.sampl.project.model.user.User;
+import fu.prm391.sampl.project.remote.ApiClient;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+
+public class EditProfiles extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
+
+ private ImageView btnBack, cover;
+ private EditText firstName, lastName, phoneNumber;
+ private Spinner gender;
+ private FloatingActionButton fab;
+ private Button btnSave;
+ private TextView emailAddress;
+ private String encodedImage;
+ private String stringUri;
+
+ @SuppressLint("WrongThread")
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_edit_profiles);
+
+ // findViewById
+ cover = findViewById(R.id.coverImg);
+ fab = findViewById(R.id.floatingActionButton);
+ btnBack = findViewById(R.id.imageViewBackEditProfile);
+ firstName = findViewById(R.id.txtFirstName);
+ lastName = findViewById(R.id.txtLastName);
+ emailAddress = findViewById(R.id.textViewtEmailAddressEditProfile);
+ phoneNumber = findViewById(R.id.textPhoneEditProfile);
+ btnSave = findViewById(R.id.btnSaveEditProfiles);
+
+ // spinner for select gender
+ gender = findViewById(R.id.spinnerGender);
+ ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.Gender, R.layout.color_spinner_layout);
+ adapter.setDropDownViewResource(R.layout.spinner_dropdown_layout);
+ gender.setAdapter(adapter);
+ gender.setOnItemSelectedListener(this);
+
+ getInfoFromProfiles();
+
+ // btnSave action
+ btnSave.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ btnSave.setEnabled(false);
+ // check format edit text fill
+ if (TextUtils.isEmpty(emailAddress.getText().toString().trim())
+ || TextUtils.isEmpty(firstName.getText().toString().trim())
+ || TextUtils.isEmpty(lastName.getText().toString().trim()) || TextUtils.isEmpty(phoneNumber.getText().toString().trim())) {
+ Toast.makeText(EditProfiles.this, "All fields are required!", Toast.LENGTH_SHORT).show();
+ btnSave.setEnabled(true);
+ } else if (phoneNumber.length() != 10) {
+ Toast.makeText(EditProfiles.this, "Wrong format phone number", Toast.LENGTH_SHORT).show();
+ btnSave.setEnabled(true);
+ } else {
+ // proceed save
+ updateProfileAction();
+ }
+ }
+ });
+
+ // upload image from phone
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ ImagePicker.with(EditProfiles.this)
+ .crop() //Crop image(Optional), Check Customization for more option
+ .compress(1024) //Final image size will be less than 1 MB(Optional)
+ .maxResultSize(150, 150) //Final image resolution will be less than 1080 x 1080(Optional)
+ .start(294);
+ }
+ });
+
+ // BtnBack action
+ btnBack.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ finish();
+ }
+ });
+ }
+
+ // get info from profile and put
+ private void getInfoFromProfiles() {
+ Intent intent = getIntent();
+ User user = (User) intent.getSerializableExtra("userInfo");
+ emailAddress.setText(user.getEmail());
+ firstName.setText(user.getFirstName());
+ lastName.setText(user.getLastName());
+ phoneNumber.setText(user.getPhone());
+ Picasso.get().load(user.getAvatar()).fit().into(cover);
+ // check and set gender
+ if (user.getGender() == 0) {
+ gender.setSelection(2);
+ } else {
+ gender.setSelection(user.getGender() - 1);
+ }
+ }
+
+ private void updateProfileAction() {
+ String token = PreferencesHelpers.loadStringData(EditProfiles.this, "token");
+ UpdateUserInfoRequest updateUserInfoRequest = new UpdateUserInfoRequest();
+ updateUserInfoRequest.setFirstName(firstName.getText().toString().trim());
+ updateUserInfoRequest.setLastName(lastName.getText().toString().trim());
+ updateUserInfoRequest.setGender(gender.getSelectedItemPosition() + 1);
+ updateUserInfoRequest.setPhone(phoneNumber.getText().toString().trim());
+
+ if (encodedImage == null) {
+ updateUserInfoRequest.setImage(stringUri);
+ } else {
+ updateUserInfoRequest.setImage("data:image/jpeg;base64," + encodedImage);
+ }
+
+ // call Api
+ Call updateUserInfoResponseCall = ApiClient.getUserService().updateUserInformation("Bearer " + token, updateUserInfoRequest);
+ updateUserInfoResponseCall.enqueue(new Callback() {
+ @Override
+ public void onResponse(Call call, Response response) {
+ if (response.isSuccessful()) {
+ UpdateUserInfoResponse updateUserInfoResponse = response.body();
+ Toast.makeText(EditProfiles.this, updateUserInfoResponse.getMessage(), Toast.LENGTH_SHORT).show();
+ finish();
+ } else {
+ try {
+ JSONObject jsonObject = new JSONObject(response.errorBody().string());
+ Toast.makeText(EditProfiles.this, jsonObject.getString("message"), Toast.LENGTH_SHORT).show();
+ } catch (JSONException | IOException e) {
+ Toast.makeText(EditProfiles.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
+ }
+ btnSave.setEnabled(true);
+ }
+ }
+
+ @Override
+ public void onFailure(Call call, Throwable t) {
+ btnSave.setEnabled(true);
+ }
+ });
+ }
+
+ @Override
+ public void onItemSelected(AdapterView> parent, View view, int position, long l) {
+ String text = parent.getItemAtPosition(position).toString();
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> parent) {
+
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == 294 && resultCode == RESULT_OK) {
+ Uri imageUri = data.getData();
+ cover.setImageURI(imageUri);
+ stringUri = imageUri.toString();
+ InputStream imageStream = null;
+ try {
+ imageStream = getContentResolver().openInputStream(imageUri);
+ Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
+ encodedImage = encodeImage(selectedImage);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ //Encode Bitmap in base64
+ private String encodeImage(Bitmap bm) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
+ byte[] b = baos.toByteArray();
+ String encImage = Base64.encodeToString(b, Base64.DEFAULT);
+ return encImage;
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/button.xml b/app/src/main/res/drawable/button.xml
new file mode 100644
index 0000000..75a6f71
--- /dev/null
+++ b/app/src/main/res/drawable/button.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/editprofile.png b/app/src/main/res/drawable/editprofile.png
index d8f0b4b..38d32b8 100644
Binary files a/app/src/main/res/drawable/editprofile.png and b/app/src/main/res/drawable/editprofile.png differ
diff --git a/app/src/main/res/layout/activity_edit_profiles.xml b/app/src/main/res/layout/activity_edit_profiles.xml
new file mode 100644
index 0000000..c203bd5
--- /dev/null
+++ b/app/src/main/res/layout/activity_edit_profiles.xml
@@ -0,0 +1,270 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/color_spinner_layout.xml b/app/src/main/res/layout/color_spinner_layout.xml
new file mode 100644
index 0000000..8918f53
--- /dev/null
+++ b/app/src/main/res/layout/color_spinner_layout.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_profiles.xml b/app/src/main/res/layout/fragment_profiles.xml
index 9d0c902..eaba257 100644
--- a/app/src/main/res/layout/fragment_profiles.xml
+++ b/app/src/main/res/layout/fragment_profiles.xml
@@ -39,43 +39,70 @@
-
+
+
+
+ app:layout_constraintTop_toBottomOf="@+id/cardView">
+ android:layout_height="match_parent">
+
+
+
+
+
+
-
-
-
-
+ app:cornerRadius="@null"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toStartOf="@+id/btnEditProfiles" />
-
-
-
-
-
+
+
+
+ >
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/custom_styles.xml b/app/src/main/res/values/custom_styles.xml
new file mode 100644
index 0000000..0ad8528
--- /dev/null
+++ b/app/src/main/res/values/custom_styles.xml
@@ -0,0 +1,6 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b4d638c..9dd7719 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -120,4 +120,17 @@
Add to Cart
Similar Products
1
+ Edit Profiles
+ User Information
+ First Name
+ Last Name
+ Email Address
+
+ - Male
+ - Female
+ - Other
+
+ Phone
+ Save
+ Gender
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 533ea98..13de72a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -11,7 +11,13 @@ buildscript {
// in the individual module build.gradle files
}
}
-
+allprojects {
+ repositories {
+ google()
+ mavenCentral()
+ maven { url "https://jitpack.io" }
+ }
+}
task clean(type: Delete) {
delete rootProject.buildDir
}
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 09f6cc6..e674e0b 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,9 +1,12 @@
+import org.gradle.api.initialization.resolve.RepositoriesMode
+
dependencyResolutionManagement {
- repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
- jcenter() // Warning: this repository is going to shut down soon
+ maven { url "https://jitpack.io" }
+ jcenter()// Warning: this repository is going to shut down soon
}
}
rootProject.name = "Project"