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

@@ -0,0 +1,5 @@
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,6 +169,16 @@ public class HomeFragment extends Fragment {
169 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 182
     public void loadFavourites()
173 183
     {
174 184
         List<UserFavouriteStopsDbo> favourites = STSBusiness.getFavouriteStops(getContext());
@@ -209,7 +219,7 @@ public class HomeFragment extends Fragment {
209 219
 
210 220
     public void loadSchedules()
211 221
     {
212
-        _swipeRefreshLayout.setRefreshing(true);
222
+        setRefreshing(true);
213 223
         _adapter.setSchedules(null);
214 224
         TimeZone tz = TimeZone.getDefault();
215 225
         DateTimeZone dtz = DateTimeZone.forOffsetMillis(tz.getRawOffset() + (tz.inDaylightTime(new Date()) ? tz.getDSTSavings() : 0));
@@ -220,13 +230,13 @@ public class HomeFragment extends Fragment {
220 230
                     @Override
221 231
                     public void execute(List<SchedulesDbo> data) {
222 232
                         _adapter.setSchedules(data);
223
-                        _swipeRefreshLayout.setRefreshing(false);
233
+                        setRefreshing(false);
224 234
                     }
225 235
                 }, new LuConsumer<LuPromiseError>() {
226 236
                     @Override
227 237
                     public void execute(LuPromiseError data) {
228 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,10 +1,12 @@
1 1
 package com.rthoni.stssaguenay.ui.fragments;
2 2
 
3
+import android.app.Activity;
3 4
 import android.app.ProgressDialog;
4 5
 import android.graphics.Color;
5 6
 import android.os.Bundle;
6 7
 import android.support.annotation.Nullable;
7 8
 import android.support.v4.app.Fragment;
9
+import android.support.v4.widget.SwipeRefreshLayout;
8 10
 import android.support.v7.widget.LinearLayoutManager;
9 11
 import android.support.v7.widget.RecyclerView;
10 12
 import android.view.LayoutInflater;
@@ -49,6 +51,9 @@ public class StopViewerFragment extends Fragment {
49 51
     @BindView(R.id.listRoutes)
50 52
     RecyclerView _listRoutes;
51 53
 
54
+    @BindView(R.id.swipeContainer)
55
+    SwipeRefreshLayout _swipeRefreshLayout;
56
+
52 57
     private StopsDbo _stopsDbo;
53 58
 
54 59
     private RoutesAdapter _adapter;
@@ -113,7 +118,7 @@ public class StopViewerFragment extends Fragment {
113 118
                 holder._textView2.setText(text.toString());
114 119
             }
115 120
             else {
116
-                holder._textView2.setText("");
121
+                holder._textView2.setText(R.string.loading_schedules);
117 122
             }
118 123
         }
119 124
 
@@ -149,11 +154,28 @@ public class StopViewerFragment extends Fragment {
149 154
         _listRoutes.setAdapter(_adapter);
150 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 164
         loadRoutesAndSchedules();
153 165
 
154 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 179
     public void loadRoutesAndSchedules()
158 180
     {
159 181
         final ProgressDialog progressDialog = new ProgressDialog(getContext());
@@ -184,12 +206,8 @@ public class StopViewerFragment extends Fragment {
184 206
 
185 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 212
         UserFavouriteStopsDbo favouriteStopsDbo = new UserFavouriteStopsDbo();
195 213
         favouriteStopsDbo.setStop(_stopsDbo);
@@ -205,13 +223,13 @@ public class StopViewerFragment extends Fragment {
205 223
                 .then(new LuConsumer<List<SchedulesDbo>>() {
206 224
                     @Override
207 225
                     public void execute(List<SchedulesDbo> data) {
208
-                        progressDialog.dismiss();
226
+                        setRefreshing(false);
209 227
                         _adapter.setSchedules(data);
210 228
                     }
211 229
                 }, new LuConsumer<LuPromiseError>() {
212 230
                     @Override
213 231
                     public void execute(LuPromiseError data) {
214
-                        progressDialog.dismiss();
232
+                        setRefreshing(false);
215 233
 //                        _routesAdapter.setRoutes(new Vector<RoutesDbo>()); TODO
216 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,5 +1,6 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+                xmlns:tools="http://schemas.android.com/tools"
3 4
                 android:layout_width="match_parent"
4 5
                 android:layout_height="match_parent">
5 6
 
@@ -7,8 +8,8 @@
7 8
         android:layout_width="wrap_content"
8 9
         android:layout_height="wrap_content"
9 10
         android:textAppearance="?android:attr/textAppearanceLarge"
10
-        android:text="@string/favourites_stops"
11 11
         android:id="@+id/textView"
12
+        android:text="@string/favourites_stops"
12 13
         android:layout_alignParentTop="true"
13 14
         android:layout_alignParentLeft="true"
14 15
         android:layout_alignParentStart="true"
@@ -30,7 +31,9 @@
30 31
         <android.support.v7.widget.RecyclerView
31 32
             android:layout_width="wrap_content"
32 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 38
     </android.support.v4.widget.SwipeRefreshLayout>
36 39
 </RelativeLayout>

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

@@ -1,22 +1,39 @@
1 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 7
     <TextView
9 8
         android:layout_width="match_parent"
10 9
         android:layout_height="wrap_content"
10
+        android:textAppearance="?android:attr/textAppearanceLarge"
11 11
         android:id="@+id/textView"
12
-        android:textAppearance="?android:attr/textAppearanceMedium"
13 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 22
         android:layout_width="match_parent"
18 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,6 +4,7 @@
4 4
 
5 5
     <string name="app_name">Saguenay Transit</string>
6 6
 
7
+    <string name="title_activity_main">Saguenay Transit</string>
7 8
     <string name="title_activity_stop_picker">Pick a stop - Saguenay Transit</string>
8 9
     <string name="favourites_stops">Favourites stops:</string>
9 10
     <string name="search_stop">Search a stop</string>

+ 1
- 1
build.gradle View File

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

Loading…
Cancel
Save