Skip to content
This repository
Browse code

Refactor other fragments to use that nifty new method

Signed-off-by: Eddie Ringle <eddie@eringle.net>
  • Loading branch information...
commit 6607eaf785b6c7acada054fa4c0da800f7f52547 1 parent 80b59f2
Eddie Ringle authored April 25, 2012
234  src/net/idlesoft/android/apps/github/ui/fragments/EventsFragment.java
@@ -28,6 +28,9 @@
28 28
 import android.view.View;
29 29
 import android.view.ViewGroup;
30 30
 import android.widget.AdapterView;
  31
+import com.actionbarsherlock.view.Menu;
  32
+import com.actionbarsherlock.view.MenuInflater;
  33
+import com.actionbarsherlock.view.MenuItem;
31 34
 import com.viewpagerindicator.TitlePageIndicator;
32 35
 import net.idlesoft.android.apps.github.R;
33 36
 import net.idlesoft.android.apps.github.ui.adapters.EventListAdapter;
@@ -68,10 +71,9 @@
68 71
 	class EventsDataFragment extends DataFragment
69 72
 	{
70 73
 		ArrayList<ListHolder> eventLists;
  74
+		ListViewPager.MultiListPagerAdapter pagerAdapter;
71 75
 		User targetUser;
72 76
 		int currentItem;
73  
-		int currentItemScroll;
74  
-		int currentItemScrollTop;
75 77
 
76 78
 		public
77 79
 		int findListIndexByType(int listType)
@@ -182,7 +184,6 @@ void onItemClick(AdapterView<?> parent, View view, int position, long id)
182 184
 
183 185
 	ListViewPager mViewPager;
184 186
 	TitlePageIndicator mTitlePageIndicator;
185  
-	int mCurrentPage;
186 187
 
187 188
 	public
188 189
 	EventsFragment()
@@ -207,45 +208,26 @@ View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInst
207 208
 		return v;
208 209
 	}
209 210
 
210  
-	@Override
211 211
 	public
212  
-	void onActivityCreated(Bundle savedInstanceState)
  212
+	void fetchData(final boolean freshen)
213 213
 	{
214  
-		super.onActivityCreated(savedInstanceState);
215  
-
216  
-		final Bundle args = getArguments();
217  
-		final String userJson;
218  
-		if (args != null) {
219  
-			userJson = args.getString(ARG_TARGET_USER, null);
220  
-			if (userJson != null) {
221  
-				mDataFragment.targetUser = GsonUtils.fromJson(userJson, User.class);
222  
-			}
223  
-		}
224  
-		if (mDataFragment.targetUser == null) {
225  
-			mDataFragment.targetUser = new User();
226  
-			mDataFragment.targetUser.setLogin(getBaseActivity().getCurrentUserLogin());
227  
-		}
228  
-
229  
-		if (mDataFragment.eventLists == null)
230  
-			mDataFragment.eventLists = new ArrayList<ListHolder>();
231  
-
232  
-		ListViewPager.MultiListPagerAdapter adapter =
233  
-				new ListViewPager.MultiListPagerAdapter(getContext());
234  
-
235 214
 		if (mDataFragment.targetUser.getLogin().equals(getBaseActivity().getCurrentUserLogin())
236 215
 				&& !mDataFragment.targetUser.getLogin().equals("")) {
237 216
 			/* Display received events */
238  
-			final IdleList<Event> list = new IdleList<Event>(getContext());
  217
+			final IdleList<Event> list;
239 218
 			final ListHolder holder;
  219
+			final int index = mDataFragment.findListIndexByType(LIST_RECEIVED);
  220
+
  221
+			if (freshen && index >= 0)
  222
+				list = mViewPager.getAdapter().getList(index);
  223
+			else
  224
+				list = new IdleList<Event>(getContext());
240 225
 
241 226
 			list.setOnItemClickListener(new OnEventListItemClickListener());
242 227
 			list.setAdapter(new EventListAdapter(getBaseActivity()));
243 228
 
244  
-			final int index = mDataFragment.findListIndexByType(LIST_RECEIVED);
245  
-
246  
-			if (index >= 0) {
  229
+			if (index >= 0 && !freshen) {
247 230
 				holder = mDataFragment.eventLists.get(index);
248  
-
249 231
 				list.setTitle(holder.title);
250 232
 				list.getListAdapter().fillWithItems(holder.events);
251 233
 				list.getListAdapter().notifyDataSetChanged();
@@ -256,79 +238,81 @@ void onActivityCreated(Bundle savedInstanceState)
256 238
 				list.setTitle(holder.title);
257 239
 				holder.gravatars = new ArrayList<Bitmap>();
258 240
 				holder.events = new ArrayList<Event>();
259  
-
260 241
 				mDataFragment.eventLists.add(holder);
261 242
 
262 243
 				final DataFragment.DataTask.DataTaskRunnable receivedRunnable =
263 244
 						new DataFragment.DataTask.DataTaskRunnable()
264  
-				{
265  
-					@Override
266  
-					public
267  
-					void runTask() throws InterruptedException
268  
-					{
269  
-						try {
270  
-							final EventService es =
271  
-									new EventService(getBaseActivity().getGHClient());
272  
-							PageIterator<Event> itr =
273  
-									es.pageUserReceivedEvents(mDataFragment.targetUser.getLogin());
274  
-							holder.events.addAll(itr.next());
275  
-						} catch (IOException e) {
276  
-							e.printStackTrace();
277  
-						} catch (AccountsException e) {
278  
-							e.printStackTrace();
279  
-						}
280  
-					}
281  
-				};
  245
+						{
  246
+							@Override
  247
+							public
  248
+							void runTask() throws InterruptedException
  249
+							{
  250
+								try {
  251
+									final EventService es =
  252
+											new EventService(getBaseActivity().getGHClient());
  253
+									PageIterator<Event> itr =
  254
+											es.pageUserReceivedEvents(mDataFragment.targetUser.getLogin());
  255
+									holder.events.addAll(itr.next());
  256
+								} catch (IOException e) {
  257
+									e.printStackTrace();
  258
+								} catch (AccountsException e) {
  259
+									e.printStackTrace();
  260
+								}
  261
+							}
  262
+						};
282 263
 
283 264
 				final DataFragment.DataTask.DataTaskCallbacks receivedCallbacks =
284 265
 						new DataFragment.DataTask.DataTaskCallbacks()
285  
-				{
286  
-					@Override
287  
-					public
288  
-					void onTaskStart()
289  
-					{
290  
-						list.getProgressBar().setVisibility(View.VISIBLE);
291  
-						list.setFooterShown(true);
292  
-						list.setListShown(true);
293  
-					}
294  
-
295  
-					@Override
296  
-					public
297  
-					void onTaskCancelled()
298  
-					{
299  
-					}
300  
-
301  
-					@Override
302  
-					public
303  
-					void onTaskComplete()
304  
-					{
305  
-						list.setListShown(false);
306  
-						list.getListAdapter().fillWithItems(holder.events);
307  
-						list.getListAdapter().notifyDataSetChanged();
308  
-						list.getProgressBar().setVisibility(View.GONE);
309  
-						list.setListShown(true);
310  
-					}
311  
-				};
  266
+						{
  267
+							@Override
  268
+							public
  269
+							void onTaskStart()
  270
+							{
  271
+								list.getProgressBar().setVisibility(View.VISIBLE);
  272
+								list.setFooterShown(true);
  273
+								list.setListShown(true);
  274
+							}
  275
+
  276
+							@Override
  277
+							public
  278
+							void onTaskCancelled()
  279
+							{
  280
+							}
  281
+
  282
+							@Override
  283
+							public
  284
+							void onTaskComplete()
  285
+							{
  286
+								list.setListShown(false);
  287
+								list.getListAdapter().fillWithItems(holder.events);
  288
+								list.getListAdapter().notifyDataSetChanged();
  289
+								list.getProgressBar().setVisibility(View.GONE);
  290
+								list.setListShown(true);
  291
+							}
  292
+						};
312 293
 
313 294
 				mDataFragment.executeNewTask(receivedRunnable, receivedCallbacks);
  295
+				if (index < 0)
  296
+					mViewPager.getAdapter().addList(list);
314 297
 			}
315  
-
316  
-			adapter.addList(list);
317 298
 		}
318 299
 
319 300
 		if (!mDataFragment.targetUser.getLogin().equals("")) {
320 301
 			/* Display a user's public events */
321  
-			final IdleList<Event> list = new IdleList<Event>(getContext());
  302
+			final IdleList<Event> list;
322 303
 			final ListHolder holder;
  304
+			final int index = mDataFragment.findListIndexByType(LIST_PUBLIC);
  305
+
  306
+			if (freshen && index >= 0)
  307
+				list = mViewPager.getAdapter().getList(index);
  308
+			else
  309
+				list = new IdleList<Event>(getContext());
323 310
 
324 311
 			list.setOnItemClickListener(new OnEventListItemClickListener());
325 312
 			list.setAdapter(new EventListAdapter(getBaseActivity()));
326 313
 
327  
-			final int index = mDataFragment.findListIndexByType(LIST_PUBLIC);
328  
-
329  
-			if (index >= 0) {
  314
+			if (index >= 0 && !freshen) {
330 315
 				holder = mDataFragment.eventLists.get(index);
331  
-
332 316
 				list.setTitle(holder.title);
333 317
 				list.getListAdapter().fillWithItems(holder.events);
334 318
 				list.getListAdapter().notifyDataSetChanged();
@@ -338,7 +322,6 @@ void onTaskComplete()
338 322
 				holder.title = getString(R.string.events_public);
339 323
 				list.setTitle(holder.title);
340 324
 				holder.events = new ArrayList<Event>();
341  
-
342 325
 				mDataFragment.eventLists.add(holder);
343 326
 
344 327
 				final DataFragment.DataTask.DataTaskRunnable publicRunnable =
@@ -393,24 +376,27 @@ void onTaskComplete()
393 376
 						};
394 377
 
395 378
 				mDataFragment.executeNewTask(publicRunnable, receivedCallbacks);
  379
+				if (index < 0)
  380
+					mViewPager.getAdapter().addList(list);
396 381
 			}
397  
-
398  
-			adapter.addList(list);
399 382
 		}
400 383
 
401 384
 		{
402 385
 			/* Display timeline events */
403  
-			final IdleList<Event> list = new IdleList<Event>(getContext());
  386
+			final IdleList<Event> list;
404 387
 			final ListHolder holder;
  388
+			final int index = mDataFragment.findListIndexByType(LIST_TIMELINE);
  389
+
  390
+			if (freshen && index >= 0)
  391
+				list = mViewPager.getAdapter().getList(index);
  392
+			else
  393
+				list = new IdleList<Event>(getContext());
405 394
 
406 395
 			list.setOnItemClickListener(new OnEventListItemClickListener());
407 396
 			list.setAdapter(new EventListAdapter(getBaseActivity()));
408 397
 
409  
-			final int index = mDataFragment.findListIndexByType(LIST_TIMELINE);
410  
-
411  
-			if (index >= 0) {
  398
+			if (index >= 0 && !freshen) {
412 399
 				holder = mDataFragment.eventLists.get(index);
413  
-
414 400
 				list.setTitle(holder.title);
415 401
 				list.getListAdapter().fillWithItems(holder.events);
416 402
 				list.getListAdapter().notifyDataSetChanged();
@@ -420,7 +406,6 @@ void onTaskComplete()
420 406
 				holder.title = getString(R.string.events_timeline);
421 407
 				list.setTitle(holder.title);
422 408
 				holder.events = new ArrayList<Event>();
423  
-
424 409
 				mDataFragment.eventLists.add(holder);
425 410
 
426 411
 				final DataFragment.DataTask.DataTaskRunnable publicRunnable =
@@ -475,13 +460,41 @@ void onTaskComplete()
475 460
 						};
476 461
 
477 462
 				mDataFragment.executeNewTask(publicRunnable, receivedCallbacks);
  463
+				if (index < 0)
  464
+					mViewPager.getAdapter().addList(list);
478 465
 			}
  466
+		}
  467
+	}
  468
+
  469
+	@Override
  470
+	public
  471
+	void onActivityCreated(Bundle savedInstanceState)
  472
+	{
  473
+		super.onActivityCreated(savedInstanceState);
479 474
 
480  
-			adapter.addList(list);
  475
+		final Bundle args = getArguments();
  476
+		final String userJson;
  477
+		if (args != null) {
  478
+			userJson = args.getString(ARG_TARGET_USER, null);
  479
+			if (userJson != null) {
  480
+				mDataFragment.targetUser = GsonUtils.fromJson(userJson, User.class);
  481
+			}
481 482
 		}
  483
+		if (mDataFragment.targetUser == null) {
  484
+			mDataFragment.targetUser = new User();
  485
+			mDataFragment.targetUser.setLogin(getBaseActivity().getCurrentUserLogin());
  486
+		}
  487
+
  488
+		if (mDataFragment.eventLists == null)
  489
+			mDataFragment.eventLists = new ArrayList<ListHolder>();
  490
+
  491
+		if (mDataFragment.pagerAdapter == null)
  492
+			mDataFragment.pagerAdapter = new ListViewPager.MultiListPagerAdapter(getContext());
482 493
 
483  
-		mViewPager.setAdapter(adapter);
  494
+		mViewPager.setAdapter(mDataFragment.pagerAdapter);
484 495
 		mTitlePageIndicator.setViewPager(mViewPager);
  496
+
  497
+		fetchData(false);
485 498
 	}
486 499
 
487 500
 	@Override
@@ -491,12 +504,6 @@ void onPause()
491 504
 		super.onPause();
492 505
 
493 506
 		mDataFragment.currentItem = mViewPager.getCurrentItem();
494  
-
495  
-		mDataFragment.currentItemScroll = mViewPager.getAdapter().getList(mDataFragment.currentItem)
496  
-													.getFirstVisiblePosition();
497  
-		mDataFragment.currentItemScrollTop = mViewPager.getAdapter()
498  
-													   .getList(mDataFragment.currentItem)
499  
-													   .getChildAt(0).getTop();
500 507
 	}
501 508
 
502 509
 	@Override
@@ -506,8 +513,27 @@ void onResume()
506 513
 		super.onResume();
507 514
 
508 515
 		mViewPager.setCurrentItem(mDataFragment.currentItem);
509  
-		mViewPager.getAdapter().getList(mDataFragment.currentItem)
510  
-				  .setSelectionFromTop(mDataFragment.currentItemScroll,
511  
-									   mDataFragment.currentItemScrollTop);
  516
+	}
  517
+
  518
+	@Override
  519
+	public
  520
+	void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
  521
+	{
  522
+		super.onCreateOptionsMenu(menu, inflater);
  523
+
  524
+		menu.findItem(R.id.actionbar_action_refresh).setVisible(true);
  525
+	}
  526
+
  527
+	@Override
  528
+	public
  529
+	boolean onOptionsItemSelected(MenuItem item)
  530
+	{
  531
+		switch (item.getItemId()) {
  532
+		case R.id.actionbar_action_refresh:
  533
+			fetchData(true);
  534
+			return true;
  535
+		}
  536
+
  537
+		return super.onOptionsItemSelected(item);
512 538
 	}
513 539
 }
122  src/net/idlesoft/android/apps/github/ui/fragments/FollowersFollowingFragment.java
@@ -27,6 +27,9 @@
27 27
 import android.view.View;
28 28
 import android.view.ViewGroup;
29 29
 import android.widget.AdapterView;
  30
+import com.actionbarsherlock.view.Menu;
  31
+import com.actionbarsherlock.view.MenuInflater;
  32
+import com.actionbarsherlock.view.MenuItem;
30 33
 import com.viewpagerindicator.TitlePageIndicator;
31 34
 import net.idlesoft.android.apps.github.HubroidConstants;
32 35
 import net.idlesoft.android.apps.github.R;
@@ -64,10 +67,9 @@
64 67
 	class FollowersFollowingDataFragment extends DataFragment
65 68
 	{
66 69
 		ArrayList<ListHolder> userLists;
  70
+		ListViewPager.MultiListPagerAdapter pagerAdapter;
67 71
 		User targetUser;
68 72
 		int currentItem;
69  
-		int currentItemScroll;
70  
-		int currentItemScrollTop;
71 73
 
72 74
 		public
73 75
 		int findListIndexByType(int listType)
@@ -85,7 +87,6 @@ int findListIndexByType(int listType)
85 87
 
86 88
 	ListViewPager mViewPager;
87 89
 	TitlePageIndicator mTitlePageIndicator;
88  
-	int mCurrentPage;
89 90
 
90 91
 	public
91 92
 	FollowersFollowingFragment()
@@ -110,43 +111,24 @@ View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInst
110 111
 		return v;
111 112
 	}
112 113
 
113  
-	@Override
114 114
 	public
115  
-	void onActivityCreated(Bundle savedInstanceState)
  115
+	void fetchData(final boolean freshen)
116 116
 	{
117  
-		super.onActivityCreated(savedInstanceState);
118  
-
119  
-		final Bundle args = getArguments();
120  
-		final String userJson;
121  
-		if (args != null) {
122  
-			userJson = args.getString(HubroidConstants.ARG_TARGET_USER);
123  
-			if (userJson != null) {
124  
-				mDataFragment.targetUser = GsonUtils.fromJson(userJson, User.class);
125  
-			}
126  
-		}
127  
-		if (mDataFragment.targetUser == null) {
128  
-			mDataFragment.targetUser = new User();
129  
-			mDataFragment.targetUser.setLogin(getBaseActivity().getCurrentUserLogin());
130  
-		}
131  
-		getBaseActivity().getSupportActionBar().setTitle(mDataFragment.targetUser.getLogin());
132  
-		if (mDataFragment.userLists == null)
133  
-			mDataFragment.userLists = new ArrayList<ListHolder>();
134  
-
135  
-		ListViewPager.MultiListPagerAdapter adapter =
136  
-				new ListViewPager.MultiListPagerAdapter(getContext());
137  
-
138 117
 		if (!mDataFragment.targetUser.getLogin().equals("")) {
139 118
 			/* Display a user's followers */
140  
-			final IdleList<User> list = new IdleList<User>(getContext());
  119
+			final IdleList<User> list;
141 120
 			final ListHolder holder;
  121
+			final int index = mDataFragment.findListIndexByType(LIST_FOLLOWERS);
142 122
 
143  
-			list.setAdapter(new UserListAdapter(getBaseActivity()));
  123
+			if (freshen && index >= 0)
  124
+				list = mViewPager.getAdapter().getList(index);
  125
+			else
  126
+				list = new IdleList<User>(getContext());
144 127
 
145  
-			final int index = mDataFragment.findListIndexByType(LIST_FOLLOWERS);
  128
+			list.setAdapter(new UserListAdapter(getBaseActivity()));
146 129
 
147 130
 			if (index >= 0) {
148 131
 				holder = mDataFragment.userLists.get(index);
149  
-
150 132
 				list.setTitle(holder.title);
151 133
 				list.getListAdapter().fillWithItems(holder.users);
152 134
 				list.getListAdapter().notifyDataSetChanged();
@@ -156,7 +138,6 @@ void onActivityCreated(Bundle savedInstanceState)
156 138
 				holder.title = getString(R.string.followers);
157 139
 				list.setTitle(holder.title);
158 140
 				holder.users = new ArrayList<User>();
159  
-
160 141
 				mDataFragment.userLists.add(holder);
161 142
 
162 143
 				final DataFragment.DataTask.DataTaskRunnable followersRunnable =
@@ -211,6 +192,8 @@ void onTaskComplete()
211 192
 						};
212 193
 
213 194
 				mDataFragment.executeNewTask(followersRunnable, followersCallbacks);
  195
+				if (index < 0)
  196
+					mViewPager.getAdapter().addList(list);
214 197
 			}
215 198
 
216 199
 			list.setOnItemClickListener(new AdapterView.OnItemClickListener()
@@ -229,22 +212,23 @@ void onItemClick(AdapterView<?> parent, View view, int position, long id)
229 212
 					getBaseActivity().finishFragmentTransaction();
230 213
 				}
231 214
 			});
232  
-
233  
-			adapter.addList(list);
234 215
 		}
235 216
 
236 217
 		if (!mDataFragment.targetUser.getLogin().equals("")) {
237 218
 			/* Display a user's following */
238  
-			final IdleList<User> list = new IdleList<User>(getContext());
  219
+			final IdleList<User> list;
239 220
 			final ListHolder holder;
  221
+			final int index = mDataFragment.findListIndexByType(LIST_FOLLOWING);
240 222
 
241  
-			list.setAdapter(new UserListAdapter(getBaseActivity()));
  223
+			if (freshen && index >= 0)
  224
+				list = mViewPager.getAdapter().getList(index);
  225
+			else
  226
+				list = new IdleList<User>(getContext());
242 227
 
243  
-			final int index = mDataFragment.findListIndexByType(LIST_FOLLOWING);
  228
+			list.setAdapter(new UserListAdapter(getBaseActivity()));
244 229
 
245 230
 			if (index >= 0) {
246 231
 				holder = mDataFragment.userLists.get(index);
247  
-
248 232
 				list.setTitle(holder.title);
249 233
 				list.getListAdapter().fillWithItems(holder.users);
250 234
 				list.getListAdapter().notifyDataSetChanged();
@@ -254,7 +238,6 @@ void onItemClick(AdapterView<?> parent, View view, int position, long id)
254 238
 				holder.title = getString(R.string.following);
255 239
 				list.setTitle(holder.title);
256 240
 				holder.users = new ArrayList<User>();
257  
-
258 241
 				mDataFragment.userLists.add(holder);
259 242
 
260 243
 				final DataFragment.DataTask.DataTaskRunnable followingRunnable =
@@ -309,6 +292,8 @@ void onTaskComplete()
309 292
 						};
310 293
 
311 294
 				mDataFragment.executeNewTask(followingRunnable, followingCallbacks);
  295
+				if (index < 0)
  296
+					mViewPager.getAdapter().addList(list);
312 297
 			}
313 298
 
314 299
 			list.setOnItemClickListener(new AdapterView.OnItemClickListener()
@@ -327,12 +312,38 @@ void onItemClick(AdapterView<?> parent, View view, int position, long id)
327 312
 					getBaseActivity().finishFragmentTransaction();
328 313
 				}
329 314
 			});
  315
+		}
  316
+	}
330 317
 
331  
-			adapter.addList(list);
  318
+	@Override
  319
+	public
  320
+	void onActivityCreated(Bundle savedInstanceState)
  321
+	{
  322
+		super.onActivityCreated(savedInstanceState);
  323
+
  324
+		final Bundle args = getArguments();
  325
+		final String userJson;
  326
+		if (args != null) {
  327
+			userJson = args.getString(HubroidConstants.ARG_TARGET_USER);
  328
+			if (userJson != null) {
  329
+				mDataFragment.targetUser = GsonUtils.fromJson(userJson, User.class);
  330
+			}
332 331
 		}
  332
+		if (mDataFragment.targetUser == null) {
  333
+			mDataFragment.targetUser = new User();
  334
+			mDataFragment.targetUser.setLogin(getBaseActivity().getCurrentUserLogin());
  335
+		}
  336
+		getBaseActivity().getSupportActionBar().setTitle(mDataFragment.targetUser.getLogin());
  337
+		if (mDataFragment.userLists == null)
  338
+			mDataFragment.userLists = new ArrayList<ListHolder>();
  339
+
  340
+		if (mDataFragment.pagerAdapter == null)
  341
+			mDataFragment.pagerAdapter = new ListViewPager.MultiListPagerAdapter(getContext());
333 342
 
334  
-		mViewPager.setAdapter(adapter);
  343
+		mViewPager.setAdapter(mDataFragment.pagerAdapter);
335 344
 		mTitlePageIndicator.setViewPager(mViewPager);
  345
+
  346
+		fetchData(false);
336 347
 	}
337 348
 
338 349
 	@Override
@@ -342,12 +353,6 @@ void onPause()
342 353
 		super.onPause();
343 354
 
344 355
 		mDataFragment.currentItem = mViewPager.getCurrentItem();
345  
-
346  
-		mDataFragment.currentItemScroll = mViewPager.getAdapter().getList(mDataFragment.currentItem)
347  
-													.getFirstVisiblePosition();
348  
-		mDataFragment.currentItemScrollTop = mViewPager.getAdapter()
349  
-													   .getList(mDataFragment.currentItem)
350  
-													   .getChildAt(0).getTop();
351 356
 	}
352 357
 
353 358
 	@Override
@@ -357,8 +362,27 @@ void onResume()
357 362
 		super.onResume();
358 363
 
359 364
 		mViewPager.setCurrentItem(mDataFragment.currentItem);
360  
-		mViewPager.getAdapter().getList(mDataFragment.currentItem)
361  
-				  .setSelectionFromTop(mDataFragment.currentItemScroll,
362  
-									   mDataFragment.currentItemScrollTop);
  365
+	}
  366
+
  367
+	@Override
  368
+	public
  369
+	void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
  370
+	{
  371
+		super.onCreateOptionsMenu(menu, inflater);
  372
+
  373
+		menu.findItem(R.id.actionbar_action_refresh).setVisible(true);
  374
+	}
  375
+
  376
+	@Override
  377
+	public
  378
+	boolean onOptionsItemSelected(MenuItem item)
  379
+	{
  380
+		switch (item.getItemId()) {
  381
+		case R.id.actionbar_action_refresh:
  382
+			fetchData(true);
  383
+			return true;
  384
+		}
  385
+
  386
+		return super.onOptionsItemSelected(item);
363 387
 	}
364 388
 }
110  src/net/idlesoft/android/apps/github/ui/fragments/ForksFragment.java
@@ -27,6 +27,9 @@
27 27
 import android.view.View;
28 28
 import android.view.ViewGroup;
29 29
 import android.widget.AdapterView;
  30
+import com.actionbarsherlock.view.Menu;
  31
+import com.actionbarsherlock.view.MenuInflater;
  32
+import com.actionbarsherlock.view.MenuItem;
30 33
 import com.viewpagerindicator.TitlePageIndicator;
31 34
 import net.idlesoft.android.apps.github.R;
32 35
 import net.idlesoft.android.apps.github.ui.adapters.RepositoryListAdapter;
@@ -62,10 +65,9 @@
62 65
 	class ForksDataFragment extends DataFragment
63 66
 	{
64 67
 		ArrayList<ListHolder> repositoryLists;
  68
+		ListViewPager.MultiListPagerAdapter pagerAdapter;
65 69
 		Repository targetRepository;
66 70
 		int currentItem;
67  
-		int currentItemScroll;
68  
-		int currentItemScrollTop;
69 71
 
70 72
 		public
71 73
 		int findListIndexByType(int listType)
@@ -83,7 +85,6 @@ int findListIndexByType(int listType)
83 85
 
84 86
 	ListViewPager mViewPager;
85 87
 	TitlePageIndicator mTitlePageIndicator;
86  
-	int mCurrentPage;
87 88
 
88 89
 	public
89 90
 	ForksFragment()
@@ -108,47 +109,23 @@ View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInst
108 109
 		return v;
109 110
 	}
110 111
 
111  
-	@Override
112  
-	public
113  
-	void onActivityCreated(Bundle savedInstanceState)
114  
-	{
115  
-		super.onActivityCreated(savedInstanceState);
116  
-
117  
-		final Bundle args = getArguments();
118  
-		final String repositoryJson;
119  
-		if (args != null) {
120  
-			repositoryJson = args.getString(ARG_TARGET_REPO);
121  
-			if (repositoryJson != null) {
122  
-				mDataFragment.targetRepository = GsonUtils.fromJson(repositoryJson,
123  
-																	Repository.class);
124  
-			}
125  
-		}
126  
-		getBaseActivity().getSupportActionBar().setTitle(mDataFragment.targetRepository.getName());
127  
-		if (mDataFragment.repositoryLists == null)
128  
-			mDataFragment.repositoryLists = new ArrayList<ListHolder>();
129  
-		ListViewPager.MultiListPagerAdapter adapter =
130  
-				new ListViewPager.MultiListPagerAdapter(getContext());
131  
-
132  
-		mViewPager.setAdapter(adapter);
133  
-		mTitlePageIndicator.setViewPager(mViewPager);
134  
-
135  
-		fetchData(false);
136  
-	}
137  
-
138 112
 	public
139 113
 	void fetchData(boolean freshen)
140 114
 	{
141 115
 		/* Display a user's repositories */
142  
-		final IdleList<Repository> list = new IdleList<Repository>(getContext());
  116
+		final IdleList<Repository> list;
143 117
 		final ListHolder holder;
  118
+		final int index = mDataFragment.findListIndexByType(LIST_FORKS);
144 119
 
145  
-		list.setAdapter(new RepositoryListAdapter(getBaseActivity()));
  120
+		if (freshen && index >= 0)
  121
+			list = mViewPager.getAdapter().getList(index);
  122
+		else
  123
+			list = new IdleList<Repository>(getContext());
146 124
 
147  
-		final int index = mDataFragment.findListIndexByType(LIST_FORKS);
  125
+		list.setAdapter(new RepositoryListAdapter(getBaseActivity()));
148 126
 
149 127
 		if (index >= 0) {
150 128
 			holder = mDataFragment.repositoryLists.get(index);
151  
-
152 129
 			list.setTitle(holder.title);
153 130
 			list.getListAdapter().fillWithItems(holder.repositories);
154 131
 			list.getListAdapter().notifyDataSetChanged();
@@ -158,7 +135,6 @@ void fetchData(boolean freshen)
158 135
 			holder.title = getString(R.string.forks);
159 136
 			list.setTitle(holder.title);
160 137
 			holder.repositories = new ArrayList<Repository>();
161  
-
162 138
 			mDataFragment.repositoryLists.add(holder);
163 139
 
164 140
 			final DataFragment.DataTask.DataTaskRunnable forksRunnable =
@@ -214,6 +190,8 @@ void onTaskComplete()
214 190
 					};
215 191
 
216 192
 			mDataFragment.executeNewTask(forksRunnable, forksCallbacks);
  193
+			if (index < 0)
  194
+				mViewPager.getAdapter().addList(list);
217 195
 		}
218 196
 
219 197
 		list.setOnItemClickListener(new AdapterView.OnItemClickListener()
@@ -227,13 +205,38 @@ void onItemClick(AdapterView<?> parent, View view, int position, long id)
227 205
 				args.putString(ARG_TARGET_REPO, GsonUtils.toJson(target));
228 206
 				getBaseActivity().startFragmentTransaction();
229 207
 				getBaseActivity().addFragmentToTransaction(RepositoryFragment.class,
230  
-														   R.id.fragment_container_more,
231  
-														   args);
  208
+														   R.id.fragment_container_more, args);
232 209
 				getBaseActivity().finishFragmentTransaction();
233 210
 			}
234 211
 		});
  212
+	}
  213
+
  214
+	@Override
  215
+	public
  216
+	void onActivityCreated(Bundle savedInstanceState)
  217
+	{
  218
+		super.onActivityCreated(savedInstanceState);
  219
+
  220
+		final Bundle args = getArguments();
  221
+		final String repositoryJson;
  222
+		if (args != null) {
  223
+			repositoryJson = args.getString(ARG_TARGET_REPO);
  224
+			if (repositoryJson != null) {
  225
+				mDataFragment.targetRepository = GsonUtils.fromJson(repositoryJson,
  226
+																	Repository.class);
  227
+			}
  228
+		}
  229
+		getBaseActivity().getSupportActionBar().setTitle(mDataFragment.targetRepository.getName());
  230
+		if (mDataFragment.repositoryLists == null)
  231
+			mDataFragment.repositoryLists = new ArrayList<ListHolder>();
  232
+
  233
+		if (mDataFragment.pagerAdapter == null)
  234
+			mDataFragment.pagerAdapter = new ListViewPager.MultiListPagerAdapter(getContext());
235 235
 
236  
-		mViewPager.getAdapter().addList(list);
  236
+		mViewPager.setAdapter(mDataFragment.pagerAdapter);
  237
+		mTitlePageIndicator.setViewPager(mViewPager);
  238
+
  239
+		fetchData(false);
237 240
 	}
238 241
 
239 242
 	@Override
@@ -243,12 +246,6 @@ void onPause()
243 246
 		super.onPause();
244 247
 
245 248
 		mDataFragment.currentItem = mViewPager.getCurrentItem();
246  
-
247  
-		mDataFragment.currentItemScroll = mViewPager.getAdapter().getList(mDataFragment.currentItem)
248  
-													.getFirstVisiblePosition();
249  
-		mDataFragment.currentItemScrollTop = mViewPager.getAdapter()
250  
-													   .getList(mDataFragment.currentItem)
251  
-													   .getChildAt(0).getTop();
252 249
 	}
253 250
 
254 251
 	@Override
@@ -258,8 +255,27 @@ void onResume()
258 255
 		super.onResume();
259 256
 
260 257
 		mViewPager.setCurrentItem(mDataFragment.currentItem);
261  
-		mViewPager.getAdapter().getList(mDataFragment.currentItem)
262  
-				  .setSelectionFromTop(mDataFragment.currentItemScroll,
263  
-									   mDataFragment.currentItemScrollTop);
  258
+	}
  259
+
  260
+	@Override
  261
+	public
  262
+	void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
  263
+	{
  264
+		super.onCreateOptionsMenu(menu, inflater);
  265
+
  266
+		menu.findItem(R.id.actionbar_action_refresh).setVisible(true);
  267
+	}
  268
+
  269
+	@Override
  270
+	public
  271
+	boolean onOptionsItemSelected(MenuItem item)
  272
+	{
  273
+		switch (item.getItemId()) {
  274
+		case R.id.actionbar_action_refresh:
  275
+			fetchData(true);
  276
+			return true;
  277
+		}
  278
+
  279
+		return super.onOptionsItemSelected(item);
264 280
 	}
265 281
 }
5  src/net/idlesoft/android/apps/github/ui/fragments/IssuesFragment.java
@@ -75,8 +75,6 @@
75 75
 		ListViewPager.MultiListPagerAdapter pagerAdapter;
76 76
 		Repository targetRepository;
77 77
 		int currentItem;
78  
-		int currentItemScroll;
79  
-		int currentItemScrollTop;
80 78
 
81 79
 		public
82 80
 		int findListIndexByType(int listType)
@@ -94,7 +92,6 @@ int findListIndexByType(int listType)
94 92
 
95 93
 	ListViewPager mViewPager;
96 94
 	TitlePageIndicator mTitlePageIndicator;
97  
-	int mCurrentPage;
98 95
 
99 96
 	public
100 97
 	IssuesFragment()
@@ -233,7 +230,6 @@ void onTaskComplete()
233 230
 				list.setTitle(holder.title);
234 231
 				holder.gravatars = new ArrayList<Bitmap>();
235 232
 				holder.issues = new ArrayList<Issue>();
236  
-
237 233
 				mDataFragment.issuesLists.add(holder);
238 234
 
239 235
 				final DataFragment.DataTask.DataTaskRunnable closedRunnable =
@@ -323,7 +319,6 @@ void onTaskComplete()
323 319
 				list.setTitle(holder.title);
324 320
 				holder.gravatars = new ArrayList<Bitmap>();
325 321
 				holder.issues = new ArrayList<Issue>();
326  
-
327 322
 				mDataFragment.issuesLists.add(holder);
328 323
 
329 324
 				final DataFragment.DataTask.DataTaskRunnable assignedRunnable =
125  src/net/idlesoft/android/apps/github/ui/fragments/RepositoriesFragment.java
@@ -27,6 +27,9 @@
27 27
 import android.view.View;
28 28
 import android.view.ViewGroup;
29 29
 import android.widget.AdapterView;
  30
+import com.actionbarsherlock.view.Menu;
  31
+import com.actionbarsherlock.view.MenuInflater;
  32
+import com.actionbarsherlock.view.MenuItem;
30 33
 import com.viewpagerindicator.TitlePageIndicator;
31 34
 import net.idlesoft.android.apps.github.HubroidConstants;
32 35
 import net.idlesoft.android.apps.github.R;
@@ -67,10 +70,9 @@
67 70
 	class RepositoriesDataFragment extends DataFragment
68 71
 	{
69 72
 		ArrayList<ListHolder> repositoryLists;
  73
+		ListViewPager.MultiListPagerAdapter pagerAdapter;
70 74
 		User targetUser;
71 75
 		int currentItem;
72  
-		int currentItemScroll;
73  
-		int currentItemScrollTop;
74 76
 
75 77
 		public
76 78
 		int findListIndexByType(int listType)
@@ -88,7 +90,6 @@ int findListIndexByType(int listType)
88 90
 
89 91
 	ListViewPager mViewPager;
90 92
 	TitlePageIndicator mTitlePageIndicator;
91  
-	int mCurrentPage;
92 93
 
93 94
 	public
94 95
 	RepositoriesFragment()
@@ -113,44 +114,24 @@ View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInst
113 114
 		return v;
114 115
 	}
115 116
 
116  
-	@Override
117 117
 	public
118  
-	void onActivityCreated(Bundle savedInstanceState)
  118
+	void fetchData(final boolean freshen)
119 119
 	{
120  
-		super.onActivityCreated(savedInstanceState);
121  
-
122  
-		final Bundle args = getArguments();
123  
-		final String userJson;
124  
-		if (args != null) {
125  
-			userJson = args.getString(HubroidConstants.ARG_TARGET_USER);
126  
-			if (userJson != null) {
127  
-				mDataFragment.targetUser = GsonUtils.fromJson(userJson, User.class);
128  
-			}
129  
-		}
130  
-		if (mDataFragment.targetUser == null) {
131  
-			mDataFragment.targetUser = new User();
132  
-			mDataFragment.targetUser.setLogin(getBaseActivity().getCurrentUserLogin());
133  
-		}
134  
-
135  
-		if (mDataFragment.repositoryLists == null)
136  
-			mDataFragment.repositoryLists = new ArrayList<ListHolder>();
137  
-
138  
-		getBaseActivity().getSupportActionBar().setTitle(R.string.repositories);
139  
-		ListViewPager.MultiListPagerAdapter adapter =
140  
-				new ListViewPager.MultiListPagerAdapter(getContext());
141  
-
142 120
 		if (!mDataFragment.targetUser.getLogin().equals("")) {
143 121
 			/* Display a user's repositories */
144  
-			final IdleList<Repository> list = new IdleList<Repository>(getContext());
  122
+			final IdleList<Repository> list;
145 123
 			final ListHolder holder;
  124
+			final int index = mDataFragment.findListIndexByType(LIST_YOURS);
146 125
 
147  
-			list.setAdapter(new RepositoryListAdapter(getBaseActivity()));
  126
+			if (freshen && index >= 0)
  127
+				list = mViewPager.getAdapter().getList(index);
  128
+			else
  129
+				list = new IdleList<Repository>(getContext());
148 130
 
149  
-			final int index = mDataFragment.findListIndexByType(LIST_YOURS);
  131
+			list.setAdapter(new RepositoryListAdapter(getBaseActivity()));
150 132
 
151 133
 			if (index >= 0) {
152 134
 				holder = mDataFragment.repositoryLists.get(index);
153  
-
154 135
 				list.setTitle(holder.title);
155 136
 				list.getListAdapter().fillWithItems(holder.repositories);
156 137
 				list.getListAdapter().notifyDataSetChanged();
@@ -160,7 +141,6 @@ void onActivityCreated(Bundle savedInstanceState)
160 141
 				holder.title = mDataFragment.targetUser.getLogin();
161 142
 				list.setTitle(holder.title);
162 143
 				holder.repositories = new ArrayList<Repository>();
163  
-
164 144
 				mDataFragment.repositoryLists.add(holder);
165 145
 
166 146
 				final DataFragment.DataTask.DataTaskRunnable yoursRunnable =
@@ -222,6 +202,8 @@ void onTaskComplete()
222 202
 						};
223 203
 
224 204
 				mDataFragment.executeNewTask(yoursRunnable, yoursCallbacks);
  205
+				if (index < 0)
  206
+					mViewPager.getAdapter().addList(list);
225 207
 			}
226 208
 
227 209
 			list.setOnItemClickListener(new AdapterView.OnItemClickListener()
@@ -240,22 +222,23 @@ void onItemClick(AdapterView<?> parent, View view, int position, long id)
240 222
 					getBaseActivity().finishFragmentTransaction();
241 223
 				}
242 224
 			});
243  
-
244  
-			adapter.addList(list);
245 225
 		}
246 226
 
247 227
 		if (!mDataFragment.targetUser.getLogin().equals("")) {
248 228
 			/* Display a user's watched repositories */
249  
-			final IdleList<Repository> list = new IdleList<Repository>(getContext());
  229
+			final IdleList<Repository> list;
250 230
 			final ListHolder holder;
  231
+			final int index = mDataFragment.findListIndexByType(LIST_WATCHED);
251 232
 
252  
-			list.setAdapter(new RepositoryListAdapter(getBaseActivity()));
  233
+			if (freshen && index >= 0)
  234
+				list = mViewPager.getAdapter().getList(index);
  235
+			else
  236
+				list = new IdleList<Repository>(getContext());
253 237
 
254  
-			final int index = mDataFragment.findListIndexByType(LIST_WATCHED);
  238
+			list.setAdapter(new RepositoryListAdapter(getBaseActivity()));
255 239
 
256 240
 			if (index >= 0) {
257 241
 				holder = mDataFragment.repositoryLists.get(index);
258  
-
259 242
 				list.setTitle(holder.title);
260 243
 				list.getListAdapter().fillWithItems(holder.repositories);
261 244
 				list.getListAdapter().notifyDataSetChanged();
@@ -265,7 +248,6 @@ void onItemClick(AdapterView<?> parent, View view, int position, long id)
265 248
 				holder.title = getString(R.string.repositories_watched);
266 249
 				list.setTitle(holder.title);
267 250
 				holder.repositories = new ArrayList<Repository>();
268  
-
269 251
 				mDataFragment.repositoryLists.add(holder);
270 252
 
271 253
 				final DataFragment.DataTask.DataTaskRunnable watchedRunnable =
@@ -320,6 +302,8 @@ void onTaskComplete()
320 302
 						};
321 303
 
322 304
 				mDataFragment.executeNewTask(watchedRunnable, watchedCallbacks);
  305
+				if (index < 0)
  306
+					mViewPager.getAdapter().addList(list);
323 307
 			}
324 308
 
325 309
 			list.setOnItemClickListener(new AdapterView.OnItemClickListener()
@@ -338,12 +322,40 @@ void onItemClick(AdapterView<?> parent, View view, int position, long id)
338 322
 					getBaseActivity().finishFragmentTransaction();
339 323
 				}
340 324
 			});
  325
+		}
  326
+	}
341 327
 
342  
-			adapter.addList(list);
  328
+	@Override
  329
+	public
  330
+	void onActivityCreated(Bundle savedInstanceState)
  331
+	{
  332
+		super.onActivityCreated(savedInstanceState);
  333
+
  334
+		final Bundle args = getArguments();
  335
+		final String userJson;
  336
+		if (args != null) {
  337
+			userJson = args.getString(HubroidConstants.ARG_TARGET_USER);
  338
+			if (userJson != null) {
  339
+				mDataFragment.targetUser = GsonUtils.fromJson(userJson, User.class);
  340
+			}
343 341
 		}
  342
+		if (mDataFragment.targetUser == null) {
  343
+			mDataFragment.targetUser = new User();
  344
+			mDataFragment.targetUser.setLogin(getBaseActivity().getCurrentUserLogin());
  345
+		}
  346
+
  347
+		if (mDataFragment.repositoryLists == null)
  348
+			mDataFragment.repositoryLists = new ArrayList<ListHolder>();
344 349
 
345  
-		mViewPager.setAdapter(adapter);
  350
+		getBaseActivity().getSupportActionBar().setTitle(R.string.repositories);
  351
+
  352
+		if (mDataFragment.pagerAdapter == null)