forked from kev5/GoMeet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
199 lines (177 loc) · 7.85 KB
/
MainActivity.java
File metadata and controls
199 lines (177 loc) · 7.85 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package com.example.meetgo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
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.lorentzos.flingswipe.SwipeFlingAdapterView;
import java.util.ArrayList;
import static android.content.ContentValues.TAG;
public class MainActivity extends AppCompatActivity {
public writeToFireBase mWrite = new writeToFireBase();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
private ArrayList<Post> postsToWrite;
Post post01 = new Post("this is the very first post!\n",user.getUid());
Post post02 = new Post("this is the second post!\n",user.getUid());
Post post03 = new Post("this is the third post!\n",user.getUid());
Post post04 = new Post("this is the fourth post!\n",user.getUid());
Post post05 = new Post("this is the fifth post!\n",user.getUid());
Post post06 = new Post("this is the sixth post!\n",user.getUid());
private ArrayList<String> al;
private ArrayList<Post> postArray;
private ArrayAdapter<String> arrayAdapter;
private int i;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWrite.writePosts("1",post01);
mWrite.writePosts("2",post02);
mWrite.writePosts("3",post03);
mWrite.writePosts("4",post04);
mWrite.writePosts("5",post05);
mWrite.writePosts("6",post06);
al = new ArrayList<>();
al.add(post01.getPostText());
// al.add(post02.getPostText());
// al.add(post03.getPostText());
// al.add(post04.getPostText());
// al.add(post05.getPostText());
// al.add(post06.getPostText());
ValueEventListener postListener01;
DatabaseReference ref01 = FirebaseDatabase.getInstance().getReference("posts").child("01").child("postText");
postListener01 = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post text
String str = dataSnapshot.getValue(String.class);
al.add(str);
// ...
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
ref01.addValueEventListener(postListener01);
ValueEventListener postListener02;
DatabaseReference ref02 = FirebaseDatabase.getInstance().getReference("posts").child("02").child("postText");
postListener02 = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post text
String str = dataSnapshot.getValue(String.class);
al.add(str);
// ...
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
ref02.addValueEventListener(postListener02);
//
// ArrayList<ValueEventListener> postListenerList;
// postListenerList = new ArrayList<ValueEventListener>();
// ArrayList<DatabaseReference> refList;
// refList = new ArrayList<DatabaseReference>();
// for (int j=0;j<6;j++){
// refList.set(j,(FirebaseDatabase.getInstance().getReference("posts").child("0"+j).child("postText")));
// postListenerList.set(j, new ValueEventListener() {
// @Override
// public void onDataChange(DataSnapshot dataSnapshot) {
// // Get Post text
// String str = dataSnapshot.getValue(String.class);
// al.add(str);
// // ...
// }
// @Override
// public void onCancelled(DatabaseError databaseError) {
// // Getting Post failed, log a message
// Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// // ...
// }
// });
//
// refList.get(j).addValueEventListener(postListenerList.get(j));
// }
// readFromFireBase mRead = new readFromFireBase("1");
// al.add(mRead.readPostText());
// readFromFireBase mRead;
// for(int j=0; j<6; j++){
// DatabaseReference ref = FirebaseDatabase.getInstance().getReference("posts").child(""+j);
// postListener = new ValueEventListener() {
// @Override
// public void onDataChange(DataSnapshot dataSnapshot) {
// // Get Post Text
// String str = dataSnapshot.getValue(String.class);
// al.add(str);
// // ...
// }
// @Override
// public void onCancelled(DatabaseError databaseError) {
// // Getting Post failed, log a message
// Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// // ...
// }
// };
// ref.addValueEventListener(postListener);
// }
arrayAdapter = new ArrayAdapter<>(this, R.layout.item, R.id.helloText, al );
SwipeFlingAdapterView flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
flingContainer.setAdapter(arrayAdapter);
flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
@Override
public void removeFirstObjectInAdapter() {
// this is the simplest way to delete an object from the Adapter (/AdapterView)
Log.d("LIST", "removed object!");
al.remove(0);
arrayAdapter.notifyDataSetChanged();
}
@Override
public void onLeftCardExit(Object dataObject) {
//Do something on the left!
//You also have access to the original object.
//If you want to use it just cast it (String) dataObject
Toast.makeText(MainActivity.this, "Nope" , Toast.LENGTH_SHORT).show();
mWrite.dislikePost("01");
}
@Override
public void onRightCardExit(Object dataObject) {
Toast.makeText(MainActivity.this, "Like!", Toast.LENGTH_SHORT).show();
mWrite.likePost("01");
}
@Override
public void onAdapterAboutToEmpty(int itemsInAdapter) {
// Ask for more data here
al.add("XML ".concat(String.valueOf(i)));
arrayAdapter.notifyDataSetChanged();
Log.d("LIST", "notified");
i++;
}
@Override
public void onScroll(float scrollProgressPercent) {
}
});
// Optionally add an OnItemClickListener
flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() {
@Override
public void onItemClicked(int itemPosition, Object dataObject) {
Toast.makeText(MainActivity.this, "Click!", Toast.LENGTH_SHORT).show();
}
});
}
}