получение изображений из firebase в виде recylcler с glide - PullRequest
0 голосов
/ 29 января 2020

Я могу вставлять изображения в базу данных Firebase (облачное хранилище), но не могу получать изображения в режиме утилизации, я использую Glide вместо Picaso .. мой buid.gradle (app):

 apply plugin: 'com.android.application'

  android {
 compileSdkVersion 28
 defaultConfig {
    applicationId "com.example.firestoreexample"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
        minifyEnabled false
     proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-       rules.pro'
    }
    }
    }

  dependencies {
 implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:18.2.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-storage:16.0.4'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-database:16.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.firebaseui:firebase-ui-storage:4.3.2'

 }
 apply plugin: 'com.google.gms.google-services'

my ImageAdapter. java

package com.example.firestoreexample;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
 import java.util.List;

import static com.example.firestoreexample.R.*;

public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {

private Context mContext;
private List<Upload> muploads;

// creating constructor
public ImageAdapter(Context context,List<Upload> uploads){
    mContext = context;
    muploads = uploads;
}
@NonNull
@Override

public ImageViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View v = LayoutInflater.from(mContext).inflate(layout.image_item,viewGroup,false); // i think i am having problem here
    return new ImageViewHolder(v);

}
@Override
public void onBindViewHolder(@NonNull ImageViewHolder imageViewHolder, int i) {
    Upload uploadCurrent = muploads.get(i);
    imageViewHolder.textViewName.setText(uploadCurrent.getName());
    Glide.with(mContext)
            .load(uploadCurrent.getImageUrl())
            .into(imageViewHolder.imageView);

}

@Override
public int getItemCount() {
    return muploads.size();
}

public class ImageViewHolder extends RecyclerView.ViewHolder{
    public TextView textViewName;
     public ImageView imageView;

     public ImageViewHolder(View itemView){
         super(itemView);
         textViewName = itemView.findViewById(id.text_view_name);
         imageView = itemView.findViewById(id.image_view_upload);
     }
}

}

my activity_images. xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".ImagesActivity">
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/recycler_view">

  </android.support.v7.widget.RecyclerView>
  </RelativeLayout>

ImageActivity. java

package com.example.firestoreexample;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;

import java.util.ArrayList;
import java.util.List;

public class ImagesActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
private ImageAdapter mAdapter;
private DatabaseReference mDbRef ;
 List<Upload> mUploads;
@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_images);
    mRecyclerView = findViewById(R.id.recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mUploads = new ArrayList<>();
    mDbRef  = FirebaseDatabase.getInstance().getReference("uploads");

        mDbRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                for(DataSnapshot postSnapshot:dataSnapshot.getChildren()){
                   Upload upload = postSnapshot.getValue(Upload.class);
                   mUploads.add(upload);
                }
                mAdapter = new ImageAdapter(ImagesActivity.this,mUploads);
                mRecyclerView.setAdapter(mAdapter);
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
                Toast.makeText(ImagesActivity.this,databaseError.getMessage(),Toast.LENGTH_SHORT).show();
            }
        });

    }
}

, пожалуйста, помогите мне, где я ошибаюсь, приложение работает, но не может получить изображения ...

короткий экран https://imagizer.imageshack.com/img921/1471/3ZXtgO.png

...