Skip to content

Commit

Permalink
last shot
Browse files Browse the repository at this point in the history
  • Loading branch information
abcmonboi committed Feb 21, 2022
1 parent 7e3b414 commit cb7c8a8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {

defaultConfig {
applicationId "fu.prm391.sampl.project"
minSdk 29
minSdk 28
targetSdk 32
versionCode 1
versionName "1.0"
Expand Down
110 changes: 55 additions & 55 deletions app/src/main/java/fu/prm391/sampl/project/view/fragment/Profiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public class Profiles extends Fragment {
private Button btnVerifyProfiles, btnEditProfiles;
private TextView labelVerified, profilesName, emailProfiles;
private ImageView verifyImage, imageProfiles;
private ActivityResultLauncher<Intent> launcher;
private String stringUri = "";
private String token = "";

public Profiles() {
// Required empty public constructor
Expand Down Expand Up @@ -94,17 +93,18 @@ 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();
}
// create launcher

labelVerified = view.findViewById(R.id.labelVerifiedProfile);
verifyImage = view.findViewById(R.id.imageVerifiedProfile);
Expand All @@ -113,18 +113,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
imageProfiles = view.findViewById(R.id.imageProfiles);
btnVerifyProfiles = view.findViewById(R.id.btnVerifyProfiles);
btnEditProfiles = view.findViewById(R.id.btnEditProfiles);
viewShippingAddress = view.findViewById(R.id.viewShippingAddressProfiles);
viewLogOut = view.findViewById(R.id.viewLogoutProfile);

launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == 201) {
Intent data = result.getData();
profilesName.setText(data.getStringExtra("userName"));
stringUri = data.getStringExtra("profileImage");
Picasso.get().load(stringUri).fit().into(imageProfiles);
}
}
});
// set invisible when api have not called
profilesName.setVisibility(View.INVISIBLE);
emailProfiles.setVisibility(View.INVISIBLE);
Expand All @@ -134,6 +125,48 @@ public void onActivityResult(ActivityResult result) {
btnEditProfiles.setVisibility(View.INVISIBLE);

// call Api
callApiProfiles();

// action change page to shipping Address
viewShippingAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getContext(), ProfileShippingAddress.class);
startActivity(intent);
// getActivity().finish();
}
});

// logOut action
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;
}

private void callApiProfiles() {
Call<UserResponse> userResponseCall = ApiClient.getUserService().getUserInformation("Bearer " + token);
userResponseCall.enqueue(new Callback<UserResponse>() {
@Override
Expand Down Expand Up @@ -190,10 +223,7 @@ public void onClick(View view) {
public void onClick(View view) {
Intent intent = new Intent(getContext(), EditProfiles.class);
intent.putExtra("userInfo", user);
if (stringUri != "") {
intent.putExtra("stringUri2", stringUri);
}
launcher.launch(intent);
startActivity(intent);
}
});
}
Expand All @@ -203,41 +233,11 @@ public void onClick(View view) {
public void onFailure(Call<UserResponse> call, Throwable t) {
}
});
viewShippingAddress = view.findViewById(R.id.viewShippingAddressProfiles);
viewShippingAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getContext(), ProfileShippingAddress.class);
startActivity(intent);
// getActivity().finish();
}
});
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ protected void onCreate(Bundle savedInstanceState) {
@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();
Expand All @@ -105,13 +109,10 @@ public void onClick(View v) {
@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);

}
});

Expand Down Expand Up @@ -146,15 +147,15 @@ private void updateProfileAction() {
UpdateUserInfoRequest updateUserInfoRequest = new UpdateUserInfoRequest();
updateUserInfoRequest.setFirstName(firstName.getText().toString().trim());
updateUserInfoRequest.setLastName(lastName.getText().toString().trim());
updateUserInfoRequest.setGender(gender.getSelectedItemPosition() - 1);
updateUserInfoRequest.setGender(gender.getSelectedItemPosition() + 1);
updateUserInfoRequest.setPhone(phoneNumber.getText().toString().trim());

if (encodedImage == null) {
updateUserInfoRequest.setImage(null);
updateUserInfoRequest.setImage(stringUri);
} else {
updateUserInfoRequest.setImage("data:image/jpeg;base64," + encodedImage);
}


// call Api
Call<UpdateUserInfoResponse> updateUserInfoResponseCall = ApiClient.getUserService().updateUserInformation("Bearer " + token, updateUserInfoRequest);
updateUserInfoResponseCall.enqueue(new Callback<UpdateUserInfoResponse>() {
Expand All @@ -163,10 +164,6 @@ public void onResponse(Call<UpdateUserInfoResponse> call, Response<UpdateUserInf
if (response.isSuccessful()) {
UpdateUserInfoResponse updateUserInfoResponse = response.body();
Toast.makeText(EditProfiles.this, updateUserInfoResponse.getMessage(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("userName", firstName.getText().toString().trim() + " " + lastName.getText().toString().trim());
intent.putExtra("profileImage", stringUri);
setResult(201, intent);
finish();
} else {
try {
Expand All @@ -189,7 +186,6 @@ public void onFailure(Call<UpdateUserInfoResponse> call, Throwable t) {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
String text = parent.getItemAtPosition(position).toString();

}

@Override
Expand Down

0 comments on commit cb7c8a8

Please sign in to comment.