com.gianlu.commonutils.dialogs.DialogUtils Java Examples

The following examples show how to use com.gianlu.commonutils.dialogs.DialogUtils. 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: AskPermission.java    From CommonUtils with Apache License 2.0 6 votes vote down vote up
public static void ask(@NonNull final FragmentActivity activity, @NonNull final String permission, @NonNull final Listener listener) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        listener.permissionGranted(permission);
        return;
    }

    if (ContextCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED) {
        listener.permissionGranted(permission);
    } else {
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
            MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(activity);
            listener.askRationale(builder);
            builder.setPositiveButton(android.R.string.ok, (dialog, which) -> request(activity, permission, listener));

            DialogUtils.showDialog(activity, builder);
        } else {
            request(activity, permission, listener);
        }
    }
}
 
Example #2
Source File: UrbanDictSheet.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreateBody(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @NonNull String payload) {
    inflater.inflate(R.layout.sheet_urban_dict, parent, true);

    message = parent.findViewById(R.id.urbanDictSheet_message);
    list = parent.findViewById(R.id.urbanDictSheet_list);
    list.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
    list.addItemDecoration(new DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL));

    UrbanDictApi.get().define(payload, getActivity(), new UrbanDictApi.OnDefine() {
        @Override
        public void onResult(@NonNull Definitions result) {
            update(result);
            isLoading(false);

            ThisApplication.sendAnalytics(Utils.ACTION_OPEN_URBAN_DICT);
        }

        @Override
        public void onException(@NonNull Exception ex) {
            Log.e(TAG, "Failed getting definition.", ex);
            DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedLoading));
            dismissAllowingStateLoss();
        }
    });
}
 
Example #3
Source File: GamesFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
private void askForPassword(@NonNull OnPassword listener) {
    if (getContext() == null) {
        listener.onPassword(null);
        return;
    }

    final EditText password = new EditText(getContext());
    password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
    builder.setTitle(R.string.gamePassword)
            .setView(password)
            .setNegativeButton(android.R.string.cancel, null)
            .setPositiveButton(R.string.submit, (dialog, which) -> listener.onPassword(password.getText().toString()));

    DialogUtils.showDialog(getActivity(), builder);
}
 
Example #4
Source File: UserInfoDialog.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
public static void loadAndShow(@NonNull RegisteredPyx pyx, @NonNull FragmentActivity activity, @NonNull String name) {
    DialogUtils.showDialog(activity, DialogUtils.progressDialog(activity, R.string.loading));
    pyx.request(PyxRequests.whois(name), activity, new Pyx.OnResult<WhoisResult>() {
        @Override
        public void onDone(@NonNull WhoisResult result) {
            DialogUtils.dismissDialog(activity);
            DialogUtils.showDialog(activity, UserInfoDialog.get(result), null);
        }

        @Override
        public void onException(@NonNull Exception ex) {
            DialogUtils.dismissDialog(activity);
            Log.e(TAG, "Failed whois.", ex);
            Toaster.with(activity).message(R.string.failedLoading).show();
        }
    });
}
 
Example #5
Source File: OngoingGameFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
public void goBack() {
    if (isVisible() && DialogUtils.hasVisibleDialog(getActivity())) {
        DialogUtils.dismissDialog(getActivity());
        return;
    }

    if (getContext() == null) return;

    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
    builder.setTitle(R.string.leaveGame)
            .setMessage(R.string.leaveGame_confirm)
            .setPositiveButton(android.R.string.yes, (dialog, which) -> leaveGame())
            .setNegativeButton(android.R.string.no, null);

    DialogUtils.showDialog(getActivity(), builder);
}
 
Example #6
Source File: FilesFragment.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
private void startDownloadInternal(@NonNull MultiProfile profile, @Nullable AriaFile file, @Nullable AriaDirectory dir) {
    if (helper == null) return;

    boolean single = file != null;
    FetchHelper.StartListener listener = new FetchHelper.StartListener() {
        @Override
        public void onSuccess() {
            Snackbar.make(rmv, R.string.downloadAdded, Snackbar.LENGTH_LONG)
                    .setAction(R.string.show, v -> startActivity(new Intent(getContext(), DirectDownloadActivity.class)))
                    .show();
        }

        @Override
        public void onFailed(@NonNull Throwable ex) {
            Log.e(TAG, "Failed starting download.", ex);
            DialogUtils.showToast(getContext(), Toaster.build().message(single ? R.string.failedAddingDownload : R.string.failedAddingDownloads));
        }
    };

    if (file != null) helper.start(requireContext(), profile, file, listener);
    else if (dir != null) helper.start(requireContext(), profile, dir, listener);
}
 
Example #7
Source File: OngoingGameFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void showGameOptions() {
    if (manager == null || getContext() == null) return;
    Game.Options options = manager.gameOptions();
    if (options == null) return;

    DialogUtils.showDialog(getActivity(), Dialogs.gameOptions(getContext(), options, pyx.firstLoad()));
}
 
Example #8
Source File: OngoingGameFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void showSpectators() {
    if (manager == null || getContext() == null) return;

    Collection<String> spectators = manager.spectators();
    SuperTextView text = SuperTextView.html(getContext(), spectators.isEmpty() ? "<i>none</i>" : CommonUtils.join(spectators, ", "));
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics());
    text.setPadding(padding, padding, padding, padding);

    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
    builder.setTitle(R.string.spectatorsLabel)
            .setView(text)
            .setPositiveButton(android.R.string.ok, null);

    DialogUtils.showDialog(getActivity(), builder);
}
 
Example #9
Source File: OngoingGameFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void showPlayers() {
    if (manager == null || getContext() == null) return;

    RecyclerView recyclerView = new RecyclerView(getContext());
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false));
    recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
    recyclerView.setAdapter(new PlayersAdapter(getContext(), manager.players(), this));

    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
    builder.setTitle(R.string.playersLabel)
            .setView(recyclerView)
            .setPositiveButton(android.R.string.ok, null);

    DialogUtils.showDialog(getActivity(), builder);
}
 
Example #10
Source File: UrbanDictSheet.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDefinitionSelected(@NonNull Definition definition) {
    try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(definition.permalink)));
    } catch (ActivityNotFoundException ex) {
        DialogUtils.showToast(getContext(), Toaster.build().message(R.string.missingWebBrowser));
    }
}
 
Example #11
Source File: GamesFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void joinGame(int gid, @Nullable String password) {
    if (getContext() == null) return;

    DialogUtils.showDialog(getActivity(), DialogUtils.progressDialog(getContext(), R.string.loading));
    pyx.request(PyxRequests.joinGame(gid, password), getActivity(), new Pyx.OnResult<GamePermalink>() {
        @Override
        public void onDone(@NonNull GamePermalink game) {
            if (handler != null) handler.onParticipatingGame(game);
            DialogUtils.dismissDialog(getActivity());

            AnalyticsApplication.sendAnalytics(Utils.ACTION_JOIN_GAME);
        }

        @Override
        public void onException(@NonNull Exception ex) {
            Log.e(TAG, "Failed joining game.", ex);
            DialogUtils.dismissDialog(getActivity());

            if (ex instanceof PyxException) {
                switch (((PyxException) ex).errorCode) {
                    case "wp":
                        showToast(Toaster.build().message(R.string.wrongPassword));
                        return;
                    case "gf":
                        showToast(Toaster.build().message(R.string.gameFull));
                        return;
                }
            }

            showToast(Toaster.build().message(R.string.failedJoining));
        }
    });
}
 
Example #12
Source File: GamesFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void spectateGame(final int gid, @Nullable String password) {
    if (getContext() == null) return;

    DialogUtils.showDialog(getActivity(), DialogUtils.progressDialog(getContext(), R.string.loading));
    pyx.request(PyxRequests.spectateGame(gid, password), getActivity(), new Pyx.OnResult<GamePermalink>() {
        @Override
        public void onDone(@NonNull GamePermalink game) {
            if (handler != null) handler.onParticipatingGame(game);
            DialogUtils.dismissDialog(getActivity());

            AnalyticsApplication.sendAnalytics(Utils.ACTION_SPECTATE_GAME);
        }

        @Override
        public void onException(@NonNull Exception ex) {
            DialogUtils.dismissDialog(getActivity());
            Log.e(TAG, "Failed spectating game.", ex);

            if (ex instanceof PyxException) {
                switch (((PyxException) ex).errorCode) {
                    case "wp":
                        showToast(Toaster.build().message(R.string.wrongPassword));
                        return;
                    case "gf":
                        showToast(Toaster.build().message(R.string.gameFull));
                        return;
                }
            }

            showToast(Toaster.build().message(R.string.failedSpectating));
        }
    });
}
 
Example #13
Source File: MetricsActivity.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
private void loadGame(@NonNull GamePermalink game) {
    final String gameId = game.extractGameMetricsId();
    if (gameId == null) {
        Toaster.with(MetricsActivity.this).message(R.string.failedLoading).show();
        onBackPressed();
        return;
    }

    ProgressDialog pd = DialogUtils.progressDialog(this, R.string.loading);
    showDialog(pd);
    pyx.getGameHistory(gameId, this, new Pyx.OnResult<GameHistory>() {
        @Override
        public void onDone(@NonNull GameHistory result) {
            dismissDialog();

            breadcrumbs.addItem(new BreadcrumbsView.Item(getString(R.string.ongoingGame), TYPE_GAME, null));

            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.metrics_container, GameHistoryFragment.get(result), TAG_GAME)
                    .commit();
        }

        @Override
        public void onException(@NonNull Exception ex) {
            dismissDialog();
            Log.e(TAG, "Failed loading history.", ex);
            Toaster.with(MetricsActivity.this).message(R.string.failedLoading).show();
            onBackPressed();
        }
    });
}
 
Example #14
Source File: FilesFragment.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
private void changeSelectionForBatch(Collection<AriaFile> files, boolean select) {
    download.changeSelection(AriaFile.allIndexes(files), select, new AbstractClient.OnResult<Download.ChangeSelectionResult>() {
        @Override
        public void onResult(@NonNull Download.ChangeSelectionResult result) {
            Toaster toaster = Toaster.build();
            toaster.extra(result);
            switch (result) {
                case EMPTY:
                    toaster.message(R.string.cannotDeselectAllFiles);
                    break;
                case SELECTED:
                    toaster.message(R.string.fileSelected);
                    break;
                case DESELECTED:
                    toaster.message(R.string.fileDeselected);
                    break;
                default:
                    toaster.message(R.string.failedAction);
                    break;
            }

            DialogUtils.showToast(getContext(), toaster);
            exitActionMode();
        }

        @Override
        public void onException(@NonNull @NotNull Exception ex) {
            Log.e(TAG, "Failed changing selection", ex);
            showToast(Toaster.build().message(R.string.failedFileChangeSelection));
        }
    });
}
 
Example #15
Source File: OptionsDialog.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onException(@NonNull Exception ex) {
    if (!isAdded()) return;

    Log.e(TAG, "Failed loading options.", ex);
    DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedLoading));
    dismissAllowingStateLoss();
}
 
Example #16
Source File: AboutAria2Dialog.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onException(@NonNull Exception ex) {
    if (!isAdded()) return;

    Log.e(TAG, "Failed loading info.", ex);
    DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedLoading));
    dismissAllowingStateLoss();
}
 
Example #17
Source File: DiagnosticFragment.java    From DNSHero with GNU General Public License v3.0 5 votes vote down vote up
private void showHelpDialog() {
    if (getContext() == null) return;
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(R.string.help)
            .setView(R.layout.dialog_diagnostic_help)
            .setPositiveButton(android.R.string.ok, null);

    DialogUtils.showDialog(getActivity(), builder);
}
 
Example #18
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
public void donate(@NonNull Activity activity, boolean wasWaiting) {
    if (!wasWaiting)
        listener.showDialog(DialogUtils.progressDialog(activity, R.string.connectingBillingService));

    if (billingClient != null && billingClient.isReady()) {
        SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
        params.setSkusList(products).setType(BillingClient.SkuType.INAPP);
        billingClient.querySkuDetailsAsync(params.build(), (billingResult, skuDetailsList) -> {
            listener.dismissDialog();

            if (billingResult.getResponseCode() == BillingResponseCode.OK)
                showDonateDialog(activity, skuDetailsList);
            else
                handleBillingErrors(billingResult.getResponseCode());
        });
    } else {
        new Thread() {
            @Override
            public void run() {
                synchronized (billingReady) {
                    try {
                        billingReady.wait();
                        donate(activity, true);
                    } catch (InterruptedException ex) {
                        Log.w(TAG, ex);
                    }
                }
            }
        }.start();
    }
}
 
Example #19
Source File: Toaster.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
public void show(@NonNull Context context) {
    if (shown) {
        if (CommonUtils.isDebug()) System.out.println("Skipping toast, already shown!");
        return;
    }

    if (!DialogUtils.isContextValid(context)) {
        if (CommonUtils.isDebug())
            System.out.println("Skipping toast, context is invalid: " + context);
        return;
    }

    if (msg == null) {
        if (msgRes != 0) {
            msg = context.getString(msgRes, args);
            msgRes = 0;
            args = null;
        } else {
            throw new IllegalArgumentException("Missing toast message!");
        }
    }

    final int duration;
    if (msg.length() > 48) duration = Toast.LENGTH_LONG;
    else duration = Toast.LENGTH_SHORT;

    Runnable action = () -> {
        if (DialogUtils.isContextValid(context))
            Toast.makeText(context, msg, duration).show();
    };

    if (Looper.myLooper() == Looper.getMainLooper()) action.run();
    else handler.post(action);

    Log.v(TAG, buildLogMessage(context));
    shown = true;
}
 
Example #20
Source File: TutorialManager.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
@UiThread
public void tryShowingTutorials(final Activity activity) {
    if (isShowingTutorial || !DialogUtils.isContextValid(activity)) return;

    for (BaseTutorial tutorial : tutorials) {
        if (shouldShowFor(tutorial) && listener.canShow(tutorial)) {
            show(activity, tutorial);
            return;
        }
    }
}
 
Example #21
Source File: OngoingGameFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 4 votes vote down vote up
private void editGameOptions() {
    if (manager == null || getContext() == null) return;

    DialogUtils.showDialog(getActivity(), EditGameOptionsDialog.get(perm.gid, manager.gameOptions()), null);
}
 
Example #22
Source File: EditGameOptionsDialog.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    layout = (LinearLayout) inflater.inflate(R.layout.dialog_edit_game_options, container, false);

    Bundle args = getArguments();
    Game.Options options;
    if (args == null || (options = (Game.Options) args.getSerializable("options")) == null
            || (gid = args.getInt("gid", -1)) == -1 || getContext() == null) {
        dismissAllowingStateLoss();
        return layout;
    }


    try {
        pyx = RegisteredPyx.get();
    } catch (LevelMismatchException ex) {
        DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedLoading));
        dismissAllowingStateLoss();
        return layout;
    }

    scoreLimit = layout.findViewById(R.id.editGameOptions_scoreLimit);
    CommonUtils.setText(scoreLimit, String.valueOf(options.scoreLimit));

    playerLimit = layout.findViewById(R.id.editGameOptions_playerLimit);
    CommonUtils.setText(playerLimit, String.valueOf(options.playersLimit));

    spectatorLimit = layout.findViewById(R.id.editGameOptions_spectatorLimit);
    CommonUtils.setText(spectatorLimit, String.valueOf(options.spectatorsLimit));

    timerMultiplier = layout.findViewById(R.id.editGameOptions_timerMultiplier);
    AutoCompleteTextView timerMultiplierEditText = (AutoCompleteTextView) CommonUtils.getEditText(timerMultiplier);
    timerMultiplierEditText.setAdapter(new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, Game.Options.VALID_TIMER_MULTIPLIERS));
    timerMultiplierEditText.setText(options.timerMultiplier, false);
    timerMultiplierEditText.setValidator(new AutoCompleteTextView.Validator() {
        @Override
        public boolean isValid(CharSequence text) {
            return Game.Options.timerMultiplierIndex(String.valueOf(text)) != -1;
        }

        @Override
        public CharSequence fixText(CharSequence invalidText) {
            return null;
        }
    });

    blankCards = layout.findViewById(R.id.editGameOptions_blankCards);
    CommonUtils.setText(blankCards, String.valueOf(options.blanksLimit));
    if (pyx.config().blankCardsEnabled()) blankCards.setVisibility(View.VISIBLE);
    else blankCards.setVisibility(View.GONE);

    password = layout.findViewById(R.id.editGameOptions_password);
    CommonUtils.setText(password, options.password);

    decksTitle = layout.findViewById(R.id.editGameOptions_decksTitle);

    decks = layout.findViewById(R.id.editGameOptions_decks);
    decks.removeAllViews();
    for (Deck set : pyx.firstLoad().decks) {
        MaterialCheckBox item = new MaterialCheckBox(getContext());
        item.setTag(set);
        item.setText(set.name);
        item.setChecked(options.cardSets.contains(set.id));
        item.setOnCheckedChangeListener((buttonView, isChecked) -> updateDecksCount());

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.topMargin = lp.bottomMargin = (int) -TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
        decks.addView(item, lp);
    }

    updateDecksCount();

    Button cancel = layout.findViewById(R.id.editGameOptions_cancel);
    cancel.setOnClickListener(v -> dismissAllowingStateLoss());

    Button apply = layout.findViewById(R.id.editGameOptions_apply);
    apply.setOnClickListener(v -> done());

    return layout;
}
 
Example #23
Source File: GameRoundDialog.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onException(@NonNull Exception ex) {
    Log.e(TAG, "Failed loading round.", ex);
    DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedLoading));
    dismissAllowingStateLoss();
}
 
Example #24
Source File: BaseModalBottomSheet.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
@UiThread
public final void update(@NonNull Update payload) {
    if (getDialog() != null && getDialog().isShowing() && DialogUtils.isContextValid(getContext()))
        onReceivedUpdate(payload);
}
 
Example #25
Source File: FileSheet.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreateBody(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @NonNull SetupPayload payload) {
    inflater.inflate(R.layout.sheet_file, parent, true);

    final DownloadWithUpdate download = payload.download;
    final AriaFile file = payload.file;

    SuperTextView index = parent.findViewById(R.id.fileSheet_index);
    index.setHtml(R.string.index, file.index);

    SuperTextView path = parent.findViewById(R.id.fileSheet_path);
    path.setHtml(R.string.path, file.path);

    length = parent.findViewById(R.id.fileSheet_length);
    completedLength = parent.findViewById(R.id.fileSheet_completedLength);
    selected = parent.findViewById(R.id.fileSheet_selected);

    update(file);

    if (download.update().canDeselectFiles()) {
        selected.setEnabled(true);
        selected.setOnCheckedChangeListener((buttonView, isChecked) -> download.changeSelection(new Integer[]{file.index}, isChecked, new AbstractClient.OnResult<Download.ChangeSelectionResult>() {
            @Override
            public void onResult(@NonNull Download.ChangeSelectionResult result) {
                if (!isAdded()) return;

                Toaster toaster = Toaster.build();
                toaster.extra(result);
                switch (result) {
                    case EMPTY:
                        toaster.message(R.string.cannotDeselectAllFiles);
                        break;
                    case SELECTED:
                        file.selected = true;
                        toaster.message(R.string.fileSelected);
                        break;
                    case DESELECTED:
                        file.selected = false;
                        toaster.message(R.string.fileDeselected);
                        break;
                    default:
                        toaster.message(R.string.failedAction);
                        break;
                }

                dismissAllowingStateLoss();
                DialogUtils.showToast(getContext(), toaster);
            }

            @Override
            public void onException(@NonNull Exception ex) {
                if (!isAdded() || getContext() == null) return;

                dismissAllowingStateLoss();
                Log.e(TAG, "Failed changing selection.", ex);
                DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedFileChangeSelection));
            }
        }));
    } else {
        selected.setEnabled(false);
    }

    isLoading(false);
}
 
Example #26
Source File: DirectorySheet.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreateBody(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, @NonNull SetupPayload payload) {
    inflater.inflate(R.layout.sheet_dir, parent, true);
    currentDir = payload.dir;

    final DownloadWithUpdate download = payload.download;

    SuperTextView indexes = parent.findViewById(R.id.dirSheet_indexes);
    indexes.setHtml(R.string.indexes, CommonUtils.join(currentDir.indexes, ", "));

    SuperTextView path = parent.findViewById(R.id.dirSheet_path);
    path.setHtml(R.string.path, download.update().dir + currentDir.path);

    length = parent.findViewById(R.id.dirSheet_length);
    selected = parent.findViewById(R.id.dirSheet_selected);
    completedLength = parent.findViewById(R.id.dirSheet_completedLength);

    update(currentDir);

    if (download.update().canDeselectFiles()) {
        selected.setEnabled(true);
        selected.setOnCheckedChangeListener((buttonView, isChecked) -> download.changeSelection(currentDir.indexes.toArray(new Integer[0]), isChecked, new AbstractClient.OnResult<Download.ChangeSelectionResult>() {
            @Override
            public void onResult(@NonNull Download.ChangeSelectionResult result) {
                if (!isAdded()) return;

                Toaster toaster = Toaster.build();
                toaster.extra(result);
                switch (result) {
                    case EMPTY:
                        toaster.message(R.string.cannotDeselectAllFiles);
                        break;
                    case SELECTED:
                        toaster.message(R.string.fileSelected);
                        break;
                    case DESELECTED:
                        toaster.message(R.string.fileDeselected);
                        break;
                    default:
                        toaster.message(R.string.failedAction);
                        break;
                }

                dismissAllowingStateLoss();
                DialogUtils.showToast(getContext(), toaster);
            }

            @Override
            public void onException(@NonNull Exception ex) {
                if (!isAdded()) return;

                dismissAllowingStateLoss();
                Log.e(TAG, "Failed changing selection.", ex);
                DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedFileChangeSelection));
            }
        }));
    } else {
        selected.setEnabled(false);
    }

    isLoading(false);
}
 
Example #27
Source File: OptionsDialog.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onEditOption(@NonNull final Option option) {
    if (getContext() == null) return;
    DialogUtils.showDialog(getActivity(), OptionsUtils.getEditOptionDialog(getContext(), option, optionsView.getAdapter()));
}
 
Example #28
Source File: OptionsDialog.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialog_options, container, false);
    loading = layout.findViewById(R.id.optionsDialog_loading);
    optionsView = layout.findViewById(R.id.optionsDialog_options);
    export = layout.findViewById(R.id.optionsDialog_export);
    export.setOnClickListener(v -> export());
    apply = layout.findViewById(R.id.optionsDialog_apply);
    apply.setOnClickListener(v -> apply());
    Button cancel = layout.findViewById(R.id.optionsDialog_cancel);
    cancel.setOnClickListener(v -> dismissAllowingStateLoss());

    loading.setVisibility(View.VISIBLE);
    optionsView.setVisibility(View.GONE);
    export.setVisibility(View.GONE);
    apply.setVisibility(View.GONE);

    Bundle args = getArguments();
    if (args == null) {
        dismissAllowingStateLoss();
        return null;
    }

    quick = args.getBoolean("quick", false);
    global = args.getBoolean("global", true);
    gid = args.getString("gid", null);

    if (quick && Prefs.isSetEmpty(PK.A2_QUICK_OPTIONS_MIXED)) {
        DialogUtils.showToast(getContext(), Toaster.build().message(R.string.noQuickOptions));
        dismissAllowingStateLoss();
        return null;
    }

    AbstractClient.AriaRequestWithResult<OptionsMap> req;
    if (global || gid == null) req = AriaRequests.getGlobalOptions();
    else req = AriaRequests.getDownloadOptions(gid);

    try {
        helper = Aria2Helper.instantiate(requireContext());
    } catch (Aria2Helper.InitializingException ex) {
        Log.e(TAG, "Failed initialising.", ex);
        DialogUtils.showToast(getContext(), Toaster.build().message(R.string.failedLoading));
        dismissAllowingStateLoss();
        return null;
    }

    helper.request(req, this);

    return layout;
}
 
Example #29
Source File: BaseModalBottomSheet.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
public final void show(@Nullable Fragment fragment, @NonNull Setup payload) {
    if (fragment == null) return;

    this.payload = payload;
    DialogUtils.showDialog(fragment, this, null);
}
 
Example #30
Source File: BaseModalBottomSheet.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
public final void show(@Nullable FragmentActivity activity, @NonNull Setup payload) {
    if (activity == null) return;

    this.payload = payload;
    DialogUtils.showDialog(activity, this, null);
}