Fragment_profile
@Override
public void onClick(View v) {
final int id = v.getId();
if (id == R.id.layoutCameraGallery) {
openImageCropper();
}
}
private void openImageCropper() {
try {
fileUri = null;
imgUri = null;
List<PowerMenuItem> list = new ArrayList<>();
list.add(new PowerMenuItem(getString(R.string.strGallery), R.drawable.ic_popup_gallery));
list.add(new PowerMenuItem(getString(R.string.strCamera), R.drawable.ic_popup_camera));
PowerMenu powerMenu = new PowerMenu.Builder(mActivity)
.addItemList(list)
.setAnimation(MenuAnimation.ELASTIC_CENTER)
.setCircularEffect(CircularEffect.BODY)
.setTextGravity(Gravity.NO_GRAVITY)
.setMenuRadius(10f) // sets the corner radius.
.setMenuShadow(10f) // sets the shadow.
.setTextTypeface(Utils.getRegularFont(mActivity))
.setTextSize(15)
.setSelectedTextColor(Color.WHITE)
.setMenuColor(Color.WHITE)
.setSelectedEffect(true)
.setTextColor(ContextCompat.getColor(mActivity, R.color.grey_800))
.setSelectedMenuColor(ContextCompat.getColor(mActivity, R.color.colorAccent))
.setDismissIfShowAgain(true)
.setAutoDismiss(true)
.setOnMenuItemClickListener((position, item) -> {
if (item.getTitle().toString().equalsIgnoreCase(getString(R.string.strGallery))) {
openImage();
} else {
openCamera();
}
})
.build();
powerMenu.showAsAnchorCenter(getView());
} catch (Exception e) {
Utils.getErrors(e);
}
}
How to set limit to change photo profile only once a day in android programmatically? I use firebase. I want to limit each user to only be able to change their profile photo once a day.
2
Answers
There is different types of ways to do this. But best one is here
hence you will get today’s date you can upload also this with the profile photo or you can store in SharedPreferrence when user updates profile photo.
After use wants to update his profile photo then you have check if date has changed or not.
If date has changed then you can allow. Hope it can help you
If you are using firebase you could store every time a user changes the profile picture in firestore/ database. And then you can check every time a user wants to update the picture if the last update is more than 24 hours ago.
You can also use for example SharedPreferences and store the timestamp after the update of the picture. But then you can only check if one device changes the picture only ones a day. Then a user can change the picture on another device in less than 24 hours.