Search in sources :

Example 21 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class CommentPage method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = this.getArguments();
    subreddit = bundle.getString("subreddit", "");
    fullname = bundle.getString("id", "");
    page = bundle.getInt("page", 0);
    single = bundle.getBoolean("single", false);
    context = bundle.getString("context", "");
    contextNumber = bundle.getInt("contextNumber", 5);
    np = bundle.getBoolean("np", false);
    archived = bundle.getBoolean("archived", false);
    locked = bundle.getBoolean("locked", false);
    contest = bundle.getBoolean("contest", false);
    loadMore = (!context.isEmpty() && !context.equals(Reddit.EMPTY_STRING));
    if (!single)
        loadMore = false;
    int subredditStyle = new ColorPreferences(getActivity()).getThemeSubreddit(subreddit);
    contextThemeWrapper = new ContextThemeWrapper(getActivity(), subredditStyle);
    mLayoutManager = new PreCachingLayoutManagerComments(getActivity());
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) Bundle(android.os.Bundle) PreCachingLayoutManagerComments(me.ccrama.redditslide.Views.PreCachingLayoutManagerComments)

Example 22 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class MainActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    inNightMode = SettingValues.isNight();
    disableSwipeBackLayout();
    super.onCreate(savedInstanceState);
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
        // Activity was brought to front and not created
        finish();
        return;
    }
    if (!Slide.hasStarted) {
        Slide.hasStarted = true;
    }
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
        }
    }
    boolean first = false;
    if (Reddit.colors != null && !Reddit.colors.contains("firstStart53")) {
        new AlertDialogWrapper.Builder(this).setTitle("Content settings have moved!").setMessage("NSFW content is now disabled by default. If you are over the age of 18, to re-enable NSFW content, visit Settings > Content settings").setPositiveButton(R.string.btn_ok, null).setCancelable(false).show();
        Reddit.colors.edit().putBoolean("firstStart53", true).apply();
    }
    if (Reddit.colors != null && !Reddit.colors.contains("Tutorial")) {
        first = true;
        if (Reddit.appRestart == null) {
            Reddit.appRestart = getSharedPreferences("appRestart", 0);
        }
        Reddit.appRestart.edit().putBoolean("firststart52", true).apply();
        Intent i = new Intent(this, Tutorial.class);
        doForcePrefs();
        startActivity(i);
    } else {
        if (Authentication.didOnline && NetworkUtil.isConnected(MainActivity.this) && !checkedPopups) {
            runAfterLoad = new Runnable() {

                @Override
                public void run() {
                    runAfterLoad = null;
                    if (Authentication.isLoggedIn) {
                        new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                    if (!Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, "").isEmpty()) {
                        new CheckForMail.AsyncGetSubs(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                    new AsyncTask<Void, Void, Submission>() {

                        @Override
                        protected Submission doInBackground(Void... params) {
                            if (Authentication.isLoggedIn)
                                UserSubscriptions.doOnlineSyncing();
                            try {
                                SubredditPaginator p = new SubredditPaginator(Authentication.reddit, "slideforreddit");
                                p.setLimit(2);
                                ArrayList<Submission> posts = new ArrayList<>(p.next());
                                for (Submission s : posts) {
                                    String version = BuildConfig.VERSION_NAME;
                                    if (version.length() > 5) {
                                        version = version.substring(0, version.lastIndexOf("."));
                                    }
                                    if (s.isStickied() && s.getSubmissionFlair().getText() != null && s.getSubmissionFlair().getText().equalsIgnoreCase("Announcement") && !Reddit.appRestart.contains("announcement" + s.getFullName()) && s.getTitle().contains(version)) {
                                        Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
                                        return s;
                                    } else if (BuildConfig.VERSION_NAME.contains("alpha") && s.isStickied() && s.getSubmissionFlair().getText() != null && s.getSubmissionFlair().getText().equalsIgnoreCase("Alpha") && !Reddit.appRestart.contains("announcement" + s.getFullName()) && s.getTitle().contains(BuildConfig.VERSION_NAME)) {
                                        Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
                                        return s;
                                    } else if (s.isStickied() && s.getSubmissionFlair().getText().equalsIgnoreCase("PRO") && !SettingValues.tabletUI && !Reddit.appRestart.contains("announcement" + s.getFullName())) {
                                        Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
                                        return s;
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(final Submission s) {
                            checkedPopups = true;
                            if (s != null) {
                                Reddit.appRestart.edit().putString("page", s.getDataNode().get("selftext_html").asText()).apply();
                                Reddit.appRestart.edit().putString("title", s.getTitle()).apply();
                                Reddit.appRestart.edit().putString("url", s.getUrl()).apply();
                                String title;
                                if (s.getTitle().toLowerCase(Locale.ENGLISH).contains("release")) {
                                    title = getString(R.string.btn_changelog);
                                } else {
                                    title = getString(R.string.btn_view);
                                }
                                Snackbar snack = Snackbar.make(pager, s.getTitle(), Snackbar.LENGTH_INDEFINITE).setAction(title, new OnSingleClickListener() {

                                    @Override
                                    public void onSingleClick(View v) {
                                        Intent i = new Intent(MainActivity.this, Announcement.class);
                                        startActivity(i);
                                    }
                                });
                                View view = snack.getView();
                                TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                                tv.setTextColor(Color.WHITE);
                                snack.show();
                            }
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                // todo this  new AsyncStartNotifSocket().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            };
        }
    }
    if (savedInstanceState != null && !changed) {
        Authentication.isLoggedIn = savedInstanceState.getBoolean(LOGGED_IN);
        Authentication.name = savedInstanceState.getString(USERNAME, "LOGGEDOUT");
        Authentication.didOnline = savedInstanceState.getBoolean(IS_ONLINE);
    } else {
        changed = false;
    }
    if (getIntent().getBooleanExtra("EXIT", false))
        finish();
    applyColorTheme();
    setContentView(R.layout.activity_overview);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    setSupportActionBar(mToolbar);
    if (getIntent() != null && getIntent().hasExtra(EXTRA_PAGE_TO)) {
        toGoto = getIntent().getIntExtra(EXTRA_PAGE_TO, 0);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = this.getWindow();
        window.setStatusBarColor(Palette.getDarkerColor(Palette.getDarkerColor(Palette.getDefaultColor())));
    }
    mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    header = findViewById(R.id.header);
    // Gets the height of the header
    if (header != null) {
        header.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                headerHeight = header.getHeight();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    header.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                } else {
                    header.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
            }
        });
    }
    pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
    singleMode = SettingValues.single;
    if (singleMode) {
        commentPager = SettingValues.commentPager;
    }
    // Inflate tabs if single mode is disabled
    if (!singleMode) {
        mTabLayout = (TabLayout) ((ViewStub) findViewById(R.id.stub_tabs)).inflate();
    }
    // Disable swiping if single mode is enabled
    if (singleMode) {
        pager.setSwipingEnabled(false);
    }
    sidebarBody = (SpoilerRobotoTextView) findViewById(R.id.sidebar_text);
    sidebarOverflow = (CommentOverflow) findViewById(R.id.commentOverflow);
    if (!Reddit.appRestart.getBoolean("isRestarting", false) && Reddit.colors.contains("Tutorial")) {
        LogUtil.v("Starting main " + Authentication.name);
        Authentication.isLoggedIn = Reddit.appRestart.getBoolean("loggedin", false);
        Authentication.name = Reddit.appRestart.getString("name", "LOGGEDOUT");
        UserSubscriptions.doMainActivitySubs(this);
    } else if (!first) {
        LogUtil.v("Starting main 2 " + Authentication.name);
        Authentication.isLoggedIn = Reddit.appRestart.getBoolean("loggedin", false);
        Authentication.name = Reddit.appRestart.getString("name", "LOGGEDOUT");
        Reddit.appRestart.edit().putBoolean("isRestarting", false).commit();
        Reddit.isRestarting = false;
        UserSubscriptions.doMainActivitySubs(this);
    }
    final SharedPreferences seen = getSharedPreferences("SEEN", 0);
    if (!seen.contains("isCleared") && !seen.getAll().isEmpty() || !Reddit.appRestart.contains("hasCleared")) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                KVManger m = KVStore.getInstance();
                Map<String, ?> values = seen.getAll();
                for (Map.Entry<String, ?> entry : values.entrySet()) {
                    if (entry.getKey().length() == 6 && entry.getValue() instanceof Boolean) {
                        m.insert(entry.getKey(), "true");
                    } else if (entry.getValue() instanceof Long) {
                        m.insert(entry.getKey(), String.valueOf(seen.getLong(entry.getKey(), 0)));
                    }
                }
                seen.edit().clear().putBoolean("isCleared", true).apply();
                if (getSharedPreferences("HIDDEN_POSTS", 0).getAll().size() != 0) {
                    getSharedPreferences("HIDDEN", 0).edit().clear().apply();
                    getSharedPreferences("HIDDEN_POSTS", 0).edit().clear().apply();
                }
                if (!Reddit.appRestart.contains("hasCleared")) {
                    SharedPreferences.Editor e = Reddit.appRestart.edit();
                    Map<String, ?> toClear = Reddit.appRestart.getAll();
                    for (Map.Entry<String, ?> entry : toClear.entrySet()) {
                        if (entry.getValue() instanceof String && ((String) entry.getValue()).length() > 300) {
                            e.remove(entry.getKey());
                        }
                    }
                    e.putBoolean("hasCleared", true);
                    e.apply();
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                dismissProgressDialog();
            }

            @Override
            protected void onPreExecute() {
                d = new MaterialDialog.Builder(MainActivity.this).title(R.string.misc_setting_up).content(R.string.misc_setting_up_message).progress(true, 100).cancelable(false).build();
                d.show();
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
    if (!FDroid.isFDroid && Authentication.isLoggedIn && NetworkUtil.isConnected(MainActivity.this)) {
        // Display an snackbar that asks the user to rate the app after this
        // activity was created 6 times, never again when once clicked or with a maximum of
        // two times.
        SnackEngage.from(MainActivity.this).withSnack(new RateSnack().withConditions(new NeverAgainWhenClickedOnce(), new AfterNumberOfOpportunities(10), new WithLimitedNumberOfTimes(2)).overrideActionText(getString(R.string.misc_rate_msg)).overrideTitleText(getString(R.string.misc_rate_title)).withDuration(BaseSnack.DURATION_LONG)).build().engageWhenAppropriate();
    }
    if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) {
        setupSubredditSearchToolbar();
    }
    /**
     * int for the current base theme selected.
     * 0 = Dark, 1 = Light, 2 = AMOLED, 3 = Dark blue, 4 = AMOLED with contrast, 5 = Sepia
     */
    SettingValues.currentTheme = new ColorPreferences(this).getFontStyle().getThemeType();
    networkStateReceiver = new NetworkStateReceiver();
    networkStateReceiver.addListener(this);
    try {
        this.registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
    } catch (Exception e) {
    }
}
Also used : RateSnack(org.ligi.snackengage.snacks.RateSnack) NeverAgainWhenClickedOnce(org.ligi.snackengage.conditions.NeverAgainWhenClickedOnce) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) AfterNumberOfOpportunities(org.ligi.snackengage.conditions.AfterNumberOfOpportunities) SubredditPaginator(net.dean.jraw.paginators.SubredditPaginator) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) WithLimitedNumberOfTimes(org.ligi.snackengage.conditions.WithLimitedNumberOfTimes) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ViewTreeObserver(android.view.ViewTreeObserver) Window(android.view.Window) IntentFilter(android.content.IntentFilter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Submission(net.dean.jraw.models.Submission) ColorPreferences(me.ccrama.redditslide.ColorPreferences) SharedPreferences(android.content.SharedPreferences) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException) ViewStub(android.view.ViewStub) KVManger(com.lusfold.androidkeyvaluestore.core.KVManger) Map(java.util.Map) HashMap(java.util.HashMap) NetworkStateReceiver(me.ccrama.redditslide.util.NetworkStateReceiver) Snackbar(android.support.design.widget.Snackbar)

Example 23 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class MainActivity method doSubSidebarNoLoad.

public void doSubSidebarNoLoad(final String subreddit) {
    if (mAsyncGetSubreddit != null) {
        mAsyncGetSubreddit.cancel(true);
    }
    findViewById(R.id.loader).setVisibility(View.GONE);
    invalidateOptionsMenu();
    if (!subreddit.equalsIgnoreCase("all") && !subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("mod") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
        if (drawerLayout != null) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, GravityCompat.END);
        }
        findViewById(R.id.sidebar_text).setVisibility(View.GONE);
        findViewById(R.id.sub_title).setVisibility(View.GONE);
        findViewById(R.id.subscribers).setVisibility(View.GONE);
        findViewById(R.id.active_users).setVisibility(View.GONE);
        findViewById(R.id.header_sub).setBackgroundColor(Palette.getColor(subreddit));
        ((TextView) findViewById(R.id.sub_infotitle)).setText(subreddit);
        // Sidebar buttons should use subreddit's accent color
        int subColor = new ColorPreferences(this).getColor(subreddit);
        ((TextView) findViewById(R.id.theme_text)).setTextColor(subColor);
        ((TextView) findViewById(R.id.wiki_text)).setTextColor(subColor);
        ((TextView) findViewById(R.id.post_text)).setTextColor(subColor);
        ((TextView) findViewById(R.id.mods_text)).setTextColor(subColor);
        ((TextView) findViewById(R.id.flair_text)).setTextColor(subColor);
        ((TextView) drawerLayout.findViewById(R.id.sorting).findViewById(R.id.sort)).setTextColor(subColor);
        ((TextView) findViewById(R.id.sync)).setTextColor(subColor);
    } else {
        if (drawerLayout != null) {
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
        }
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) Point(android.graphics.Point)

Example 24 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class MainActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final String subreddit = usedArray.get(Reddit.currentPosition);
    switch(item.getItemId()) {
        case R.id.filter:
            filterContent(shouldLoad);
            return true;
        case R.id.sidebar:
            if (!subreddit.equals("all") && !subreddit.equals("frontpage") && !subreddit.contains(".") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
                drawerLayout.openDrawer(GravityCompat.END);
            } else {
                Toast.makeText(this, R.string.sidebar_notfound, Toast.LENGTH_SHORT).show();
            }
            return true;
        case R.id.night:
            {
                LayoutInflater inflater = getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.choosethemesmall, null);
                AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(MainActivity.this);
                final TextView title = dialoglayout.findViewById(R.id.title);
                title.setBackgroundColor(Palette.getDefaultColor());
                builder.setView(dialoglayout);
                final Dialog d = builder.show();
                back = new ColorPreferences(MainActivity.this).getFontStyle().getThemeType();
                if (SettingValues.isNight()) {
                    dialoglayout.findViewById(R.id.nightmsg).setVisibility(View.VISIBLE);
                }
                dialoglayout.findViewById(R.id.black).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 2) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.blacklighter).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 4) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.deep).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 8) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.sepia).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 5) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.pixel).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 7) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.red).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 6) {
                                back = theme.getThemeType();
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.light).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 1) {
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                back = theme.getThemeType();
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.dark).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 0) {
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                back = theme.getThemeType();
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
                dialoglayout.findViewById(R.id.blue).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
                        String name = names[names.length - 1];
                        final String newName = name.replace("(", "");
                        for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                            if (theme.toString().contains(newName) && theme.getThemeType() == 3) {
                                new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                back = theme.getThemeType();
                                d.dismiss();
                                restartTheme();
                                break;
                            }
                        }
                    }
                });
            }
            return true;
        case R.id.action_refresh:
            if (adapter != null && adapter.getCurrentFragment() != null) {
                ((SubmissionsView) adapter.getCurrentFragment()).forceRefresh();
            }
            return true;
        case R.id.action_sort:
            if (subreddit.equalsIgnoreCase("friends")) {
                Snackbar s = Snackbar.make(findViewById(R.id.anchor), getString(R.string.friends_sort_error), Snackbar.LENGTH_SHORT);
                View view = s.getView();
                TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                tv.setTextColor(Color.WHITE);
                s.show();
            } else {
                openPopup();
            }
            return true;
        case R.id.search:
            MaterialDialog.Builder builder = new MaterialDialog.Builder(this).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {

                @Override
                public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
                    term = charSequence.toString();
                }
            });
            // Add "search current sub" if it is not frontpage/all/random
            if (!subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("all") && !subreddit.contains(".") && !subreddit.contains("/m/") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("random") && !subreddit.equalsIgnoreCase("popular") && !subreddit.equalsIgnoreCase("myrandom") && !subreddit.equalsIgnoreCase("randnsfw")) {
                builder.positiveText(getString(R.string.search_subreddit, subreddit)).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        i.putExtra(Search.EXTRA_SUBREDDIT, subreddit);
                        Log.v(LogUtil.getTag(), "INTENT SHOWS " + term + " AND " + subreddit);
                        startActivity(i);
                    }
                });
                builder.neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        startActivity(i);
                    }
                });
            } else {
                builder.positiveText(R.string.search_all).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        startActivity(i);
                    }
                });
            }
            builder.show();
            return true;
        case R.id.save:
            saveOffline(((SubmissionsView) adapter.getCurrentFragment()).posts.posts, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
            return true;
        case R.id.hide_posts:
            ((SubmissionsView) adapter.getCurrentFragment()).clearSeenPosts(false);
            return true;
        case R.id.share:
            Reddit.defaultShareText("Slide for Reddit", "https://play.google.com/store/apps/details?id=me.ccrama.redditslide", MainActivity.this);
            return true;
        case R.id.submit:
            {
                Intent i = new Intent(MainActivity.this, Submit.class);
                i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
                startActivity(i);
            }
            return true;
        case R.id.gallery:
            if (SettingValues.tabletUI) {
                List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i2 = new Intent(this, Gallery.class);
                    i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                    i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                    startActivity(i2);
                }
            } else {
                AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(this).setTitle(R.string.general_gallerymode_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                        } catch (ActivityNotFoundException e) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                        }
                    }
                }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }
                });
                if (SettingValues.previews > 0) {
                    b.setNeutralButton(getString(R.string.pro_previews, SettingValues.previews), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
                            SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
                            List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                            if (posts != null && !posts.isEmpty()) {
                                Intent i2 = new Intent(MainActivity.this, Gallery.class);
                                i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                                i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                                startActivity(i2);
                            }
                        }
                    });
                }
                b.show();
            }
            return true;
        case R.id.action_shadowbox:
            if (SettingValues.tabletUI) {
                List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i2 = new Intent(this, Shadowbox.class);
                    i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                    i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                    i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                    startActivity(i2);
                }
            } else {
                AlertDialogWrapper.Builder b = new AlertDialogWrapper.Builder(this).setTitle(R.string.general_shadowbox_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                        } catch (ActivityNotFoundException e) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                        }
                    }
                }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }
                });
                if (SettingValues.previews > 0) {
                    b.setNeutralButton("Preview (" + SettingValues.previews + ")", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
                            SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
                            List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                            if (posts != null && !posts.isEmpty()) {
                                Intent i2 = new Intent(MainActivity.this, Shadowbox.class);
                                i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                                i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                                i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                                startActivity(i2);
                            }
                        }
                    });
                }
                b.show();
            }
            return true;
        default:
            return false;
    }
}
Also used : DialogInterface(android.content.DialogInterface) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) List(java.util.List) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point) ActivityNotFoundException(android.content.ActivityNotFoundException) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) Snackbar(android.support.design.widget.Snackbar)

Example 25 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class MainActivity method doPageSelectedComments.

public void doPageSelectedComments(int position) {
    pager.setSwipeLeftOnly(false);
    header.animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
    Reddit.currentPosition = position;
    if (position + 1 != currentComment) {
        doSubSidebarNoLoad(usedArray.get(position));
    }
    SubmissionsView page = (SubmissionsView) adapter.getCurrentFragment();
    if (page != null && page.adapter != null) {
        SubredditPosts p = page.adapter.dataSet;
        if (p.offline && p.cached != null) {
            Toast.makeText(MainActivity.this, getString(R.string.offline_last_update, TimeUtils.getTimeAgo(p.cached.time, MainActivity.this)), Toast.LENGTH_LONG).show();
        }
    }
    if (hea != null) {
        hea.setBackgroundColor(Palette.getColor(usedArray.get(position)));
        if (accountsArea != null) {
            accountsArea.setBackgroundColor(Palette.getDarkerColor(usedArray.get(position)));
        }
    }
    header.setBackgroundColor(Palette.getColor(usedArray.get(position)));
    themeSystemBars(usedArray.get(position));
    setRecentBar(usedArray.get(position));
    if (SettingValues.single) {
        getSupportActionBar().setTitle(usedArray.get(position));
    } else {
        if (mTabLayout != null) {
            mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(MainActivity.this).getColor(usedArray.get(position)));
        }
    }
    selectedSub = usedArray.get(position);
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts)

Aggregations

ColorPreferences (me.ccrama.redditslide.ColorPreferences)50 View (android.view.View)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)16 DialogInterface (android.content.DialogInterface)14 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)14 ArrayList (java.util.ArrayList)14 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)13 LayoutInflater (android.view.LayoutInflater)12 RecyclerView (android.support.v7.widget.RecyclerView)10 ImageView (android.widget.ImageView)10 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)10 Context (android.content.Context)9 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)9 HorizontalScrollView (android.widget.HorizontalScrollView)9 Snackbar (android.support.design.widget.Snackbar)8 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)8 CaseInsensitiveArrayList (me.ccrama.redditslide.CaseInsensitiveArrayList)8 LinearInterpolator (android.view.animation.LinearInterpolator)7 Dialog (android.app.Dialog)6