Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. downloadUrl = taskSnapshot.getDownloadUrl();
  2.  
  3. public class EditProfile extends Fragment{
  4. private static final int GALLERY_INTENT=2;
  5. private EditText editProfileName;
  6. private EditText editProfilePhone;
  7. private EditText editProfileNick;
  8. private ImageView image;
  9. private Uri downloadUrl;
  10. private Button saveBtn;
  11. private final int LENGTH = 1000;
  12. private FirebaseUser user;
  13. private ProgressDialog progressDialog;
  14.  
  15. public EditProfile() {
  16. }
  17.  
  18.  
  19. @Override
  20. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  21. Bundle savedInstanceState) {
  22. // Inflate the layout for this fragment
  23. View v = inflater.inflate(R.layout.fragment_edit_profile, container, false);
  24. image=(ImageView)v.findViewById(R.id.edit_profile_photo);
  25. user= FirebaseAuth.getInstance().getCurrentUser();
  26. editProfileName=(EditText)v.findViewById(R.id.edit_profile_name);
  27. editProfilePhone=(EditText)v.findViewById(R.id.edit_profile_phone);
  28. saveBtn=(Button)v.findViewById(R.id.edit_profile_save);
  29. progressDialog = new ProgressDialog(getContext());
  30. saveBtn.setOnClickListener(new View.OnClickListener() {
  31. @Override
  32. public void onClick(View v) {
  33. chageProfile();
  34. }
  35. });
  36. image.setOnClickListener(new View.OnClickListener() {
  37. @Override
  38. public void onClick(View v) {
  39. setImage();
  40. }
  41. });
  42. return v;
  43. }
  44.  
  45. public void setImage(){
  46.  
  47. Intent intent = new Intent(Intent.ACTION_PICK);
  48.  
  49. intent.setType("image/*");
  50. intent.setAction(Intent.ACTION_GET_CONTENT);
  51.  
  52. startActivityForResult(intent,GALLERY_INTENT);
  53. }
  54. @Override
  55. public void onActivityResult(int requestCode, int resultCode, Intent data) {
  56. super.onActivityResult(requestCode, resultCode, data);
  57.  
  58. if(requestCode==GALLERY_INTENT && resultCode==RESULT_OK){
  59.  
  60. progressDialog.setTitle("Uploading");
  61. progressDialog.show();
  62. Uri uri = data.getData();
  63. StorageReference storageReference=FirebaseStorage.getInstance().getReference();
  64. StorageReference file=storageReference.child(user.getUid()+"/photo.jpg");
  65. file.putFile(uri)
  66. .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
  67. @Override
  68. public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
  69. // Get a URL to the uploaded content
  70. downloadUrl = taskSnapshot.getDownloadUrl();
  71. UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
  72. .setPhotoUri(downloadUrl)
  73. .build();
  74. user.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
  75. @Override
  76. public void onComplete(@NonNull Task<Void> task) {
  77. progressDialog.dismiss();
  78. Toast.makeText(getApplicationContext(),"Фото добавлено",Toast.LENGTH_SHORT).show();
  79. }
  80. });
  81. }
  82. })
  83. .addOnFailureListener(new OnFailureListener() {
  84. @Override
  85. public void onFailure(@NonNull Exception exception) {
  86. // Handle unsuccessful uploads
  87. // ...
  88. }
  89. });
  90. }
  91. image.setImageURI(user.getPhotoUrl());
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement