Browse Source

fixed swipe refresh

develop
Robin Thoni 8 years ago
parent
commit
7140b86a19

+ 5
- 0
app/src/demo/res/values/config.xml View File

1
+<?xml version="1.0" encoding="utf-8"?>
2
+<resources>
3
+    <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
4
+    <string name="app_name">demo - Saguenay Transit</string>
5
+</resources>

+ 13
- 3
app/src/main/java/com/rthoni/stssaguenay/ui/fragments/HomeFragment.java View File

169
         return v;
169
         return v;
170
     }
170
     }
171
 
171
 
172
+    public void setRefreshing(final boolean refreshing)
173
+    {
174
+        _swipeRefreshLayout.post(new Runnable() {
175
+            @Override
176
+            public void run() {
177
+                _swipeRefreshLayout.setRefreshing(refreshing);
178
+            }
179
+        });
180
+    }
181
+
172
     public void loadFavourites()
182
     public void loadFavourites()
173
     {
183
     {
174
         List<UserFavouriteStopsDbo> favourites = STSBusiness.getFavouriteStops(getContext());
184
         List<UserFavouriteStopsDbo> favourites = STSBusiness.getFavouriteStops(getContext());
209
 
219
 
210
     public void loadSchedules()
220
     public void loadSchedules()
211
     {
221
     {
212
-        _swipeRefreshLayout.setRefreshing(true);
222
+        setRefreshing(true);
213
         _adapter.setSchedules(null);
223
         _adapter.setSchedules(null);
214
         TimeZone tz = TimeZone.getDefault();
224
         TimeZone tz = TimeZone.getDefault();
215
         DateTimeZone dtz = DateTimeZone.forOffsetMillis(tz.getRawOffset() + (tz.inDaylightTime(new Date()) ? tz.getDSTSavings() : 0));
225
         DateTimeZone dtz = DateTimeZone.forOffsetMillis(tz.getRawOffset() + (tz.inDaylightTime(new Date()) ? tz.getDSTSavings() : 0));
220
                     @Override
230
                     @Override
221
                     public void execute(List<SchedulesDbo> data) {
231
                     public void execute(List<SchedulesDbo> data) {
222
                         _adapter.setSchedules(data);
232
                         _adapter.setSchedules(data);
223
-                        _swipeRefreshLayout.setRefreshing(false);
233
+                        setRefreshing(false);
224
                     }
234
                     }
225
                 }, new LuConsumer<LuPromiseError>() {
235
                 }, new LuConsumer<LuPromiseError>() {
226
                     @Override
236
                     @Override
227
                     public void execute(LuPromiseError data) {
237
                     public void execute(LuPromiseError data) {
228
                         Toast.makeText(getContext(), data.getError(), Toast.LENGTH_LONG).show();
238
                         Toast.makeText(getContext(), data.getError(), Toast.LENGTH_LONG).show();
229
-                        _swipeRefreshLayout.setRefreshing(false);
239
+                        setRefreshing(false);
230
                     }
240
                     }
231
                 });
241
                 });
232
     }
242
     }

+ 27
- 9
app/src/main/java/com/rthoni/stssaguenay/ui/fragments/StopViewerFragment.java View File

1
 package com.rthoni.stssaguenay.ui.fragments;
1
 package com.rthoni.stssaguenay.ui.fragments;
2
 
2
 
3
+import android.app.Activity;
3
 import android.app.ProgressDialog;
4
 import android.app.ProgressDialog;
4
 import android.graphics.Color;
5
 import android.graphics.Color;
5
 import android.os.Bundle;
6
 import android.os.Bundle;
6
 import android.support.annotation.Nullable;
7
 import android.support.annotation.Nullable;
7
 import android.support.v4.app.Fragment;
8
 import android.support.v4.app.Fragment;
9
+import android.support.v4.widget.SwipeRefreshLayout;
8
 import android.support.v7.widget.LinearLayoutManager;
10
 import android.support.v7.widget.LinearLayoutManager;
9
 import android.support.v7.widget.RecyclerView;
11
 import android.support.v7.widget.RecyclerView;
10
 import android.view.LayoutInflater;
12
 import android.view.LayoutInflater;
49
     @BindView(R.id.listRoutes)
51
     @BindView(R.id.listRoutes)
50
     RecyclerView _listRoutes;
52
     RecyclerView _listRoutes;
51
 
53
 
54
+    @BindView(R.id.swipeContainer)
55
+    SwipeRefreshLayout _swipeRefreshLayout;
56
+
52
     private StopsDbo _stopsDbo;
57
     private StopsDbo _stopsDbo;
53
 
58
 
54
     private RoutesAdapter _adapter;
59
     private RoutesAdapter _adapter;
113
                 holder._textView2.setText(text.toString());
118
                 holder._textView2.setText(text.toString());
114
             }
119
             }
115
             else {
120
             else {
116
-                holder._textView2.setText("");
121
+                holder._textView2.setText(R.string.loading_schedules);
117
             }
122
             }
118
         }
123
         }
119
 
124
 
149
         _listRoutes.setAdapter(_adapter);
154
         _listRoutes.setAdapter(_adapter);
150
         _listRoutes.setLayoutManager(new LinearLayoutManager(getContext()));
155
         _listRoutes.setLayoutManager(new LinearLayoutManager(getContext()));
151
 
156
 
157
+        _swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
158
+            @Override
159
+            public void onRefresh() {
160
+                loadSchedules();
161
+            }
162
+        });
163
+
152
         loadRoutesAndSchedules();
164
         loadRoutesAndSchedules();
153
 
165
 
154
         return v;
166
         return v;
155
     }
167
     }
156
 
168
 
169
+    public void setRefreshing(final boolean refreshing)
170
+    {
171
+        _swipeRefreshLayout.post(new Runnable() {
172
+            @Override
173
+            public void run() {
174
+                _swipeRefreshLayout.setRefreshing(refreshing);
175
+            }
176
+        });
177
+    }
178
+
157
     public void loadRoutesAndSchedules()
179
     public void loadRoutesAndSchedules()
158
     {
180
     {
159
         final ProgressDialog progressDialog = new ProgressDialog(getContext());
181
         final ProgressDialog progressDialog = new ProgressDialog(getContext());
184
 
206
 
185
     public void loadSchedules()
207
     public void loadSchedules()
186
     {
208
     {
187
-        final ProgressDialog progressDialog = new ProgressDialog(getContext());
188
-        progressDialog.setIndeterminate(true);
189
-        progressDialog.setCancelable(false);
190
-        progressDialog.show();
191
-        progressDialog.setTitle(R.string.loading);
192
-        progressDialog.setMessage(getString(R.string.loading_schedules));
209
+        setRefreshing(true);
210
+        _adapter.setSchedules(null);
193
 
211
 
194
         UserFavouriteStopsDbo favouriteStopsDbo = new UserFavouriteStopsDbo();
212
         UserFavouriteStopsDbo favouriteStopsDbo = new UserFavouriteStopsDbo();
195
         favouriteStopsDbo.setStop(_stopsDbo);
213
         favouriteStopsDbo.setStop(_stopsDbo);
205
                 .then(new LuConsumer<List<SchedulesDbo>>() {
223
                 .then(new LuConsumer<List<SchedulesDbo>>() {
206
                     @Override
224
                     @Override
207
                     public void execute(List<SchedulesDbo> data) {
225
                     public void execute(List<SchedulesDbo> data) {
208
-                        progressDialog.dismiss();
226
+                        setRefreshing(false);
209
                         _adapter.setSchedules(data);
227
                         _adapter.setSchedules(data);
210
                     }
228
                     }
211
                 }, new LuConsumer<LuPromiseError>() {
229
                 }, new LuConsumer<LuPromiseError>() {
212
                     @Override
230
                     @Override
213
                     public void execute(LuPromiseError data) {
231
                     public void execute(LuPromiseError data) {
214
-                        progressDialog.dismiss();
232
+                        setRefreshing(false);
215
 //                        _routesAdapter.setRoutes(new Vector<RoutesDbo>()); TODO
233
 //                        _routesAdapter.setRoutes(new Vector<RoutesDbo>()); TODO
216
                         Toast.makeText(getContext(), data.getError(), Toast.LENGTH_LONG).show();
234
                         Toast.makeText(getContext(), data.getError(), Toast.LENGTH_LONG).show();
217
                     }
235
                     }

+ 5
- 2
app/src/main/res/layout/fragment_home.xml View File

1
 <?xml version="1.0" encoding="utf-8"?>
1
 <?xml version="1.0" encoding="utf-8"?>
2
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+                xmlns:tools="http://schemas.android.com/tools"
3
                 android:layout_width="match_parent"
4
                 android:layout_width="match_parent"
4
                 android:layout_height="match_parent">
5
                 android:layout_height="match_parent">
5
 
6
 
7
         android:layout_width="wrap_content"
8
         android:layout_width="wrap_content"
8
         android:layout_height="wrap_content"
9
         android:layout_height="wrap_content"
9
         android:textAppearance="?android:attr/textAppearanceLarge"
10
         android:textAppearance="?android:attr/textAppearanceLarge"
10
-        android:text="@string/favourites_stops"
11
         android:id="@+id/textView"
11
         android:id="@+id/textView"
12
+        android:text="@string/favourites_stops"
12
         android:layout_alignParentTop="true"
13
         android:layout_alignParentTop="true"
13
         android:layout_alignParentLeft="true"
14
         android:layout_alignParentLeft="true"
14
         android:layout_alignParentStart="true"
15
         android:layout_alignParentStart="true"
30
         <android.support.v7.widget.RecyclerView
31
         <android.support.v7.widget.RecyclerView
31
             android:layout_width="wrap_content"
32
             android:layout_width="wrap_content"
32
             android:layout_height="wrap_content"
33
             android:layout_height="wrap_content"
33
-            android:id="@+id/listFavouritesStops"/>
34
+            android:id="@+id/listFavouritesStops"
35
+            android:scrollbars="vertical"
36
+            android:fadeScrollbars="true"/>
34
 
37
 
35
     </android.support.v4.widget.SwipeRefreshLayout>
38
     </android.support.v4.widget.SwipeRefreshLayout>
36
 </RelativeLayout>
39
 </RelativeLayout>

+ 29
- 12
app/src/main/res/layout/fragment_stop_viewer.xml View File

1
 <?xml version="1.0" encoding="utf-8"?>
1
 <?xml version="1.0" encoding="utf-8"?>
2
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
-              xmlns:tools="http://schemas.android.com/tools"
4
-              android:orientation="vertical"
5
-              android:layout_width="match_parent"
6
-              android:layout_height="match_parent">
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+                xmlns:tools="http://schemas.android.com/tools"
4
+                android:layout_width="match_parent"
5
+                android:layout_height="match_parent">
7
 
6
 
8
     <TextView
7
     <TextView
9
         android:layout_width="match_parent"
8
         android:layout_width="match_parent"
10
         android:layout_height="wrap_content"
9
         android:layout_height="wrap_content"
10
+        android:textAppearance="?android:attr/textAppearanceLarge"
11
         android:id="@+id/textView"
11
         android:id="@+id/textView"
12
-        android:textAppearance="?android:attr/textAppearanceMedium"
13
         tools:text="268 - Émile-Girardin / Roitelets"
12
         tools:text="268 - Émile-Girardin / Roitelets"
14
-        android:gravity="center_horizontal"/>
13
+        android:layout_alignParentTop="true"
14
+        android:layout_alignParentLeft="true"
15
+        android:layout_alignParentStart="true"
16
+        android:layout_alignParentRight="true"
17
+        android:layout_alignParentEnd="true"/>
15
 
18
 
16
-    <android.support.v7.widget.RecyclerView
19
+    <android.support.v4.widget.SwipeRefreshLayout
20
+        xmlns:android="http://schemas.android.com/apk/res/android"
21
+        android:id="@+id/swipeContainer"
17
         android:layout_width="match_parent"
22
         android:layout_width="match_parent"
18
         android:layout_height="match_parent"
23
         android:layout_height="match_parent"
19
-        android:id="@+id/listRoutes"
20
-        android:scrollbars="vertical"
21
-        android:fadeScrollbars="true"/>
22
-</LinearLayout>
24
+        android:layout_below="@+id/textView"
25
+        android:layout_alignParentLeft="true"
26
+        android:layout_alignParentStart="true"
27
+        android:layout_alignParentRight="true"
28
+        android:layout_alignParentEnd="true"
29
+        android:layout_alignParentBottom="true">
30
+
31
+        <android.support.v7.widget.RecyclerView
32
+            android:layout_width="wrap_content"
33
+            android:layout_height="wrap_content"
34
+            android:id="@+id/listRoutes"
35
+            android:scrollbars="vertical"
36
+            android:fadeScrollbars="true"/>
37
+
38
+    </android.support.v4.widget.SwipeRefreshLayout>
39
+</RelativeLayout>

+ 1
- 0
app/src/main/res/values/strings.xml View File

4
 
4
 
5
     <string name="app_name">Saguenay Transit</string>
5
     <string name="app_name">Saguenay Transit</string>
6
 
6
 
7
+    <string name="title_activity_main">Saguenay Transit</string>
7
     <string name="title_activity_stop_picker">Pick a stop - Saguenay Transit</string>
8
     <string name="title_activity_stop_picker">Pick a stop - Saguenay Transit</string>
8
     <string name="favourites_stops">Favourites stops:</string>
9
     <string name="favourites_stops">Favourites stops:</string>
9
     <string name="search_stop">Search a stop</string>
10
     <string name="search_stop">Search a stop</string>

+ 1
- 1
build.gradle View File

9
         }
9
         }
10
     }
10
     }
11
     dependencies {
11
     dependencies {
12
-        classpath 'com.android.tools.build:gradle:2.2.2'
12
+        classpath 'com.android.tools.build:gradle:2.2.3'
13
         classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
13
         classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
14
         classpath 'com.google.gms:google-services:3.0.0'
14
         classpath 'com.google.gms:google-services:3.0.0'
15
         classpath 'de.mobilej.unmock:UnMockPlugin:0.5.0'
15
         classpath 'de.mobilej.unmock:UnMockPlugin:0.5.0'

Loading…
Cancel
Save