мой RecyclerView не показывает сохраненные изображения на FireBase.
Для более удобного управления моими данными я использую FirebaseUI, а для загрузки своих imgs я использую GLIDE (подход GlideApp).
так:
МАНИФЕСТ:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
Gradle:
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-crash:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-database:4.0.1'
implementation 'com.firebaseui:firebase-ui-storage:4.0.1'
kapt 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'com.github.bumptech.glide:annotations:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
моя база данных:
мой FOTOMODEL.CLASS:
public class PhotoModel {
@Exclude private String desc;
@Exclude private String image;
@Exclude private String title;
public PhotoModel(String desc, String image, String title) {
this.desc = desc;
this.image = image;
this.title = title;
}
//firebase
public PhotoModel (){
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
@Keep
public String getImage() {
return image;
}
@Keep
public void setImage(String image) {
this.image = image;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
МОДУЛЬ СЛАЙДОВ:
public void registerComponents(Context context, Glide glide, Registry registry) {
// Register FirebaseImageLoader to handle StorageReference
registry.append(StorageReference.class, InputStream.class,
new FirebaseImageLoader.Factory());
* *} Тысяча двадцать-один
и наконец мой код:
private RecyclerView recyclerList;
DatabaseReference mDatabaseStorage ;
FirebaseStorage mFirebaseStorage;
FirebaseRecyclerAdapter firebaseRecyclerAdapter;
Query query;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_photo);
super.onCreate(savedInstanceState);
mDatabaseStorage = FirebaseDatabase.getInstance().getReference().child("Blog");
Toolbar toolbar = (Toolbar) findViewById(R.id.myToolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(view -> onBackPressed());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
query = FirebaseDatabase.getInstance().getReference("Blog");
ChildEventListener childEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
// ...
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
// ...
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
// ...
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
// ...
}
@Override
public void onCancelled(DatabaseError databaseError) {
// ...
}
};
query.addChildEventListener(childEventListener);
recyclerList = (RecyclerView)findViewById(R.id.recycler_view);
recyclerList.setHasFixedSize(true);
recyclerList.setLayoutManager(new LinearLayoutManager(this));
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions<PhotoModel> options = new FirebaseRecyclerOptions.Builder<PhotoModel>()
.setQuery(query, PhotoModel.class)
.build();
mFirebaseStorage = FirebaseStorage.getInstance();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<PhotoModel, PhotoViewHolder>(options) {
@Override
public void onError(DatabaseError e) {
Log.e("FirebaseRecyclerAdapter", e.toString());
}
@NonNull
@Override
public PhotoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.recycler_single_photo_row, parent, false);
return new PhotoViewHolder (view) ;
}
@Override
protected void onBindViewHolder(@NonNull PhotoViewHolder holder, int position, @NonNull PhotoModel model) {
Uri myUri = Uri.parse(model.getImage().toString());
Log.i("ImageFromModel", model.getImage().toString());
GlideApp.with(getApplicationContext())
.load(myUri)
.centerCrop()
.error(R.drawable.ic_error_black_24dp)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
Log.e("TAG_FROM_GLIDE", "Error loading image", e);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.fitCenter()
.into(holder.firebaseImages);
}
};
recyclerList.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
public static class PhotoViewHolder extends RecyclerView.ViewHolder {
public ImageView firebaseImages;
View globalView;
public PhotoViewHolder(View itemView) {
super(itemView);
this.firebaseImages = (ImageView) itemView.findViewById(R.id.imageFirebase);
globalView = itemView;
}
public void setTitle (String title){
TextView post_name = (TextView) globalView.findViewById(R.id.photo_name);
post_name.setText(title);
}
public void setDesc (String desc){
TextView post_desc = (TextView) globalView.findViewById(R.id.photo_desc);
post_desc.setText(desc);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if ( item.getItemId() == R.id.addPhotoActivity) {
Intent intent = new Intent(PhotoActivity.this, AddNewPhotoActivity.class);
startActivity(intent);
}
return true;
}
мой logcat от Glide (слушатель):
06-25 11:09:20.853 3460-3460/com.example.htw.mytestapp E/TAG_FROM_GLIDE: Error loading image
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 3 causes:
java.io.FileNotFoundException(No such file or directory)
java.io.FileNotFoundException(No such file or directory)
java.io.FileNotFoundException(No such file or directory)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 4): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, LOCAL
There was 1 cause:
java.io.FileNotFoundException(No such file or directory)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.io.FileNotFoundException: No such file or directory
Cause (2 of 4): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.os.ParcelFileDescriptor, LOCAL
There was 1 cause:
java.io.FileNotFoundException(No such file or directory)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.io.FileNotFoundException: No such file or directory
Cause (3 of 4): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.content.res.AssetFileDescriptor, LOCAL
There was 1 cause:
java.io.FileNotFoundException(No such file or directory)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.io.FileNotFoundException: No such file or directory
Cause (4 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{StringUri->Object->Drawable}, LOCAL
Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Drawable->Drawable}
Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Bitmap->Drawable}
LOG из Log.i ("ImageFromModel", model.getImage (). ToString ());
содержание: //com.example.htw.mytestapp.provider/my_images/Android/data/com.example.htw.mytestapp/files/Pictures/JPEG_20180613_104007_-1022454302.jpg
Содержание: //com.example.htw.mytestapp.provider/my_images/Android/data/com.example.htw.mytestapp/files/Pictures/JPEG_20180613_104052_-450216218.jpg
Содержание: //com.example.htw.mytestapp.provider/my_images/Android/data/com.example.htw.mytestapp/files/Pictures/JPEG_20180613_104118_1956285222.jpg
Содержание: //com.example.htw.mytestapp.provider/my_images/Android/data/com.example.htw.mytestapp/files/Pictures/JPEG_20180619_114556_5693763765908649752.jpg
Содержание: //com.example.htw.mytestapp.provider/my_images/Android/data/com.example.htw.mytestapp/files/Pictures/JPEG_20180621_123728_-880882730.jpg
Я также пытаюсь:
StorageReference storage = mFirebaseStorage.getReference (). Child (model.getImage ());
+
GlideApp.with (getApplicationContext ())
.load (хранение)
но не рабочий журнал:
06-25 11:42:49.454 17886-17886/com.example.htw.mytestapp E/TAG_FROM_GLIDE: Error loading image
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
com.google.firebase.storage.StorageException(Object does not exist at location.)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
There was 1 cause:
com.google.firebase.storage.StorageException(Object does not exist at location.)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.google.firebase.storage.StorageException: Object does not exist at location.