Search in sources :

Example 1 with ItemOffsetDecoration

use of io.virtualapp.home.adapters.decorations.ItemOffsetDecoration in project VirtualApp by asLody.

the class HomeActivity method initLaunchpad.

private void initLaunchpad() {
    mLauncherView.setHasFixedSize(true);
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL);
    mLauncherView.setLayoutManager(layoutManager);
    mLaunchpadAdapter = new LaunchpadAdapter(this);
    SmartRecyclerAdapter wrap = new SmartRecyclerAdapter(mLaunchpadAdapter);
    View footer = new View(this);
    footer.setLayoutParams(new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, VUiKit.dpToPx(this, 60)));
    wrap.setFooterView(footer);
    mLauncherView.setAdapter(wrap);
    mLauncherView.addItemDecoration(new ItemOffsetDecoration(this, R.dimen.desktop_divider));
    ItemTouchHelper touchHelper = new ItemTouchHelper(new LauncherTouchCallback());
    touchHelper.attachToRecyclerView(mLauncherView);
    mLaunchpadAdapter.setAppClickListener((pos, data) -> {
        if (!data.isLoading()) {
            mLaunchpadAdapter.notifyItemChanged(pos);
            mPresenter.launchApp(data);
        }
    });
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ItemOffsetDecoration(io.virtualapp.home.adapters.decorations.ItemOffsetDecoration) SmartRecyclerAdapter(io.virtualapp.abs.nestedadapter.SmartRecyclerAdapter) View(android.view.View) TwoGearsView(io.virtualapp.widgets.TwoGearsView) RecyclerView(android.support.v7.widget.RecyclerView) LaunchpadAdapter(io.virtualapp.home.adapters.LaunchpadAdapter)

Example 2 with ItemOffsetDecoration

use of io.virtualapp.home.adapters.decorations.ItemOffsetDecoration in project VirtualApp by asLody.

the class ListAppFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    mRecyclerView = (DragSelectRecyclerView) view.findViewById(R.id.select_app_recycler_view);
    mProgressBar = (ProgressBar) view.findViewById(R.id.select_app_progress_bar);
    mInstallButton = (Button) view.findViewById(R.id.select_app_install_btn);
    mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL));
    mRecyclerView.addItemDecoration(new ItemOffsetDecoration(VUiKit.dpToPx(getContext(), 2)));
    mAdapter = new CloneAppListAdapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new CloneAppListAdapter.ItemEventListener() {

        @Override
        public void onItemClick(AppInfo info, int position) {
            int count = mAdapter.getSelectedCount();
            if (!mAdapter.isIndexSelected(position)) {
                if (count >= 9) {
                    Toast.makeText(getContext(), "No more then 9 apps can be chosen at a time!", Toast.LENGTH_SHORT).show();
                    return;
                }
            }
            mAdapter.toggleSelected(position);
        }

        @Override
        public boolean isSelectable(int position) {
            return mAdapter.isIndexSelected(position) || mAdapter.getSelectedCount() < 9;
        }
    });
    mAdapter.setSelectionListener(count -> {
        mInstallButton.setEnabled(count > 0);
        mInstallButton.setText(String.format(Locale.ENGLISH, "Install to SandBox (%d)", count));
    });
    mInstallButton.setOnClickListener(v -> {
        Integer[] selectedIndices = mAdapter.getSelectedIndices();
        ArrayList<AppInfoLite> dataList = new ArrayList<AppInfoLite>(selectedIndices.length);
        for (int index : selectedIndices) {
            AppInfo info = mAdapter.getItem(index);
            dataList.add(new AppInfoLite(info.packageName, info.path, info.fastOpen));
        }
        Intent data = new Intent();
        data.putParcelableArrayListExtra(VCommends.EXTRA_APP_INFO_LIST, dataList);
        getActivity().setResult(Activity.RESULT_OK, data);
        getActivity().finish();
    });
    new ListAppPresenterImpl(getActivity(), this, getSelectFrom()).start();
}
Also used : ArrayList(java.util.ArrayList) AppInfoLite(io.virtualapp.home.models.AppInfoLite) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) Intent(android.content.Intent) ItemOffsetDecoration(io.virtualapp.home.adapters.decorations.ItemOffsetDecoration) AppInfo(io.virtualapp.home.models.AppInfo) CloneAppListAdapter(io.virtualapp.home.adapters.CloneAppListAdapter)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)2 ItemOffsetDecoration (io.virtualapp.home.adapters.decorations.ItemOffsetDecoration)2 Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 View (android.view.View)1 SmartRecyclerAdapter (io.virtualapp.abs.nestedadapter.SmartRecyclerAdapter)1 CloneAppListAdapter (io.virtualapp.home.adapters.CloneAppListAdapter)1 LaunchpadAdapter (io.virtualapp.home.adapters.LaunchpadAdapter)1 AppInfo (io.virtualapp.home.models.AppInfo)1 AppInfoLite (io.virtualapp.home.models.AppInfoLite)1 TwoGearsView (io.virtualapp.widgets.TwoGearsView)1 ArrayList (java.util.ArrayList)1