use of butterknife.Unbinder in project Shuttle by timusus.
the class QueuePagerFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_queue_pager, container, false);
unbinder = ButterKnife.bind(this, rootView);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
if (ShuttleUtils.isLandscape(getContext())) {
textProtectionScrim.setVisibility(View.GONE);
}
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(viewModelAdapter);
SnapHelper snapHelper = new PagerSnapHelper() {
@Override
public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
int snapPosition = super.findTargetSnapPosition(layoutManager, velocityX, velocityY);
if (snapPosition < viewModelAdapter.items.size()) {
Observable.timer(200, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(o -> {
if (mediaManager.getQueuePosition() != snapPosition) {
mediaManager.setQueuePosition(snapPosition);
}
}, throwable -> LogUtils.logException(TAG, "Error setting queue position", throwable));
}
return snapPosition;
}
};
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.addOnScrollListener(new RecyclerViewPreloader<>(new ListPreloader.PreloadModelProvider<QueuePagerItemView>() {
@Override
public List<QueuePagerItemView> getPreloadItems(int position) {
QueuePagerItemView queuePagerItemView = (QueuePagerItemView) viewModelAdapter.items.get(position);
return Collections.singletonList(queuePagerItemView);
}
@Override
public GenericRequestBuilder getPreloadRequestBuilder(QueuePagerItemView item) {
return requestManager.load(item.song).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(PlaceholderProvider.getInstance(getContext()).getPlaceHolderDrawable(item.song.name, true, settingsManager));
}
}, (item, adapterPosition, perItemPosition) -> imageSize, 3));
recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
// This null check doesn't make sense to me, but there was an NPE here..
if (recyclerView != null) {
imageSize = new int[] { recyclerView.getWidth(), recyclerView.getHeight() };
recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
}
return false;
}
});
return rootView;
}
use of butterknife.Unbinder in project butterknife by JakeWharton.
the class BindArrayTest method asStringArray.
@Test
public void asStringArray() {
StringArrayTarget target = new StringArrayTarget();
String[] expected = context.getResources().getStringArray(R.array.string_one_two_three);
Unbinder unbinder = ButterKnife.bind(target, tree);
assertThat(target.actual).isEqualTo(expected);
unbinder.unbind();
assertThat(target.actual).isEqualTo(expected);
}
use of butterknife.Unbinder in project butterknife by JakeWharton.
the class BindBoolTest method asBoolean.
@Test
public void asBoolean() {
Target target = new Target();
boolean expected = context.getResources().getBoolean(R.bool.just_true);
Unbinder unbinder = ButterKnife.bind(target, tree);
assertThat(target.actual).isEqualTo(expected);
unbinder.unbind();
assertThat(target.actual).isEqualTo(expected);
}
use of butterknife.Unbinder in project butterknife by JakeWharton.
the class BindAnimTest method anim.
@Test
public void anim() {
Target target = new Target();
Unbinder unbinder = ButterKnife.bind(target, tree);
// Check more?
assertNotNull(target.actual);
unbinder.unbind();
assertNotNull(target.actual);
}
use of butterknife.Unbinder in project butterknife by JakeWharton.
the class BindBitmapTest method asBitmap.
@Test
public void asBitmap() {
Target target = new Target();
Bitmap expected = BitmapFactory.decodeResource(context.getResources(), R.drawable.pixel);
Unbinder unbinder = ButterKnife.bind(target, tree);
assertTrue(target.actual.sameAs(expected));
unbinder.unbind();
assertTrue(target.actual.sameAs(expected));
}
Aggregations