I have a problem that I do not know which is a bug, when I press the add photo button or the send button does not happen at all and I do not get any error,
The first button should open my photos, and the second should send to a RecyclerView in a fragament I give my code
Sorry for my english use the google translate
the fragment
public class PostCreateDialog extends DialogFragment implements View.OnClickListener{
private static final int RC_PHOTO_PICKER = 1;
private Post mPost;
private ProgressDialog mProgressDialog;
private ImageView mPostImageView;
private View mRootView;
private Uri mSelectedUri;
private ImageButton sendPostButton;
private ImageButton selectFotoButton;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
mPost = new Post();
mProgressDialog = new ProgressDialog(getContext());
mRootView = getActivity().getLayoutInflater().inflate(R.layout.create_post_dialog, null);
mPostImageView = (ImageView) mRootView.findViewById(R.id.post_dialog_display);
selectFotoButton = (ImageButton) mRootView.findViewById(R.id.post_dialog_select_imageview);
sendPostButton = (ImageButton) mRootView.findViewById(R.id.post_dialog_send_imageview);
builder.setView(mRootView);
return builder.create();
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.post_dialog_select_imageview:
selectImage();
break;
case R.id.post_dialog_send_imageview:
sendPost();
break;
}
}
private void sendPost() {
mProgressDialog.setMessage("Sending post...");
mProgressDialog.setCancelable(false);
mProgressDialog.setIndeterminate(true);
mProgressDialog.show();
FirebaseUtils.getUserRef(FirebaseUtils.getCurrentUser().getEmail().replace(".",",")).addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
final String postId = FirebaseUtils.getUid();
TextView postDialogText = (TextView) mRootView.findViewById(R.id.post_dialog_edittext);
String text = postDialogText.getText().toString();
mPost.setUser(user);
mPost.setNumOfLikes(0);
mPost.setNumOfComments(0);
mPost.setNumOfUnlikes(0);
mPost.setTimeOfcreation(System.currentTimeMillis());
mPost.setPostText(text);
if(mSelectedUri != null){
FirebaseUtils.getImageRef().child(mSelectedUri.getLastPathSegment()).putFile(mSelectedUri).addOnSuccessListener(getActivity(), new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String url = Contants.POST_IMAGES + "/" + mSelectedUri.getLastPathSegment();
mPost.setImageUrl(url);
addToMyPostList(postId);
}
});
}else {
addToMyPostList(postId);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
mProgressDialog.dismiss();
}
});
}
// ESTE DE AQUI ES COMO UN FINAL A TOODO SI SE COMPLETA O SI CANCELA
private void addToMyPostList(String postId){
FirebaseUtils.getPostRef().child(postId).setValue(mPost);
FirebaseUtils.getPostRef().child(postId).setValue(true).addOnCompleteListener(getActivity(), new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
mProgressDialog.dismiss();
dismiss();
}
});
}
// ESTOS DOS METODOS SIRVEN PARA SELECCIONAR LA IMAGEN
private void selectImage() {
Intent intent1 = new Intent(Intent.ACTION_GET_CONTENT);
intent1.setType("image/jpeg");
intent1.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent1, "Comlete action using"), RC_PHOTO_PICKER);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_PHOTO_PICKER){
if(resultCode == RESULT_OK){
mSelectedUri = data.getData();
mPostImageView.setImageURI(mSelectedUri);
}
}
}
}
the dialog:
public class PostCreateDialog extends DialogFragment implements View.OnClickListener{
private static final int RC_PHOTO_PICKER = 1;
private Post mPost;
private ProgressDialog mProgressDialog;
private ImageView mPostImageView;
private View mRootView;
private Uri mSelectedUri;
private ImageButton sendPostButton;
private ImageButton selectFotoButton;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
mPost = new Post();
mProgressDialog = new ProgressDialog(getContext());
mRootView = getActivity().getLayoutInflater().inflate(R.layout.create_post_dialog, null);
mPostImageView = (ImageView) mRootView.findViewById(R.id.post_dialog_display);
selectFotoButton = (ImageButton) mRootView.findViewById(R.id.post_dialog_select_imageview);
sendPostButton = (ImageButton) mRootView.findViewById(R.id.post_dialog_send_imageview);
builder.setView(mRootView);
return builder.create();
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.post_dialog_select_imageview:
selectImage();
break;
case R.id.post_dialog_send_imageview:
sendPost();
break;
}
}
private void sendPost() {
mProgressDialog.setMessage("Sending post...");
mProgressDialog.setCancelable(false);
mProgressDialog.setIndeterminate(true);
mProgressDialog.show();
FirebaseUtils.getUserRef(FirebaseUtils.getCurrentUser().getEmail().replace(".",",")).addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
final String postId = FirebaseUtils.getUid();
TextView postDialogText = (TextView) mRootView.findViewById(R.id.post_dialog_edittext);
String text = postDialogText.getText().toString();
mPost.setUser(user);
mPost.setNumOfLikes(0);
mPost.setNumOfComments(0);
mPost.setNumOfUnlikes(0);
mPost.setTimeOfcreation(System.currentTimeMillis());
mPost.setPostText(text);
if(mSelectedUri != null){
FirebaseUtils.getImageRef().child(mSelectedUri.getLastPathSegment()).putFile(mSelectedUri).addOnSuccessListener(getActivity(), new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
String url = Contants.POST_IMAGES + "/" + mSelectedUri.getLastPathSegment();
mPost.setImageUrl(url);
addToMyPostList(postId);
}
});
}else {
addToMyPostList(postId);
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
mProgressDialog.dismiss();
}
});
}
// ESTE DE AQUI ES COMO UN FINAL A TOODO SI SE COMPLETA O SI CANCELA
private void addToMyPostList(String postId){
FirebaseUtils.getPostRef().child(postId).setValue(mPost);
FirebaseUtils.getPostRef().child(postId).setValue(true).addOnCompleteListener(getActivity(), new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
mProgressDialog.dismiss();
dismiss();
}
});
}
// ESTOS DOS METODOS SIRVEN PARA SELECCIONAR LA IMAGEN
private void selectImage() {
Intent intent1 = new Intent(Intent.ACTION_GET_CONTENT);
intent1.setType("image/jpeg");
intent1.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent1, "Comlete action using"), RC_PHOTO_PICKER);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_PHOTO_PICKER){
if(resultCode == RESULT_OK){
mSelectedUri = data.getData();
mPostImageView.setImageURI(mSelectedUri);
}
}
}
}
Try to display any toast on button click.
If toast appears then your click event is working and if the toast is not shown then your button click is not working.
Related
Firebase image
Model class
public class Category
{
private String Name;
private String Image;
public Category(String name, String image) {
Name = name;
Image = image;
}
public Category() {
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getImage() {
return Image;
}
public void setImage(String image) {
Image = image;
}
}
Activity class
public class Home extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference reference;
FirebaseStorage storage;
StorageReference storageReference;
//Add new menu
MaterialEditText edtTxtName;
Button selectImage;
Button uploadImage;
//Adding new category
Category newCategory;
Uri savedImageUri;
private final int PICK_IMAGE_REQUEST=71;
MaterialEditText edtTxtNewCategoryName;
FloatingActionButton fab;
FirebaseRecyclerAdapter<Category,MenuViewHolder> recyclerAdapter;
TextView userName;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
edtTxtNewCategoryName=findViewById(R.id.edt_txt_new_item_name);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Menu Mangement");
setSupportActionBar(toolbar);
fab =findViewById(R.id.fab);
//Firebase init
database=FirebaseDatabase.getInstance();
reference=database.getReference("Category");
storage=FirebaseStorage.getInstance();
storageReference=storage.getReference();
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showDailog();
}
});
DrawerLayout drawer =findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//Setting header name
/* View view=navigationView.getHeaderView(0);
userName = view.findViewById(R.id.username);
userName.setText(Common.currentUser.getName());*/
//View init
recyclerView=findViewById(R.id.recycler_menu);
layoutManager=new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
loadMenu();
}
private void selectImage() {
Intent intent=new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,PICK_IMAGE_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
if(requestCode==PICK_IMAGE_REQUEST && resultCode==Activity.RESULT_OK
&& data!=null && data.getData()!=null)
{
savedImageUri=data.getData();//getting uri
selectImage.setText("Image Selected !");
}
}
private void uploadImage() {
final ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.setMessage("Uploading Image");
progressDialog.show();
String image= UUID.randomUUID().toString();
final StorageReference imageFolder=storageReference.child("images/"+image);
imageFolder.putFile(savedImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
Toast.makeText(Home.this, "Uploaded", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
{
#Override
public void onSuccess(Uri uri)
{
newCategory=new Category(edtTxtName.getText().toString(),uri.toString());
Toast.makeText(Home.this, ""+uri.toString(), Toast.LENGTH_SHORT).show();
}
});
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(Home.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress=(100.0 * taskSnapshot.getBytesTransferred()
/ taskSnapshot.getTotalByteCount());
progressDialog.setMessage("Uploaded "+progress+" %");
}
});
}
private void showDailog() {
final AlertDialog.Builder alertDailog=new AlertDialog.Builder(this);
alertDailog.setTitle("Add new Category");
alertDailog.setMessage("Please fill all the fields");
LayoutInflater inflater=this.getLayoutInflater();
View view=inflater.inflate(R.layout.add_new_menu_layout,null);
edtTxtName=view.findViewById(R.id.edt_txt_new_item_name);
alertDailog.setView(view);
alertDailog.setIcon(R.drawable.ic_shopping_cart_black_24dp);
alertDailog.setPositiveButton("Add", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
if(newCategory!=null){
reference.push().setValue(newCategory);
}
}
});
alertDailog.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDailog.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDailog.show();
}
private void loadMenu()
{
recyclerAdapter=new FirebaseRecyclerAdapter<Category, MenuViewHolder>(
Category.class,R.layout.menu_layout,
MenuViewHolder.class,reference) {
#Override
protected void populateViewHolder(MenuViewHolder viewHolder, final Category model, int position)
{
viewHolder.menuName.setText(model.getName());
Picasso.get().load(model.getImage()).into(viewHolder.imageView);
viewHolder.setItemClickListner(new ItemClickListner() {
#Override
public void onClick(View view, int position, boolean isLongClick) {
//Getting menuId
Intent intent=new Intent(Home.this,FoodList.class);
intent.putExtra("CategoryId",recyclerAdapter.getRef(position).getKey());
startActivity(intent);
}
});
}
};
recyclerAdapter.notifyDataSetChanged();//notifiy us if data has been changed.
recyclerView.setAdapter(recyclerAdapter);
}
In activity class,firebase adapter is implemented.by refrence of firebase database ,images are loading with only id "-LO061DOhjG2hVZlqY79" but with id's like '01' '02' are not loading
Adapter is loading images very slow
Output of this code
Help will highly appreciated
Because you are using private fields and public getters and setters, the name of your fields in your Category class, doesn't matter. If you want to use different names in your class than in the database, you might use an annotation called PropertyName in front of the getter.
images are loading with the only id "-LO061DOhjG2hVZlqY79" but with id's like '01' '02' are not loading
As I see in your screenshot, the image of the first element "01" with the name "Finger Foods" is displayed correctly in the UI. So it doesn't matter if the children have a key that looks like this 01, 02, or -LO061DOhjG2hVZlqY79 the data should be displayed. As a matter of fact, it is displayed, the name of the next item, "Western Soups" is displayed, so most likely the problem is with your URL. So please make sure that the URL actually exists and has it contains a valid image.
This is the error i am getting i am trying to upload/update/delete information to firebase on the app. It shows and the dialog box but when I click save/view changes it crashes and does not work.
ERROR
Process: com.coffeeshopapp.ruhul08.myapplication, PID: 1131
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.coffeeshopapp.ruhul08.myapplication/com.coffeeshopapp.ruhul08.myapplication.FoodDetails}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.FloatingActionButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.FloatingActionButton.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.coffeeshopapp.ruhul08.myapplication.FoodDetails.onCreate(FoodDetails.java:52)
at android.app.Activity.performCreate(Activity.java:7326)
at android.app.Activity.performCreate(Activity.java:7317)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3066)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3229)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6981)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
I/Process: Sending signal. PID: 1131 SIG: 9
Process 1131 terminated.
CODE
public class AdminFoodList extends AppCompatActivity {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
//RelativeLayout rootLayout;
FloatingActionButton fab;
//Firebase
FirebaseDatabase database;
DatabaseReference foodList;
FirebaseStorage storage;
StorageReference storageReference;
String categoryId="";
FirebaseRecyclerAdapter<Foods, FoodViewHolder> adapter;
DrawerLayout drawer;
private EditText editName, editDescription, editPrice, editDiscount;
private Button btnSelect;
private Button btnUpload;
Foods newFood;
Uri saveUri;
private final int PICK_IMAGE_REQUEST = 71;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_food_list);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
database = FirebaseDatabase.getInstance();
foodList = database.getReference("Foods");
storage = FirebaseStorage.getInstance();
storageReference = storage.getReference();
//Init
recyclerView = (RecyclerView)findViewById(R.id.recycler_food);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
if (getIntent() != null){
categoryId = getIntent().getStringExtra("CategoryId");
}
if(!categoryId.isEmpty() && categoryId != null){
loadListFood(categoryId);
}
// rootLayout = (RelativeLayout)findViewById(R.id.rootLayout);
fab = (FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showAddFoodDialog();
}
});
}
private void showAddFoodDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(com.coffeeshopapp.app.myapplication.AdminFoodList.this);
alertDialog.setTitle("Add new Food");
alertDialog.setMessage("Please fill full information");
LayoutInflater inflater = this.getLayoutInflater();
View add_menu_layout = inflater.inflate(R.layout.add_new_food_layout,null);
editName = add_menu_layout.findViewById(R.id.edit_Name);
editDescription = add_menu_layout.findViewById(R.id.edit_Description);
editPrice = add_menu_layout.findViewById(R.id.edit_Price);
editDiscount = add_menu_layout.findViewById(R.id.edit_Discount);
btnSelect = add_menu_layout.findViewById(R.id.btn_select);
btnUpload = add_menu_layout.findViewById(R.id.btn_upload);
//event for button
btnSelect.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
chooseImage(); //let user choose image from gallery and then save it to url of this image
}
});
btnUpload.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
uploadImage();
}
});
alertDialog.setView(add_menu_layout);
alertDialog.setIcon(R.drawable.ic_shopping_cart);
alertDialog.setPositiveButton("Save/View Changes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
if(newFood != null)
{
foodList.push().setValue(newFood);
Snackbar.make(drawer, "New Food "+newFood.getName()+" was added", Snackbar.LENGTH_SHORT)
.show();
}
}
});
alertDialog.setNegativeButton("Back", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
alertDialog.show();
}
private void uploadImage() {
if (saveUri != null)
{
final ProgressDialog mDialog = new ProgressDialog(this);
mDialog.setMessage("Uploading..");
mDialog.show();
String imageName = UUID.randomUUID().toString();
final StorageReference imageFolder = storageReference.child("images/"+imageName);
imageFolder.putFile(saveUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>(){
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
mDialog.dismiss();
Toast.makeText(com.coffeeshopapp.app.myapplication.AdminFoodList.this, "Uploaded!!!", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
newFood = new Foods();
newFood.setName(editName.getText().toString());
newFood.setDescription(editDescription.getText().toString());
newFood.setPrice(editPrice.getText().toString());
newFood.setDiscount(editDiscount.getText().toString());
newFood.setMenuId(categoryId);
newFood.setImage(uri.toString());
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e){
mDialog.dismiss();
Toast.makeText(com.coffeeshopapp.app.myapplication.AdminFoodList.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
mDialog.setMessage("Uploaded"+progress+"%");
}
});
}
}
private void chooseImage() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data !=null && data.getData()!=null)
{
saveUri = data.getData();
btnSelect.setText("Your image is selected!");
}
}
#Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle().equals(Common.UPDATE))
{
showUpdateFoodDialog(adapter.getRef(item.getOrder()).getKey(),adapter.getItem(item.getOrder()));
}
else if(item.getTitle().equals(Common.Delete))
{
deleteFood(adapter.getRef(item.getOrder()).getKey());
}
return super.onContextItemSelected(item);
}
private void showUpdateFoodDialog(final String key, final Foods item) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(com.coffeeshopapp.app.myapplication.AdminFoodList.this);
alertDialog.setTitle("Edit Food");
alertDialog.setMessage("Please fill full information");
LayoutInflater inflater = this.getLayoutInflater();
View add_menu_layout = inflater.inflate(R.layout.add_new_food_layout,null);
editName = add_menu_layout.findViewById(R.id.edit_Name);
editDescription = add_menu_layout.findViewById(R.id.edit_Description);
editPrice = add_menu_layout.findViewById(R.id.edit_Price);
editDiscount = add_menu_layout.findViewById(R.id.edit_Discount);
editName.setText(item.getName());
editDescription.setText(item.getDescription());
editPrice.setText(item.getPrice());
editDiscount.setText(item.getDiscount());
btnSelect = add_menu_layout.findViewById(R.id.btn_select);
btnUpload = add_menu_layout.findViewById(R.id.btn_upload);
//event for button
btnSelect.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
chooseImage(); //let user choose image from gallery and then save it to url of this image
}
});
btnUpload.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
changeImage(item);
}
});
alertDialog.setView(add_menu_layout);
alertDialog.setIcon(R.drawable.ic_shopping_cart);
alertDialog.setPositiveButton("Save/View Changes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
//update info
item.setName(editName.getText().toString());
item.setPrice(editPrice.getText().toString());
item.setDiscount(editDiscount.getText().toString());
item.setDescription(editDescription.getText().toString());
foodList.child(key).setValue(item);
Snackbar.make(drawer, "food "+item.getName()+" was updated", Snackbar.LENGTH_SHORT)
.show();
}
});
alertDialog.setNegativeButton("Back", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
alertDialog.show();
}
private void loadListFood(String categoryId) {
adapter = new FirebaseRecyclerAdapter<Foods, FoodViewHolder>(
Foods.class,
R.layout.food_item,
FoodViewHolder.class,
foodList.orderByChild("MenuId").equalTo(categoryId))
{
#Override
protected void populateViewHolder(FoodViewHolder viewHolder, Foods model, int position) {
viewHolder.food_name.setText(model.getName());
Picasso.get().load(model.getImage()).into(viewHolder.food_image);
final Foods local = model;
viewHolder.setItemClickListener(new ItemClickListener() {
#Override
public void onClick(View view, int position, boolean isLongClick) {
//code later
}
});
}
};
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
}
private void changeImage(final Foods item){
if (saveUri != null)
{
final ProgressDialog mDialog = new ProgressDialog(this);
mDialog.setMessage("Uploading..");
mDialog.show();
String imageName = UUID.randomUUID().toString();
final StorageReference imageFolder = storageReference.child("images/"+imageName);
imageFolder.putFile(saveUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>(){
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
mDialog.dismiss();
Toast.makeText(com.coffeeshopapp.app.myapplication.AdminFoodList.this, "Uploaded!!!", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
item.setImage(uri.toString());
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e){
mDialog.dismiss();
Toast.makeText(com.coffeeshopapp.app.myapplication.AdminFoodList.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
mDialog.setMessage("Uploaded"+progress+"%");
}
});
}
}
private void deleteFood(String key){
foodList.child(key).removeValue();
}
}
this is the code for the xml activity_admin_food_list. I am not sure about the floating action button as this is included in the code for this xml page.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rootLayout"
tools:context=".FoodList">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_food"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="61dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:layout_marginStart="16dp"
android:layout_marginTop="712dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/recycler_food"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/addicon" />
</android.support.design.widget.CoordinatorLayout>
fab = (FloatingActionButton)findViewById(R.id.fab);
is not being found in your XML R.layout.activity_admin_food_list, check if you have your fab button there
Firebase image
Model class
public class Category
{
private String Name;
private String Image;
public Category(String name, String image) {
Name = name;
Image = image;
}
public Category() {
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getImage() {
return Image;
}
public void setImage(String image) {
Image = image;
}
}
Activity class
public class Home extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference reference;
FirebaseStorage storage;
StorageReference storageReference;
//Add new menu
MaterialEditText edtTxtName;
Button selectImage;
Button uploadImage;
//Adding new category
Category newCategory;
Uri savedImageUri;
private final int PICK_IMAGE_REQUEST=71;
MaterialEditText edtTxtNewCategoryName;
FloatingActionButton fab;
FirebaseRecyclerAdapter<Category,MenuViewHolder> recyclerAdapter;
TextView userName;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
edtTxtNewCategoryName=findViewById(R.id.edt_txt_new_item_name);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("Menu Mangement");
setSupportActionBar(toolbar);
fab =findViewById(R.id.fab);
//Firebase init
database=FirebaseDatabase.getInstance();
reference=database.getReference("Category");
storage=FirebaseStorage.getInstance();
storageReference=storage.getReference();
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showDailog();
}
});
DrawerLayout drawer =findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//Setting header name
/* View view=navigationView.getHeaderView(0);
userName = view.findViewById(R.id.username);
userName.setText(Common.currentUser.getName());*/
//View init
recyclerView=findViewById(R.id.recycler_menu);
layoutManager=new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
loadMenu();
}
private void selectImage() {
Intent intent=new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,PICK_IMAGE_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
if(requestCode==PICK_IMAGE_REQUEST && resultCode==Activity.RESULT_OK
&& data!=null && data.getData()!=null)
{
savedImageUri=data.getData();//getting uri
selectImage.setText("Image Selected !");
}
}
private void uploadImage() {
final ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.setMessage("Uploading Image");
progressDialog.show();
String image= UUID.randomUUID().toString();
final StorageReference imageFolder=storageReference.child("images/"+image);
imageFolder.putFile(savedImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
Toast.makeText(Home.this, "Uploaded", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
{
#Override
public void onSuccess(Uri uri)
{
newCategory=new Category(edtTxtName.getText().toString(),uri.toString());
Toast.makeText(Home.this, ""+uri.toString(), Toast.LENGTH_SHORT).show();
}
});
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(Home.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress=(100.0 * taskSnapshot.getBytesTransferred()
/ taskSnapshot.getTotalByteCount());
progressDialog.setMessage("Uploaded "+progress+" %");
}
});
}
private void showDailog() {
final AlertDialog.Builder alertDailog=new AlertDialog.Builder(this);
alertDailog.setTitle("Add new Category");
alertDailog.setMessage("Please fill all the fields");
LayoutInflater inflater=this.getLayoutInflater();
View view=inflater.inflate(R.layout.add_new_menu_layout,null);
edtTxtName=view.findViewById(R.id.edt_txt_new_item_name);
alertDailog.setView(view);
alertDailog.setIcon(R.drawable.ic_shopping_cart_black_24dp);
alertDailog.setPositiveButton("Add", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
if(newCategory!=null){
reference.push().setValue(newCategory);
}
}
});
alertDailog.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDailog.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDailog.show();
}
private void loadMenu()
{
recyclerAdapter=new FirebaseRecyclerAdapter<Category, MenuViewHolder>(
Category.class,R.layout.menu_layout,
MenuViewHolder.class,reference) {
#Override
protected void populateViewHolder(MenuViewHolder viewHolder, final Category model, int position)
{
viewHolder.menuName.setText(model.getName());
Picasso.get().load(model.getImage()).into(viewHolder.imageView);
viewHolder.setItemClickListner(new ItemClickListner() {
#Override
public void onClick(View view, int position, boolean isLongClick) {
//Getting menuId
Intent intent=new Intent(Home.this,FoodList.class);
intent.putExtra("CategoryId",recyclerAdapter.getRef(position).getKey());
startActivity(intent);
}
});
}
};
recyclerAdapter.notifyDataSetChanged();//notifiy us if data has been changed.
recyclerView.setAdapter(recyclerAdapter);
}
In activity class,firebase adapter is implemented.by refrence of firebase database ,images are loading with only id "-LO061DOhjG2hVZlqY79" but with id's like '01' '02' are not loading
Adapter is loading images very slow
Output of this code
Help will highly appreciated
Because you are using private fields and public getters and setters, the name of your fields in your Category class, doesn't matter. If you want to use different names in your class than in the database, you might use an annotation called PropertyName in front of the getter.
images are loading with the only id "-LO061DOhjG2hVZlqY79" but with id's like '01' '02' are not loading
As I see in your screenshot, the image of the first element "01" with the name "Finger Foods" is displayed correctly in the UI. So it doesn't matter if the children have a key that looks like this 01, 02, or -LO061DOhjG2hVZlqY79 the data should be displayed. As a matter of fact, it is displayed, the name of the next item, "Western Soups" is displayed, so most likely the problem is with your URL. So please make sure that the URL actually exists and has it contains a valid image.
hi guys how can i send a data to firebase when i logging in want to see different info from other accounts now i see the save data that i sent. this is a code:
This is my Activity_category Activity
public class Activity_category extends Activity {
class Layout{
Layout(){
textView2= (TextView)findViewById(R.id.textView2);
listview1=(RecyclerView)findViewById(R.id.listview1);
registerForContextMenu(listview1);
}
TextView textView2;
RecyclerView listview1;
}
class Events{
Events(){
firebaseDatabase = FirebaseDatabase.getInstance();
myRef = FirebaseDatabase.getInstance().getReference("User_Details");
l.listview1.setLayoutManager(new LinearLayoutManager(Activity_category.this));
Toast.makeText(Activity_category.this, "Wait ! Fetching List...", Toast.LENGTH_SHORT).show();
// l.listview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// #Override
// public void onItemClick(AdapterView<?> adapterView, View view, int i, long id) {
// }
// });
}
}
Layout l;
Events e;
FirebaseDatabase firebaseDatabase;
DatabaseReference myRef;
FirebaseRecyclerAdapter<showdataitems, ShowDataViewHolder> mFirebaseAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
l = new Layout(); e = new Events();
}
public Activity_category() {
// Required empty public constructor
}
#Override
public void onStart() {
super.onStart();
//Log.d("LOGGED", "IN onStart ");
mFirebaseAdapter = new FirebaseRecyclerAdapter<showdataitems, ShowDataViewHolder>(showdataitems.class, R.layout.category, ShowDataViewHolder.class, myRef) {
public void populateViewHolder(final ShowDataViewHolder viewHolder, showdataitems model, final int position) {
viewHolder.Image_URL(model.getImage_URL());
viewHolder.Image_Title(model.getImage_Title());
//OnClick Item
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(Activity_category.this);
builder.setMessage("Do you want to Delete this data ?").setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
int selectedItems = position;
mFirebaseAdapter.getRef(selectedItems).removeValue();
mFirebaseAdapter.notifyItemRemoved(selectedItems);
l.listview1.invalidate();
onStart();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.setTitle("Confirm");
dialog.show();
}
});
}
};
l.listview1.setAdapter(mFirebaseAdapter);
}
//View Holder For Recycler View
public static class ShowDataViewHolder extends RecyclerView.ViewHolder {
private final TextView text1;
private final ImageView imageView3;
public ShowDataViewHolder(final View itemView) {
super(itemView);
imageView3 = (ImageView) itemView.findViewById(R.id.imageView3);
text1 = (TextView) itemView.findViewById(R.id.text1);
}
private void Image_Title(String title) {
text1.setText(title);
}
private void Image_URL(String title) {
// image_url.setImageResource(R.drawable.loading);
Glide.with(itemView.getContext())
.load(title)
.crossFade()
.placeholder(R.drawable.newmenu1)
.thumbnail(0.1f)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView3);
}
}
#Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()){
case 1:
break;
}
return super.onContextItemSelected(item);
}
This is my Uploadinfo Activity
public class Uploadinfo extends Activity{
class Layout{
Layout(){
menuBtn= (Button)findViewById(R.id.menuBtn);
cancelBtn= (Button)findViewById(R.id.cancelBtn);
btnAddimage= (Button)findViewById(R.id.btnAddimage);
imageView= (ImageView)findViewById(R.id.imageView);
editText= (EditText)findViewById(R.id.editText);
}
Button menuBtn , cancelBtn,btnAddimage;
ImageView imageView;
EditText editText;
}
class Events{
Events(){
mProgressDialog = new ProgressDialog(Uploadinfo.this);
l.btnAddimage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(), "Call for Permission", Toast.LENGTH_SHORT).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, READ_EXTERNAL_STORAGE);
}
}
else
{
callgalary();
}
}
});
mdatabaseRef = FirebaseDatabase.getInstance().getReference();
mRoofRef = new Firebase("https://restaurant-menu-4bdf2.firebaseio.com/").child("User_Details").push(); // Push will create new child every time we upload data
mStorage = FirebaseStorage.getInstance().getReferenceFromUrl("gs://restaurant-menu-4bdf2.appspot.com/");
l.menuBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String mName = l.editText.getText().toString().trim();
if(mName.isEmpty())
{
Toast.makeText(getApplicationContext(), "Fill all Field", Toast.LENGTH_SHORT).show();
return;
}
Firebase childRef_name = mRoofRef.child("Image_Title");
childRef_name.setValue(mName);
Toast.makeText(getApplicationContext(), "Updated Info", Toast.LENGTH_SHORT).show();
}
});
}
}
Layout l;
Events e;
public static final int READ_EXTERNAL_STORAGE = 0;
private static final int GALLERY_INTENT = 2;
private ProgressDialog mProgressDialog;
private Firebase mRoofRef;
private Uri mImageUri = null;
private DatabaseReference mdatabaseRef;
private StorageReference mStorage;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
l = new Layout(); e = new Events();
}
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case READ_EXTERNAL_STORAGE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
callgalary();
return;
}
Toast.makeText(getApplicationContext(), "...", Toast.LENGTH_SHORT).show();
}
private void callgalary() {
Intent intent1 = new Intent();
intent1.setType("image/*");
intent1.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent1, "Select Picture"), GALLERY_INTENT);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_INTENT && resultCode == RESULT_OK) {
mImageUri = data.getData();
l.imageView.setImageURI(mImageUri);
StorageReference filePath = mStorage.child("User_Images").child(mImageUri.getLastPathSegment());
mProgressDialog.setMessage("Uploading Image....");
mProgressDialog.show();
filePath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUri = taskSnapshot.getDownloadUrl(); //Ignore This error
mRoofRef.child("Image_URL").setValue(downloadUri.toString());
Glide.with(getApplicationContext())
.load(downloadUri)
.crossFade()
.placeholder(R.drawable.newmenu1)
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.into( l.imageView);
Toast.makeText(getApplicationContext(), "Updated.", Toast.LENGTH_SHORT).show();
mProgressDialog.dismiss();
}
});
}
}
what am I doing wrong? In this code, I load the image into Firebase Storage and then try to display it. But for some reason the display does not work. It loads it to Storage, but does not want to display it. Can Uri not take it right? As for me, for some reason, the red line underlines this line:
downloadUrl = taskSnapshot.getDownloadUrl();
What's wrong here?
public class EditProfile extends Fragment{
private static final int GALLERY_INTENT=2;
private EditText editProfileName;
private EditText editProfilePhone;
private EditText editProfileNick;
private ImageView image;
private Uri downloadUrl;
private Button saveBtn;
private final int LENGTH = 1000;
private FirebaseUser user;
private ProgressDialog progressDialog;
public EditProfile() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_edit_profile, container, false);
image=(ImageView)v.findViewById(R.id.edit_profile_photo);
user= FirebaseAuth.getInstance().getCurrentUser();
editProfileName=(EditText)v.findViewById(R.id.edit_profile_name);
editProfilePhone=(EditText)v.findViewById(R.id.edit_profile_phone);
saveBtn=(Button)v.findViewById(R.id.edit_profile_save);
progressDialog = new ProgressDialog(getContext());
saveBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chageProfile();
}
});
image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setImage();
}
});
return v;
}
public void setImage(){
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,GALLERY_INTENT);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==GALLERY_INTENT && resultCode==RESULT_OK){
progressDialog.setTitle("Uploading");
progressDialog.show();
Uri uri = data.getData();
StorageReference storageReference=FirebaseStorage.getInstance().getReference();
StorageReference file=storageReference.child(user.getUid()+"/photo.jpg");
file.putFile(uri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
downloadUrl = taskSnapshot.getDownloadUrl();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setPhotoUri(downloadUrl)
.build();
user.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
progressDialog.dismiss();
Toast.makeText(getApplicationContext(),"Фото добавлено",Toast.LENGTH_SHORT).show();
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception exception) {
// Handle unsuccessful uploads
// ...
}
});
}
image.setImageURI(user.getPhotoUrl());
}
}