Search in sources :

Example 1 with AppInfoLite

use of io.virtualapp.home.models.AppInfoLite in project VirtualApp by asLody.

the class HomePresenterImpl method addApp.

@Override
public void addApp(AppInfoLite info) {
    class AddResult {

        private PackageAppData appData;

        private int userId;
    }
    AddResult addResult = new AddResult();
    VUiKit.defer().when(() -> {
        InstalledAppInfo installedAppInfo = VirtualCore.get().getInstalledAppInfo(info.packageName, 0);
        if (installedAppInfo != null) {
            int[] userIds = installedAppInfo.getInstalledUsers();
            int nextUserId = userIds.length;
            addResult.userId = nextUserId;
            if (VUserManager.get().getUserInfo(nextUserId) == null) {
                String nextUserName = "Space " + nextUserId + 1;
                VUserInfo newUserInfo = VUserManager.get().createUser(nextUserName, VUserInfo.FLAG_ADMIN);
                if (newUserInfo == null) {
                    throw new IllegalStateException();
                }
            }
            boolean success = VirtualCore.get().installPackageAsUser(nextUserId, info.packageName);
            if (!success) {
                throw new IllegalStateException();
            }
        } else {
            InstallResult res = mRepo.addVirtualApp(info);
            if (!res.isSuccess) {
                throw new IllegalStateException();
            }
        }
    }).then((res) -> {
        addResult.appData = PackageAppDataStorage.get().acquire(info.packageName);
    }).done(res -> {
        if (addResult.userId == 0) {
            PackageAppData data = addResult.appData;
            data.isLoading = true;
            mView.addAppToLauncher(data);
            handleOptApp(data);
        } else {
            MultiplePackageAppData data = new MultiplePackageAppData(addResult.appData, addResult.userId);
            data.isLoading = true;
            mView.addAppToLauncher(data);
            handleMultipleApp(data);
        }
    });
}
Also used : VUserInfo(com.lody.virtual.os.VUserInfo) PackageAppDataStorage(io.virtualapp.home.repo.PackageAppDataStorage) InstallResult(com.lody.virtual.remote.InstallResult) VirtualCore(com.lody.virtual.client.core.VirtualCore) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) VUserManager(com.lody.virtual.os.VUserManager) PackageAppData(io.virtualapp.home.models.PackageAppData) AppData(io.virtualapp.home.models.AppData) IOException(java.io.IOException) AppRepository(io.virtualapp.home.repo.AppRepository) VCommends(io.virtualapp.VCommends) AppInfoLite(io.virtualapp.home.models.AppInfoLite) Bitmap(android.graphics.Bitmap) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) VUiKit(io.virtualapp.abs.ui.VUiKit) Once(jonathanfinerty.once.Once) Activity(android.app.Activity) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData) InstallResult(com.lody.virtual.remote.InstallResult) VUserInfo(com.lody.virtual.os.VUserInfo)

Example 2 with AppInfoLite

use of io.virtualapp.home.models.AppInfoLite 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

AppInfoLite (io.virtualapp.home.models.AppInfoLite)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 VirtualCore (com.lody.virtual.client.core.VirtualCore)1 VUserInfo (com.lody.virtual.os.VUserInfo)1 VUserManager (com.lody.virtual.os.VUserManager)1 InstallResult (com.lody.virtual.remote.InstallResult)1 InstalledAppInfo (com.lody.virtual.remote.InstalledAppInfo)1 VCommends (io.virtualapp.VCommends)1 VUiKit (io.virtualapp.abs.ui.VUiKit)1 CloneAppListAdapter (io.virtualapp.home.adapters.CloneAppListAdapter)1 ItemOffsetDecoration (io.virtualapp.home.adapters.decorations.ItemOffsetDecoration)1 AppData (io.virtualapp.home.models.AppData)1 AppInfo (io.virtualapp.home.models.AppInfo)1 MultiplePackageAppData (io.virtualapp.home.models.MultiplePackageAppData)1 PackageAppData (io.virtualapp.home.models.PackageAppData)1 AppRepository (io.virtualapp.home.repo.AppRepository)1 PackageAppDataStorage (io.virtualapp.home.repo.PackageAppDataStorage)1