Search in sources :

Example 1 with CaseInsensitiveArrayList

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

the class MultiredditOverview method doDrawerSubs.

public void doDrawerSubs(int position) {
    MultiReddit current = usedArray.get(position);
    LinearLayout l = (LinearLayout) findViewById(R.id.sidebar_scroll);
    l.removeAllViews();
    CaseInsensitiveArrayList toSort = new CaseInsensitiveArrayList();
    for (MultiSubreddit s : current.getSubreddits()) {
        toSort.add(s.getDisplayName().toLowerCase(Locale.ENGLISH));
    }
    for (String sub : UserSubscriptions.sortNoExtras(toSort)) {
        final View convertView = getLayoutInflater().inflate(R.layout.subforsublist, l, false);
        final String subreddit = sub;
        final TextView t = ((TextView) convertView.findViewById(R.id.name));
        t.setText(subreddit);
        convertView.findViewById(R.id.color).setBackgroundResource(R.drawable.circle);
        convertView.findViewById(R.id.color).getBackground().setColorFilter(Palette.getColor(subreddit), PorterDuff.Mode.MULTIPLY);
        convertView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent inte = new Intent(MultiredditOverview.this, SubredditView.class);
                inte.putExtra(SubredditView.EXTRA_SUBREDDIT, subreddit);
                MultiredditOverview.this.startActivityForResult(inte, 4);
            }
        });
        l.addView(convertView);
    }
}
Also used : MultiSubreddit(net.dean.jraw.models.MultiSubreddit) TextView(android.widget.TextView) Intent(android.content.Intent) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) MultiReddit(net.dean.jraw.models.MultiReddit) View(android.view.View) TextView(android.widget.TextView) MultiredditView(me.ccrama.redditslide.Fragments.MultiredditView) LinearLayout(android.widget.LinearLayout)

Example 2 with CaseInsensitiveArrayList

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

the class ReorderSubreddits method doShowSubs.

public void doShowSubs() {
    subs = new CaseInsensitiveArrayList(UserSubscriptions.getSubscriptions(this));
    recyclerView = (RecyclerView) findViewById(R.id.subslist);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setItemAnimator(null);
    DragSortRecycler dragSortRecycler = new DragSortRecycler();
    dragSortRecycler.setViewHandleId();
    dragSortRecycler.setFloatingAlpha();
    dragSortRecycler.setAutoScrollSpeed();
    dragSortRecycler.setAutoScrollWindow();
    dragSortRecycler.setOnItemMovedListener(new DragSortRecycler.OnItemMovedListener() {

        @Override
        public void onItemMoved(int from, int to) {
            if (to == subs.size()) {
                to -= 1;
            }
            String item = subs.remove(from);
            subs.add(to, item);
            adapter.notifyDataSetChanged();
            CaseInsensitiveArrayList pinned = UserSubscriptions.getPinned();
            if (pinned.contains(item) && pinned.size() != 1) {
                pinned.remove(item);
                if (to > pinned.size()) {
                    to = pinned.size();
                }
                pinned.add(to, item);
                setPinned(pinned);
            }
        }
    });
    dragSortRecycler.setOnDragStateChangedListener(new DragSortRecycler.OnDragStateChangedListener() {

        @Override
        public void onDragStart() {
        }

        @Override
        public void onDragStop() {
        }
    });
    final FloatingActionsMenu fab = (FloatingActionsMenu) findViewById(R.id.add);
    {
        FloatingActionButton collection = (FloatingActionButton) findViewById(R.id.collection);
        Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.collection, null);
        collection.setIconDrawable(icon);
        collection.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                fab.collapse();
                if (UserSubscriptions.multireddits != null && !UserSubscriptions.multireddits.isEmpty()) {
                    new AlertDialogWrapper.Builder(ReorderSubreddits.this).setTitle(R.string.create_or_import_multi).setPositiveButton(R.string.btn_new, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            doCollection();
                        }
                    }).setNegativeButton(R.string.btn_import_multi, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            final String[] multis = new String[UserSubscriptions.multireddits.size()];
                            int i = 0;
                            for (MultiReddit m : UserSubscriptions.multireddits) {
                                multis[i] = m.getDisplayName();
                                i++;
                            }
                            MaterialDialog.Builder builder = new MaterialDialog.Builder(ReorderSubreddits.this);
                            builder.title(R.string.reorder_subreddits_title).items(multis).itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {

                                @Override
                                public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                                    String name = multis[which];
                                    MultiReddit r = UserSubscriptions.getMultiredditByDisplayName(name);
                                    StringBuilder b = new StringBuilder();
                                    for (MultiSubreddit s : r.getSubreddits()) {
                                        b.append(s.getDisplayName());
                                        b.append("+");
                                    }
                                    int pos = addSubAlphabetically(MULTI_REDDIT + r.getDisplayName());
                                    UserSubscriptions.setSubNameToProperties(MULTI_REDDIT + r.getDisplayName(), b.toString());
                                    adapter.notifyDataSetChanged();
                                    recyclerView.smoothScrollToPosition(pos);
                                    return false;
                                }
                            }).show();
                        }
                    }).show();
                } else {
                    doCollection();
                }
            }
        });
    }
    {
        FloatingActionButton collection = (FloatingActionButton) findViewById(R.id.sub);
        Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.sub, null);
        collection.setIconDrawable(icon);
        collection.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                fab.collapse();
                MaterialDialog.Builder b = new MaterialDialog.Builder(ReorderSubreddits.this).title(R.string.reorder_add_or_search_subreddit).alwaysCallInputCallback().input(getString(R.string.reorder_subreddit_name), null, false, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(MaterialDialog dialog, CharSequence raw) {
                        input = raw.toString();
                    }
                }).positiveText(R.string.btn_add).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(MaterialDialog dialog, DialogAction which) {
                        new AsyncGetSubreddit().execute(input);
                    }
                }).negativeText(R.string.btn_cancel).onNegative(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(MaterialDialog dialog, DialogAction which) {
                    }
                });
                b.show();
            }
        });
    }
    {
        FloatingActionButton collection = (FloatingActionButton) findViewById(R.id.domain);
        Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.link, null);
        collection.setIconDrawable(icon);
        collection.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                fab.collapse();
                new MaterialDialog.Builder(ReorderSubreddits.this).title(R.string.reorder_add_domain).alwaysCallInputCallback().input("example.com" + getString(R.string.reorder_domain_placeholder), null, false, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(MaterialDialog dialog, CharSequence raw) {
                        input = raw.toString().replaceAll("\\s", // remove whitespace from input
                        "");
                        if (input.contains(".")) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        } else {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
                        }
                    }
                }).positiveText(R.string.btn_add).inputRange(1, 35).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(MaterialDialog dialog, DialogAction which) {
                        try {
                            String url = (input);
                            List<String> sortedSubs = UserSubscriptions.sortNoExtras(subs);
                            if (sortedSubs.equals(subs)) {
                                subs.add(url);
                                subs = UserSubscriptions.sortNoExtras(subs);
                                adapter = new CustomAdapter(subs);
                                recyclerView.setAdapter(adapter);
                            } else {
                                int pos = addSubAlphabetically(url);
                                adapter.notifyDataSetChanged();
                                recyclerView.smoothScrollToPosition(pos);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            // todo make this better
                            new AlertDialogWrapper.Builder(ReorderSubreddits.this).setTitle(R.string.reorder_url_err).setMessage(R.string.misc_please_try_again).show();
                        }
                    }
                }).negativeText(R.string.btn_cancel).onNegative(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(MaterialDialog dialog, DialogAction which) {
                    }
                }).show();
            }
        });
    }
    recyclerView.addItemDecoration(dragSortRecycler);
    recyclerView.addOnItemTouchListener(dragSortRecycler);
    recyclerView.addOnScrollListener(dragSortRecycler.getScrollListener());
    dragSortRecycler.setViewHandleId();
    if (subs != null && !subs.isEmpty()) {
        adapter = new CustomAdapter(subs);
        // adapter.setHasStableIds(true);
        recyclerView.setAdapter(adapter);
    } else {
        subs = new CaseInsensitiveArrayList();
    }
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
                diff += dy;
            } else {
                diff = 0;
            }
            if (dy <= 0 && fab.getId() != 0) {
            } else {
                fab.collapse();
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MultiReddit(net.dean.jraw.models.MultiReddit) FloatingActionButton(com.getbase.floatingactionbutton.FloatingActionButton) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FloatingActionsMenu(com.getbase.floatingactionbutton.FloatingActionsMenu) Drawable(android.graphics.drawable.Drawable) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) DialogAction(com.afollestad.materialdialogs.DialogAction) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with CaseInsensitiveArrayList

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

the class ReorderSubreddits method onPause.

@Override
public void onPause() {
    try {
        UserSubscriptions.setSubscriptions(new CaseInsensitiveArrayList(subs));
        SettingsTheme.changed = true;
    } catch (Exception e) {
    }
    super.onPause();
}
Also used : CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList)

Example 4 with CaseInsensitiveArrayList

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

the class MainActivity method setDataSet.

public void setDataSet(List<String> data) {
    if (data != null && !data.isEmpty()) {
        usedArray = new CaseInsensitiveArrayList(data);
        if (adapter == null) {
            if (commentPager && singleMode) {
                adapter = new OverviewPagerAdapterComment(getSupportFragmentManager());
            } else {
                adapter = new OverviewPagerAdapter(getSupportFragmentManager());
            }
        } else {
            adapter.notifyDataSetChanged();
        }
        pager.setAdapter(adapter);
        pager.setOffscreenPageLimit(1);
        if (toGoto == -1) {
            toGoto = 0;
        }
        if (toGoto >= usedArray.size()) {
            toGoto -= 1;
        }
        shouldLoad = usedArray.get(toGoto);
        selectedSub = (usedArray.get(toGoto));
        themeSystemBars(usedArray.get(toGoto));
        final String USEDARRAY_0 = usedArray.get(0);
        header.setBackgroundColor(Palette.getColor(USEDARRAY_0));
        if (hea != null) {
            hea.setBackgroundColor(Palette.getColor(USEDARRAY_0));
            if (accountsArea != null) {
                accountsArea.setBackgroundColor(Palette.getDarkerColor(USEDARRAY_0));
            }
        }
        if (!SettingValues.single) {
            mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(MainActivity.this).getColor(USEDARRAY_0));
            pager.setCurrentItem(toGoto);
            mTabLayout.setupWithViewPager(pager);
            if (mTabLayout != null) {
                mTabLayout.setupWithViewPager(pager);
                scrollToTabAfterLayout(toGoto);
            }
        } else {
            getSupportActionBar().setTitle(usedArray.get(toGoto));
            pager.setCurrentItem(toGoto);
        }
        setToolbarClick();
        setRecentBar(usedArray.get(toGoto));
        doSubSidebarNoLoad(usedArray.get(toGoto));
    } else if (NetworkUtil.isConnected(this)) {
        UserSubscriptions.doMainActivitySubs(this);
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList)

Example 5 with CaseInsensitiveArrayList

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

the class NewsActivity method setDataSet.

public void setDataSet(List<String> data) {
    if (data != null && !data.isEmpty()) {
        usedArray = new CaseInsensitiveArrayList(data);
        if (adapter == null) {
            adapter = new OverviewPagerAdapter(getSupportFragmentManager());
        } else {
            adapter.notifyDataSetChanged();
        }
        pager.setAdapter(adapter);
        pager.setOffscreenPageLimit(1);
        if (toGoto == -1) {
            toGoto = 0;
        }
        if (toGoto >= usedArray.size()) {
            toGoto -= 1;
        }
        shouldLoad = usedArray.get(toGoto);
        selectedSub = (usedArray.get(toGoto));
        themeSystemBars(usedArray.get(toGoto));
        final String USEDARRAY_0 = usedArray.get(0);
        mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(NewsActivity.this).getColor(USEDARRAY_0));
        pager.setCurrentItem(toGoto);
        mTabLayout.setupWithViewPager(pager);
        if (mTabLayout != null) {
            mTabLayout.setupWithViewPager(pager);
            scrollToTabAfterLayout(toGoto);
        }
        setToolbarClick();
    } else if (NetworkUtil.isConnected(this)) {
        UserSubscriptions.doNewsSubs(this);
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList)

Aggregations

CaseInsensitiveArrayList (me.ccrama.redditslide.CaseInsensitiveArrayList)6 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 TextView (android.widget.TextView)2 ColorPreferences (me.ccrama.redditslide.ColorPreferences)2 MultiReddit (net.dean.jraw.models.MultiReddit)2 MultiSubreddit (net.dean.jraw.models.MultiSubreddit)2 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LinearLayout (android.widget.LinearLayout)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 FloatingActionButton (com.getbase.floatingactionbutton.FloatingActionButton)1 FloatingActionsMenu (com.getbase.floatingactionbutton.FloatingActionsMenu)1 MultiredditView (me.ccrama.redditslide.Fragments.MultiredditView)1 Subreddit (net.dean.jraw.models.Subreddit)1