提交 3d81fc2b 编写于 作者: S Sam Judd

Code comment fixes for RequestManagerRetriever.

上级 00b0acca
......@@ -16,13 +16,12 @@ import com.bumptech.glide.Glide;
/**
* A test activity to reproduce Issue #117: https://github.com/bumptech/glide/issues/117.
*/
public class Issue117Activity extends FragmentActivity {
class Issue117Activity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewPager viewPager = new ViewPager(this);
int id = View.generateViewId();
viewPager.setId(id);
viewPager.setId(View.generateViewId());
setContentView(viewPager,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
viewPager.setAdapter(new Issue117Adapter(getSupportFragmentManager()));
......
......@@ -20,7 +20,7 @@ import org.robolectric.util.ActivityController;
import static com.bumptech.glide.tests.BackgroundUtil.testInBackground;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
......@@ -40,14 +40,13 @@ public class RequestManagerRetrieverTest {
retriever = new RequestManagerRetriever();
harnesses = new RetrieverHarness[] { new DefaultRetrieverHarness(), new SupportRetrieverHarness() };
Robolectric.shadowOf(Looper.getMainLooper()).pause();
}
@After
public void tearDown() {
Robolectric.shadowOf(Looper.getMainLooper()).runToEndOfTasks();
assertTrue(retriever.pendingRequestManagerFragments.isEmpty());
assertTrue(retriever.pendingSupportRequestManagerFragments.isEmpty());
assertThat(retriever.pendingRequestManagerFragments.entrySet(), empty());
assertThat(retriever.pendingSupportRequestManagerFragments.entrySet(), empty());
}
@Test
......@@ -56,7 +55,7 @@ public class RequestManagerRetrieverTest {
harness.doGet();
Robolectric.shadowOf(Looper.getMainLooper()).runToEndOfTasks();
assertThat(harness.hasFragmentWithTag(RequestManagerRetriever.TAG), is(true));
assertTrue(harness.hasFragmentWithTag(RequestManagerRetriever.TAG));
}
}
......@@ -241,8 +240,11 @@ public class RequestManagerRetrieverTest {
// See Issue #117: https://github.com/bumptech/glide/issues/117.
@Test
public void testCanCallGetInOnAttachToWindowInFragmentInViewPager() {
// Robolectric by default runs messages posted to the main looper synchronously, the framework does not. We post
// to the main thread here to work around an issue caused by a recursive method call so we need (and reasonably
// expect) our message to not run immediately
Robolectric.shadowOf(Looper.getMainLooper()).pause();
Robolectric.buildActivity(Issue117Activity.class).create().start().resume().visible();
Robolectric.shadowOf(Looper.getMainLooper()).runToEndOfTasks();
}
private interface RetrieverHarness {
......
......@@ -12,6 +12,7 @@ import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.util.Util;
......@@ -202,17 +203,26 @@ public class RequestManagerRetriever implements Handler.Callback {
@Override
public boolean handleMessage(Message message) {
boolean handled = true;
Object removed = null;
Object key = null;
switch (message.what) {
case ID_REMOVE_FRAGMENT_MANAGER:
android.app.FragmentManager fm = (android.app.FragmentManager) message.obj;
pendingRequestManagerFragments.remove(fm);
return true;
key = fm;
removed = pendingRequestManagerFragments.remove(fm);
break;
case ID_REMOVE_SUPPORT_FRAGMENT_MANAGER:
FragmentManager supportFm = (FragmentManager) message.obj;
pendingSupportRequestManagerFragments.remove(supportFm);
return true;
key = supportFm;
removed = pendingSupportRequestManagerFragments.remove(supportFm);
break;
default:
return false;
handled = false;
}
if (handled && removed == null && Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Failed to remove expected request manager fragment, manager: " + key);
}
return handled;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册