androidx.recyclerview.widget.SimpleItemAnimator Java Examples

The following examples show how to use androidx.recyclerview.widget.SimpleItemAnimator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScannerActivity.java    From Android-nRF-Blinky with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scanner);
    ButterKnife.bind(this);

    final MaterialToolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_name);
    setSupportActionBar(toolbar);

    // Create view model containing utility methods for scanning
    scannerViewModel = new ViewModelProvider(this).get(ScannerViewModel.class);
    scannerViewModel.getScannerState().observe(this, this::startScan);

    // Configure the recycler view
    final RecyclerView recyclerView = findViewById(R.id.recycler_view_ble_devices);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    final RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
    if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
    }
    final DevicesAdapter adapter = new DevicesAdapter(this, scannerViewModel.getDevices());
    adapter.setOnItemClickListener(this);
    recyclerView.setAdapter(adapter);
}
 
Example #2
Source File: MultiImagePickerFragment.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化相关adapter
 */
private void initAdapters() {
    mFolderListRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mImageSetAdapter = new PickerFolderAdapter(presenter, uiConfig);
    mFolderListRecyclerView.setAdapter(mImageSetAdapter);
    mImageSetAdapter.refreshData(imageSets);

    mAdapter = new PickerItemAdapter(selectList, new ArrayList<ImageItem>(), selectConfig, presenter, uiConfig);
    mAdapter.setHasStableIds(true);
    mAdapter.setOnActionResult(this);
    layoutManager = new GridLayoutManager(mContext, selectConfig.getColumnCount());
    if (mRecyclerView.getItemAnimator() instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
        mRecyclerView.getItemAnimator().setChangeDuration(0);// 通过设置动画执行时间为0来解决闪烁问题
    }
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setAdapter(mAdapter);
}
 
Example #3
Source File: MaterialAboutFragment.java    From material-about-library with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.mal_material_about_content, container, false);

    recyclerView = (RecyclerView) rootView.findViewById(R.id.mal_recyclerview);
    adapter = new MaterialAboutListAdapter(getViewTypeManager());
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setAdapter(adapter);

    RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
    if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
    }

    recyclerView.setAlpha(0f);
    recyclerView.setTranslationY(20);

    new ListTask(this).execute();

    return rootView;
}
 
Example #4
Source File: PresetPickerView.java    From ColorPickerDialog with Apache License 2.0 6 votes vote down vote up
@Override
protected void init() {
    inflate(getContext(), R.layout.colorpicker_layout_preset_picker, this);

    adapter = new PresetColorAdapter(DEFAULT_PRESETS).withListener(this);

    RecyclerView recycler = findViewById(R.id.recycler);
    recycler.setHasFixedSize(true);

    RecyclerView.ItemAnimator animator = recycler.getItemAnimator();
    if (animator instanceof SimpleItemAnimator)
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);

    recycler.setLayoutManager(new GridLayoutManager(getContext(), 4));
    recycler.setAdapter(adapter);
}
 
Example #5
Source File: AbstractPagerFragment.java    From cloudinary_android with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_pager_page, container, false);

    recyclerView = (RecyclerView) rootView.findViewById(R.id.mainGallery);
    recyclerView.setHasFixedSize(true);
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    RecyclerView.LayoutManager layoutManager = getLayoutManager(getContext());
    recyclerView.setLayoutManager(layoutManager);
    emptyView = rootView.findViewById(R.id.emptyListView);
    dividerSize = getResources().getDimensionPixelSize(R.dimen.grid_divider_width);
    addItemDecoration(recyclerView);
    observer = new RecyclerView.AdapterDataObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            emptyView.setVisibility(recyclerView.getAdapter().getItemCount() == 0 ? View.VISIBLE : View.INVISIBLE);
        }

        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
            emptyView.setVisibility(recyclerView.getAdapter().getItemCount() == 0 ? View.VISIBLE : View.INVISIBLE);

        }

        @Override
        public void onItemRangeRemoved(int positionStart, int itemCount) {
            super.onItemRangeRemoved(positionStart, itemCount);
            emptyView.setVisibility(recyclerView.getAdapter().getItemCount() == 0 ? View.VISIBLE : View.INVISIBLE);

        }
    };

    return rootView;
}
 
Example #6
Source File: BoxBrowseFolderGridFragment.java    From box-android-browse-sdk with Apache License 2.0 5 votes vote down vote up
protected void initRecyclerView(RecyclerView view){
    int numColumns = (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) ? 5 : 3;
    view.setLayoutManager(new GridLayoutManager(getActivity(),numColumns));
    view.addItemDecoration(new SpacesItemDecoration(8));
    if (view.getItemAnimator() instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) view.getItemAnimator()).setSupportsChangeAnimations(false);
    }
}
 
Example #7
Source File: BoxBrowseFragment.java    From box-android-browse-sdk with Apache License 2.0 5 votes vote down vote up
protected void initRecyclerView(RecyclerView view){
    view.addItemDecoration(new BoxItemDividerDecoration(getResources()));
    view.addItemDecoration(new FooterDecoration(getResources()));
    view.setLayoutManager(new LinearLayoutManager(getActivity()));
    if (view.getItemAnimator() instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) view.getItemAnimator()).setSupportsChangeAnimations(false);
    }
}
 
Example #8
Source File: ItemAnimatorControllableRecyclerView.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
/**
 * 设置是否支持移除动画
 *
 * @param supportsChangeAnimations 是否支持
 * @see Adapter#notifyItemChanged(int)
 * @see Adapter#notifyItemRangeChanged(int, int)
 */
public void setSupportsChangeAnimations(boolean supportsChangeAnimations) {
    ItemAnimator animator = getItemAnimator();
    if (animator == null)
        return;
    if (supportsChangeAnimations) {
        animator.setChangeDuration(mChangeDuration);
    } else {
        animator.setChangeDuration(0);
    }
    if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(supportsChangeAnimations);
    }
}
 
Example #9
Source File: PromotionsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void setupRecyclerView() {
  promotionsList.setAdapter(promotionsAdapter);
  promotionsList.setLayoutManager(
      new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
  RecyclerView.ItemAnimator animator = promotionsList.getItemAnimator();
  if (animator instanceof SimpleItemAnimator) {
    ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
  }
}
 
Example #10
Source File: ManageDevicesRecyclerFragment.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(
    LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

  View view = inflater.inflate(R.layout.fragment_manage_devices, container, false);

  RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler);
  HeaderAdapter myHeader = new HeaderAdapter(R.layout.device_header, R.string.my_devices);
  HeaderAdapter availableHeader =
      new HeaderAdapter(R.layout.device_header, R.string.available_devices);
  if (savedInstanceState != null) {
    myDevices.onRestoreInstanceState(savedInstanceState.getBundle(KEY_MY_DEVICES));
    availableDevices.onRestoreInstanceState(savedInstanceState.getBundle(KEY_AVAILABLE_DEVICES));
  }
  CompositeRecyclerAdapter adapter =
      new CompositeRecyclerAdapter(myHeader, myDevices, availableHeader, availableDevices);
  adapter.setHasStableIds(true);
  recyclerView.setAdapter(adapter);
  recyclerView.setLayoutManager(
      new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
  // Don't animate on change: https://code.google.com/p/android/issues/detail?id=204277.
  SimpleItemAnimator animator = new DefaultItemAnimator();
  animator.setSupportsChangeAnimations(false);
  recyclerView.setItemAnimator(animator);
  return view;
}
 
Example #11
Source File: MaterialAboutActivity.java    From material-about-library with Apache License 2.0 5 votes vote down vote up
private void initViews() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    adapter = new MaterialAboutListAdapter(getViewTypeManager());
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);
    RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
    if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
    }
}
 
Example #12
Source File: TreeView.java    From TreeView with Apache License 2.0 5 votes vote down vote up
@NonNull
private RecyclerView buildRootView() {
    RecyclerView recyclerView = new RecyclerView(context);
    /**
     * disable multi touch event to prevent terrible data set error when calculate list.
     */
    recyclerView.setMotionEventSplittingEnabled(false);
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);

    recyclerView.setLayoutManager(new LinearLayoutManager(context));
    adapter = new TreeViewAdapter(context, root, baseNodeViewFactory);
    adapter.setTreeView(this);
    recyclerView.setAdapter(adapter);
    return recyclerView;
}
 
Example #13
Source File: ColorListPickerDialog.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
private View buildDialogView() {
    View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_color_picker, null);

    RecyclerView recyclerView = view.findViewById(R.id.items);
    recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
    recyclerView.setAdapter(new ColorListAdapter(this));
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);

    return view;
}
 
Example #14
Source File: ScannerActivity.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scanner);
    ButterKnife.bind(this);

    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.app_name);

    // Create view model containing utility methods for scanning
    mScannerViewModel = new ViewModelProvider(this, mViewModelFactory)
            .get(ScannerViewModel.class);
    mScannerViewModel.getScannerState().observe(this, this::startScan);

    // Configure the recycler view
    final RecyclerView recyclerView = findViewById(R.id.recycler_view_ble_devices);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final DividerItemDecoration dividerItemDecoration =
            new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
    recyclerView.addItemDecoration(dividerItemDecoration);
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    final DevicesAdapter adapter =
            new DevicesAdapter(this, mScannerViewModel.getDevices());
    adapter.setOnItemClickListener(this);
    recyclerView.setAdapter(adapter);
}
 
Example #15
Source File: ScannerActivity.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scanner);
    ButterKnife.bind(this);

    // Create view model containing utility methods for scanning
    mViewModel = new ViewModelProvider(this, mViewModelFactory).get(ScannerViewModel.class);

    final Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.title_scanner);
    setSupportActionBar(toolbar);
    //noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    if (getIntent() != null) {
        mScanWithProxyService = getIntent().getBooleanExtra(Utils.EXTRA_DATA_PROVISIONING_SERVICE, true);
        if (mScanWithProxyService) {
            getSupportActionBar().setSubtitle(R.string.sub_title_scanning_nodes);
        } else {
            getSupportActionBar().setSubtitle(R.string.sub_title_scanning_proxy_node);
        }
    }

    // Configure the recycler view
    final RecyclerView recyclerViewDevices = findViewById(R.id.recycler_view_ble_devices);
    recyclerViewDevices.setLayoutManager(new LinearLayoutManager(this));
    final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerViewDevices.getContext(), DividerItemDecoration.VERTICAL);
    recyclerViewDevices.addItemDecoration(dividerItemDecoration);

    final SimpleItemAnimator itemAnimator = (SimpleItemAnimator) recyclerViewDevices.getItemAnimator();
    if (itemAnimator != null) itemAnimator.setSupportsChangeAnimations(false);

    final DevicesAdapter adapter = new DevicesAdapter(this, mViewModel.getScannerRepository().getScannerResults());
    adapter.setOnItemClickListener(this);
    recyclerViewDevices.setAdapter(adapter);

    mViewModel.getScannerRepository().getScannerState().observe(this, this::startScan);
}
 
Example #16
Source File: TrackersListAdapter.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
public TrackersListAdapter(Context c,
                           RecyclerView root,
                           Integer appUid) {
    recyclerView = root;
    mContext = c;
    mAppUid = appUid;

    // Removes blinks
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
}
 
Example #17
Source File: PuzzleSelectorActivity.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
private void initPhotos() {
    rvPhotos = (RecyclerView) findViewById(R.id.rv_photos);
    ((SimpleItemAnimator) rvPhotos.getItemAnimator()).setSupportsChangeAnimations(false);//去除item更新的闪光

    photoList.addAll(albumModel.getCurrAlbumItemPhotos(0));
    photosAdapter = new PuzzleSelectorAdapter(this, photoList, this);

    int columns = getResources().getInteger(R.integer.photos_columns_easy_photos);

    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, columns);
    rvPhotos.setLayoutManager(gridLayoutManager);
    rvPhotos.setAdapter(photosAdapter);
}
 
Example #18
Source File: PictureMultiCuttingActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * 动态添加多图裁剪底部预览图片列表
 */
private void addPhotoRecyclerView() {
    boolean isMultipleSkipCrop = getIntent().getBooleanExtra(UCrop.Options.EXTRA_SKIP_MULTIPLE_CROP, true);
    mRecyclerView = new RecyclerView(this);
    mRecyclerView.setId(R.id.id_recycler);
    mRecyclerView.setBackgroundColor(ContextCompat.getColor(this, R.color.ucrop_color_widget_background));
    RelativeLayout.LayoutParams lp =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                    ScreenUtils.dip2px(this, 80));
    mRecyclerView.setLayoutParams(lp);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
    mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    if (isAnimation) {
        LayoutAnimationController animation = AnimationUtils
                .loadLayoutAnimation(getApplicationContext(), R.anim.ucrop_layout_animation_fall_down);
        mRecyclerView.setLayoutAnimation(animation);
    }
    mRecyclerView.setLayoutManager(mLayoutManager);
    // 解决调用 notifyItemChanged 闪烁问题,取消默认动画
    ((SimpleItemAnimator) mRecyclerView.getItemAnimator())
            .setSupportsChangeAnimations(false);
    resetCutDataStatus();
    list.get(cutIndex).setCut(true);
    mAdapter = new PicturePhotoGalleryAdapter(this, list);
    mRecyclerView.setAdapter(mAdapter);
    if (isMultipleSkipCrop) {
        mAdapter.setOnItemClickListener(new PicturePhotoGalleryAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, View view) {
                CutInfo cutInfo = list.get(position);
                if (MimeType.isHasVideo(cutInfo.getMimeType())) {
                    return;
                }
                if (cutIndex == position) {
                    return;
                }
                resetLastCropStatus();
                cutIndex = position;
                oldCutIndex = cutIndex;
                resetCutData();
            }
        });
    }
    uCropPhotoBox.addView(mRecyclerView);
    changeLayoutParams(mShowBottomControls);

    // 裁剪框居于RecyclerView之上
    FrameLayout uCropFrame = findViewById(R.id.ucrop_frame);
    ((RelativeLayout.LayoutParams) uCropFrame.getLayoutParams())
            .addRule(RelativeLayout.ABOVE, R.id.id_recycler);

    // RecyclerView居于BottomControls之上
    ((RelativeLayout.LayoutParams) mRecyclerView.getLayoutParams())
            .addRule(RelativeLayout.ABOVE, R.id.controls_wrapper);
}
 
Example #19
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
@Override
protected void initWidgets() {
    super.initWidgets();
    container = findViewById(R.id.container);
    titleViewBg = findViewById(R.id.titleViewBg);
    mIvPictureLeftBack = findViewById(R.id.pictureLeftBack);
    mTvPictureTitle = findViewById(R.id.picture_title);
    mTvPictureRight = findViewById(R.id.picture_right);
    mTvPictureOk = findViewById(R.id.picture_tv_ok);
    mCbOriginal = findViewById(R.id.cb_original);
    mIvArrow = findViewById(R.id.ivArrow);
    mTvPicturePreview = findViewById(R.id.picture_id_preview);
    mTvPictureImgNum = findViewById(R.id.picture_tvMediaNum);
    mRecyclerView = findViewById(R.id.picture_recycler);
    mBottomLayout = findViewById(R.id.rl_bottom);
    mTvEmpty = findViewById(R.id.tv_empty);
    isNumComplete(numComplete);
    if (!numComplete) {
        animation = AnimationUtils.loadAnimation(this, R.anim.picture_anim_modal_in);
    }
    mTvPicturePreview.setOnClickListener(this);
    if (config.isAutomaticTitleRecyclerTop) {
        titleViewBg.setOnClickListener(this);
    }
    mTvPicturePreview.setVisibility(config.chooseMode != PictureMimeType.ofAudio() && config.enablePreview ? View.VISIBLE : View.GONE);
    mBottomLayout.setVisibility(config.selectionMode == PictureConfig.SINGLE
            && config.isSingleDirectReturn ? View.GONE : View.VISIBLE);
    mIvPictureLeftBack.setOnClickListener(this);
    mTvPictureRight.setOnClickListener(this);
    mTvPictureOk.setOnClickListener(this);
    mTvPictureImgNum.setOnClickListener(this);
    mTvPictureTitle.setOnClickListener(this);
    mIvArrow.setOnClickListener(this);
    String title = config.chooseMode == PictureMimeType.ofAudio() ?
            getString(R.string.picture_all_audio) : getString(R.string.picture_camera_roll);
    mTvPictureTitle.setText(title);
    mTvPictureTitle.setTag(R.id.view_tag, -1);
    folderWindow = new FolderPopWindow(this, config);
    folderWindow.setArrowImageView(mIvArrow);
    folderWindow.setOnAlbumItemClickListener(this);
    mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(config.imageSpanCount,
            ScreenUtils.dip2px(this, 2), false));
    mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), config.imageSpanCount));
    if (!config.isPageStrategy) {
        mRecyclerView.setHasFixedSize(true);
    } else {
        mRecyclerView.setReachBottomRow(RecyclerPreloadView.BOTTOM_PRELOAD);
        mRecyclerView.setOnRecyclerViewPreloadListener(PictureSelectorActivity.this);
    }
    RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
    if (itemAnimator != null) {
        ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
        mRecyclerView.setItemAnimator(null);
    }
    loadAllMediaData();
    mTvEmpty.setText(config.chooseMode == PictureMimeType.ofAudio() ?
            getString(R.string.picture_audio_empty)
            : getString(R.string.picture_empty));
    StringUtils.tempTextFont(mTvEmpty, config.chooseMode);
    mAdapter = new PictureImageGridAdapter(getContext(), config);
    mAdapter.setOnPhotoSelectChangedListener(this);

    switch (config.animationMode) {
        case AnimationType
                .ALPHA_IN_ANIMATION:
            mRecyclerView.setAdapter(new AlphaInAnimationAdapter(mAdapter));
            break;
        case AnimationType
                .SLIDE_IN_BOTTOM_ANIMATION:
            mRecyclerView.setAdapter(new SlideInBottomAnimationAdapter(mAdapter));
            break;
        default:
            mRecyclerView.setAdapter(mAdapter);
            break;
    }
    if (config.isOriginalControl) {
        mCbOriginal.setVisibility(View.VISIBLE);
        mCbOriginal.setChecked(config.isCheckOriginalImage);
        mCbOriginal.setOnCheckedChangeListener((buttonView, isChecked) -> {
            config.isCheckOriginalImage = isChecked;
        });
    }
}
 
Example #20
Source File: ThreadFragment.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    final Bundle bundle = getArguments();
    final ThreadFragmentArgs arguments = ThreadFragmentArgs.fromBundle(bundle == null ? new Bundle() : bundle);
    final String threadId = arguments.getThread();
    final String label = arguments.getLabel();
    final boolean triggerRead = !Arrays.asList(arguments.getKeywords()).contains(Keyword.SEEN);
    final ViewModelProvider viewModelProvider = new ViewModelProvider(
            getViewModelStore(),
            new ThreadViewModelFactory(
                    requireActivity().getApplication(),
                    getLttrsViewModel().getAccount(),
                    threadId,
                    label,
                    triggerRead
            )
    );
    threadViewModel = viewModelProvider.get(ThreadViewModel.class);
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_thread, container, false);

    //do we want a custom layout manager that does *NOT* remember scroll position when more
    //than one item is expanded. with variable sized items this might be annoying

    threadAdapter = new ThreadAdapter(threadViewModel.expandedItems);
    threadAdapter.setSubjectWithImportance(SubjectWithImportance.of(
            threadId,
            Strings.emptyToNull(arguments.getSubject()),
            arguments.getImportant()
    ));

    //the default change animation causes UI glitches when expanding or collapsing item
    //for now it's better to just disable it. In the future we may write our own animator
    RecyclerView.ItemAnimator itemAnimator = binding.list.getItemAnimator();
    if (itemAnimator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
    }

    binding.list.setAdapter(threadAdapter);
    threadViewModel.getEmails().observe(getViewLifecycleOwner(), this::onEmailsChanged);
    threadViewModel.getSubjectWithImportance().observe(getViewLifecycleOwner(), threadAdapter::setSubjectWithImportance);
    threadViewModel.getFlagged().observe(getViewLifecycleOwner(), threadAdapter::setFlagged);
    threadViewModel.getMenuConfiguration().observe(getViewLifecycleOwner(), menuConfiguration -> {
        this.menuConfiguration = menuConfiguration;
        requireActivity().invalidateOptionsMenu();
    });
    threadAdapter.setOnFlaggedToggledListener(this);
    threadAdapter.setOnComposeActionTriggeredListener(this);
    threadViewModel.getThreadViewRedirect().observe(getViewLifecycleOwner(), this::onThreadViewRedirect);
    return binding.getRoot();
}
 
Example #21
Source File: DownloadsScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_download, container, false);

    View content = ViewUtils.$$(view, R.id.content);
    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view);
    FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller);
    mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mViewTransition = new ViewTransition(content, tip);

    Context context = getContext2();
    AssertUtils.assertNotNull(content);
    Resources resources = context.getResources();

    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_download);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);

    mAdapter = new DownloadAdapter();
    mAdapter.setHasStableIds(true);
    mRecyclerView.setAdapter(mAdapter);
    mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
    mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
    mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setOnItemLongClickListener(this);
    mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM);
    mRecyclerView.setCustomCheckedListener(new DownloadChoiceListener());
    // Cancel change animation
    RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
    if (itemAnimator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
    }
    int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
    int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
    int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
    MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
    mRecyclerView.addItemDecoration(decoration);
    decoration.applyPaddings(mRecyclerView);
    if (mInitPosition >= 0) {
        mRecyclerView.scrollToPosition(mInitPosition);
        mInitPosition = -1;
    }

    fastScroller.attachToRecyclerView(mRecyclerView);
    HandlerDrawable handlerDrawable = new HandlerDrawable();
    handlerDrawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent));
    fastScroller.setHandlerDrawable(handlerDrawable);
    fastScroller.setOnDragHandlerListener(this);

    mFabLayout.setExpanded(false, false);
    mFabLayout.setHidePrimaryFab(true);
    mFabLayout.setAutoCancel(false);
    mFabLayout.setOnClickFabListener(this);
    addAboveSnackView(mFabLayout);

    updateView();

    guide();

    return view;
}
 
Example #22
Source File: DownloadsScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_download, container, false);

    View content = ViewUtils.$$(view, R.id.content);
    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view);
    FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller);
    mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mViewTransition = new ViewTransition(content, tip);

    Context context = getContext2();
    AssertUtils.assertNotNull(content);
    Resources resources = context.getResources();

    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_download);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);

    mAdapter = new DownloadAdapter();
    mAdapter.setHasStableIds(true);
    mRecyclerView.setAdapter(mAdapter);
    mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
    mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
    mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setOnItemLongClickListener(this);
    mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM);
    mRecyclerView.setCustomCheckedListener(new DownloadChoiceListener());
    // Cancel change animation
    RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
    if (itemAnimator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
    }
    int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
    int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
    int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
    MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
    mRecyclerView.addItemDecoration(decoration);
    decoration.applyPaddings(mRecyclerView);
    if (mInitPosition >= 0) {
        mRecyclerView.scrollToPosition(mInitPosition);
        mInitPosition = -1;
    }

    fastScroller.attachToRecyclerView(mRecyclerView);
    HandlerDrawable handlerDrawable = new HandlerDrawable();
    handlerDrawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent));
    fastScroller.setHandlerDrawable(handlerDrawable);
    fastScroller.setOnDragHandlerListener(this);

    mFabLayout.setExpanded(false, false);
    mFabLayout.setHidePrimaryFab(true);
    mFabLayout.setAutoCancel(false);
    mFabLayout.setOnClickFabListener(this);
    addAboveSnackView(mFabLayout);

    updateView();

    guide();

    return view;
}
 
Example #23
Source File: EasyPhotosActivity.java    From EasyPhotos with Apache License 2.0 4 votes vote down vote up
private void initView() {

        if (albumModel.getAlbumItems().isEmpty()) {
            Toast.makeText(this, R.string.no_photos_easy_photos, Toast.LENGTH_LONG).show();
            if (Setting.isShowCamera) {
                launchCamera(Code.REQUEST_CAMERA);
            } else {
                finish();
            }
            return;
        }

        EasyPhotos.setAdListener(this);
        if (Setting.hasPhotosAd()) {
            findViewById(R.id.m_tool_bar_bottom_line).setVisibility(View.GONE);
        }
        ivCamera = findViewById(R.id.fab_camera);
        if (Setting.isShowCamera && Setting.isBottomRightCamera()) {
            ivCamera.setVisibility(View.VISIBLE);
        }
        if (!Setting.showPuzzleMenu) {
            findViewById(R.id.tv_puzzle).setVisibility(View.GONE);
        }
        mSecondMenus = findViewById(R.id.m_second_level_menu);
        int columns = getResources().getInteger(R.integer.photos_columns_easy_photos);
        tvAlbumItems = findViewById(R.id.tv_album_items);
        tvAlbumItems.setText(albumModel.getAlbumItems().get(0).name);
        tvDone = findViewById(R.id.tv_done);
        rvPhotos = findViewById(R.id.rv_photos);
        ((SimpleItemAnimator) rvPhotos.getItemAnimator()).setSupportsChangeAnimations(false);
        //去除item更新的闪光
        photoList.clear();
        photoList.addAll(albumModel.getCurrAlbumItemPhotos(0));
        int index = 0;
        if (Setting.hasPhotosAd()) {
            photoList.add(index, Setting.photosAdView);
        }
        if (Setting.isShowCamera && !Setting.isBottomRightCamera()) {
            if (Setting.hasPhotosAd()) index = 1;
            photoList.add(index, null);
        }
        photosAdapter = new PhotosAdapter(this, photoList, this);

        gridLayoutManager = new GridLayoutManager(this, columns);
        if (Setting.hasPhotosAd()) {
            gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    if (position == 0) {
                        return gridLayoutManager.getSpanCount();//独占一行
                    } else {
                        return 1;//只占一行中的一列
                    }
                }
            });
        }
        rvPhotos.setLayoutManager(gridLayoutManager);
        rvPhotos.setAdapter(photosAdapter);
        tvOriginal = findViewById(R.id.tv_original);
        if (Setting.showOriginalMenu) {
            processOriginalMenu();
        } else {
            tvOriginal.setVisibility(View.GONE);
        }
        tvPreview = findViewById(R.id.tv_preview);

        initAlbumItems();
        shouldShowMenuDone();
        setClick(R.id.iv_album_items, R.id.tv_clear, R.id.iv_second_menu, R.id.tv_puzzle);
        setClick(tvAlbumItems, rootViewAlbumItems, tvDone, tvOriginal, tvPreview, ivCamera);
    }