Search in sources :

Example 96 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project EhViewer by seven332.

the class CommonOperations method startDownload.

// TODO Add context if activity and context are different style
public static void startDownload(final MainActivity activity, final List<GalleryInfo> galleryInfos, boolean forceDefault) {
    final DownloadManager dm = EhApplication.getDownloadManager(activity);
    LongList toStart = new LongList();
    List<GalleryInfo> toAdd = new ArrayList<>();
    for (GalleryInfo gi : galleryInfos) {
        if (dm.containDownloadInfo(gi.gid)) {
            toStart.add(gi.gid);
        } else {
            toAdd.add(gi);
        }
    }
    if (!toStart.isEmpty()) {
        Intent intent = new Intent(activity, DownloadService.class);
        intent.setAction(DownloadService.ACTION_START_RANGE);
        intent.putExtra(DownloadService.KEY_GID_LIST, toStart);
        activity.startService(intent);
    }
    if (toAdd.isEmpty()) {
        activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
        return;
    }
    boolean justStart = forceDefault;
    String label = null;
    // Get default download label
    if (!justStart && Settings.getHasDefaultDownloadLabel()) {
        label = Settings.getDefaultDownloadLabel();
        justStart = label == null || dm.containLabel(label);
    }
    // If there is no other label, just use null label
    if (!justStart && 0 == dm.getLabelList().size()) {
        justStart = true;
        label = null;
    }
    if (justStart) {
        // Got default label
        for (GalleryInfo gi : toAdd) {
            Intent intent = new Intent(activity, DownloadService.class);
            intent.setAction(DownloadService.ACTION_START);
            intent.putExtra(DownloadService.KEY_LABEL, label);
            intent.putExtra(DownloadService.KEY_GALLERY_INFO, gi);
            activity.startService(intent);
        }
        // Notify
        activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
    } else {
        // Let use chose label
        List<DownloadLabel> list = dm.getLabelList();
        final String[] items = new String[list.size() + 1];
        items[0] = activity.getString(R.string.default_download_label_name);
        for (int i = 0, n = list.size(); i < n; i++) {
            items[i + 1] = list.get(i).getLabel();
        }
        new ListCheckBoxDialogBuilder(activity, items, new ListCheckBoxDialogBuilder.OnItemClickListener() {

            @Override
            public void onItemClick(ListCheckBoxDialogBuilder builder, AlertDialog dialog, int position) {
                String label;
                if (position == 0) {
                    label = null;
                } else {
                    label = items[position];
                    if (!dm.containLabel(label)) {
                        label = null;
                    }
                }
                // Start download
                for (GalleryInfo gi : toAdd) {
                    Intent intent = new Intent(activity, DownloadService.class);
                    intent.setAction(DownloadService.ACTION_START);
                    intent.putExtra(DownloadService.KEY_LABEL, label);
                    intent.putExtra(DownloadService.KEY_GALLERY_INFO, gi);
                    activity.startService(intent);
                }
                // Save settings
                if (builder.isChecked()) {
                    Settings.putHasDefaultDownloadLabel(true);
                    Settings.putDefaultDownloadLabel(label);
                } else {
                    Settings.putHasDefaultDownloadLabel(false);
                }
                // Notify
                activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
            }
        }, activity.getString(R.string.remember_download_label), false).setTitle(R.string.download).show();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) ArrayList(java.util.ArrayList) Intent(android.content.Intent) LongList(com.hippo.yorozuya.collect.LongList) DownloadManager(com.hippo.ehviewer.download.DownloadManager) DownloadService(com.hippo.ehviewer.download.DownloadService) ListCheckBoxDialogBuilder(com.hippo.app.ListCheckBoxDialogBuilder) DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel)

Example 97 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project EhViewer by seven332.

the class AboutFragment method showDonationDialog.

private void showDonationDialog() {
    AlertDialog dialog = new AlertDialog.Builder(getActivity()).setView(R.layout.dialog_donate).show();
    String alipayStr = base64Decode("c2V2ZW4zMzJAMTYzLmNvbQ==");
    TextView alipayText = dialog.findViewById(R.id.alipay_text);
    alipayText.setText(alipayStr);
    dialog.findViewById(R.id.alipay_copy).setOnClickListener(v -> copyToClipboard(alipayStr));
    String paypalStr = base64Decode("aHR0cHM6Ly9wYXlwYWwubWUvc2V2ZW4zMzI=");
    TextView paypalText = dialog.findViewById(R.id.paypal_text);
    paypalText.setText(paypalStr);
    dialog.findViewById(R.id.paypal_open).setOnClickListener(v -> openUrl(paypalStr));
    dialog.findViewById(R.id.paypal_copy).setOnClickListener(v -> copyToClipboard(paypalStr));
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) TextView(android.widget.TextView)

Example 98 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project EhViewer by seven332.

the class DownloadLabelsScene method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    Context context = getContext2();
    if (null == context) {
        return false;
    }
    int id = item.getItemId();
    switch(id) {
        case R.id.action_add:
            {
                EditTextDialogBuilder builder = new EditTextDialogBuilder(context, null, getString(R.string.download_labels));
                builder.setTitle(R.string.new_label_title);
                builder.setPositiveButton(android.R.string.ok, null);
                AlertDialog dialog = builder.show();
                new NewLabelDialogHelper(builder, dialog);
            }
    }
    return false;
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) EditTextDialogBuilder(com.hippo.app.EditTextDialogBuilder)

Example 99 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project EhViewer by seven332.

the class GalleryListScene method showAddQuickSearchDialog.

private void showAddQuickSearchDialog(final List<QuickSearch> list, final ArrayAdapter<QuickSearch> adapter, final ListView listView, final TextView tip) {
    Context context = getContext2();
    final ListUrlBuilder urlBuilder = mUrlBuilder;
    if (null == context || null == urlBuilder) {
        return;
    }
    // Can't add image search as quick search
    if (ListUrlBuilder.MODE_IMAGE_SEARCH == urlBuilder.getMode()) {
        showTip(R.string.image_search_not_quick_search, LENGTH_LONG);
        return;
    }
    // Check duplicate
    for (QuickSearch q : list) {
        if (urlBuilder.equalsQuickSearch(q)) {
            showTip(getString(R.string.duplicate_quick_search, q.name), LENGTH_LONG);
            return;
        }
    }
    final EditTextDialogBuilder builder = new EditTextDialogBuilder(context, getSuitableTitleForUrlBuilder(context.getResources(), urlBuilder, false), getString(R.string.quick_search));
    builder.setTitle(R.string.add_quick_search_dialog_title);
    builder.setPositiveButton(android.R.string.ok, null);
    final AlertDialog dialog = builder.show();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String text = builder.getText().trim();
            // Check name empty
            if (TextUtils.isEmpty(text)) {
                builder.setError(getString(R.string.name_is_empty));
                return;
            }
            // Check name duplicate
            for (QuickSearch q : list) {
                if (text.equals(q.name)) {
                    builder.setError(getString(R.string.duplicate_name));
                    return;
                }
            }
            builder.setError(null);
            dialog.dismiss();
            QuickSearch quickSearch = urlBuilder.toQuickSearch();
            quickSearch.name = text;
            EhDB.insertQuickSearch(quickSearch);
            list.add(quickSearch);
            adapter.notifyDataSetChanged();
            if (0 == list.size()) {
                tip.setVisibility(View.VISIBLE);
                listView.setVisibility(View.GONE);
            } else {
                tip.setVisibility(View.GONE);
                listView.setVisibility(View.VISIBLE);
            }
        }
    });
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) ListUrlBuilder(com.hippo.ehviewer.client.data.ListUrlBuilder) QuickSearch(com.hippo.ehviewer.dao.QuickSearch) EditTextDialogBuilder(com.hippo.app.EditTextDialogBuilder) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 100 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project EhViewer by seven332.

the class GalleryListScene method showGoToDialog.

private void showGoToDialog() {
    Context context = getContext2();
    if (null == context || null == mHelper) {
        return;
    }
    final int page = mHelper.getPageForTop();
    final int pages = mHelper.getPages();
    String hint = getString(R.string.go_to_hint, page + 1, pages);
    final EditTextDialogBuilder builder = new EditTextDialogBuilder(context, null, hint);
    builder.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    final AlertDialog dialog = builder.setTitle(R.string.go_to).setPositiveButton(android.R.string.ok, null).show();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (null == mHelper) {
                dialog.dismiss();
                return;
            }
            String text = builder.getText().trim();
            int goTo;
            try {
                goTo = Integer.parseInt(text) - 1;
            } catch (NumberFormatException e) {
                builder.setError(getString(R.string.error_invalid_number));
                return;
            }
            if (goTo < 0 || goTo >= pages) {
                builder.setError(getString(R.string.error_out_of_range));
                return;
            }
            builder.setError(null);
            mHelper.goTo(goTo);
            AppHelper.hideSoftInput(dialog);
            dialog.dismiss();
        }
    });
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) EditTextDialogBuilder(com.hippo.app.EditTextDialogBuilder) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point)

Aggregations

AlertDialog (androidx.appcompat.app.AlertDialog)256 Test (org.junit.Test)89 View (android.view.View)48 DialogInterface (android.content.DialogInterface)40 Button (android.widget.Button)39 TextView (android.widget.TextView)39 Intent (android.content.Intent)30 ShadowAlertDialogCompat (com.android.settings.testutils.shadow.ShadowAlertDialogCompat)30 NonNull (androidx.annotation.NonNull)27 Context (android.content.Context)26 Bundle (android.os.Bundle)20 SuppressLint (android.annotation.SuppressLint)17 EditText (android.widget.EditText)17 ArrayList (java.util.ArrayList)17 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)14 List (java.util.List)12 Activity (android.app.Activity)11 Uri (android.net.Uri)11 LayoutInflater (android.view.LayoutInflater)11 ListView (android.widget.ListView)10