Search in sources :

Example 61 with ViewPager

use of androidx.viewpager.widget.ViewPager in project Slide by ccrama.

the class Inbox method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    if (Authentication.reddit == null || !Authentication.reddit.isAuthenticated() || Authentication.me == null) {
        LogUtil.v("Reauthenticating");
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                if (Authentication.reddit == null) {
                    new Authentication(getApplicationContext());
                }
                try {
                    Authentication.me = Authentication.reddit.me();
                    Authentication.mod = Authentication.me.isMod();
                    Authentication.authentication.edit().putBoolean(Reddit.SHARED_PREF_IS_MOD, Authentication.mod).apply();
                    if (Reddit.notificationTime != -1) {
                        Reddit.notifications = new NotificationJobScheduler(Inbox.this);
                        Reddit.notifications.start();
                    }
                    if (Reddit.cachedData.contains("toCache")) {
                        Reddit.autoCache = new AutoCacheScheduler(Inbox.this);
                        Reddit.autoCache.start();
                    }
                    final String name = Authentication.me.getFullName();
                    Authentication.name = name;
                    LogUtil.v("AUTHENTICATED");
                    UserSubscriptions.doCachedModSubs();
                    if (Authentication.reddit.isAuthenticated()) {
                        final Set<String> accounts = Authentication.authentication.getStringSet("accounts", new HashSet<String>());
                        if (accounts.contains(name)) {
                            // convert to new system
                            accounts.remove(name);
                            accounts.add(name + ":" + Authentication.refresh);
                            Authentication.authentication.edit().putStringSet("accounts", accounts).apply();
                        }
                        Authentication.isLoggedIn = true;
                        Reddit.notFirst = true;
                    }
                } catch (Exception ignored) {
                }
                return null;
            }
        }.execute();
    }
    super.onCreate(savedInstance);
    last = SettingValues.prefs.getLong("lastInbox", System.currentTimeMillis() - (60 * 1000 * 60));
    SettingValues.prefs.edit().putLong("lastInbox", System.currentTimeMillis()).apply();
    applyColorTheme("");
    setContentView(R.layout.activity_inbox);
    setupAppBar(R.id.toolbar, R.string.title_inbox, true, true);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabs.setSelectedTabIndicatorColor(new ColorPreferences(Inbox.this).getColor("no sub"));
    pager = (ViewPager) findViewById(R.id.content_view);
    findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
    adapter = new InboxPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);
    if (getIntent() != null && getIntent().hasExtra(EXTRA_UNREAD)) {
        pager.setCurrentItem(1);
    }
    tabs.setupWithViewPager(pager);
    pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            findViewById(R.id.header).animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
            if (position == 3 && findViewById(R.id.read) != null) {
                findViewById(R.id.read).setVisibility(View.GONE);
            } else if (findViewById(R.id.read) != null) {
                findViewById(R.id.read).setVisibility(View.VISIBLE);
            }
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AutoCacheScheduler(me.ccrama.redditslide.Autocache.AutoCacheScheduler) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) NotificationJobScheduler(me.ccrama.redditslide.Notifications.NotificationJobScheduler) ViewPager(androidx.viewpager.widget.ViewPager) LinearInterpolator(android.view.animation.LinearInterpolator) Authentication(me.ccrama.redditslide.Authentication) HashSet(java.util.HashSet)

Example 62 with ViewPager

use of androidx.viewpager.widget.ViewPager in project Slide by ccrama.

the class Discover method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstance);
    applyColorTheme("");
    setContentView(R.layout.activity_multireddits);
    ((DrawerLayout) findViewById(R.id.drawer_layout)).setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    setupAppBar(R.id.toolbar, R.string.discover_title, true, false);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
    TabLayout tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_FIXED);
    tabs.setSelectedTabIndicatorColor(new ColorPreferences(Discover.this).getColor("no sub"));
    ViewPager pager = (ViewPager) findViewById(R.id.content_view);
    pager.setAdapter(new DiscoverPagerAdapter(getSupportFragmentManager()));
    tabs.setupWithViewPager(pager);
    pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            findViewById(R.id.header).animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
        }
    });
}
Also used : ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) TabLayout(com.google.android.material.tabs.TabLayout) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) ViewPager(androidx.viewpager.widget.ViewPager)

Example 63 with ViewPager

use of androidx.viewpager.widget.ViewPager in project Alarmio by TheAndroidMaster.

the class SoundChooserDialog method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.dialog_sound_chooser, container, false);
    Aesthetic.Companion.get().colorPrimary().take(1).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            view.setBackgroundColor(integer);
        }
    });
    TabLayout tabLayout = view.findViewById(R.id.tabLayout);
    ViewPager viewPager = view.findViewById(R.id.viewPager);
    AlarmSoundChooserFragment alarmFragment = new AlarmSoundChooserFragment();
    RingtoneSoundChooserFragment ringtoneFragment = new RingtoneSoundChooserFragment();
    RadioSoundChooserFragment radioFragment = new RadioSoundChooserFragment();
    alarmFragment.setListener(this);
    ringtoneFragment.setListener(this);
    radioFragment.setListener(this);
    viewPager.setAdapter(new SimplePagerAdapter(getChildFragmentManager(), alarmFragment, ringtoneFragment, radioFragment));
    tabLayout.setupWithViewPager(viewPager);
    return view;
}
Also used : RadioSoundChooserFragment(james.alarmio.fragments.RadioSoundChooserFragment) TabLayout(com.google.android.material.tabs.TabLayout) AlarmSoundChooserFragment(james.alarmio.fragments.AlarmSoundChooserFragment) SimplePagerAdapter(james.alarmio.adapters.SimplePagerAdapter) ViewPager(androidx.viewpager.widget.ViewPager) RingtoneSoundChooserFragment(james.alarmio.fragments.RingtoneSoundChooserFragment) Nullable(androidx.annotation.Nullable)

Example 64 with ViewPager

use of androidx.viewpager.widget.ViewPager in project Slide by ccrama.

the class Tumblr method onCreate.

public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstanceState);
    getTheme().applyStyle(new ColorPreferences(this).getDarkThemeSubreddit(ColorPreferences.FONT_STYLE), true);
    setContentView(R.layout.album);
    // Keep the screen on
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    final ViewPager pager = (ViewPager) findViewById(R.id.images);
    album = new TumblrPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(album);
    pager.setCurrentItem(1);
    if (getIntent().hasExtra(SUBREDDIT)) {
        subreddit = getIntent().getStringExtra(SUBREDDIT);
    }
    pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (position == 0 && positionOffsetPixels == 0) {
                finish();
            }
            if (position == 0 && ((TumblrPagerAdapter) pager.getAdapter()).blankPage != null) {
                if (((TumblrPagerAdapter) pager.getAdapter()).blankPage != null) {
                    ((TumblrPagerAdapter) pager.getAdapter()).blankPage.doOffset(positionOffset);
                }
                ((TumblrPagerAdapter) pager.getAdapter()).blankPage.realBack.setBackgroundColor(Palette.adjustAlpha(positionOffset * 0.7f));
            }
        }
    });
    if (!Reddit.appRestart.contains("tutorialSwipe")) {
        startActivityForResult(new Intent(this, SwipeTutorial.class), 3);
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) Intent(android.content.Intent) ViewPager(androidx.viewpager.widget.ViewPager)

Example 65 with ViewPager

use of androidx.viewpager.widget.ViewPager in project Slide by ccrama.

the class Profile method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstance);
    name = getIntent().getExtras().getString(EXTRA_PROFILE, "");
    setShareUrl("https://reddit.com/u/" + name);
    applyColorTheme();
    setContentView(R.layout.activity_profile);
    setupUserAppBar(R.id.toolbar, name, true, name);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    profSort = Sorting.HOT;
    profTime = TimePeriod.ALL;
    findViewById(R.id.header).setBackgroundColor(Palette.getColorUser(name));
    tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabs.setSelectedTabIndicatorColor(new ColorPreferences(Profile.this).getColor("no sub"));
    pager = (ViewPager) findViewById(R.id.content_view);
    if (name.equals(Authentication.name))
        setDataSet(new String[] { getString(R.string.profile_overview), getString(R.string.profile_comments), getString(R.string.profile_submitted), getString(R.string.profile_gilded), getString(R.string.profile_upvoted), getString(R.string.profile_downvoted), getString(R.string.profile_saved), getString(R.string.profile_hidden), getString(R.string.profile_history) });
    else
        setDataSet(new String[] { getString(R.string.profile_overview), getString(R.string.profile_comments), getString(R.string.profile_submitted), getString(R.string.profile_gilded) });
    new getProfile().execute(name);
    pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            isSavedView = position == 6;
            findViewById(R.id.header).animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
            if (sortItem != null) {
                sortItem.setVisible(position < 3);
            }
            if (categoryItem != null && Authentication.me != null && Authentication.me.hasGold()) {
                categoryItem.setVisible(position == 6);
            }
        }
    });
    if (getIntent().hasExtra(EXTRA_SAVED) && name.equals(Authentication.name)) {
        pager.setCurrentItem(6);
    }
    if (getIntent().hasExtra(EXTRA_COMMENT) && name.equals(Authentication.name)) {
        pager.setCurrentItem(1);
    }
    if (getIntent().hasExtra(EXTRA_SUBMIT) && name.equals(Authentication.name)) {
        pager.setCurrentItem(2);
    }
    if (getIntent().hasExtra(EXTRA_HISTORY) && name.equals(Authentication.name)) {
        pager.setCurrentItem(8);
    }
    if (getIntent().hasExtra(EXTRA_UPVOTE) && name.equals(Authentication.name)) {
        pager.setCurrentItem(4);
    }
    isSavedView = pager.getCurrentItem() == 6;
    if (pager.getCurrentItem() != 0) {
        LayoutUtils.scrollToTabAfterLayout(tabs, pager.getCurrentItem());
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) ViewPager(androidx.viewpager.widget.ViewPager)

Aggregations

ViewPager (androidx.viewpager.widget.ViewPager)68 View (android.view.View)24 Intent (android.content.Intent)12 TabLayout (com.google.android.material.tabs.TabLayout)12 Toolbar (androidx.appcompat.widget.Toolbar)11 ViewGroup (android.view.ViewGroup)9 TextView (android.widget.TextView)9 ColorPreferences (me.ccrama.redditslide.Visuals.ColorPreferences)9 ImageView (android.widget.ImageView)8 PageNavigationView (me.majiajie.pagerbottomtabstrip.PageNavigationView)8 Bundle (android.os.Bundle)6 PagerAdapter (androidx.viewpager.widget.PagerAdapter)6 MyViewPagerAdapter (me.majiajie.pagerbottomtabstriptest.other.MyViewPagerAdapter)6 CircleIndicator (me.relex.circleindicator.CircleIndicator)6 LayoutInflater (android.view.LayoutInflater)5 Button (android.widget.Button)5 SamplePagerAdapter (me.relex.circleindicator.sample.SamplePagerAdapter)5 LinearInterpolator (android.view.animation.LinearInterpolator)4 NonNull (androidx.annotation.NonNull)4 FragmentStatePagerAdapter (androidx.fragment.app.FragmentStatePagerAdapter)4