20
20
import android .widget .Toast ;
21
21
import com .eusecom .attendance .Constants ;
22
22
import com .eusecom .attendance .FbmessClient ;
23
- import com .eusecom .attendance .PostsFragment ;
24
23
import com .eusecom .attendance .SettingsActivity ;
25
24
import com .eusecom .attendance .animators .BaseItemAnimator ;
26
25
import com .eusecom .attendance .animators .FadeInAnimator ;
38
37
import com .eusecom .attendance .retrofit .RfUser ;
39
38
import com .eusecom .attendance .rxbus .RxBus ;
40
39
import com .eusecom .attendance .rxfirebase2 .database .RxFirebaseDatabase ;
41
- import com .eusecom .attendance .rxfirebase2models .BlogPostEntity ;
42
40
import com .google .firebase .auth .FirebaseAuth ;
43
41
import com .google .firebase .database .DataSnapshot ;
44
42
import com .google .firebase .database .DatabaseError ;
57
55
import java .util .Date ;
58
56
import java .util .List ;
59
57
import java .util .concurrent .TimeUnit ;
60
-
61
58
import io .reactivex .Observable ;
62
59
import io .reactivex .android .schedulers .AndroidSchedulers ;
63
60
import io .reactivex .disposables .CompositeDisposable ;
69
66
import rx .Subscription ;
70
67
import static android .text .TextUtils .isEmpty ;
71
68
72
- public abstract class ApproveListFragment extends Fragment {
69
+ public class ApproveListFragment extends Fragment {
73
70
74
71
private static final String TAG = "ApproveListFragment" ;
75
72
@@ -132,14 +129,10 @@ public void onCreate(Bundle savedInstanceState) {
132
129
if (event instanceof ApproveListFragment .TapEvent ) {
133
130
///_showTapText();
134
131
}
135
- if (event instanceof BlogPostEntity ) {
136
- //saveAbsServer(((Attendance) event).daod + " / " + ((Attendance) event).dado, ((Attendance) event));
137
- String keys = ((BlogPostEntity ) event ).getAuthor ();
138
-
139
- //showProgress(true);
140
- Log .d ("In FRGM shortClick" , keys );
141
- BlogPostEntity postx = new BlogPostEntity (null , null , null );
142
- //delBlogPostRx(postx,1, keys);
132
+ if (event instanceof Attendance ) {
133
+ String keys = ((Attendance ) event ).getRok ();
134
+ Log .d ("In FRGM longClick" , keys );
135
+ getApproveDialog ( keys , (Attendance ) event );
143
136
144
137
}
145
138
}));
@@ -182,7 +175,7 @@ public View onCreateView (LayoutInflater inflater, ViewGroup container,
182
175
public void onActivityCreated (Bundle savedInstanceState ) {
183
176
super .onActivityCreated (savedInstanceState );
184
177
185
- mAdapter = new ApproveRxAdapter (Collections .<BlogPostEntity >emptyList (), _rxBus );
178
+ mAdapter = new ApproveRxAdapter (Collections .<Attendance >emptyList (), _rxBus );
186
179
getApproveSubscriber = new ApproveListFragment .GetApproveSubscriber ();
187
180
188
181
DatabaseReference gettimestramp = FirebaseDatabase .getInstance ().getReference ("gettimestamp" );
@@ -204,11 +197,6 @@ public void onCancelled(DatabaseError databaseError) { }
204
197
mManager .setReverseLayout (true );
205
198
mManager .setStackFromEnd (true );
206
199
mRecycler .setLayoutManager (mManager );
207
-
208
- // Set up FirebaseRecyclerAdapter with the Query
209
- Query absencesQuery = getQuery (mDatabase );
210
-
211
-
212
200
mRecycler .setAdapter (mAdapter );
213
201
mRecycler .setItemAnimator (new FadeInRightAnimator ());
214
202
mRecycler .getItemAnimator ().setAddDuration (300 );
@@ -222,13 +210,18 @@ public void onCancelled(DatabaseError databaseError) { }
222
210
223
211
private void loadAbsencesForApproving () {
224
212
225
- Query fbQuery = firebaseRef .child ("fireblog" );
213
+ final String companyIco = SettingsActivity .getUsIco (getActivity ());
214
+ Query recentAbsencesQuery = firebaseRef .child ("company-absences" ).child (companyIco ).orderByChild ("aprv" ).equalTo ("0" )
215
+ .limitToFirst (200 );
216
+
226
217
//showProgress(true);
227
- RxFirebaseDatabase .getInstance ().observeValueEvent (fbQuery ).subscribe (getApproveSubscriber );
218
+ showfProgressDialog ();
219
+ RxFirebaseDatabase .getInstance ().observeValueEvent (recentAbsencesQuery ).subscribe (getApproveSubscriber );
228
220
}
229
221
230
- private void renderApproveList (List <BlogPostEntity > blogPostEntities ) {
222
+ private void renderApproveList (List <Attendance > blogPostEntities ) {
231
223
//showProgress(false);
224
+ hidefProgressDialog ();
232
225
mAdapter .setData (blogPostEntities );
233
226
//Log.d("blogPostEntities", blogPostEntities.get(0).getTitle());
234
227
//Log.d("blogPostEntities", blogPostEntities.get(1).getTitle());
@@ -244,15 +237,17 @@ public void onDestroy() {
244
237
subscription .unsubscribe ();
245
238
}
246
239
_disposables .dispose ();
240
+ if (getApproveSubscriber != null && !getApproveSubscriber .isUnsubscribed ()) {
241
+ getApproveSubscriber .unsubscribe ();
242
+ }
243
+
247
244
}
248
245
249
246
public String getUid () {
250
247
return FirebaseAuth .getInstance ().getCurrentUser ().getUid ();
251
248
}
252
249
253
250
254
- public abstract Query getQuery (DatabaseReference databaseReference );
255
-
256
251
// [START deletefan_out]
257
252
private void approveAbsenceToServer (String postkey , int anodaj , Attendance model ) {
258
253
@@ -324,7 +319,7 @@ public void onNext(Pair pair) {
324
319
}
325
320
// [END delete_fan_out]
326
321
327
- private void getDialog (String postkey , Attendance model ) {
322
+ private void getApproveDialog (String postkey , Attendance model ) {
328
323
329
324
//if savetofir > 0 then save to server
330
325
String savetofir = SettingsActivity .getFir (getActivity ());
@@ -335,7 +330,7 @@ private void getDialog(String postkey, Attendance model) {
335
330
dialog .setContentView (R .layout .approve_dialog );
336
331
dialog .setTitle (R .string .item );
337
332
// set the custom dialog components - text, image and button
338
- String textx = getString (R .string .item ) + " " + abskeydel ;
333
+ String textx = getString (R .string .item ) + " " + postkey ;
339
334
TextView text = (TextView ) dialog .findViewById (R .id .text );
340
335
text .setText (textx );
341
336
ImageView image = (ImageView ) dialog .findViewById (R .id .image );
@@ -534,31 +529,32 @@ public void onNext(Message message) {
534
529
private final class GetApproveSubscriber extends Subscriber <DataSnapshot > {
535
530
@ Override public void onCompleted () {
536
531
//showProgress(false);
537
- //getPostsSubscriber.unsubscribe();
532
+ hidefProgressDialog ();
533
+ getApproveSubscriber .unsubscribe ();
538
534
}
539
535
540
536
@ Override public void onError (Throwable e ) {
541
537
//showProgress(false);
542
538
//showError(e.getMessage());
543
- //getPostsSubscriber.unsubscribe();
539
+ hidefProgressDialog ();
540
+ getApproveSubscriber .unsubscribe ();
544
541
}
545
542
546
543
@ SuppressWarnings ("unchecked" ) @ Override public void onNext (DataSnapshot dataSnapshot ) {
547
- List <BlogPostEntity > blogPostEntities = new ArrayList <>();
544
+ List <Attendance > blogPostEntities = new ArrayList <>();
548
545
for (DataSnapshot childDataSnapshot : dataSnapshot .getChildren ()) {
549
546
String keys = childDataSnapshot .getKey ();
550
547
Log .d ("keys " , keys );
551
- BlogPostEntity resultx = childDataSnapshot .getValue (BlogPostEntity .class );
552
- resultx .setAuthor (keys );
548
+ Attendance resultx = childDataSnapshot .getValue (Attendance .class );
549
+ resultx .setRok (keys );
553
550
blogPostEntities .add (resultx );
554
551
}
555
552
renderApproveList (blogPostEntities );
556
553
557
554
}
558
- }//end of GetPostsSubscriber
555
+ }//end of getApproveSubscriber
559
556
560
557
public static class TapEvent {}
561
558
562
559
563
-
564
560
}
0 commit comments