use of com.google.firebase.database.DataSnapshot in project MadMax by deviz92.
the class GroupsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.i(TAG, "onCreateView");
setInterface((OnItemClickInterface) getActivity(), (OnItemLongClickInterface) getActivity());
final View view = inflater.inflate(R.layout.skeleton_list, container, false);
databaseReference = FirebaseDatabase.getInstance().getReference();
RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(ContextCompat.getColor(getContext(), R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
recyclerView = (RecyclerView) view.findViewById(R.id.rv_skeleton);
layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(divider);
groups.clear();
groupsViewAdapter = new GroupsViewAdapter(this.getContext(), this, this, groups, GroupsFragment.TAG);
recyclerView.setAdapter(groupsViewAdapter);
// Ascolto i gruppi dello user
databaseReference.child("users").child(MainActivity.getCurrentUID()).child("groups").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Per ogni gruppo dello user
for (DataSnapshot groupSnapshot : dataSnapshot.getChildren()) {
// Se il gruppo è true, ossia è ancora tra quelli dello user
try {
Boolean trueGroup = (Boolean) groupSnapshot.getValue();
if (trueGroup)
getGroupAndBalance(MainActivity.getCurrentUID(), groupSnapshot.getKey());
else {
// tolgo il gruppo da quelli che verranno stampati, così lo vedo sparire realtime
groups.remove(groupSnapshot.getKey());
groupsViewAdapter.update(groups);
groupsViewAdapter.notifyDataSetChanged();
}
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, groupSnapshot.getValue().toString());
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, databaseError.toException());
}
});
return view;
}
use of com.google.firebase.database.DataSnapshot in project FindMyHome by DjangoBlockchained.
the class ShelterDetailActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shelter_details);
list = findViewById(R.id.shelterdetails);
claimbutton = (Button) findViewById(R.id.claimbutton);
adapter = new ArrayAdapter(ShelterDetailActivity.this, android.R.layout.simple_list_item_1, details);
username = getIntent().getStringExtra("username");
String name = getIntent().getStringExtra("Shelter Name");
shelterRef = FirebaseDatabase.getInstance().getReference().child("shelters").child(name);
claimbutton.setOnClickListener((view) -> {
Intent intent = new Intent(ShelterDetailActivity.this, ClaimScreenActivity.class);
intent.putExtra("username", username);
intent.putExtra("Shelter Name", name);
startActivity(intent);
});
shelterRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Object data = dataSnapshot.getValue();
details.add(getLabel(dataSnapshot.getKey(), data));
adapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Object data = dataSnapshot.getValue();
String key = dataSnapshot.getKey();
// Find the current row for the key and replace it with the new value.
int index = -1;
boolean found = false;
for (int i = 0; i < details.size() && !found; i++) {
if (details.get(i).contains(key)) {
index = i;
found = true;
}
}
if (index != -1) {
details.set(index, getLabel(dataSnapshot.getKey(), data));
} else {
details.add(getLabel(dataSnapshot.getKey(), data));
}
adapter.notifyDataSetChanged();
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
list.setAdapter(adapter);
}
use of com.google.firebase.database.DataSnapshot in project FindMyHome by DjangoBlockchained.
the class ShelterListActivity method showSearchedShelter.
private void showSearchedShelter(String name, String gender, String age) {
shelterRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Map<String, Object> string = (Map<String, Object>) dataSnapshot.getValue();
String restriction = string.get("restrictions").toString();
String dbname = string.get("name").toString();
if (gender.equals("Any")) {
if (dbname.toLowerCase().contains(name.toLowerCase()) && (((!(restriction.contains("Men") || (restriction.contains("Women")))) || (restriction.contains("Anyone"))) && ((restriction.contains(age)) || (restriction.contains("Anyone"))))) {
names.add(string.get("name").toString());
adapter.notifyDataSetChanged();
}
} else if (!gender.equals("")) {
if (dbname.toLowerCase().contains(name.toLowerCase()) && (((!restriction.contains(gender)) || (restriction.contains("Anyone"))) && ((restriction.contains(age)) || (restriction.contains("Anyone"))))) {
names.add(string.get("name").toString());
adapter.notifyDataSetChanged();
}
} else {
if (dbname.toLowerCase().contains(name.toLowerCase()) && ((restriction.contains(age)) || (restriction.contains("Anyone")))) {
names.add(string.get("name").toString());
adapter.notifyDataSetChanged();
}
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
list.setAdapter(adapter);
list.setOnItemClickListener((parent, view, position, id) -> {
String selected = (String) list.getItemAtPosition(position);
Intent intent = new Intent(ShelterListActivity.this, ShelterDetailActivity.class);
intent.putExtra("username", username);
intent.putExtra("Shelter Name", selected);
startActivity(intent);
});
}
use of com.google.firebase.database.DataSnapshot in project SocialRec by Jkuras.
the class MainActivity method getPosts.
// sets listener at db/posts/deals/:all
// loads posts into mPosts, listener calls setUI
public void getPosts() {
mref = mDataBase.getReference("posts/deals");
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// initialize array of all posts and add them to mPosts
mPosts = new ArrayList<DealPost>();
for (DataSnapshot child : dataSnapshot.getChildren()) {
mPosts.add((DealPost) child.getValue(DealPost.class));
}
setUI();
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
mref.addListenerForSingleValueEvent(postListener);
}
Aggregations