Search in sources :

Example 1 with PowerSpinnerView

use of com.skydoves.powerspinner.PowerSpinnerView in project Hentoid by avluis.

the class ViewerDeleteDialogFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View rootView, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(rootView, savedInstanceState);
    RadioButton pageBtn = rootView.findViewById(R.id.delete_mode_page);
    RadioButton bookBtn = rootView.findViewById(R.id.delete_mode_book);
    PowerSpinnerView spin = rootView.findViewById(R.id.book_prefs_delete_spin);
    spin.setItems(R.array.page_delete_choices);
    spin.selectItemByIndex(0);
    if (!isDeletePageAllowed)
        pageBtn.setEnabled(false);
    View okBtn = rootView.findViewById(R.id.book_delete_ok_btn);
    okBtn.setOnClickListener(v -> {
        if (!pageBtn.isChecked() && !bookBtn.isChecked())
            return;
        Preferences.setViewerDeleteAskMode(spin.getSelectedIndex());
        Preferences.setViewerDeleteTarget(pageBtn.isChecked() ? Preferences.Constant.VIEWER_DELETE_TARGET_PAGE : Preferences.Constant.VIEWER_DELETE_TARGET_BOOK);
        parent.onDeleteElement(pageBtn.isChecked());
        dismiss();
    });
}
Also used : PowerSpinnerView(com.skydoves.powerspinner.PowerSpinnerView) RadioButton(android.widget.RadioButton) View(android.view.View) PowerSpinnerView(com.skydoves.powerspinner.PowerSpinnerView)

Example 2 with PowerSpinnerView

use of com.skydoves.powerspinner.PowerSpinnerView in project Hentoid by avluis.

the class ViewerPrefsDialogFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View rootView, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(rootView, savedInstanceState);
    Resources res = rootView.getContext().getResources();
    // == Dropdown lists
    String[] browseModes = getResources().getStringArray(R.array.pref_viewer_browse_mode_entries);
    List<String> browseItems = new ArrayList<>();
    // App pref
    browseItems.add(res.getString(R.string.use_app_prefs, browseModes[Preferences.getViewerBrowseMode()]));
    // Available prefs
    browseItems.addAll(Arrays.asList(browseModes));
    PowerSpinnerView browseSpin = rootView.findViewById(R.id.book_prefs_browse_spin);
    browseSpin.setItems(browseItems);
    browseSpin.selectItemByIndex(browseMode + 1);
    String[] renderingModes = getResources().getStringArray(R.array.pref_viewer_rendering_entries);
    List<String> renderingItems = new ArrayList<>();
    // App pref
    renderingItems.add(res.getString(R.string.use_app_prefs, renderingModes[Preferences.isViewerSmoothRendering() ? 1 : 0].replace(" (" + getString(R.string._default) + ")", "")));
    // Available prefs
    for (int i = 0; i < renderingModes.length; i++) {
        // No smooth mode for Android 5
        if (1 == i && Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
            continue;
        renderingItems.add(renderingModes[i].replace(" (" + getString(R.string._default) + ")", ""));
    }
    PowerSpinnerView renderSpin = rootView.findViewById(R.id.book_prefs_rendering_spin);
    renderSpin.setItems(renderingItems);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        renderSpin.selectItemByIndex(0);
        renderSpin.setEnabled(false);
    } else
        renderSpin.selectItemByIndex(renderingMode + 1);
    // == Bottom buttons
    View appSettingsBtn = rootView.findViewById(R.id.book_prefs_app_prefs_btn);
    appSettingsBtn.setOnClickListener(v -> {
        Intent intent = new Intent(requireActivity(), PrefsActivity.class);
        PrefsBundle prefsBundle = new PrefsBundle();
        prefsBundle.setViewerPrefs(true);
        intent.putExtras(prefsBundle.toBundle());
        requireContext().startActivity(intent);
    });
    View okBtn = rootView.findViewById(R.id.book_prefs_ok_btn);
    okBtn.setOnClickListener(v -> {
        Map<String, String> newPrefs = new HashMap<>();
        if (renderSpin.getSelectedIndex() > 0)
            newPrefs.put(VIEWER_RENDERING, (renderSpin.getSelectedIndex() - 1) + "");
        if (browseSpin.getSelectedIndex() > 0)
            newPrefs.put(VIEWER_BROWSE_MODE, (browseSpin.getSelectedIndex() - 1) + "");
        parent.onBookPreferenceChanged(newPrefs);
        dismiss();
    });
}
Also used : HashMap(java.util.HashMap) PrefsBundle(me.devsaki.hentoid.activities.bundles.PrefsBundle) PowerSpinnerView(com.skydoves.powerspinner.PowerSpinnerView) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Resources(android.content.res.Resources) View(android.view.View) PowerSpinnerView(com.skydoves.powerspinner.PowerSpinnerView)

Aggregations

View (android.view.View)2 PowerSpinnerView (com.skydoves.powerspinner.PowerSpinnerView)2 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 RadioButton (android.widget.RadioButton)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 PrefsBundle (me.devsaki.hentoid.activities.bundles.PrefsBundle)1