1
1
package mavonie .subterminal ;
2
2
3
- import android .content .Context ;
4
3
import android .os .Bundle ;
4
+ import android .support .annotation .NonNull ;
5
5
import android .support .v7 .widget .LinearLayoutManager ;
6
6
import android .support .v7 .widget .RecyclerView ;
7
7
import android .view .LayoutInflater ;
8
8
import android .view .View ;
9
9
import android .view .ViewGroup ;
10
10
11
- import java .util .HashMap ;
12
-
13
11
import mavonie .subterminal .Models .Model ;
14
12
import mavonie .subterminal .Models .Synchronizable ;
15
13
import mavonie .subterminal .Utils .BaseFragment ;
14
+ import mavonie .subterminal .Utils .DB .Query ;
16
15
import mavonie .subterminal .ViewAdapters .ExitRecycler ;
17
16
18
17
/**
@@ -25,47 +24,32 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
25
24
Bundle savedInstanceState ) {
26
25
View view = inflater .inflate (R .layout .fragment_exit_list , container , false );
27
26
28
- // Set the adapter
29
- if (view instanceof RecyclerView ) {
30
- Context context = view .getContext ();
31
-
32
- RecyclerView recyclerView = (RecyclerView ) view ;
33
- recyclerView .setLayoutManager (new LinearLayoutManager (context ));
34
-
35
- HashMap <String , Object > params = new HashMap <>();
36
-
37
- params .put (Model .FILTER_ORDER_DIR , Model .FILTER_ORDER_DIR_ASC );
38
- params .put (Model .FILTER_ORDER_FIELD , mavonie .subterminal .Models .Exit .COLUMN_NAME_NAME );
39
-
40
- HashMap <String , Object > whereNotDeleted = new HashMap <>();
41
- whereNotDeleted .put (Model .FILTER_WHERE_FIELD , Synchronizable .COLUMN_DELETED );
42
- whereNotDeleted .put (Model .FILTER_WHERE_VALUE , Synchronizable .DELETED_FALSE .toString ());
43
-
44
- HashMap <Integer , HashMap > wheres = new HashMap <>();
45
- wheres .put (wheres .size (), whereNotDeleted );
27
+ RecyclerView recyclerView = (RecyclerView ) view ;
28
+ recyclerView .setLayoutManager (new LinearLayoutManager (view .getContext ()));
29
+ recyclerView .setAdapter (new ExitRecycler (new mavonie .subterminal .Models .Exit ().getItems (getQuery ().getParams ()), getmListener ()));
46
30
47
- params .put (Model .FILTER_WHERE , wheres );
48
-
49
- if (getArguments () != null && getArguments ().getInt (Exit .TAB ) == Exit .TAB_MY_EXITS ) {
50
-
51
- HashMap <String , Object > whereGlobalIdNull = new HashMap <>();
52
- whereGlobalIdNull .put (Model .FILTER_WHERE_FIELD , mavonie .subterminal .Models .Exit .COLUMN_NAME_GLOBAL_ID );
53
- whereGlobalIdNull .put (Model .FILTER_WHERE_VALUE , null );
31
+ return view ;
32
+ }
54
33
55
- wheres .put (wheres .size (), whereGlobalIdNull );
56
- }
34
+ @ NonNull
35
+ private Query getQuery () {
36
+ Query query = new Query ();
37
+ query .orderDir (mavonie .subterminal .Models .Exit .COLUMN_NAME_NAME , Model .FILTER_ORDER_DIR_ASC );
38
+ query .getParams ().putAll (Synchronizable .getActiveParams ());
57
39
58
- recyclerView .setAdapter (new ExitRecycler (new mavonie .subterminal .Models .Exit ().getItems (params ), getmListener ()));
40
+ if (getArguments () != null && getArguments ().getInt (Exit .TAB ) == Exit .TAB_MY_EXITS ) {
41
+ query .addWhere (mavonie .subterminal .Models .Exit .COLUMN_NAME_GLOBAL_ID , null );
59
42
}
60
- return view ;
43
+
44
+ return query ;
61
45
}
62
46
63
47
@ Override
64
48
public void onResume () {
65
49
super .onResume ();
66
50
67
51
// Set title
68
- String title = getString (R .string .title_exit ) + " (" + new mavonie .subterminal .Models .Exit ().count (Synchronizable . getActiveParams ()) + ")" ;
52
+ String title = getString (R .string .title_exit ) + " (" + new mavonie .subterminal .Models .Exit ().count (getQuery (). getParams ()) + ")" ;
69
53
MainActivity .getActivity ().setTitle (title );
70
54
}
71
55
0 commit comments