@Test public void testDataRenderedCallbacksAreNotTriggered() { final ChangeSetCompleteCallback changeSetCompleteCallback = mock(ChangeSetCompleteCallback.class); final ComponentsLogger componentsLogger = mock(ComponentsLogger.class); final ComponentContext componentContext = new ComponentContext(RuntimeEnvironment.application, "", componentsLogger); final RecyclerBinder recyclerBinder = new RecyclerBinder.Builder().rangeRatio(RANGE_RATIO).build(componentContext); for (int i = 0; i < 40; i++) { recyclerBinder.notifyChangeSetComplete(true, changeSetCompleteCallback); } final RecyclerView recyclerView = mock(LithoRecylerView.class); when(recyclerView.hasPendingAdapterUpdates()).thenReturn(true); when(recyclerView.isAttachedToWindow()).thenReturn(true); when(recyclerView.getWindowVisibility()).thenReturn(View.VISIBLE); when(recyclerView.getAlpha()).thenReturn(1f); when(recyclerView.getVisibility()).thenReturn(View.VISIBLE); when(recyclerView.getGlobalVisibleRect(any(Rect.class))).thenReturn(true); recyclerBinder.mount(recyclerView); recyclerBinder.notifyChangeSetComplete(true, changeSetCompleteCallback); verify(componentsLogger).emitMessage(eq(ComponentsLogger.LogLevel.ERROR), anyString()); assertThat(recyclerBinder.mDataRenderedCallbacks).isEmpty(); }
@Test public void testOnDataRenderedWithNoPendingUpdate() { final ChangeSetCompleteCallback changeSetCompleteCallback = mock(ChangeSetCompleteCallback.class); final RecyclerBinder recyclerBinder = new RecyclerBinder.Builder().rangeRatio(RANGE_RATIO).build(mComponentContext); final ArrayList<RenderInfo> renderInfos = new ArrayList<>(); for (int i = 0; i < 5; i++) { final Component component = TestDrawableComponent.create(mComponentContext).widthPx(100).heightPx(100).build(); renderInfos.add(ComponentRenderInfo.create().component(component).build()); } final RecyclerView recyclerView = mock(LithoRecylerView.class); when(recyclerView.hasPendingAdapterUpdates()).thenReturn(false); when(recyclerView.isAttachedToWindow()).thenReturn(true); when(recyclerView.getWindowVisibility()).thenReturn(View.VISIBLE); when(recyclerView.getAlpha()).thenReturn(1f); when(recyclerView.getVisibility()).thenReturn(View.VISIBLE); when(recyclerView.getGlobalVisibleRect(any(Rect.class))).thenReturn(true); recyclerBinder.mount(recyclerView); recyclerBinder.insertRangeAt(0, renderInfos); recyclerBinder.notifyChangeSetComplete(true, changeSetCompleteCallback); verify(changeSetCompleteCallback).onDataRendered(eq(true), anyLong()); }
@Test public void testOnDataRenderedWithViewVisibilityIsGone() { final ChangeSetCompleteCallback changeSetCompleteCallback = mock(ChangeSetCompleteCallback.class); final RecyclerBinder recyclerBinder = new RecyclerBinder.Builder().rangeRatio(RANGE_RATIO).build(mComponentContext); final ArrayList<RenderInfo> renderInfos = new ArrayList<>(); for (int i = 0; i < 5; i++) { final Component component = TestDrawableComponent.create(mComponentContext).widthPx(100).heightPx(100).build(); renderInfos.add(ComponentRenderInfo.create().component(component).build()); } final RecyclerView recyclerView = mock(LithoRecylerView.class); when(recyclerView.hasPendingAdapterUpdates()).thenReturn(true); when(recyclerView.isAttachedToWindow()).thenReturn(true); when(recyclerView.getWindowVisibility()).thenReturn(View.GONE); when(recyclerView.getAlpha()).thenReturn(1f); when(recyclerView.getVisibility()).thenReturn(View.GONE); when(recyclerView.getGlobalVisibleRect(any(Rect.class))).thenReturn(false); recyclerBinder.mount(recyclerView); recyclerBinder.insertRangeAt(0, renderInfos); recyclerBinder.notifyChangeSetComplete(true, changeSetCompleteCallback); verify(changeSetCompleteCallback).onDataRendered(eq(true), anyLong()); }
@Test public void testOnDataRenderedWithViewDetachedFromWindow() { final ChangeSetCompleteCallback changeSetCompleteCallback = mock(ChangeSetCompleteCallback.class); final RecyclerBinder recyclerBinder = new RecyclerBinder.Builder().rangeRatio(RANGE_RATIO).build(mComponentContext); final ArrayList<RenderInfo> renderInfos = new ArrayList<>(); for (int i = 0; i < 5; i++) { final Component component = TestDrawableComponent.create(mComponentContext).widthPx(100).heightPx(100).build(); renderInfos.add(ComponentRenderInfo.create().component(component).build()); } final RecyclerView recyclerView = mock(LithoRecylerView.class); when(recyclerView.hasPendingAdapterUpdates()).thenReturn(true); when(recyclerView.isAttachedToWindow()).thenReturn(false); when(recyclerView.getWindowVisibility()).thenReturn(View.VISIBLE); when(recyclerView.getAlpha()).thenReturn(1f); when(recyclerView.getVisibility()).thenReturn(View.VISIBLE); when(recyclerView.getGlobalVisibleRect(any(Rect.class))).thenReturn(true); recyclerBinder.mount(recyclerView); recyclerBinder.insertRangeAt(0, renderInfos); recyclerBinder.notifyChangeSetComplete(true, changeSetCompleteCallback); verify(changeSetCompleteCallback).onDataRendered(eq(true), anyLong()); }
@Override public void run() { if (mMountedView == null || !mMountedView.hasPendingAdapterUpdates()) { if (mViewportManager.shouldUpdate()) { mViewportManager.onViewportChanged(State.DATA_CHANGES); } mPostUpdateViewportAttempts = 0; return; } // If the view gets detached, we might still have pending updates. // If the view's visibility is GONE, layout won't happen until it becomes visible. We have // to exit here, otherwise we keep posting this runnable to the next frame until it // becomes visible. if (!mMountedView.isAttachedToWindow() || mMountedView.getVisibility() == View.GONE) { mPostUpdateViewportAttempts = 0; return; } if (mPostUpdateViewportAttempts >= POST_UPDATE_VIEWPORT_AND_COMPUTE_RANGE_MAX_ATTEMPTS) { mPostUpdateViewportAttempts = 0; if (mViewportManager.shouldUpdate()) { mViewportManager.onViewportChanged(State.DATA_CHANGES); } return; } // If we have pending updates, wait until the sync operations are finished and try again // in the next frame. mPostUpdateViewportAttempts++; ViewCompat.postOnAnimation(mMountedView, mUpdateViewportRunnable); } };
protected boolean isListShown() { if(mRecyclerView == null) return false; return mRecyclerView.getVisibility() == View.VISIBLE; }
private boolean canShareThing() { boolean canShare = true; if (mEtTitle.getText().toString().isEmpty() && mRvImageAttachment.getVisibility() != View.VISIBLE && mRvAudioAttachment.getVisibility() != View.VISIBLE) { if (mEtContent.getVisibility() == View.VISIBLE) { if (mEtContent.getText().toString().isEmpty()) { canShare = false; } } else if (mRvCheckList.getVisibility() == View.VISIBLE) { if (mEditable && mCheckListAdapter.getItemCount() == 1) { canShare = false; } } } return canShare; }
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if (recyclerview_poi_history.getVisibility() == View.VISIBLE) { recyclerview_poi_history.setVisibility(View.GONE); return true; } } return super.onKeyDown(keyCode, event); }
@Override public void onBackPressed() { if (endpointsRecyclerView.getVisibility() == View.GONE) { setEndpointsView(); } else { super.onBackPressed(); } }
private String getThingContent() { String content; if (mRvCheckList.getVisibility() == View.VISIBLE) { content = CheckListHelper.toCheckListStr(mCheckListAdapter.getItems()); if (mHabitFinishedThisTime) { content = content.replaceAll(CheckListHelper.SIGNAL + "1", CheckListHelper.SIGNAL + "0"); } } else { content = mEtContent.getText().toString(); } return content; }
private void scrollShortComment() { Observable.create(new ObservableOnSubscribe<Object>() { @Override public void subscribe(ObservableEmitter emitter) throws Exception { while(isFirst && mShortView.getVisibility() == View.VISIBLE){ emitter.onNext(new Object()); isFirst=false; } } }).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<Object>() { @Override public void accept(Object Object) throws Exception { if(mIl.getVisibility() == View.VISIBLE){ mScrollView.scrollBy(0,getScrollViewHeight()-getItemHeight()); }else{ mScrollView.scrollBy(0,mLongView.getMeasuredHeight()+getItemHeight()); } } }); }
private void copyContent() { String content = ""; if (mEtContent.getVisibility() == View.VISIBLE) { content = mEtContent.getText().toString(); } else if (mRvCheckList != null && mRvCheckList.getVisibility() == View.VISIBLE && mCheckListAdapter != null) { content = CheckListHelper.toContentStr( CheckListHelper.toCheckListStr(mCheckListAdapter.getItems()), "X ", "√ "); } ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText( getString(R.string.act_copy_content), content); clipboardManager.setPrimaryClip(clipData); Toast.makeText(this, R.string.success_clipboard, Toast.LENGTH_SHORT).show(); }
@Override public void onKeyboardShow(int keyboardHeight) { if (mFlRoot.getPaddingBottom() == 0) { //set the padding of the contentView for the keyboard mFlRoot.setPadding(0, 0, 0, keyboardHeight); if (mRvCheckList == null || mRvCheckList.getVisibility() != View.VISIBLE) { int toScroll = DisplayUtil.getCursorY(mEtContent); toScroll += mEtTitle.getHeight(); if (mRvImageAttachment != null && mRvImageAttachment.getVisibility() == View.VISIBLE) { toScroll += mRvImageAttachment.getHeight(); } final int fToScroll = toScroll; mScrollView.post(new Runnable() { @Override public void run() { mScrollView.scrollTo(0, fToScroll - screenHeightDivide6); } }); } } }
private String getThingAttachment() { List<String> imageItems = null, audioItems = null; if (mRvImageAttachment.getVisibility() == View.VISIBLE) { imageItems = mImageAttachmentAdapter.getItems(); } if (mRvAudioAttachment.getVisibility() == View.VISIBLE) { audioItems = mAudioAttachmentAdapter.getItems(); } String attachment = AttachmentHelper.toAttachmentStr(imageItems, audioItems); List<String> attachmentsToDelete = AttachmentHelper .getAttachmentsToDelete(mThing.getAttachment(), attachment); if (attachmentsToDelete != null && !attachmentsToDelete.isEmpty()) { mApp.addAttachmentsToDeleteFile(attachmentsToDelete); } return attachment; }
private void setupRecyclerView(boolean updating, int newColumns) { if (mRecyclerView == null) return; Preferences mPrefs = new Preferences(context); if (updating && gridSpacing != null) { mPrefs.setWallsColumnsNumber(newColumns); mRecyclerView.removeItemDecoration(gridSpacing); } int columnsNumber = mPrefs.getWallsColumnsNumber(); if (context.getResources().getConfiguration().orientation == 2) { columnsNumber += 2; } mRecyclerView.setLayoutManager(new GridLayoutManager(context, columnsNumber)); gridSpacing = new GridSpacingItemDecoration(columnsNumber, context.getResources().getDimensionPixelSize(R.dimen.lists_padding), true); mRecyclerView.addItemDecoration(gridSpacing); mRecyclerView.setHasFixedSize(true); if (mRecyclerView.getVisibility() != View.VISIBLE) { mRecyclerView.setVisibility(View.VISIBLE); } if (mRecyclerView.getAdapter() != null && fastScroller != null) { fastScroller.attachRecyclerView(mRecyclerView); if (fastScroller.getVisibility() != View.VISIBLE) { fastScroller.setVisibility(View.VISIBLE); } } }
private void updateBottomBarShadow() { Rect windowRect = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(windowRect); final View bottomBarShadow = f(R.id.bottom_bar_shadow); final int bottomBarHeight = (int) (screenDensity * 56); final int statusBarHeight = DisplayUtil.getStatusbarHeight(this); int scrollY = mScrollView.getScrollY(); int childHeight = mScrollView.getChildAt(0).getHeight(); int marginTop = statusBarHeight; if (mRvImageAttachment.getVisibility() != View.VISIBLE) { marginTop += bottomBarHeight; } else if (DeviceUtil.hasKitKatApi()) { marginTop -= statusBarHeight; } float aY = childHeight - windowRect.bottom + bottomBarHeight + marginTop - screenDensity * 40; float tY = aY + screenDensity * 24; if (scrollY <= aY) { bottomBarShadow.setAlpha(1.0f); } else if (scrollY >= tY) { bottomBarShadow.setAlpha(0); } else { float progress = tY - scrollY; bottomBarShadow.setAlpha(progress / (tY - aY)); } }
@Override public void onBackPressed() { if (MediaPlayerManager.instance().backPress()) { return; } if (recycler_view.getVisibility() == View.VISIBLE) { MediaPlayerManager.instance().releasePlayerAndView(this); recycler_view.setVisibility(View.GONE); return; } super.onBackPressed(); }
private void updateCardSeparatorsIfNeeded(BaseThingViewHolder holder) { if (holder.flImageAttachment.getVisibility() == View.VISIBLE && holder.tvTitle.getVisibility() == View.GONE && holder.tvContent.getVisibility() == View.GONE && holder.rvChecklist.getVisibility() == View.GONE && holder.llAudioAttachment.getVisibility() == View.GONE) { if (holder.rlReminder.getVisibility() == View.VISIBLE) { holder.vReminderSeparator.setVisibility(View.GONE); } else if (holder.rlHabit.getVisibility() == View.VISIBLE) { holder.vHabitSeparator1.setVisibility(View.GONE); } } else { if (holder.rlReminder.getVisibility() == View.VISIBLE) { holder.vReminderSeparator.setVisibility(View.VISIBLE); } else if (holder.rlHabit.getVisibility() == View.VISIBLE) { holder.vHabitSeparator1.setVisibility(View.VISIBLE); } } }
/** * Get Item Position and call Filter Function * * @param view - view which is clicked * @param position - position of item clicked */ @Override public void onItemClick(View view, int position) { //setting mClicked true when none filter is selected otherwise false mClicked = position == 0; // Brush effect is in second position if (position == 1) { mPhotoEditor = new PhotoEditor.Builder(this, mPhotoEditorView) .setPinchTextScalable(true) .build(); if (doodleSeekBar.getVisibility() == View.GONE && brushColorsView.getVisibility() == View.GONE) { showBrushEffect(); } else if (doodleSeekBar.getVisibility() == View.VISIBLE && brushColorsView.getVisibility() == View.VISIBLE) { hideBrushEffect(); } } else { applyFilter(mFilterItems.get(position).getFilter()); } }
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (mEditable) { mColorPicker.dismiss(); quickRemindPicker.dismiss(); mNormalSnackbar.dismiss(); } setSpans(); if (mRvImageAttachment.getVisibility() == View.VISIBLE) { int size = mImageAttachmentAdapter.getItemCount(); AttachmentHelper.setImageRecyclerViewHeight(mRvImageAttachment, size, mMaxSpanImage); mImageLayoutManager.setSpanCount(size < mMaxSpanImage ? size : mMaxSpanImage); mImageAttachmentAdapter.notifyDataSetChanged(); } if (mRvAudioAttachment.getVisibility() == View.VISIBLE) { AttachmentHelper.setAudioRecyclerViewHeight(mRvAudioAttachment, mAudioAttachmentAdapter.getItemCount(), mSpanAudio); mAudioLayoutManager.setSpanCount(mSpanAudio); mAudioAttachmentAdapter.notifyDataSetChanged(); } }