Search in sources :

Example 1 with TimelinePagerAdapter

use of com.keylesspalace.tusky.pager.TimelinePagerAdapter in project Tusky by tuskyapp.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    int tabPosition = 0;
    accountManager = TuskyApplication.getInstance(this).getServiceLocator().get(AccountManager.class);
    if (intent != null) {
        long accountId = intent.getLongExtra(NotificationHelper.ACCOUNT_ID, -1);
        if (accountId != -1) {
            // user clicked a notification, show notification tab and switch user if necessary
            tabPosition = 1;
            AccountEntity account = accountManager.getActiveAccount();
            if (account == null || accountId != account.getId()) {
                accountManager.setActiveAccount(accountId);
            }
        }
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FloatingActionButton floatingBtn = findViewById(R.id.floating_btn);
    ImageButton drawerToggle = findViewById(R.id.drawer_toggle);
    TabLayout tabLayout = findViewById(R.id.tab_layout);
    viewPager = findViewById(R.id.pager);
    floatingBtn.setOnClickListener(v -> {
        Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class);
        startActivityForResult(composeIntent, COMPOSE_RESULT);
    });
    setupDrawer();
    // Setup the navigation drawer toggle button.
    ThemeUtils.setDrawableTint(this, drawerToggle.getDrawable(), R.attr.toolbar_icon_tint);
    drawerToggle.setOnClickListener(v -> drawer.openDrawer());
    /* Fetch user info while we're doing other things. This has to be done after setting up the
         * drawer, though, because its callback touches the header in the drawer. */
    fetchUserInfo();
    // Setup the tabs and timeline pager.
    TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());
    int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
    viewPager.setPageMargin(pageMargin);
    Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable, R.drawable.tab_page_margin_dark);
    viewPager.setPageMarginDrawable(pageMarginDrawable);
    viewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);
    int[] tabIcons = { R.drawable.ic_home_24dp, R.drawable.ic_notifications_24dp, R.drawable.ic_local_24dp, R.drawable.ic_public_24dp };
    String[] pageTitles = { getString(R.string.title_home), getString(R.string.title_notifications), getString(R.string.title_public_local), getString(R.string.title_public_federated) };
    for (int i = 0; i < 4; i++) {
        TabLayout.Tab tab = tabLayout.getTabAt(i);
        tab.setIcon(tabIcons[i]);
        tab.setContentDescription(pageTitles[i]);
    }
    if (tabPosition != 0) {
        TabLayout.Tab tab = tabLayout.getTabAt(tabPosition);
        if (tab != null) {
            tab.select();
        } else {
            tabPosition = 0;
        }
    }
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
            tintTab(tab, true);
            if (tab.getPosition() == 1) {
                NotificationHelper.clearNotificationsForActiveAccount(MainActivity.this);
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            tintTab(tab, false);
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    for (int i = 0; i < 4; i++) {
        tintTab(tabLayout.getTabAt(i), i == tabPosition);
    }
    // Setup push notifications
    if (NotificationHelper.areNotificationsEnabled(this)) {
        enablePushNotifications();
    } else {
        disablePushNotifications();
    }
    composeButton = floatingBtn;
}
Also used : Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) TimelinePagerAdapter(com.keylesspalace.tusky.pager.TimelinePagerAdapter) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) ImageButton(android.widget.ImageButton) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) AccountManager(com.keylesspalace.tusky.db.AccountManager)

Example 2 with TimelinePagerAdapter

use of com.keylesspalace.tusky.pager.TimelinePagerAdapter in project Tusky by Vavassor.

the class MainActivity method onUserRemoved.

@Override
public void onUserRemoved(String accountId) {
    TimelinePagerAdapter adapter = (TimelinePagerAdapter) viewPager.getAdapter();
    for (Fragment fragment : adapter.getRegisteredFragments()) {
        if (fragment instanceof StatusRemoveListener) {
            StatusRemoveListener listener = (StatusRemoveListener) fragment;
            listener.removePostsByUser(accountId);
        }
    }
}
Also used : TimelinePagerAdapter(com.keylesspalace.tusky.pager.TimelinePagerAdapter) StatusRemoveListener(com.keylesspalace.tusky.interfaces.StatusRemoveListener) Fragment(android.support.v4.app.Fragment) SFragment(com.keylesspalace.tusky.fragment.SFragment)

Example 3 with TimelinePagerAdapter

use of com.keylesspalace.tusky.pager.TimelinePagerAdapter in project Tusky by Vavassor.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    pageHistory = new Stack<>();
    if (savedInstanceState != null) {
        List<Integer> restoredHistory = savedInstanceState.getIntegerArrayList("pageHistory");
        if (restoredHistory != null) {
            pageHistory.addAll(restoredHistory);
        }
    }
    ButterKnife.bind(this);
    floatingBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), ComposeActivity.class);
            startActivityForResult(intent, COMPOSE_RESULT);
        }
    });
    setupDrawer();
    setupSearchView();
    /* Fetch user info while we're doing other things. This has to be after setting up the
         * drawer, though, because its callback touches the header in the drawer. */
    fetchUserInfo();
    // Setup the tabs and timeline pager.
    TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());
    int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
    viewPager.setPageMargin(pageMargin);
    Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable, R.drawable.tab_page_margin_dark);
    viewPager.setPageMarginDrawable(pageMarginDrawable);
    viewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);
    int[] tabIcons = { R.drawable.ic_home_24dp, R.drawable.ic_notifications_24dp, R.drawable.ic_local_24dp, R.drawable.ic_public_24dp };
    String[] pageTitles = { getString(R.string.title_home), getString(R.string.title_notifications), getString(R.string.title_public_local), getString(R.string.title_public_federated) };
    for (int i = 0; i < 4; i++) {
        TabLayout.Tab tab = tabLayout.getTabAt(i);
        tab.setIcon(tabIcons[i]);
        tab.setContentDescription(pageTitles[i]);
    }
    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
            if (pageHistory.isEmpty()) {
                pageHistory.push(0);
            }
            if (pageHistory.contains(tab.getPosition())) {
                pageHistory.remove(pageHistory.indexOf(tab.getPosition()));
            }
            pageHistory.push(tab.getPosition());
            tintTab(tab, true);
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            tintTab(tab, false);
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    Intent intent = getIntent();
    int tabSelected = 0;
    if (intent != null) {
        int tabPosition = intent.getIntExtra("tab_position", 0);
        if (tabPosition != 0) {
            TabLayout.Tab tab = tabLayout.getTabAt(tabPosition);
            if (tab != null) {
                tab.select();
                tabSelected = tabPosition;
            }
        }
    }
    for (int i = 0; i < 4; i++) {
        tintTab(tabLayout.getTabAt(i), i == tabSelected);
    }
    // Setup push notifications
    if (arePushNotificationsEnabled()) {
        enablePushNotifications();
    } else {
        disablePushNotifications();
    }
    composeButton = floatingBtn;
}
Also used : Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) TimelinePagerAdapter(com.keylesspalace.tusky.pager.TimelinePagerAdapter) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) FloatingSearchView(com.arlib.floatingsearchview.FloatingSearchView) TextView(android.widget.TextView) TabLayout(android.support.design.widget.TabLayout)

Example 4 with TimelinePagerAdapter

use of com.keylesspalace.tusky.pager.TimelinePagerAdapter in project Tusky by Vavassor.

the class MainActivity method onRequestPermissionsResult.

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    TimelinePagerAdapter adapter = (TimelinePagerAdapter) viewPager.getAdapter();
    for (Fragment fragment : adapter.getRegisteredFragments()) {
        fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
Also used : TimelinePagerAdapter(com.keylesspalace.tusky.pager.TimelinePagerAdapter) Fragment(android.support.v4.app.Fragment) SFragment(com.keylesspalace.tusky.fragment.SFragment)

Aggregations

TimelinePagerAdapter (com.keylesspalace.tusky.pager.TimelinePagerAdapter)4 Intent (android.content.Intent)2 Drawable (android.graphics.drawable.Drawable)2 TabLayout (android.support.design.widget.TabLayout)2 Fragment (android.support.v4.app.Fragment)2 SFragment (com.keylesspalace.tusky.fragment.SFragment)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 FloatingSearchView (com.arlib.floatingsearchview.FloatingSearchView)1 AccountEntity (com.keylesspalace.tusky.db.AccountEntity)1 AccountManager (com.keylesspalace.tusky.db.AccountManager)1 StatusRemoveListener (com.keylesspalace.tusky.interfaces.StatusRemoveListener)1