Skip to content

Edit Profile back button handled #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,37 @@ public void onClick(View v) {
}
});

rootView.setFocusableInTouchMode(true);
rootView.requestFocus();

rootView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setMessage("Do you want to exit without saving changes?").setCancelable(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use string values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atm1504 I will create another issue and replace with string values here as well as in other appropriate places.

.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_profile_container, new ViewProfileFragment());
ft.commit();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}).show();
return true;
}
}
return false;
}
});

return rootView;
}

Expand All @@ -136,7 +167,7 @@ private void setupViews(View rootView) {
state_view = rootView.findViewById(R.id.edit_state);
achievements_view = rootView.findViewById(R.id.edit_achievements);
change_photo_button = rootView.findViewById(R.id.profile_fab);
progressBar=rootView.findViewById(R.id.edit_profile_photo_progress);
progressBar = rootView.findViewById(R.id.edit_profile_photo_progress);
}

//Function that fills the views with the datas
Expand Down Expand Up @@ -373,7 +404,7 @@ public void onResponse(String response) {
Toast.makeText(getActivity(), getString(R.string.img_upload_success), Toast.LENGTH_LONG).show();
JSONObject mJsonObject = jsonObject.getJSONObject("messages");
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
editor.putString(Constant.IMG_URL,mJsonObject.getString(Constant.IMG_URL));
editor.putString(Constant.IMG_URL, mJsonObject.getString(Constant.IMG_URL));
editor.apply();
Glide.with(getActivity())
.load(preferences.getString(Constant.IMG_URL, ""))
Expand All @@ -383,7 +414,7 @@ public void onResponse(String response) {
.placeholder(R.drawable.ic_account_circle_black_48dp)
.into(profile_image_view);

}else{
} else {
Toast.makeText(getActivity(), getString(R.string.img_upload_failure), Toast.LENGTH_LONG).show();
Timber.d(response);
}
Expand Down