我有一个使用 Firebase 的应用。当用户登录时,活动将检查 Firestore数据库中是否存在用户数据,如果存在则将其转到应用中。
这是它的代码(这是OnCreate
)
FirebaseFirestore
.getInstance()
.document("users/" + uID)
.get()
.addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
if (task.getResult().exists()) {
DocumentSnapshot documentSnapshot = task.getResult();
name.setText(documentSnapshot.getString("name"));
progressBar.setVisibility(View.VISIBLE);
Glide
.with(SetUserData.this)
.load(FirebaseStorage.getInstance().getReference("profile_images/" + uID))
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.error(R.drawable.default_user_icon)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
if (e.getRootCauses().size() == 1 && e.getRootCauses().get(0) instanceof StorageException) {
if (((StorageException) e.getRootCauses().get(0)).getErrorCode() == StorageException.ERROR_OBJECT_NOT_FOUND) {
Toast.makeText(SetUserData.this, "testing", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
progressHUD.dismiss();
}
} else {
Toast.makeText(SetUserData.this, "Some error occurred", Toast.LENGTH_LONG).show();
Log.e("Glide Exception", e.getMessage());
finish();
}
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
progressHUD.dismiss();
return false;
}
}).into(imageView);
}
else {
progressBar.setVisibility(View.GONE);
progressHUD.dismiss();
}
} else {
Toast.makeText(SetUserData.this, "Some error occurred", Toast.LENGTH_LONG).show();
Log.e("Firestore error", task.getException().getMessage());
finish();
}
}
}
);
我有一个活动,当我按下ImageView
时,会按下image cropping tool is invoked。这是setOnClickListener()
侦听器的代码:
imageView.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
CropImage
.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.start(SetUserData.this); //get image and crop - custom library
}
}
);
这是onActivityResult()
方法:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK) {
imageUri = result.getUri();
try {
imageView.setImageBitmap(MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri));
} catch (IOException e) {
e.printStackTrace();
}
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
result.getError().printStackTrace();
Toast.makeText(this, "Some error has occurred, please try again", Toast.LENGTH_LONG).show();
}
}
}
每次我尝试使用 Glide ImageView
的{{1}},onLoadFailed
方法设置图像时,我都不知道如何或为什么,我所知道的不应该。我知道由于我在该方法中放入了listener()
而使它得以执行。 Glide 语句和以下 Firestore 语句上方的代码不会不执行,仅Glide toast()
方法。 Video link
我已经花了2天了,这让我发疯了,不知道为什么会这样吗?