приложение на Java с использованием Firebase,RecyclerView проблема заключается в том что приложение используем слишком много оперативной памяти(500-550мб). Скрин из профайлера
думаю проблема в этом фрагменте
@Override
public void onResume() {
super.onResume();
FirebaseRecyclerOptions<ShopAdapter> options = new FirebaseRecyclerOptions.Builder<ShopAdapter>()
.setQuery(shops, ShopAdapter.class).build();
horizAdapter= new FirebaseRecyclerAdapter<ShopAdapter, HorizontalShopHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull HorizontalShopHolder holder, int position, @NonNull ShopAdapter model) {
textesti.setVisibility(View.VISIBLE);
holder.glavmagname.setText(model.getMagName());
holder.glavmagname.setHint(model.getMagUid());
ValueEventListener listener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
testintTwo = Integer.valueOf("" + snapshot.getChildrenCount());
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
};
DatabaseReference child = prover.child(holder.glavmagname.getHint().toString());
child.addListenerForSingleValueEvent(listener);
listenersTwo.put(child, listener);
ValueEventListener list2 = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists() && snapshot.getChildrenCount() > 0) {
double diablot = 0.0;
for (DataSnapshot ds : snapshot.getChildren()) {
ShopAdapter shopAdapter = ds.getValue(ShopAdapter.class);
assert shopAdapter != null;
String string = shopAdapter.getValue();
otztvValuestwo = Double.parseDouble(string);
diablot = diablot + otztvValuestwo;
itogt = diablot / testint;
holder.rateyellow1g.setVisibility(getRateVisibility(itogt >= 0.5));
holder.rateyellow2g.setVisibility(getRateVisibility(itogt >= 1.5));
holder.rateyellow3g.setVisibility(getRateVisibility(itogt >= 2.5));
holder.rateyellow4g.setVisibility(getRateVisibility(itogt >= 3.5));
holder.rateyellow5g.setVisibility(getRateVisibility(itogt >= 4.5));
String result=String.format("%.3f",itogt);
holder.textstarg.setText(result);
}
}
}
private int getRateVisibility(boolean b) {
return b ? View.VISIBLE : View.INVISIBLE;
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
};
DatabaseReference child1 = otzest.child(holder.glavmagname.getHint().toString());
child1.addValueEventListener(list2);
listenersTwo.put(child1, list2);
Transformation transformation = new RoundedTransformationBuilder().borderColor(Color.WHITE).borderWidthDp(3).cornerRadius(15).oval(false).build();
Picasso.get().load(model.getMagLogo()).transform(transformation).into(holder.imageGlavMag);
}
@Override
public HorizontalShopHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_horizontal_shop, parent, false);
HorizontalShopHolder holder = new HorizontalShopHolder(view);
return holder;
}
};
HorizontalRec.setAdapter(horizAdapter);
FirebaseRecyclerOptions<ShopAdapter> Options = new FirebaseRecyclerOptions.Builder<ShopAdapter>()
.setQuery(shops, ShopAdapter.class).build();
VerticalAdapter = new FirebaseRecyclerAdapter<ShopAdapter, VerticalShopHolder>(Options) {
@Override
protected void onBindViewHolder(@NonNull VerticalShopHolder holder, int position, @NonNull ShopAdapter model) {
Transformation transformation = new RoundedTransformationBuilder().borderColor(Color.WHITE).borderWidthDp(3).cornerRadius(7).oval(false).build();
Picasso.get().load(model.getMagLogo()).transform(transformation).into(holder.imageLogoApteka);
holder.aotekaname.setText(model.getMagName());
holder.aotekaname.setHint(model.getMagUid());
Log.d("Окси", holder.aotekaname.getHint().toString());
ValueEventListener listener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
testint = Integer.valueOf("" + snapshot.getChildrenCount());
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
};
DatabaseReference child = prover.child(holder.aotekaname.getHint().toString());
child.addListenerForSingleValueEvent(listener);
listeners.put(child, listener);
ValueEventListener list1 = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists() && snapshot.getChildrenCount() > 0) {
double diablo = 0.0;
for (DataSnapshot ds : snapshot.getChildren()) {
ShopAdapter shopAdapter = ds.getValue(ShopAdapter.class);
assert shopAdapter != null;
String string = shopAdapter.getValue();
otztvValues = Double.parseDouble(string);
diablo = diablo + otztvValues;
itog = diablo / testint;
holder.rateyellow1.setVisibility(getRateVisibility(itog >= 0.5));
holder.rateyellow2.setVisibility(getRateVisibility(itog >= 1.5));
holder.rateyellow3.setVisibility(getRateVisibility(itog >= 2.5));
holder.rateyellow4.setVisibility(getRateVisibility(itog >= 3.5));
holder.rateyellow5.setVisibility(getRateVisibility(itog >= 4.5));
String result=String.format("%.3f",itog);
holder.textstar.setText(result);
}
}
}
private int getRateVisibility(boolean b) {
return b ? View.VISIBLE : View.INVISIBLE;
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
};
DatabaseReference child1 = otzest.child(holder.aotekaname.getHint().toString());
child1.addValueEventListener(list1);
listeners.put(child1, list1);
}
@Override
public VerticalShopHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_vertical_shop
, parent, false);
return new VerticalShopHolder(view);
}
};
recAptek.setAdapter(VerticalAdapter);
VerticalAdapter.startListening();
horizAdapter.startListening();
}
@Override
public void onPause() {
super.onPause();
for (Map.Entry<Query, ValueEventListener> entry : listeners.entrySet()) {
entry.getKey().removeEventListener(entry.getValue());
}
for (Map.Entry<Query, ValueEventListener> entry : listenersTwo.entrySet()) {
entry.getKey().removeEventListener(entry.getValue());
}
horizAdapter.stopListening();
VerticalAdapter .stopListening();
}