Я пытался кто-то учебник по извлечению данных из хранилища Firebase. Нет ошибки при запуске устройства, но индикатор загрузки продолжает загружаться, и данные не отображаются. Это код активности и градл. Кроме того, у меня есть макет activity_friends, item_list. xml и модель с именем FriendsResponse.
FriendsActivity. java
public class FriendsActivity extends AppCompatActivity {
@BindView(R.id.progress_bar)
ProgressBar progressBar;
@BindView(R.id.friend_list)
RecyclerView friendList;
private FirebaseFirestore db;
private FirestoreRecyclerAdapter adapter;
LinearLayoutManager linearLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friends);
ButterKnife.bind(this);
init();
getFriendList();
}
private void init(){
linearLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
friendList.setLayoutManager(linearLayoutManager);
db = FirebaseFirestore.getInstance();
}
private void getFriendList(){
Query query = db.collection("Data");
FirestoreRecyclerOptions<FriendsResponse> response = new FirestoreRecyclerOptions.Builder<FriendsResponse>()
.setQuery(query, FriendsResponse.class)
.build();
adapter = new FirestoreRecyclerAdapter<FriendsResponse, FriendsHolder>(response) {
@Override
public void onBindViewHolder(FriendsHolder holder, int position, FriendsResponse model) {
progressBar.setVisibility(View.GONE);
holder.textName.setText(model.getName());
holder.textTitle.setText(model.getTitle());
holder.textCompany.setText(model.getCompany());
Glide.with(getApplicationContext())
.load(model.getImage())
.into(holder.imageView);
holder.itemView.setOnClickListener(v-> {
Snackbar.make(friendList, model.getName()+", "+model.getTitle()+" at "+model.getCompany(), Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
});
}
@Override
public FriendsHolder onCreateViewHolder(ViewGroup group, int i) {
View view = LayoutInflater.from(group.getContext())
.inflate(R.layout.list_item, group, false);
return new FriendsHolder(view);
}
@Override
public void onError(FirebaseFirestoreException e) {
Log.e("error", e.getMessage());
}
};
adapter.notifyDataSetChanged();
friendList.setAdapter(adapter);
}
public class FriendsHolder extends RecyclerView.ViewHolder {
@BindView(R.id.name)
TextView textName;
@BindView(R.id.image)
ImageView imageView;
@BindView(R.id.title)
TextView textTitle;
@BindView(R.id.company)
TextView textCompany;
public FriendsHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
@Override
public void onStart() {
super.onStart();
adapter.startListening();
}
@Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.test.project"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.firebaseui:firebase-ui-database:4.0.0'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.google.android.gms:play-services-auth:18.0.0'
implementation "com.google.firebase:firebase-firestore:21.4.2"
implementation "com.firebaseui:firebase-ui-auth:4.3.1"
implementation "com.firebaseui:firebase-ui-firestore:6.2.1"
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.android.material:material:1.1.0'
}
Это моя структура базы данных: