-
Notifications
You must be signed in to change notification settings - Fork 1
/
gradlew
76 lines (63 loc) · 5.18 KB
/
gradlew
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.example.memoria.ui.home;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.memoria.R;
import com.example.memoria.model.Memory;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;
public class HomeFragment extends Fragment {
private DatabaseReference mRef;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_home, container, false);
RecyclerView memoryRecyclerView = root.findViewById(R.id.memoryRecyclerView);
LinearLayoutManager mLayout = new LinearLayoutManager(getContext());
memoryRecyclerView.setHasFixedSize(true);
mLayout.setReverseLayout(true);
mLayout.setStackFromEnd(true);
memoryRecyclerView.setLayoutManager(mLayout);
memoryRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
Boolean reachedBottom = !recyclerView.canScrollVertically(1);
if(reachedBottom){
Toast.makeText(getContext(),"You have viewed all the memories.",Toast.LENGTH_SHORT).show();
}
}
});
mRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()){
for (DataSnapshot data : dataSnapshot.getChildren()){
String memoryId = data.getKey();
Memory memory = data.getValue(Memory.class).withId(memoryId);
listData.add(memory);
}
adapter = new MyAdapter(listData);
memoryRecyclerView.setAdapter(adapter);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getContext(),databaseError.getMessage(),Toast.LENGTH_SHORT).show();
}
});
return root;
}
}