Search in sources :

Example 1 with DialogWrapper

use of com.github.yeriomin.yalpstore.view.DialogWrapper in project YalpStore by yeriomin.

the class PurchaseTask method getNotPurchasedDialog.

private DialogWrapperAbstract getNotPurchasedDialog(Activity activity) {
    DialogWrapperAbstract builder = new DialogWrapper(activity);
    builder.setMessage(R.string.error_not_purchased).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(URL_PURCHASE + app.getPackageName()));
            context.startActivity(i);
        }
    }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    return builder.create();
}
Also used : DialogWrapperAbstract(com.github.yeriomin.yalpstore.view.DialogWrapperAbstract) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) DialogWrapper(com.github.yeriomin.yalpstore.view.DialogWrapper)

Example 2 with DialogWrapper

use of com.github.yeriomin.yalpstore.view.DialogWrapper in project YalpStore by yeriomin.

the class DownloadDirectory method draw.

@Override
public void draw() {
    preference.setSummary(Paths.getYalpPath(activity).getAbsolutePath());
    preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            YalpStorePermissionManager permissionManager = new YalpStorePermissionManager(activity);
            if (!permissionManager.checkPermission()) {
                permissionManager.requestPermission();
            }
            return true;
        }
    });
    preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            String newValue = (String) o;
            boolean result = checkNewValue(newValue);
            if (!result) {
                if (ContextUtil.isAlive(activity) && !((EditTextPreference) preference).getText().equals(Paths.FALLBACK_DIRECTORY)) {
                    getFallbackDialog().show();
                } else {
                    ContextUtil.toast(activity, R.string.error_downloads_directory_not_writable);
                }
            } else {
                try {
                    preference.setSummary(new File(Paths.getStorageRoot(activity), newValue).getCanonicalPath());
                } catch (IOException e) {
                    Log.i(getClass().getName(), "checkNewValue returned true, but drawing the path \"" + newValue + "\" in the summary failed... strange");
                    return false;
                }
            }
            return result;
        }

        private boolean checkNewValue(String newValue) {
            try {
                File storageRoot = Paths.getStorageRoot(activity);
                File newDir = new File(storageRoot, newValue).getCanonicalFile();
                if (!newDir.getCanonicalPath().startsWith(storageRoot.getCanonicalPath())) {
                    return false;
                }
                if (newDir.exists()) {
                    return newDir.canWrite();
                }
                if (activity.checkCallingOrSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    return newDir.mkdirs();
                }
                return true;
            } catch (IOException e) {
                return false;
            }
        }

        private DialogWrapperAbstract getFallbackDialog() {
            return new DialogWrapper(activity).setMessage(activity.getString(R.string.error_downloads_directory_not_writable) + "\n\n" + activity.getString(R.string.pref_message_fallback, Paths.FALLBACK_DIRECTORY)).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    preference.setText(Paths.FALLBACK_DIRECTORY);
                    preference.getOnPreferenceChangeListener().onPreferenceChange(preference, Paths.FALLBACK_DIRECTORY);
                    dialog.dismiss();
                }
            }).create();
        }
    });
}
Also used : DialogWrapperAbstract(com.github.yeriomin.yalpstore.view.DialogWrapperAbstract) DialogInterface(android.content.DialogInterface) EditTextPreference(android.preference.EditTextPreference) IOException(java.io.IOException) DialogWrapper(com.github.yeriomin.yalpstore.view.DialogWrapper) EditTextPreference(android.preference.EditTextPreference) Preference(android.preference.Preference) File(java.io.File) YalpStorePermissionManager(com.github.yeriomin.yalpstore.YalpStorePermissionManager)

Example 3 with DialogWrapper

use of com.github.yeriomin.yalpstore.view.DialogWrapper in project YalpStore by yeriomin.

the class InstallerAbstract method getSignatureMismatchDialog.

private DialogWrapperAbstract getSignatureMismatchDialog(final App app) {
    DialogWrapperAbstract builder = new DialogWrapper((Activity) context);
    builder.setMessage(R.string.details_signature_mismatch).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    if (new BlackWhiteListManager(context).isUpdatable(app.getPackageName())) {
        builder.setNegativeButton(R.string.action_ignore, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
                context.startService(getIgnoreIntent(app));
                dialog.cancel();
            }
        });
    }
    return builder.create();
}
Also used : DialogWrapperAbstract(com.github.yeriomin.yalpstore.view.DialogWrapperAbstract) DialogInterface(android.content.DialogInterface) DialogWrapper(com.github.yeriomin.yalpstore.view.DialogWrapper)

Aggregations

DialogInterface (android.content.DialogInterface)3 DialogWrapper (com.github.yeriomin.yalpstore.view.DialogWrapper)3 DialogWrapperAbstract (com.github.yeriomin.yalpstore.view.DialogWrapperAbstract)3 Intent (android.content.Intent)1 EditTextPreference (android.preference.EditTextPreference)1 Preference (android.preference.Preference)1 YalpStorePermissionManager (com.github.yeriomin.yalpstore.YalpStorePermissionManager)1 File (java.io.File)1 IOException (java.io.IOException)1