Search in sources :

Example 1 with AppCompatCheckBox

use of androidx.appcompat.widget.AppCompatCheckBox in project kcanotify by antest1.

the class KcaResoureLogFragment method setView.

public View setView(final View v) {
    Log.e("KCA", "setView " + position);
    v.setTag("fragment_view");
    v.findViewById(KcaUtils.getId(KcaUtils.format("reslog_chart_filter_box_%d", position), R.id.class)).setVisibility(View.VISIBLE);
    v.findViewById(KcaUtils.getId(KcaUtils.format("reslog_chart_filter_box_%d", 1 - position), R.id.class)).setVisibility(GONE);
    for (int i = 0; i < 4; i++) {
        final int k = i;
        AppCompatCheckBox box = v.findViewById(KcaUtils.getId(KcaUtils.format("reslog_chart_filter_%d_%d", position, i), R.id.class));
        box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                is_draw_enabled[k] = b;
                setChartDataVisibility(v, k);
            }
        });
        box.setChecked(is_draw_enabled[k]);
    }
    ((TextView) v.findViewById(R.id.reslog_item_label_0)).setText(getStringWithLocale(R.string.reslog_label_date));
    if (position == 0) {
        ((TextView) v.findViewById(R.id.reslog_item_label_1)).setText(getStringWithLocale(R.string.item_fuel));
        ((TextView) v.findViewById(R.id.reslog_item_label_2)).setText(getStringWithLocale(R.string.item_ammo));
        ((TextView) v.findViewById(R.id.reslog_item_label_3)).setText(getStringWithLocale(R.string.item_stel));
        ((TextView) v.findViewById(R.id.reslog_item_label_4)).setText(getStringWithLocale(R.string.item_baux));
    } else {
        ((TextView) v.findViewById(R.id.reslog_item_label_1)).setText(getStringWithLocale(R.string.item_bgtz));
        ((TextView) v.findViewById(R.id.reslog_item_label_2)).setText(getStringWithLocale(R.string.item_brnr));
        ((TextView) v.findViewById(R.id.reslog_item_label_3)).setText(getStringWithLocale(R.string.item_mmat));
        ((TextView) v.findViewById(R.id.reslog_item_label_4)).setText(getStringWithLocale(R.string.item_kmat));
    }
    ListView resource_data = v.findViewById(R.id.reslog_listview);
    resource_data.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    drawChart(v);
    return v;
}
Also used : ListView(android.widget.ListView) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox)

Example 2 with AppCompatCheckBox

use of androidx.appcompat.widget.AppCompatCheckBox in project Slide by ccrama.

the class MainActivity method doSubOnlyStuff.

public void doSubOnlyStuff(final Subreddit subreddit) {
    findViewById(R.id.loader).setVisibility(View.GONE);
    if (subreddit.getSubredditType() != null) {
        canSubmit = !subreddit.getSubredditType().equals("RESTRICTED");
    } else {
        canSubmit = true;
    }
    if (subreddit.getSidebar() != null && !subreddit.getSidebar().isEmpty()) {
        findViewById(R.id.sidebar_text).setVisibility(View.VISIBLE);
        final String text = subreddit.getDataNode().get("description_html").asText().trim();
        setViews(text, subreddit.getDisplayName(), sidebarBody, sidebarOverflow);
        // get all subs that have Notifications enabled
        ArrayList<String> rawSubs = StringUtil.stringToArray(Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, ""));
        HashMap<String, Integer> subThresholds = new HashMap<>();
        for (String s : rawSubs) {
            try {
                String[] split = s.split(":");
                subThresholds.put(split[0].toLowerCase(Locale.ENGLISH), Integer.valueOf(split[1]));
            } catch (Exception ignored) {
            // do nothing
            }
        }
        // whether or not this subreddit was in the keySet
        boolean isNotified = subThresholds.containsKey(subreddit.getDisplayName().toLowerCase(Locale.ENGLISH));
        ((AppCompatCheckBox) findViewById(R.id.notify_posts_state)).setChecked(isNotified);
    } else {
        findViewById(R.id.sidebar_text).setVisibility(View.GONE);
    }
    {
        View collection = findViewById(R.id.collection);
        if (Authentication.isLoggedIn) {
            collection.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    new AsyncTask<Void, Void, Void>() {

                        HashMap<String, MultiReddit> multis = new HashMap<String, MultiReddit>();

                        @Override
                        protected Void doInBackground(Void... params) {
                            if (UserSubscriptions.multireddits == null) {
                                UserSubscriptions.syncMultiReddits(MainActivity.this);
                            }
                            for (MultiReddit r : UserSubscriptions.multireddits) {
                                multis.put(r.getDisplayName(), r);
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(Void aVoid) {
                            new MaterialDialog.Builder(MainActivity.this).title(getString(R.string.multi_add_to, subreddit.getDisplayName())).items(multis.keySet()).itemsCallback(new MaterialDialog.ListCallback() {

                                @Override
                                public void onSelection(MaterialDialog dialog, View itemView, final int which, CharSequence text) {
                                    new AsyncTask<Void, Void, Void>() {

                                        @Override
                                        protected Void doInBackground(Void... params) {
                                            try {
                                                final String multiName = multis.keySet().toArray(new String[0])[which];
                                                List<String> subs = new ArrayList<String>();
                                                for (MultiSubreddit sub : multis.get(multiName).getSubreddits()) {
                                                    subs.add(sub.getDisplayName());
                                                }
                                                subs.add(subreddit.getDisplayName());
                                                new MultiRedditManager(Authentication.reddit).createOrUpdate(new MultiRedditUpdateRequest.Builder(Authentication.name, multiName).subreddits(subs).build());
                                                UserSubscriptions.syncMultiReddits(MainActivity.this);
                                                runOnUiThread(new Runnable() {

                                                    @Override
                                                    public void run() {
                                                        drawerLayout.closeDrawers();
                                                        Snackbar s = Snackbar.make(mToolbar, getString(R.string.multi_subreddit_added, multiName), Snackbar.LENGTH_LONG);
                                                        LayoutUtils.showSnackbar(s);
                                                    }
                                                });
                                            } catch (final NetworkException | ApiException e) {
                                                runOnUiThread(new Runnable() {

                                                    @Override
                                                    public void run() {
                                                        runOnUiThread(new Runnable() {

                                                            @Override
                                                            public void run() {
                                                                Snackbar.make(mToolbar, getString(R.string.multi_error), Snackbar.LENGTH_LONG).setAction(R.string.btn_ok, null).show();
                                                            }
                                                        });
                                                    }
                                                });
                                                e.printStackTrace();
                                            }
                                            return null;
                                        }
                                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                }
                            }).show();
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });
        } else {
            collection.setVisibility(View.GONE);
        }
    }
    {
        final AppCompatCheckBox notifyStateCheckBox = (AppCompatCheckBox) findViewById(R.id.notify_posts_state);
        assert notifyStateCheckBox != null;
        notifyStateCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    final String sub = subreddit.getDisplayName();
                    if (!sub.equalsIgnoreCase("all") && !sub.equalsIgnoreCase("frontpage") && !sub.equalsIgnoreCase("friends") && !sub.equalsIgnoreCase("mod") && !sub.contains("+") && !sub.contains(".") && !sub.contains("/m/")) {
                        new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.sub_post_notifs_title, sub)).setMessage(R.string.sub_post_notifs_msg).setPositiveButton(R.string.btn_ok, (dialog, which) -> new MaterialDialog.Builder(MainActivity.this).title(R.string.sub_post_notifs_threshold).items(new String[] { "1", "5", "10", "20", "40", "50" }).alwaysCallSingleChoiceCallback().itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {

                            @Override
                            public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                                ArrayList<String> subs = StringUtil.stringToArray(Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, ""));
                                subs.add(sub + ":" + text);
                                Reddit.appRestart.edit().putString(CheckForMail.SUBS_TO_GET, StringUtil.arrayToString(subs)).commit();
                                return true;
                            }
                        }).cancelable(false).show()).setNegativeButton(R.string.btn_cancel, null).setNegativeButton(R.string.btn_cancel, (dialog, which) -> notifyStateCheckBox.setChecked(false)).setOnCancelListener(dialog -> notifyStateCheckBox.setChecked(false)).show();
                    } else {
                        notifyStateCheckBox.setChecked(false);
                        Toast.makeText(MainActivity.this, R.string.sub_post_notifs_err, Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Intent cancelIntent = new Intent(MainActivity.this, CancelSubNotifs.class);
                    cancelIntent.putExtra(CancelSubNotifs.EXTRA_SUB, subreddit.getDisplayName());
                    startActivity(cancelIntent);
                }
            }
        });
    }
    {
        final TextView subscribe = (TextView) findViewById(R.id.subscribe);
        currentlySubbed = (!Authentication.isLoggedIn && usedArray.contains(subreddit.getDisplayName().toLowerCase(Locale.ENGLISH))) || subreddit.isUserSubscriber();
        MiscUtil.doSubscribeButtonText(currentlySubbed, subscribe);
        assert subscribe != null;
        subscribe.setOnClickListener(new View.OnClickListener() {

            private void doSubscribe() {
                if (Authentication.isLoggedIn) {
                    new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.subscribe_to, subreddit.getDisplayName())).setPositiveButton(R.string.reorder_add_subscribe, (dialog, which) -> new AsyncTask<Void, Void, Boolean>() {

                        @Override
                        public void onPostExecute(Boolean success) {
                            if (!success) {
                                // If subreddit was removed from account or not
                                new AlertDialog.Builder(MainActivity.this).setTitle(R.string.force_change_subscription).setMessage(R.string.force_change_subscription_desc).setPositiveButton(R.string.btn_yes, (dialog1, which1) -> {
                                    // Force add the subscription
                                    changeSubscription(subreddit, true);
                                    Snackbar s = Snackbar.make(mToolbar, getString(R.string.misc_subscribed), Snackbar.LENGTH_LONG);
                                    LayoutUtils.showSnackbar(s);
                                }).setNegativeButton(R.string.btn_no, null).setCancelable(false).show();
                            } else {
                                changeSubscription(subreddit, true);
                            }
                        }

                        @Override
                        protected Boolean doInBackground(Void... params) {
                            try {
                                new AccountManager(Authentication.reddit).subscribe(subreddit);
                            } catch (NetworkException e) {
                                // Either network crashed or trying to unsubscribe to a subreddit that the account isn't subscribed to
                                return false;
                            }
                            return true;
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)).setNeutralButton(R.string.btn_add_to_sublist, (dialog, which) -> {
                        // Force add the subscription
                        changeSubscription(subreddit, true);
                        Snackbar s = Snackbar.make(mToolbar, R.string.sub_added, Snackbar.LENGTH_LONG);
                        LayoutUtils.showSnackbar(s);
                    }).setNegativeButton(R.string.btn_cancel, null).show();
                } else {
                    changeSubscription(subreddit, true);
                }
            }

            private void doUnsubscribe() {
                if (Authentication.didOnline) {
                    new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.unsubscribe_from, subreddit.getDisplayName())).setPositiveButton(R.string.reorder_remove_unsubscribe, (dialog, which) -> new AsyncTask<Void, Void, Boolean>() {

                        @Override
                        public void onPostExecute(Boolean success) {
                            if (!success) {
                                // If subreddit was removed from account or not
                                new AlertDialog.Builder(MainActivity.this).setTitle(R.string.force_change_subscription).setMessage(R.string.force_change_subscription_desc).setPositiveButton(R.string.btn_yes, (dialog12, which12) -> {
                                    // Force add the subscription
                                    changeSubscription(subreddit, false);
                                    Snackbar s = Snackbar.make(mToolbar, getString(R.string.misc_unsubscribed), Snackbar.LENGTH_LONG);
                                    LayoutUtils.showSnackbar(s);
                                }).setNegativeButton(R.string.btn_no, null).setCancelable(false).show();
                            } else {
                                changeSubscription(subreddit, false);
                            }
                        }

                        @Override
                        protected Boolean doInBackground(Void... params) {
                            try {
                                new AccountManager(Authentication.reddit).unsubscribe(subreddit);
                            } catch (NetworkException e) {
                                // Either network crashed or trying to unsubscribe to a subreddit that the account isn't subscribed to
                                return false;
                            }
                            return true;
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)).setNeutralButton(R.string.just_unsub, (dialog, which) -> {
                        // Force add the subscription
                        changeSubscription(subreddit, false);
                        Snackbar s = Snackbar.make(mToolbar, R.string.misc_unsubscribed, Snackbar.LENGTH_LONG);
                        LayoutUtils.showSnackbar(s);
                    }).setNegativeButton(R.string.btn_cancel, null).show();
                } else {
                    changeSubscription(subreddit, false);
                }
            }

            @Override
            public void onClick(View v) {
                if (!currentlySubbed) {
                    doSubscribe();
                } else {
                    doUnsubscribe();
                }
                MiscUtil.doSubscribeButtonText(currentlySubbed, subscribe);
            }
        });
    }
    if (!subreddit.getPublicDescription().isEmpty()) {
        findViewById(R.id.sub_title).setVisibility(View.VISIBLE);
        setViews(subreddit.getDataNode().get("public_description_html").asText(), subreddit.getDisplayName().toLowerCase(Locale.ENGLISH), ((SpoilerRobotoTextView) findViewById(R.id.sub_title)), (CommentOverflow) findViewById(R.id.sub_title_overflow));
    } else {
        findViewById(R.id.sub_title).setVisibility(View.GONE);
    }
    ((ImageView) findViewById(R.id.subimage)).setImageResource(0);
    if (subreddit.getDataNode().has("icon_img") && !subreddit.getDataNode().get("icon_img").asText().isEmpty()) {
        findViewById(R.id.subimage).setVisibility(View.VISIBLE);
        ((Reddit) getApplication()).getImageLoader().displayImage(subreddit.getDataNode().get("icon_img").asText(), (ImageView) findViewById(R.id.subimage));
    } else {
        findViewById(R.id.subimage).setVisibility(View.GONE);
    }
    String bannerImage = subreddit.getBannerImage();
    if (bannerImage != null && !bannerImage.isEmpty()) {
        findViewById(R.id.sub_banner).setVisibility(View.VISIBLE);
        ((Reddit) getApplication()).getImageLoader().displayImage(bannerImage, (ImageView) findViewById(R.id.sub_banner));
    } else {
        findViewById(R.id.sub_banner).setVisibility(View.GONE);
    }
    ((TextView) findViewById(R.id.subscribers)).setText(getString(R.string.subreddit_subscribers_string, subreddit.getLocalizedSubscriberCount()));
    findViewById(R.id.subscribers).setVisibility(View.VISIBLE);
    ((TextView) findViewById(R.id.active_users)).setText(getString(R.string.subreddit_active_users_string_new, subreddit.getLocalizedAccountsActive()));
    findViewById(R.id.active_users).setVisibility(View.VISIBLE);
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Arrays(java.util.Arrays) Bundle(android.os.Bundle) R(me.ccrama.redditslide.R) NonNull(androidx.annotation.NonNull) AnimatorUtil(me.ccrama.redditslide.util.AnimatorUtil) Uri(android.net.Uri) ImageView(android.widget.ImageView) PostMatch(me.ccrama.redditslide.PostMatch) ColorDrawable(android.graphics.drawable.ColorDrawable) ContentType(me.ccrama.redditslide.ContentType) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) UserRecordPaginator(net.dean.jraw.paginators.UserRecordPaginator) NeverAgainWhenClickedOnce(org.ligi.snackengage.conditions.NeverAgainWhenClickedOnce) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) Manifest(android.Manifest) Handler(android.os.Handler) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) ClipboardManager(android.content.ClipboardManager) Canvas(android.graphics.Canvas) JsonNode(com.fasterxml.jackson.databind.JsonNode) ContextCompat(androidx.core.content.ContextCompat) ProUtil(me.ccrama.redditslide.util.ProUtil) Log(android.util.Log) CardView(androidx.cardview.widget.CardView) WithLimitedNumberOfTimes(org.ligi.snackengage.conditions.WithLimitedNumberOfTimes) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts) CheckForMail(me.ccrama.redditslide.Notifications.CheckForMail) KeyboardUtil(me.ccrama.redditslide.util.KeyboardUtil) IntentFilter(android.content.IntentFilter) CommentPage(me.ccrama.redditslide.Fragments.CommentPage) SidebarLayout(me.ccrama.redditslide.Views.SidebarLayout) Set(java.util.Set) DensityUtils(me.ccrama.redditslide.ForceTouch.util.DensityUtils) NotificationJobScheduler(me.ccrama.redditslide.Notifications.NotificationJobScheduler) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Palette(me.ccrama.redditslide.Visuals.Palette) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) SubredditPaginator(net.dean.jraw.paginators.SubredditPaginator) Executors(java.util.concurrent.Executors) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) SortingUtil(me.ccrama.redditslide.util.SortingUtil) KVManger(com.lusfold.androidkeyvaluestore.core.KVManger) DrawerItemsDialog(me.ccrama.redditslide.Fragments.DrawerItemsDialog) DrawableUtil(me.ccrama.redditslide.util.DrawableUtil) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) BuildConfig(me.ccrama.redditslide.BuildConfig) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) AfterNumberOfOpportunities(org.ligi.snackengage.conditions.AfterNumberOfOpportunities) ViewDragHelper(androidx.customview.widget.ViewDragHelper) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) BaseSnack(org.ligi.snackengage.snacks.BaseSnack) HasSeen(me.ccrama.redditslide.HasSeen) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) Editable(android.text.Editable) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) MiscUtil(me.ccrama.redditslide.util.MiscUtil) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) MultiRedditUpdateRequest(net.dean.jraw.http.MultiRedditUpdateRequest) TimePeriod(net.dean.jraw.paginators.TimePeriod) SettingsThemeFragment(me.ccrama.redditslide.ui.settings.SettingsThemeFragment) StringUtil(me.ccrama.redditslide.util.StringUtil) FragmentManager(androidx.fragment.app.FragmentManager) SettingsSubAdapter(me.ccrama.redditslide.ui.settings.SettingsSubAdapter) Parcelable(android.os.Parcelable) FlairTemplate(net.dean.jraw.models.FlairTemplate) UserSubscriptions.modOf(me.ccrama.redditslide.UserSubscriptions.modOf) Reddit(me.ccrama.redditslide.Reddit) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) Field(java.lang.reflect.Field) AutoCompleteTextView(android.widget.AutoCompleteTextView) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) Gravity(android.view.Gravity) MySynccitUpdateTask(me.ccrama.redditslide.Synccit.MySynccitUpdateTask) SharedPreferences(android.content.SharedPreferences) IconCompat(androidx.core.graphics.drawable.IconCompat) Configuration(android.content.res.Configuration) EditText(android.widget.EditText) ValueAnimator(android.animation.ValueAnimator) LinearLayout(android.widget.LinearLayout) ToggleSwipeViewPager(me.ccrama.redditslide.Views.ToggleSwipeViewPager) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) SideArrayAdapter(me.ccrama.redditslide.Adapters.SideArrayAdapter) PackageManager(android.content.pm.PackageManager) TimeUtils(me.ccrama.redditslide.util.TimeUtils) EditTextValidator(me.ccrama.redditslide.util.EditTextValidator) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) SettingsGeneralFragment(me.ccrama.redditslide.ui.settings.SettingsGeneralFragment) Animator(android.animation.Animator) DrawableRes(androidx.annotation.DrawableRes) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Locale(java.util.Locale) View(android.view.View) Sorting(net.dean.jraw.paginators.Sorting) SynccitRead(me.ccrama.redditslide.Synccit.SynccitRead) ArgbEvaluator(android.animation.ArgbEvaluator) FragmentStatePagerAdapter(androidx.fragment.app.FragmentStatePagerAdapter) AutoCacheScheduler(me.ccrama.redditslide.Autocache.AutoCacheScheduler) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) NetworkStateReceiver(me.ccrama.redditslide.util.NetworkStateReceiver) NotificationManager(android.app.NotificationManager) AsyncTask(android.os.AsyncTask) TabLayout(com.google.android.material.tabs.TabLayout) Authentication(me.ccrama.redditslide.Authentication) ApiException(net.dean.jraw.ApiException) ViewGroup(android.view.ViewGroup) List(java.util.List) NetworkUtil(me.ccrama.redditslide.util.NetworkUtil) TextView(android.widget.TextView) LinearInterpolator(android.view.animation.LinearInterpolator) RelativeLayout(android.widget.RelativeLayout) Toolbar(androidx.appcompat.widget.Toolbar) ListView(android.widget.ListView) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Window(android.view.Window) EditorInfo(android.view.inputmethod.EditorInfo) Snackbar(com.google.android.material.snackbar.Snackbar) RequestPermission(androidx.activity.result.contract.ActivityResultContracts.RequestPermission) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) Context(android.content.Context) SettingValues(me.ccrama.redditslide.SettingValues) KeyEvent(android.view.KeyEvent) AlertDialog(androidx.appcompat.app.AlertDialog) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ModerationManager(net.dean.jraw.managers.ModerationManager) Submission(net.dean.jraw.models.Submission) Pair(android.util.Pair) Intent(android.content.Intent) HashMap(java.util.HashMap) Constants(me.ccrama.redditslide.Constants) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) LogUtil(me.ccrama.redditslide.util.LogUtil) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) ClipData(android.content.ClipData) HashSet(java.util.HashSet) UserRecord(net.dean.jraw.models.UserRecord) ManageOfflineContent(me.ccrama.redditslide.ui.settings.ManageOfflineContent) Build(android.os.Build) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) ExecutorService(java.util.concurrent.ExecutorService) DialogInterface(android.content.DialogInterface) RateSnack(org.ligi.snackengage.snacks.RateSnack) ViewStub(android.view.ViewStub) MultiReddit(net.dean.jraw.models.MultiReddit) SwitchCompat(androidx.appcompat.widget.SwitchCompat) CompoundButton(android.widget.CompoundButton) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) LayoutInflater(android.view.LayoutInflater) ImageFlairs(me.ccrama.redditslide.ImageFlairs) GravityCompat(androidx.core.view.GravityCompat) KVStore(com.lusfold.androidkeyvaluestore.KVStore) Point(android.graphics.Point) DialogAction(com.afollestad.materialdialogs.DialogAction) SnackEngage(org.ligi.snackengage.SnackEngage) ResolveInfo(android.content.pm.ResolveInfo) PopupMenu(androidx.appcompat.widget.PopupMenu) ImageUtil(me.ccrama.redditslide.util.ImageUtil) SettingsActivity(me.ccrama.redditslide.ui.settings.SettingsActivity) Bitmap(android.graphics.Bitmap) ViewTreeObserver(android.view.ViewTreeObserver) Subreddit(net.dean.jraw.models.Subreddit) Activity(android.app.Activity) NetworkException(net.dean.jraw.http.NetworkException) Collections(java.util.Collections) LoggedInAccount(net.dean.jraw.models.LoggedInAccount) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) MultiReddit(net.dean.jraw.models.MultiReddit) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) MultiRedditUpdateRequest(net.dean.jraw.http.MultiRedditUpdateRequest) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NetworkException(net.dean.jraw.http.NetworkException) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) CardView(androidx.cardview.widget.CardView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException) Point(android.graphics.Point) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) AccountManager(net.dean.jraw.managers.AccountManager) CompoundButton(android.widget.CompoundButton) Snackbar(com.google.android.material.snackbar.Snackbar) ApiException(net.dean.jraw.ApiException)

Example 3 with AppCompatCheckBox

use of androidx.appcompat.widget.AppCompatCheckBox in project Slide by ccrama.

the class SubredditView method doSubOnlyStuff.

private void doSubOnlyStuff(final Subreddit subreddit) {
    if (!isFinishing()) {
        findViewById(R.id.loader).setVisibility(View.GONE);
        if (subreddit.getDataNode().has("subreddit_type") && !subreddit.getDataNode().get("subreddit_type").isNull()) {
            canSubmit = !subreddit.getDataNode().get("subreddit_type").asText().equalsIgnoreCase("RESTRICTED");
        }
        if (subreddit.getSidebar() != null && !subreddit.getSidebar().isEmpty()) {
            findViewById(R.id.sidebar_text).setVisibility(View.VISIBLE);
            final String text = subreddit.getDataNode().get("description_html").asText().trim();
            final SpoilerRobotoTextView body = (SpoilerRobotoTextView) findViewById(R.id.sidebar_text);
            CommentOverflow overflow = (CommentOverflow) findViewById(R.id.commentOverflow);
            setViews(text, subreddit.getDisplayName(), body, overflow);
            // get all subs that have Notifications enabled
            ArrayList<String> rawSubs = StringUtil.stringToArray(Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, ""));
            HashMap<String, Integer> subThresholds = new HashMap<>();
            for (String s : rawSubs) {
                try {
                    String[] split = s.split(":");
                    subThresholds.put(split[0].toLowerCase(Locale.ENGLISH), Integer.valueOf(split[1]));
                } catch (Exception ignored) {
                // do nothing
                }
            }
            // whether or not this subreddit was in the keySet
            boolean isNotified = subThresholds.containsKey(subreddit.getDisplayName().toLowerCase(Locale.ENGLISH));
            ((AppCompatCheckBox) findViewById(R.id.notify_posts_state)).setChecked(isNotified);
        } else {
            findViewById(R.id.sidebar_text).setVisibility(View.GONE);
        }
        View collection = findViewById(R.id.collection);
        if (Authentication.isLoggedIn) {
            collection.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    new AsyncTask<Void, Void, Void>() {

                        HashMap<String, MultiReddit> multis = new HashMap<String, MultiReddit>();

                        @Override
                        protected Void doInBackground(Void... params) {
                            if (UserSubscriptions.multireddits == null) {
                                UserSubscriptions.syncMultiReddits(SubredditView.this);
                            }
                            for (MultiReddit r : UserSubscriptions.multireddits) {
                                multis.put(r.getDisplayName(), r);
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(Void aVoid) {
                            new MaterialDialog.Builder(SubredditView.this).title("Add /r/" + subreddit.getDisplayName() + " to").items(multis.keySet()).itemsCallback(new MaterialDialog.ListCallback() {

                                @Override
                                public void onSelection(MaterialDialog dialog, View itemView, final int which, CharSequence text) {
                                    new AsyncTask<Void, Void, Void>() {

                                        @Override
                                        protected Void doInBackground(Void... params) {
                                            try {
                                                final String multiName = multis.keySet().toArray(new String[0])[which];
                                                List<String> subs = new ArrayList<String>();
                                                for (MultiSubreddit sub : multis.get(multiName).getSubreddits()) {
                                                    subs.add(sub.getDisplayName());
                                                }
                                                subs.add(subreddit.getDisplayName());
                                                new MultiRedditManager(Authentication.reddit).createOrUpdate(new MultiRedditUpdateRequest.Builder(Authentication.name, multiName).subreddits(subs).build());
                                                UserSubscriptions.syncMultiReddits(SubredditView.this);
                                                runOnUiThread(new Runnable() {

                                                    @Override
                                                    public void run() {
                                                        drawerLayout.closeDrawers();
                                                        Snackbar s = Snackbar.make(mToolbar, getString(R.string.multi_subreddit_added, multiName), Snackbar.LENGTH_LONG);
                                                        LayoutUtils.showSnackbar(s);
                                                    }
                                                });
                                            } catch (final NetworkException | ApiException e) {
                                                runOnUiThread(new Runnable() {

                                                    @Override
                                                    public void run() {
                                                        runOnUiThread(new Runnable() {

                                                            @Override
                                                            public void run() {
                                                                Snackbar.make(mToolbar, getString(R.string.multi_error), Snackbar.LENGTH_LONG).setAction(R.string.btn_ok, null).show();
                                                            }
                                                        });
                                                    }
                                                });
                                                e.printStackTrace();
                                            }
                                            return null;
                                        }
                                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                }
                            }).show();
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });
        } else {
            collection.setVisibility(View.GONE);
        }
        {
            final TextView subscribe = (TextView) findViewById(R.id.subscribe);
            currentlySubbed = Authentication.isLoggedIn ? subreddit.isUserSubscriber() : UserSubscriptions.getSubscriptions(this).contains(subreddit.getDisplayName().toLowerCase(Locale.ENGLISH));
            MiscUtil.doSubscribeButtonText(currentlySubbed, subscribe);
            assert subscribe != null;
            subscribe.setOnClickListener(new View.OnClickListener() {

                private void doSubscribe() {
                    if (Authentication.isLoggedIn) {
                        new AlertDialog.Builder(SubredditView.this).setTitle(getString(R.string.subscribe_to, subreddit.getDisplayName())).setPositiveButton(R.string.reorder_add_subscribe, (dialog, which) -> new AsyncTask<Void, Void, Boolean>() {

                            @Override
                            public void onPostExecute(Boolean success) {
                                if (!success) {
                                    // If subreddit was removed from account or not
                                    new AlertDialog.Builder(SubredditView.this).setTitle(R.string.force_change_subscription).setMessage(R.string.force_change_subscription_desc).setPositiveButton(R.string.btn_yes, (dialog1, which1) -> {
                                        // Force add the subscription
                                        changeSubscription(subreddit, true);
                                        Snackbar s = Snackbar.make(mToolbar, getString(R.string.misc_subscribed), Snackbar.LENGTH_SHORT);
                                        LayoutUtils.showSnackbar(s);
                                    }).setNegativeButton(R.string.btn_no, null).setCancelable(false).show();
                                } else {
                                    changeSubscription(subreddit, true);
                                }
                            }

                            @Override
                            protected Boolean doInBackground(Void... params) {
                                try {
                                    new AccountManager(Authentication.reddit).subscribe(subreddit);
                                } catch (NetworkException e) {
                                    // Either network crashed or trying to unsubscribe to a subreddit that the account isn't subscribed to
                                    return false;
                                }
                                return true;
                            }
                        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)).setNegativeButton(R.string.btn_cancel, null).setNeutralButton(R.string.btn_add_to_sublist, (dialog, which) -> {
                            // Force add the subscription
                            changeSubscription(subreddit, true);
                            Snackbar s = Snackbar.make(mToolbar, R.string.sub_added, Snackbar.LENGTH_SHORT);
                            LayoutUtils.showSnackbar(s);
                        }).show();
                    } else {
                        changeSubscription(subreddit, true);
                    }
                }

                @Override
                public void onClick(View v) {
                    if (!currentlySubbed) {
                        doSubscribe();
                    } else {
                        doUnsubscribe();
                    }
                    MiscUtil.doSubscribeButtonText(currentlySubbed, subscribe);
                }

                private void doUnsubscribe() {
                    if (Authentication.didOnline) {
                        new AlertDialog.Builder(SubredditView.this).setTitle(getString(R.string.unsubscribe_from, subreddit.getDisplayName())).setPositiveButton(R.string.reorder_remove_unsubscribe, (dialog, which) -> new AsyncTask<Void, Void, Boolean>() {

                            @Override
                            public void onPostExecute(Boolean success) {
                                if (!success) {
                                    // If subreddit was removed from account or not
                                    new AlertDialog.Builder(SubredditView.this).setTitle(R.string.force_change_subscription).setMessage(R.string.force_change_subscription_desc).setPositiveButton(R.string.btn_yes, (dialog12, which12) -> {
                                        // Force add the subscription
                                        changeSubscription(subreddit, false);
                                        Snackbar s = Snackbar.make(mToolbar, getString(R.string.misc_unsubscribed), Snackbar.LENGTH_SHORT);
                                        LayoutUtils.showSnackbar(s);
                                    }).setNegativeButton(R.string.btn_no, null).setCancelable(false).show();
                                } else {
                                    changeSubscription(subreddit, false);
                                }
                            }

                            @Override
                            protected Boolean doInBackground(Void... params) {
                                try {
                                    new AccountManager(Authentication.reddit).unsubscribe(subreddit);
                                } catch (NetworkException e) {
                                    // Either network crashed or trying to unsubscribe to a subreddit that the account isn't subscribed to
                                    return false;
                                }
                                return true;
                            }
                        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)).setNeutralButton(R.string.just_unsub, (dialog, which) -> {
                            // Force add the subscription
                            changeSubscription(subreddit, false);
                            Snackbar s = Snackbar.make(mToolbar, R.string.misc_unsubscribed, Snackbar.LENGTH_SHORT);
                            LayoutUtils.showSnackbar(s);
                        }).setNegativeButton(R.string.btn_cancel, null).show();
                    } else {
                        changeSubscription(subreddit, false);
                    }
                }
            });
        }
        {
            final AppCompatCheckBox notifyStateCheckBox = (AppCompatCheckBox) findViewById(R.id.notify_posts_state);
            assert notifyStateCheckBox != null;
            notifyStateCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        final String sub = subreddit.getDisplayName();
                        if (!sub.equalsIgnoreCase("all") && !sub.equalsIgnoreCase("frontpage") && !sub.equalsIgnoreCase("friends") && !sub.equalsIgnoreCase("mod") && !sub.contains("+") && !sub.contains(".") && !sub.contains("/m/")) {
                            new AlertDialog.Builder(SubredditView.this).setTitle(getString(R.string.sub_post_notifs_title, sub)).setMessage(R.string.sub_post_notifs_msg).setPositiveButton(R.string.btn_ok, (dialog, which) -> new MaterialDialog.Builder(SubredditView.this).title(R.string.sub_post_notifs_threshold).items(new String[] { "1", "5", "10", "20", "40", "50" }).alwaysCallSingleChoiceCallback().itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {

                                @Override
                                public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                                    ArrayList<String> subs = StringUtil.stringToArray(Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, ""));
                                    subs.add(sub + ":" + text);
                                    Reddit.appRestart.edit().putString(CheckForMail.SUBS_TO_GET, StringUtil.arrayToString(subs)).commit();
                                    return true;
                                }
                            }).cancelable(false).show()).setNegativeButton(R.string.btn_cancel, null).setNegativeButton(R.string.btn_cancel, (dialog, which) -> notifyStateCheckBox.setChecked(false)).setOnCancelListener(dialog -> notifyStateCheckBox.setChecked(false)).show();
                        } else {
                            notifyStateCheckBox.setChecked(false);
                            Toast.makeText(SubredditView.this, R.string.sub_post_notifs_err, Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Intent cancelIntent = new Intent(SubredditView.this, CancelSubNotifs.class);
                        cancelIntent.putExtra(CancelSubNotifs.EXTRA_SUB, subreddit.getDisplayName());
                        startActivity(cancelIntent);
                    }
                }
            });
        }
        if (!subreddit.getPublicDescription().isEmpty()) {
            findViewById(R.id.sub_title).setVisibility(View.VISIBLE);
            setViews(subreddit.getDataNode().get("public_description_html").asText(), subreddit.getDisplayName().toLowerCase(Locale.ENGLISH), ((SpoilerRobotoTextView) findViewById(R.id.sub_title)), (CommentOverflow) findViewById(R.id.sub_title_overflow));
        } else {
            findViewById(R.id.sub_title).setVisibility(View.GONE);
        }
        if (subreddit.getDataNode().has("icon_img") && !subreddit.getDataNode().get("icon_img").asText().isEmpty()) {
            ((Reddit) getApplication()).getImageLoader().displayImage(subreddit.getDataNode().get("icon_img").asText(), (ImageView) findViewById(R.id.subimage));
        } else {
            findViewById(R.id.subimage).setVisibility(View.GONE);
        }
        String bannerImage = subreddit.getBannerImage();
        if (bannerImage != null && !bannerImage.isEmpty()) {
            findViewById(R.id.sub_banner).setVisibility(View.VISIBLE);
            ((Reddit) getApplication()).getImageLoader().displayImage(bannerImage, (ImageView) findViewById(R.id.sub_banner));
        } else {
            findViewById(R.id.sub_banner).setVisibility(View.GONE);
        }
        ((TextView) findViewById(R.id.subscribers)).setText(getString(R.string.subreddit_subscribers_string, subreddit.getLocalizedSubscriberCount()));
        findViewById(R.id.subscribers).setVisibility(View.VISIBLE);
        ((TextView) findViewById(R.id.active_users)).setText(getString(R.string.subreddit_active_users_string_new, subreddit.getLocalizedAccountsActive()));
        findViewById(R.id.active_users).setVisibility(View.VISIBLE);
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ToggleSwipeViewPager(me.ccrama.redditslide.Views.ToggleSwipeViewPager) Bundle(android.os.Bundle) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) R(me.ccrama.redditslide.R) NonNull(androidx.annotation.NonNull) Spannable(android.text.Spannable) ImageView(android.widget.ImageView) PostMatch(me.ccrama.redditslide.PostMatch) ColorDrawable(android.graphics.drawable.ColorDrawable) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) UserRecordPaginator(net.dean.jraw.paginators.UserRecordPaginator) BlankFragment(me.ccrama.redditslide.Fragments.BlankFragment) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) Locale(java.util.Locale) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Sorting(net.dean.jraw.paginators.Sorting) FragmentStatePagerAdapter(androidx.fragment.app.FragmentStatePagerAdapter) JsonNode(com.fasterxml.jackson.databind.JsonNode) ProUtil(me.ccrama.redditslide.util.ProUtil) Log(android.util.Log) CheckForMail(me.ccrama.redditslide.Notifications.CheckForMail) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) AsyncTask(android.os.AsyncTask) Authentication(me.ccrama.redditslide.Authentication) CommentPage(me.ccrama.redditslide.Fragments.CommentPage) SidebarLayout(me.ccrama.redditslide.Views.SidebarLayout) ApiException(net.dean.jraw.ApiException) Palette(me.ccrama.redditslide.Visuals.Palette) ViewGroup(android.view.ViewGroup) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) OfflineSubreddit(me.ccrama.redditslide.OfflineSubreddit) List(java.util.List) TextView(android.widget.TextView) SortingUtil(me.ccrama.redditslide.util.SortingUtil) LinearInterpolator(android.view.animation.LinearInterpolator) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) Context(android.content.Context) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) SettingValues(me.ccrama.redditslide.SettingValues) AlertDialog(androidx.appcompat.app.AlertDialog) ModerationManager(net.dean.jraw.managers.ModerationManager) Submission(net.dean.jraw.models.Submission) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) Intent(android.content.Intent) HashMap(java.util.HashMap) Constants(me.ccrama.redditslide.Constants) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) LogUtil(me.ccrama.redditslide.util.LogUtil) MenuItem(android.view.MenuItem) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) MiscUtil(me.ccrama.redditslide.util.MiscUtil) MenuInflater(android.view.MenuInflater) UserRecord(net.dean.jraw.models.UserRecord) Toast(android.widget.Toast) Menu(android.view.Menu) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) MultiRedditUpdateRequest(net.dean.jraw.http.MultiRedditUpdateRequest) DialogInterface(android.content.DialogInterface) TimePeriod(net.dean.jraw.paginators.TimePeriod) StringUtil(me.ccrama.redditslide.util.StringUtil) FragmentManager(androidx.fragment.app.FragmentManager) SettingsSubAdapter(me.ccrama.redditslide.ui.settings.SettingsSubAdapter) Parcelable(android.os.Parcelable) MultiReddit(net.dean.jraw.models.MultiReddit) CompoundButton(android.widget.CompoundButton) FlairTemplate(net.dean.jraw.models.FlairTemplate) LayoutInflater(android.view.LayoutInflater) ImageFlairs(me.ccrama.redditslide.ImageFlairs) Reddit(me.ccrama.redditslide.Reddit) GravityCompat(androidx.core.view.GravityCompat) DialogAction(com.afollestad.materialdialogs.DialogAction) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) Color(android.graphics.Color) PopupMenu(androidx.appcompat.widget.PopupMenu) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) Subreddit(net.dean.jraw.models.Subreddit) NetworkException(net.dean.jraw.http.NetworkException) HashMap(java.util.HashMap) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) MultiReddit(net.dean.jraw.models.MultiReddit) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) List(java.util.List) ArrayList(java.util.ArrayList) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) NetworkException(net.dean.jraw.http.NetworkException) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) ImageView(android.widget.ImageView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView) ApiException(net.dean.jraw.ApiException) NetworkException(net.dean.jraw.http.NetworkException) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) AccountManager(net.dean.jraw.managers.AccountManager) CompoundButton(android.widget.CompoundButton) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 4 with AppCompatCheckBox

use of androidx.appcompat.widget.AppCompatCheckBox in project J2ME-Loader by nikita36078.

the class MicroActivity method showSaveVkAlert.

private void showSaveVkAlert(boolean keepScreenPreferred) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.CONFIRMATION_REQUIRED);
    builder.setMessage(R.string.pref_vk_save_alert);
    builder.setNegativeButton(android.R.string.no, null);
    AlertDialog dialog = builder.create();
    final VirtualKeyboard vk = ContextHolder.getVk();
    if (vk.isPhone()) {
        AppCompatCheckBox cb = new AppCompatCheckBox(this);
        cb.setText(R.string.opt_save_screen_params);
        cb.setChecked(keepScreenPreferred);
        TypedValue out = new TypedValue();
        getTheme().resolveAttribute(R.attr.dialogPreferredPadding, out, true);
        int paddingH = getResources().getDimensionPixelOffset(out.resourceId);
        int paddingT = getResources().getDimensionPixelOffset(R.dimen.abc_dialog_padding_top_material);
        dialog.setView(cb, paddingH, paddingT, paddingH, 0);
        dialog.setButton(dialog.BUTTON_POSITIVE, getText(android.R.string.yes), (d, w) -> {
            if (cb.isChecked()) {
                vk.saveScreenParams();
            }
            vk.onLayoutChanged(VirtualKeyboard.TYPE_CUSTOM);
        });
    } else {
        dialog.setButton(dialog.BUTTON_POSITIVE, getText(android.R.string.yes), (d, w) -> ContextHolder.getVk().onLayoutChanged(VirtualKeyboard.TYPE_CUSTOM));
    }
    dialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) VirtualKeyboard(javax.microedition.lcdui.keyboard.VirtualKeyboard) SuppressLint(android.annotation.SuppressLint) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) TypedValue(android.util.TypedValue)

Example 5 with AppCompatCheckBox

use of androidx.appcompat.widget.AppCompatCheckBox in project J2ME-Loader by nikita36078.

the class ChoiceGroup method initButtonGroup.

private void initButtonGroup() {
    buttongroup.setOrientation(LinearLayout.VERTICAL);
    Context context = getOwnerForm().getParentActivity();
    int size = selected.size();
    if (buttongroup instanceof RadioGroup) {
        for (int i = 0; i < size; i++) {
            addButton(new AppCompatRadioButton(context), i, strings.get(i), images.get(i), selected.get(i));
        }
    } else {
        for (int i = 0; i < size; i++) {
            addButton(new AppCompatCheckBox(context), i, strings.get(i), images.get(i), selected.get(i));
        }
    }
}
Also used : Context(android.content.Context) AppCompatRadioButton(androidx.appcompat.widget.AppCompatRadioButton) RadioGroup(android.widget.RadioGroup) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox)

Aggregations

AppCompatCheckBox (androidx.appcompat.widget.AppCompatCheckBox)8 CompoundButton (android.widget.CompoundButton)4 TextView (android.widget.TextView)4 Context (android.content.Context)3 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 MenuItem (android.view.MenuItem)3 View (android.view.View)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 PopupMenu (androidx.appcompat.widget.PopupMenu)3 Dialog (android.app.Dialog)2 DialogInterface (android.content.DialogInterface)2 Configuration (android.content.res.Configuration)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 AsyncTask (android.os.AsyncTask)2 Bundle (android.os.Bundle)2 Parcelable (android.os.Parcelable)2 Spannable (android.text.Spannable)2 Log (android.util.Log)2 Gravity (android.view.Gravity)2