Java Code Examples for androidx.recyclerview.widget.ItemTouchHelper#attachToRecyclerView()
The following examples show how to use
androidx.recyclerview.widget.ItemTouchHelper#attachToRecyclerView() .
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: SortFragment.java From prayer-times-android with Apache License 2.0 | 6 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle bdl) { View v = inflater.inflate(R.layout.vakit_sort_main, container, false); RecyclerView recyclerMan = v.findViewById(R.id.list); mAdapter = new MyAdapter(); recyclerMan.setAdapter(mAdapter); LinearLayoutManager linLayMan = new LinearLayoutManager(getContext()); recyclerMan.setLayoutManager(linLayMan); recyclerMan.setHasFixedSize(true); ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(); mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(recyclerMan); setHasOptionsMenu(true); Times.getTimes().observe(this, mAdapter); mAdapter.onChanged(Times.getTimes()); return v; }
Example 2
Source File: CGroupActivity.java From call_manage with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setThemeType(ThemeUtils.TYPE_NORMAL); setContentView(R.layout.activity_cgroup); ButterKnife.bind(this); Intent intent = getIntent(); if (intent == null || !intent.hasExtra(EXTRA_LIST_ID)) { throw new IllegalArgumentException("You must start this activity with a list id"); } long listId = intent.getLongExtra(EXTRA_LIST_ID, -1); mRecyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false)); mAdapter = new SingleCGroupAdapter(this, mRecyclerView, this); mRecyclerView.setAdapter(mAdapter); ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mAdapter); mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(mRecyclerView); mViewModel = ViewModelProviders.of(this).get(CGroupViewModel.class); mViewModel.setListId(listId); mViewModel.getContacts().observe(this, contacts -> { mContacts = contacts; mAdapter.setData(contacts); }); mViewModel.getCGroup().observe(this, cGroups -> { if (cGroups != null && !cGroups.isEmpty()) { setLabel(cGroups.get(0).getName()); } }); }
Example 3
Source File: OrderableVideosGridFragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if(videoGridAdapter instanceof OrderableVideoGridAdapter) { ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback((OrderableVideoGridAdapter)videoGridAdapter); ItemTouchHelper touchHelper = new ItemTouchHelper(callback); touchHelper.attachToRecyclerView(gridView); } return view; }
Example 4
Source File: BookSourceActivity.java From HaoReader with GNU General Public License v3.0 | 5 votes |
private void initRecyclerView() { recyclerView.setLayoutManager(new LinearLayoutManager(this)); adapter = new BookSourceAdapter(this); recyclerView.setAdapter(adapter); itemTouchHelpCallback = new MyItemTouchHelpCallback(); itemTouchHelpCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener()); itemTouchHelpCallback.setDragEnable(true); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelpCallback); itemTouchHelper.attachToRecyclerView(recyclerView); setDragEnable(getPreferences().getInt("SourceSort", 0)); }
Example 5
Source File: BrickDataManager.java From brickkit-android with Apache License 2.0 | 5 votes |
/** * This attaches the touch helper to the recycler view if swipe or drag and drop are enabled. */ private void attachTouchHelper() { ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new BrickItemTouchHelperCallback(this)); if ((dragAndDrop || swipeToDismiss) && brickRecyclerAdapter != null) { itemTouchHelper.attachToRecyclerView(brickRecyclerAdapter.getRecyclerView()); } else { itemTouchHelper.attachToRecyclerView(null); } }
Example 6
Source File: RecentlyWatchedFragment.java From YouTube-In-Background with MIT License | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_recently_watched, container, false); recyclerView = rootView.findViewById(R.id.recently_played); recyclerView.setLayoutManager(getLayoutManager()); recyclerView.addItemDecoration(getItemDecoration()); recyclerView.getItemAnimator().setAddDuration(500); recyclerView.getItemAnimator().setChangeDuration(500); recyclerView.getItemAnimator().setMoveDuration(500); recyclerView.getItemAnimator().setRemoveDuration(500); videoListAdapter = getAdapter(); videoListAdapter.setOnItemClickListener(this); videoListAdapter.setOnStartDragListener(this); recyclerView.setAdapter(videoListAdapter); ItemTouchHelper.Callback callback = new SimpleItemTouchCallback(videoListAdapter); itemTouchHelper = new ItemTouchHelper(callback); itemTouchHelper.attachToRecyclerView(recyclerView); return rootView; }
Example 7
Source File: BookSourceActivity.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
private void initRecyclerView() { recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL)); adapter = new BookSourceAdapter(this); recyclerView.setAdapter(adapter); itemTouchCallback = new ItemTouchCallback(); itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener()); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); itemTouchHelper.attachToRecyclerView(recyclerView); setDragEnable(getSort()); }
Example 8
Source File: ApplicationsDialogPreferenceFragmentX.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
@Override protected void onBindDialogView(View view) { super.onBindDialogView(view); AppCompatImageButton addButton = view.findViewById(R.id.applications_pref_dlg_add); TooltipCompat.setTooltipText(addButton, getString(R.string.applications_pref_dlg_add_button_tooltip)); RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext()); applicationsListView = view.findViewById(R.id.applications_pref_dlg_listview); //applicationsListView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL)); applicationsListView.setLayoutManager(layoutManager); applicationsListView.setHasFixedSize(true); linlaProgress = view.findViewById(R.id.applications_pref_dlg_linla_progress); rellaDialog = view.findViewById(R.id.applications_pref_dlg_rella_dialog); listAdapter = new ApplicationsDialogPreferenceAdapterX(prefContext, preference, this); // added touch helper for drag and drop items ItemTouchHelper.Callback callback = new ItemTouchHelperCallback(listAdapter, false, false); itemTouchHelper = new ItemTouchHelper(callback); itemTouchHelper.attachToRecyclerView(applicationsListView); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { preference.startEditor(null); } }); refreshListView(false); }
Example 9
Source File: RecyclerViewExampleActivity.java From realm-android-adapters with Apache License 2.0 | 5 votes |
private void setUpRecyclerView() { adapter = new MyRecyclerViewAdapter(realm.where(Parent.class).findFirst().getItemList()); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter); recyclerView.setHasFixedSize(true); recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); TouchHelperCallback touchHelperCallback = new TouchHelperCallback(); ItemTouchHelper touchHelper = new ItemTouchHelper(touchHelperCallback); touchHelper.attachToRecyclerView(recyclerView); }
Example 10
Source File: BookSourceActivity.java From a with GNU General Public License v3.0 | 5 votes |
private void initRecyclerView() { recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL)); adapter = new BookSourceAdapter(this); recyclerView.setAdapter(adapter); itemTouchCallback = new ItemTouchCallback(); itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener()); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); itemTouchHelper.attachToRecyclerView(recyclerView); setDragEnable(getSort()); }
Example 11
Source File: ManageChannelActivity.java From indigenous-android with GNU General Public License v3.0 | 5 votes |
/** * Start channels. */ public void startChannels() { noConnection.setVisibility(View.GONE); Channels = new ArrayList<>(); adapter = new ManageChannelListAdapter(this, Channels, user, this, isShare, incomingText, layout); ItemTouchHelper.Callback callback = new ItemMoveCallback(adapter); touchHelper = new ItemTouchHelper(callback); touchHelper.attachToRecyclerView(listChannel); listChannel.setAdapter(adapter); loadChannels(); }
Example 12
Source File: TxtChapterRuleActivity.java From a with GNU General Public License v3.0 | 5 votes |
private void initRecyclerView() { recyclerView.setLayoutManager(new LinearLayoutManager(this)); adapter = new TxtChapterRuleAdapter(this); recyclerView.setAdapter(adapter); ItemTouchCallback itemTouchCallback = new ItemTouchCallback(); itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener()); itemTouchCallback.setDragEnable(true); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); itemTouchHelper.attachToRecyclerView(recyclerView); }
Example 13
Source File: ReplaceRuleActivity.java From a with GNU General Public License v3.0 | 5 votes |
private void initRecyclerView() { recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL)); adapter = new ReplaceRuleAdapter(this); recyclerView.setAdapter(adapter); ItemTouchCallback itemTouchCallback = new ItemTouchCallback(); itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener()); itemTouchCallback.setDragEnable(true); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); itemTouchHelper.attachToRecyclerView(recyclerView); }
Example 14
Source File: GroupsFragment.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Nullable @Override public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { @SuppressLint("InflateParams") final View rootView = inflater.inflate(R.layout.fragment_groups, null); mViewModel = new ViewModelProvider(requireActivity(), mViewModelFactory).get(SharedViewModel.class); ButterKnife.bind(this, rootView); final ExtendedFloatingActionButton fab = rootView.findViewById(R.id.fab_add_group); // Configure the recycler view final RecyclerView recyclerViewGroups = rootView.findViewById(R.id.recycler_view_groups); recyclerViewGroups.setLayoutManager(new LinearLayoutManager(requireContext())); final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerViewGroups.getContext(), DividerItemDecoration.VERTICAL); recyclerViewGroups.addItemDecoration(dividerItemDecoration); final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this); final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback); itemTouchHelper.attachToRecyclerView(recyclerViewGroups); final GroupAdapter adapter = new GroupAdapter(requireContext()); adapter.setOnItemClickListener(this); recyclerViewGroups.setAdapter(adapter); mViewModel.getNetworkLiveData().observe(getViewLifecycleOwner(), meshNetworkLiveData -> { if (meshNetworkLiveData != null) { if (meshNetworkLiveData.getMeshNetwork().getGroups().isEmpty()) { mEmptyView.setVisibility(View.VISIBLE); } else { mEmptyView.setVisibility(View.INVISIBLE); } } }); mViewModel.getGroups().observe(getViewLifecycleOwner(), groups -> { final MeshNetwork network = mViewModel.getNetworkLiveData().getMeshNetwork(); adapter.updateAdapter(network, groups); }); fab.setOnClickListener(v -> { DialogFragmentCreateGroup fragmentCreateGroup = DialogFragmentCreateGroup.newInstance(); fragmentCreateGroup.show(getChildFragmentManager(), null); }); recyclerViewGroups.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) { super.onScrolled(recyclerView, dx, dy); final LinearLayoutManager m = (LinearLayoutManager) recyclerView.getLayoutManager(); if (m != null) { if (m.findFirstCompletelyVisibleItemPosition() == 0) { fab.extend(); } else { fab.shrink(); } } } }); return rootView; }
Example 15
Source File: BaseModelConfigurationActivity.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_model_configuration); ButterKnife.bind(this); mViewModel = new ViewModelProvider(this, mViewModelFactory).get(ModelConfigurationViewModel.class); mHandler = new Handler(); final MeshModel meshModel = mViewModel.getSelectedModel().getValue(); //noinspection ConstantConditions final String modelName = meshModel.getModelName(); // Set up views final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); //noinspection ConstantConditions getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(modelName); final int modelId = meshModel.getModelId(); getSupportActionBar().setSubtitle(getString(R.string.model_id, CompositionDataParser.formatModelIdentifier(modelId, true))); recyclerViewAddresses = findViewById(R.id.recycler_view_addresses); recyclerViewAddresses.setLayoutManager(new LinearLayoutManager(this)); final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this); final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback); itemTouchHelper.attachToRecyclerView(recyclerViewAddresses); mSubscriptionAdapter = new GroupAddressAdapter(this, mViewModel.getNetworkLiveData().getMeshNetwork(), mViewModel.getSelectedModel()); recyclerViewAddresses.setAdapter(mSubscriptionAdapter); recyclerViewBoundKeys = findViewById(R.id.recycler_view_bound_keys); recyclerViewBoundKeys.setLayoutManager(new LinearLayoutManager(this)); final ItemTouchHelper.Callback itemTouchHelperCallbackKeys = new RemovableItemTouchHelperCallback(this); final ItemTouchHelper itemTouchHelperKeys = new ItemTouchHelper(itemTouchHelperCallbackKeys); itemTouchHelperKeys.attachToRecyclerView(recyclerViewBoundKeys); mBoundAppKeyAdapter = new BoundAppKeysAdapter(this, mViewModel.getNetworkLiveData().getAppKeys(), mViewModel.getSelectedModel()); recyclerViewBoundKeys.setAdapter(mBoundAppKeyAdapter); mActionBindAppKey.setOnClickListener(v -> { final ProvisionedMeshNode node = mViewModel.getSelectedMeshNode().getValue(); if (node != null && !node.isExist(SigModelParser.CONFIGURATION_SERVER)) { return; } if (!checkConnectivity()) return; final Intent bindAppKeysIntent = new Intent(BaseModelConfigurationActivity.this, AppKeysActivity.class); bindAppKeysIntent.putExtra(EXTRA_DATA, BIND_APP_KEY); startActivityForResult(bindAppKeysIntent, SELECT_KEY); }); mPublishAddressView.setText(R.string.none); mActionSetPublication.setOnClickListener(v -> navigateToPublication()); mActionClearPublication.setOnClickListener(v -> clearPublication()); mActionSubscribe.setOnClickListener(v -> { if (!checkConnectivity()) return; //noinspection ConstantConditions final ArrayList<Group> groups = new ArrayList<>(mViewModel.getGroups().getValue()); final DialogFragmentGroupSubscription fragmentSubscriptionAddress = DialogFragmentGroupSubscription.newInstance(groups); fragmentSubscriptionAddress.show(getSupportFragmentManager(), null); }); mViewModel.getSelectedModel().observe(this, model -> { if (model != null) { updateAppStatusUi(model); updatePublicationUi(model); updateSubscriptionUi(model); } }); mViewModel.getTransactionStatus().observe(this, transactionStatus -> { if (transactionStatus != null) { hideProgressBar(); final String message = getString(R.string.operation_timed_out); DialogFragmentTransactionStatus fragmentMessage = DialogFragmentTransactionStatus.newInstance("Transaction Failed", message); fragmentMessage.show(getSupportFragmentManager(), null); } }); mViewModel.isConnectedToProxy().observe(this, isConnected -> { if (isConnected != null) { mIsConnected = isConnected; hideProgressBar(); updateClickableViews(); } invalidateOptionsMenu(); }); mViewModel.getMeshMessage().observe(this, this::updateMeshMessage); final Boolean isConnectedToNetwork = mViewModel.isConnectedToProxy().getValue(); if (isConnectedToNetwork != null) { mIsConnected = isConnectedToNetwork; } invalidateOptionsMenu(); }
Example 16
Source File: RangesActivity.java From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@SuppressWarnings("ConstantConditions") @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ranges); ButterKnife.bind(this); mViewModel = new ViewModelProvider(this, mViewModelFactory).get(RangesViewModel.class); mType = getIntent().getExtras().getInt(Utils.RANGE_TYPE); //Bind ui final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); final RecyclerView recyclerView = findViewById(R.id.recycler_view); final View rangesContainer = findViewById(R.id.info_ranges); rangesContainer.findViewById(R.id.container).setVisibility(View.VISIBLE); mRangeView = rangesContainer.findViewById(R.id.range); final TextView startAddress = rangesContainer.findViewById(R.id.start_address); final TextView endAddress = rangesContainer.findViewById(R.id.end_address); final ExtendedFloatingActionButton fab_add = findViewById(R.id.fab_add); mProvisioner = mViewModel.getSelectedProvisioner().getValue(); switch (mType) { case Utils.GROUP_RANGE: startAddress.setText(MeshAddress.formatAddress(MeshAddress.START_GROUP_ADDRESS, true)); endAddress.setText(MeshAddress.formatAddress(MeshAddress.END_GROUP_ADDRESS, true)); getSupportActionBar().setTitle(R.string.title_edit_group_ranges); mRangeAdapter = new RangeAdapter(this, mProvisioner.getProvisionerUuid(), mProvisioner.getAllocatedGroupRanges(), mViewModel.getNetworkLiveData().getProvisioners()); break; case Utils.SCENE_RANGE: startAddress.setText(MeshAddress.formatAddress(0x0000, true)); endAddress.setText(MeshAddress.formatAddress(0xFFFF, true)); getSupportActionBar().setTitle(R.string.title_edit_scene_ranges); mRangeAdapter = new RangeAdapter(this, mProvisioner.getProvisionerUuid(), mProvisioner.getAllocatedSceneRanges(), mViewModel.getNetworkLiveData().getProvisioners()); break; default: case Utils.UNICAST_RANGE: startAddress.setText(MeshAddress.formatAddress(MeshAddress.START_UNICAST_ADDRESS, true)); endAddress.setText(MeshAddress.formatAddress(MeshAddress.END_UNICAST_ADDRESS, true)); getSupportActionBar().setTitle(R.string.title_edit_unicast_ranges); mRangeAdapter = new RangeAdapter(this, mProvisioner.getProvisionerUuid(), mProvisioner.getAllocatedUnicastRanges(), mViewModel.getNetworkLiveData().getProvisioners()); break; } mRangeAdapter.setOnItemClickListener(this); recyclerView.setLayoutManager(new LinearLayoutManager(this)); final DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL); recyclerView.addItemDecoration(dividerItemDecoration); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(mRangeAdapter); final ItemTouchHelper.Callback itemTouchHelperCallback = new RemovableItemTouchHelperCallback(this); final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchHelperCallback); itemTouchHelper.attachToRecyclerView(recyclerView); fab_add.setOnClickListener(v -> { switch (mType) { case Utils.GROUP_RANGE: final DialogFragmentGroupRange groupRange = DialogFragmentGroupRange.newInstance(null); groupRange.show(getSupportFragmentManager(), null); break; case Utils.SCENE_RANGE: final DialogFragmentSceneRange sceneRange = DialogFragmentSceneRange.newInstance(null); sceneRange.show(getSupportFragmentManager(), null); break; default: case Utils.UNICAST_RANGE: final DialogFragmentUnicastRange unicastRange = DialogFragmentUnicastRange.newInstance(null); unicastRange.show(getSupportFragmentManager(), null); break; } }); mFabResolve.setOnClickListener(v -> resolveRanges()); updateRanges(); updateOtherRanges(); updateEmptyView(); updateResolveFab(); }
Example 17
Source File: QueueFragment.java From Hentoid with Apache License 2.0 | 4 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_queue, container, false); mEmptyText = requireViewById(rootView, R.id.queue_empty_txt); btnStart = requireViewById(rootView, R.id.btnStart); btnPause = requireViewById(rootView, R.id.btnPause); queueStatus = requireViewById(rootView, R.id.queueStatus); queueInfo = requireViewById(rootView, R.id.queueInfo); dlPreparationProgressBar = requireViewById(rootView, R.id.queueDownloadPreparationProgressBar); // Both queue control buttons actually just need to send a signal that will be processed accordingly by whom it may concern btnStart.setOnClickListener(v -> EventBus.getDefault().post(new DownloadEvent(DownloadEvent.EV_UNPAUSE))); btnPause.setOnClickListener(v -> EventBus.getDefault().post(new DownloadEvent(DownloadEvent.EV_PAUSE))); // Book list recyclerView = requireViewById(rootView, R.id.queue_list); fastAdapter = FastAdapter.with(itemAdapter); fastAdapter.setHasStableIds(true); ContentItem item = new ContentItem(ContentItem.ViewType.QUEUE); fastAdapter.registerItemFactory(item.getType(), item); recyclerView.setAdapter(fastAdapter); recyclerView.setHasFixedSize(true); llm = (LinearLayoutManager) recyclerView.getLayoutManager(); // Fast scroller new FastScrollerBuilder(recyclerView).build(); // Drag, drop & swiping SimpleDragCallback dragSwipeCallback = new SimpleSwipeDragCallback( this, this, requireContext().getResources().getDrawable(R.drawable.ic_action_delete_forever, null)); dragSwipeCallback.setNotifyAllDrops(true); dragSwipeCallback.setIsDragEnabled(false); // Despite its name, that's actually to disable drag on long tap touchHelper = new ItemTouchHelper(dragSwipeCallback); touchHelper.attachToRecyclerView(recyclerView); // Item click listener fastAdapter.setOnClickListener((v, a, i, p) -> onBookClick(i)); initToolbar(); attachButtons(fastAdapter); // Network usage display refresh compositeDisposable.add(Observable.timer(1, TimeUnit.SECONDS) .subscribeOn(Schedulers.computation()) .repeat() .observeOn(Schedulers.computation()) .map(v -> NetworkHelper.getIncomingNetworkUsage(requireContext())) .observeOn(AndroidSchedulers.mainThread()) .subscribe(this::updateNetworkUsage)); return rootView; }
Example 18
Source File: ErrorsFragment.java From Hentoid with Apache License 2.0 | 4 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // UI ELEMENTS View rootView = inflater.inflate(R.layout.fragment_queue_errors, container, false); mEmptyText = requireViewById(rootView, R.id.errors_empty_txt); // Book list container RecyclerView recyclerView = requireViewById(rootView, R.id.queue_list); fastAdapter = FastAdapter.with(itemAdapter); fastAdapter.setHasStableIds(true); ContentItem item = new ContentItem(ContentItem.ViewType.ERRORS); fastAdapter.registerItemFactory(item.getType(), item); // Gets (or creates and attaches if not yet existing) the extension from the given `FastAdapter` selectExtension = fastAdapter.getOrCreateExtension(SelectExtension.class); if (selectExtension != null) { selectExtension.setSelectable(true); selectExtension.setMultiSelect(true); selectExtension.setSelectOnLongClick(true); selectExtension.setSelectionListener((i, b) -> this.onSelectionChanged()); } recyclerView.setAdapter(fastAdapter); // Swiping SimpleSwipeCallback swipeCallback = new SimpleSwipeCallback( this, requireContext().getDrawable(R.drawable.ic_action_delete_forever)); touchHelper = new ItemTouchHelper(swipeCallback); touchHelper.attachToRecyclerView(recyclerView); // Fast scroller new FastScrollerBuilder(recyclerView).build(); // Item click listener fastAdapter.setOnClickListener((v, a, i, p) -> onBookClick(i)); initToolbar(); initSelectionToolbar(); attachButtons(fastAdapter); return rootView; }
Example 19
Source File: LibraryFragment.java From Hentoid with Apache License 2.0 | 4 votes |
/** * Initialize the UI components * * @param rootView Root view of the library screen */ private void initUI(@NonNull View rootView) { emptyText = requireViewById(rootView, R.id.library_empty_txt); // Search bar advancedSearchBar = requireViewById(rootView, R.id.advanced_search_background); // Link to advanced search advancedSearchButton = requireViewById(rootView, R.id.advanced_search_btn); advancedSearchButton.setOnClickListener(v -> onAdvancedSearchButtonClick()); // Clear search searchClearButton = requireViewById(rootView, R.id.search_clear_btn); searchClearButton.setOnClickListener(v -> { query = ""; mainSearchView.setQuery("", false); metadata.clear(); hideSearchSortBar(false); viewModel.searchUniversal(""); }); // Sort controls sortDirectionButton = requireViewById(rootView, R.id.sort_direction_btn); sortDirectionButton.setImageResource(Preferences.isContentSortDesc() ? R.drawable.ic_simple_arrow_up : R.drawable.ic_simple_arrow_down); sortDirectionButton.setOnClickListener(v -> { boolean sortDesc = !Preferences.isContentSortDesc(); Preferences.setContentSortDesc(sortDesc); // Update icon sortDirectionButton.setImageResource(sortDesc ? R.drawable.ic_simple_arrow_up : R.drawable.ic_simple_arrow_down); // Run a new search viewModel.updateOrder(); sortCommandsAutoHide.submit(true); }); sortFieldButton = requireViewById(rootView, R.id.sort_field_btn); sortFieldButton.setText(getNameFromFieldCode(Preferences.getContentSortField())); sortFieldButton.setOnClickListener(v -> { // Load and display the field popup menu PopupMenu popup = new PopupMenu(requireContext(), sortDirectionButton); popup.getMenuInflater() .inflate(R.menu.library_sort_menu, popup.getMenu()); popup.setOnMenuItemClickListener(item -> { // Update button text sortFieldButton.setText(item.getTitle()); item.setChecked(true); int fieldCode = getFieldCodeFromMenuId(item.getItemId()); if (fieldCode == Preferences.Constant.ORDER_FIELD_RANDOM) RandomSeedSingleton.getInstance().renewSeed(); Preferences.setContentSortField(fieldCode); // Run a new search viewModel.updateOrder(); sortCommandsAutoHide.submit(true); return true; }); popup.show(); //showing popup menu sortCommandsAutoHide.submit(true); }); //closing the setOnClickListener method // RecyclerView recyclerView = requireViewById(rootView, R.id.library_list); llm = (LinearLayoutManager) recyclerView.getLayoutManager(); new FastScrollerBuilder(recyclerView).build(); // Disable blink animation on card change (bind holder) // Disabled because with it, swiped undo panel doesn't appear // TODO test if everything's alright with that off /* RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); */ // Swiping SimpleSwipeCallback swipeCallback = new SimpleSwipeCallback( this, requireContext().getDrawable(R.drawable.ic_action_delete_forever)); touchHelper = new ItemTouchHelper(swipeCallback); touchHelper.attachToRecyclerView(recyclerView); // Pager pager.initUI(rootView); initPagingMethod(Preferences.getEndlessScroll()); }
Example 20
Source File: DragAndDropWrapper.java From RecyclerViewHelper with Apache License 2.0 | 2 votes |
/** * Attach to RecyclerView for drag & drop. * * @param recyclerView RecyclerView * @param isFreedom true: item can move up|down|left|right * false: item can move up|down */ public void attachToRecyclerView(RecyclerView recyclerView, boolean isFreedom) { ItemTouchHelper.Callback callback = new ItemMoveCallback(this, isFreedom); mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(recyclerView); }