| 
				
			 | 
			
			
				
				@@ -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
			 | 
			
			
				
				                     } 
			 |