Search in sources :

Example 31 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Slide by ccrama.

the class MainActivity method openPopupTime.

public void openPopupTime() {
    PopupMenu popup = new PopupMenu(MainActivity.this, findViewById(R.id.anchor), Gravity.RIGHT);
    String id = ((SubmissionsView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).id;
    final Spannable[] base = Reddit.getSortingSpannablesTime(getBaseContext(), id);
    for (Spannable s : base) {
        MenuItem m = popup.getMenu().add(s);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            LogUtil.v("Chosen is " + item.getOrder());
            int i = 0;
            for (Spannable s : base) {
                if (s.equals(item.getTitle())) {
                    break;
                }
                i++;
            }
            switch(i) {
                case 0:
                    Reddit.setTime(((SubmissionsView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.HOUR);
                    reloadSubs();
                    break;
                case 1:
                    Reddit.setTime(((SubmissionsView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.DAY);
                    reloadSubs();
                    break;
                case 2:
                    Reddit.setTime(((SubmissionsView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.WEEK);
                    reloadSubs();
                    break;
                case 3:
                    Reddit.setTime(((SubmissionsView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.MONTH);
                    reloadSubs();
                    break;
                case 4:
                    Reddit.setTime(((SubmissionsView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.YEAR);
                    reloadSubs();
                    break;
                case 5:
                    Reddit.setTime(((SubmissionsView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).id, TimePeriod.ALL);
                    reloadSubs();
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) PopupMenu(android.support.v7.widget.PopupMenu)

Example 32 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Slide by ccrama.

the class MultiredditOverview method openPopupTime.

public void openPopupTime() {
    PopupMenu popup = new PopupMenu(MultiredditOverview.this, findViewById(R.id.anchor), Gravity.RIGHT);
    String id = ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH);
    final Spannable[] base = Reddit.getSortingSpannablesTime(getBaseContext(), "multi" + id);
    for (Spannable s : base) {
        MenuItem m = popup.getMenu().add(s);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            int i = 0;
            for (Spannable s : base) {
                if (s.equals(item.getTitle())) {
                    break;
                }
                i++;
            }
            LogUtil.v("Chosen is " + i);
            if (pager.getAdapter() != null) {
                switch(i) {
                    case 0:
                        Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.HOUR);
                        reloadSubs();
                        break;
                    case 1:
                        Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.DAY);
                        reloadSubs();
                        break;
                    case 2:
                        Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.WEEK);
                        reloadSubs();
                        break;
                    case 3:
                        Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.MONTH);
                        reloadSubs();
                        break;
                    case 4:
                        Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.YEAR);
                        reloadSubs();
                        break;
                    case 5:
                        Reddit.setTime("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), TimePeriod.ALL);
                        reloadSubs();
                        break;
                }
            }
            return true;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) MultiredditView(me.ccrama.redditslide.Fragments.MultiredditView) Spannable(android.text.Spannable) PopupMenu(android.support.v7.widget.PopupMenu)

Example 33 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Slide by ccrama.

the class MultiredditOverview method openPopup.

public void openPopup() {
    PopupMenu popup = new PopupMenu(MultiredditOverview.this, findViewById(R.id.anchor), Gravity.RIGHT);
    String id = ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH);
    final Spannable[] base = Reddit.getSortingSpannables(getBaseContext(), "multi" + id);
    for (Spannable s : base) {
        MenuItem m = popup.getMenu().add(s);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            int i = 0;
            for (Spannable s : base) {
                if (s.equals(item.getTitle())) {
                    break;
                }
                i++;
            }
            LogUtil.v("Chosen is " + i);
            if (pager.getAdapter() != null) {
                switch(i) {
                    case 0:
                        Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.HOT);
                        reloadSubs();
                        break;
                    case 1:
                        Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.NEW);
                        reloadSubs();
                        break;
                    case 2:
                        Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.RISING);
                        reloadSubs();
                        break;
                    case 3:
                        Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.TOP);
                        openPopupTime();
                        break;
                    case 4:
                        Reddit.setSorting("multi" + ((MultiredditView) (((OverviewPagerAdapter) pager.getAdapter()).getCurrentFragment())).posts.multiReddit.getDisplayName().toLowerCase(Locale.ENGLISH), Sorting.CONTROVERSIAL);
                        openPopupTime();
                        break;
                }
            }
            return true;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) MultiredditView(me.ccrama.redditslide.Fragments.MultiredditView) Spannable(android.text.Spannable) PopupMenu(android.support.v7.widget.PopupMenu)

Example 34 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Slide by ccrama.

the class SubredditView method openPopup.

public void openPopup() {
    PopupMenu popup = new PopupMenu(SubredditView.this, findViewById(R.id.anchor), Gravity.RIGHT);
    final Spannable[] base = Reddit.getSortingSpannables(getBaseContext(), subreddit);
    for (Spannable s : base) {
        MenuItem m = popup.getMenu().add(s);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            LogUtil.v("Chosen is " + item.getOrder());
            int i = 0;
            for (Spannable s : base) {
                if (s.equals(item.getTitle())) {
                    break;
                }
                i++;
            }
            switch(i) {
                case 0:
                    Reddit.setSorting(subreddit, Sorting.HOT);
                    reloadSubs();
                    break;
                case 1:
                    Reddit.setSorting(subreddit, Sorting.NEW);
                    reloadSubs();
                    break;
                case 2:
                    Reddit.setSorting(subreddit, Sorting.RISING);
                    reloadSubs();
                    break;
                case 3:
                    Reddit.setSorting(subreddit, Sorting.TOP);
                    openPopupTime();
                    break;
                case 4:
                    Reddit.setSorting(subreddit, Sorting.CONTROVERSIAL);
                    openPopupTime();
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) PopupMenu(android.support.v7.widget.PopupMenu)

Example 35 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Slide by ccrama.

the class SubredditView method openPopupTime.

public void openPopupTime() {
    PopupMenu popup = new PopupMenu(SubredditView.this, findViewById(R.id.anchor), Gravity.RIGHT);
    final Spannable[] base = Reddit.getSortingSpannablesTime(getBaseContext(), subreddit);
    for (Spannable s : base) {
        MenuItem m = popup.getMenu().add(s);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            LogUtil.v("Chosen is " + item.getOrder());
            int i = 0;
            for (Spannable s : base) {
                if (s.equals(item.getTitle())) {
                    break;
                }
                i++;
            }
            switch(i) {
                case 0:
                    Reddit.setTime(subreddit, TimePeriod.HOUR);
                    reloadSubs();
                    break;
                case 1:
                    Reddit.setTime(subreddit, TimePeriod.DAY);
                    reloadSubs();
                    break;
                case 2:
                    Reddit.setTime(subreddit, TimePeriod.WEEK);
                    reloadSubs();
                    break;
                case 3:
                    Reddit.setTime(subreddit, TimePeriod.MONTH);
                    reloadSubs();
                    break;
                case 4:
                    Reddit.setTime(subreddit, TimePeriod.YEAR);
                    reloadSubs();
                    break;
                case 5:
                    Reddit.setTime(subreddit, TimePeriod.ALL);
                    reloadSubs();
                    break;
            }
            return true;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) Spannable(android.text.Spannable) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

PopupMenu (android.support.v7.widget.PopupMenu)142 MenuItem (android.view.MenuItem)116 View (android.view.View)86 TextView (android.widget.TextView)63 RecyclerView (android.support.v7.widget.RecyclerView)54 ImageView (android.widget.ImageView)40 Intent (android.content.Intent)32 PopupMenu (android.widget.PopupMenu)31 List (java.util.List)27 ArrayList (java.util.ArrayList)26 MenuInflater (android.view.MenuInflater)23 Menu (android.view.Menu)22 Bundle (android.os.Bundle)20 LayoutInflater (android.view.LayoutInflater)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 Context (android.content.Context)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 AdapterView (android.widget.AdapterView)17 DialogInterface (android.content.DialogInterface)16 ViewGroup (android.view.ViewGroup)15