Search in sources :

Example 1 with AppData

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

the class HomeActivity method deleteApp.

private void deleteApp(int position) {
    AppData data = mLaunchpadAdapter.getList().get(position);
    new AlertDialog.Builder(this).setTitle("Delete app").setMessage("Do you want to delete " + data.getName() + "?").setPositiveButton(android.R.string.yes, (dialog, which) -> {
        mPresenter.deleteApp(data);
    }).setNegativeButton(android.R.string.no, null).show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) PackageAppData(io.virtualapp.home.models.PackageAppData) EmptyAppData(io.virtualapp.home.models.EmptyAppData) AppData(io.virtualapp.home.models.AppData)

Example 2 with AppData

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

the class HomeActivity method addAppToLauncher.

@Override
public void addAppToLauncher(AppData model) {
    List<AppData> dataList = mLaunchpadAdapter.getList();
    boolean replaced = false;
    for (int i = 0; i < dataList.size(); i++) {
        AppData data = dataList.get(i);
        if (data instanceof EmptyAppData) {
            mLaunchpadAdapter.replace(i, model);
            replaced = true;
            break;
        }
    }
    if (!replaced) {
        mLaunchpadAdapter.add(model);
        mLauncherView.smoothScrollToPosition(mLaunchpadAdapter.getItemCount() - 1);
    }
}
Also used : PackageAppData(io.virtualapp.home.models.PackageAppData) EmptyAppData(io.virtualapp.home.models.EmptyAppData) AppData(io.virtualapp.home.models.AppData) EmptyAppData(io.virtualapp.home.models.EmptyAppData)

Example 3 with AppData

use of io.virtualapp.home.models.AppData 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 4 with AppData

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

the class AppRepository method getVirtualApps.

@Override
public Promise<List<AppData>, Throwable, Void> getVirtualApps() {
    return VUiKit.defer().when(() -> {
        List<InstalledAppInfo> infos = VirtualCore.get().getInstalledApps(0);
        List<AppData> models = new ArrayList<AppData>();
        for (InstalledAppInfo info : infos) {
            if (VirtualCore.get().getLaunchIntent(info.packageName, 0) == null) {
                continue;
            }
            PackageAppData data = new PackageAppData(mContext, info);
            models.add(data);
            int[] userIds = info.getInstalledUsers();
            for (int userId : userIds) {
                if (userId != 0) {
                    models.add(new MultiplePackageAppData(data, userId));
                }
            }
        }
        return models;
    });
}
Also used : MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData) AppData(io.virtualapp.home.models.AppData) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) ArrayList(java.util.ArrayList) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) PackageAppData(io.virtualapp.home.models.PackageAppData)

Example 5 with AppData

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

the class LaunchpadAdapter method moveItem.

public void moveItem(int pos, int targetPos) {
    AppData model = mList.remove(pos);
    mList.add(targetPos, model);
    notifyItemMoved(pos, targetPos);
}
Also used : MultiplePackageAppData(io.virtualapp.home.models.MultiplePackageAppData) AppData(io.virtualapp.home.models.AppData)

Aggregations

AppData (io.virtualapp.home.models.AppData)6 MultiplePackageAppData (io.virtualapp.home.models.MultiplePackageAppData)4 PackageAppData (io.virtualapp.home.models.PackageAppData)4 InstalledAppInfo (com.lody.virtual.remote.InstalledAppInfo)2 EmptyAppData (io.virtualapp.home.models.EmptyAppData)2 Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1 AlertDialog (android.support.v7.app.AlertDialog)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 VCommends (io.virtualapp.VCommends)1 VUiKit (io.virtualapp.abs.ui.VUiKit)1 AppInfoLite (io.virtualapp.home.models.AppInfoLite)1 AppRepository (io.virtualapp.home.repo.AppRepository)1 PackageAppDataStorage (io.virtualapp.home.repo.PackageAppDataStorage)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Once (jonathanfinerty.once.Once)1