Search in sources :

Example 1 with UserAlbumFragment

use of com.codez.collar.fragment.UserAlbumFragment in project Collar by CodeZsx.

the class UserActivity method initView.

@Override
public void initView() {
    setSupportActionBar(mBinding.toolbar);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
        mBinding.toolbar.setNavigationIcon(R.drawable.ic_toolbar_back);
        mBinding.toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
    uid = getIntent().getStringExtra(INTENT_KEY_UID);
    screen_name = getIntent().getStringExtra(INTENT_KEY_SCREEN_NAME);
    L.e("uid:" + uid + " screen_name:" + screen_name);
    if (uid != null && uid.equals(AccessTokenKeeper.getInstance().getUid())) {
        mBinding.btnFollow.setVisibility(View.GONE);
    } else {
        // 获取登录用户和此用户的关系
        HttpUtils.getInstance().getFriendshipService().showFriendships(AccessTokenKeeper.getInstance().getUid(), uid).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<FriendshipsShowResultBean>() {

            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(FriendshipsShowResultBean friendshipsShowResultBean) {
                if (friendshipsShowResultBean.getSource().isFollowing()) {
                    if (friendshipsShowResultBean.getSource().isFollowed_by()) {
                        mBinding.btnFollow.setText(BTN_BOTH_SIDE);
                        isFollowMe = true;
                    } else {
                        mBinding.btnFollow.setText(BTN_FOLLOWING);
                    }
                    // selected标志位即为是否关注的标志位
                    mBinding.btnFollow.setSelected(true);
                }
            }
        });
    }
    // 获取用户信息
    HttpUtils.getInstance().getUserService().getUserInfo(uid, screen_name).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<UserBean>() {

        @Override
        public void onCompleted() {
            L.e("onCompleted");
        }

        @Override
        public void onError(Throwable e) {
            L.e("onError");
        }

        @Override
        public void onNext(UserBean userBean) {
            L.e("onNext");
            mUserBean = userBean;
            mBinding.setUser(userBean);
        }
    });
    mBinding.appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {

        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            if (verticalOffset == 0) {
            // 展开状态
            } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
                // 折叠状态
                mBinding.collapsingToolbar.setTitleEnabled(true);
                mBinding.toolbar.setBackgroundResource(R.color.colorToolbarBg);
            } else {
                // 中间状态
                mBinding.collapsingToolbar.setTitleEnabled(false);
                mBinding.toolbar.setBackgroundColor(0x00000000);
            }
        }
    });
    mBinding.viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        String[] titles = { "微博", "相册" };

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return new StatusListFragment().newInstance(uid, screen_name, StatusListFragment.VALUE_USER);
            } else {
                return new UserAlbumFragment().newInstance(uid, screen_name);
            }
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    });
    mBinding.tabLayout.setupWithViewPager(mBinding.viewPager);
    mBinding.tvFriends.setOnClickListener(this);
    mBinding.tvFriendsCount.setOnClickListener(this);
    mBinding.tvFollowers.setOnClickListener(this);
    mBinding.tvFollowersCount.setOnClickListener(this);
    mBinding.btnFollow.setOnClickListener(this);
}
Also used : UserAlbumFragment(com.codez.collar.fragment.UserAlbumFragment) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) View(android.view.View) Fragment(android.support.v4.app.Fragment) StatusListFragment(com.codez.collar.fragment.StatusListFragment) UserAlbumFragment(com.codez.collar.fragment.UserAlbumFragment) UserBean(com.codez.collar.bean.UserBean) StatusListFragment(com.codez.collar.fragment.StatusListFragment) FriendshipsShowResultBean(com.codez.collar.bean.FriendshipsShowResultBean) AppBarLayout(android.support.design.widget.AppBarLayout) ActionBar(android.support.v7.app.ActionBar)

Aggregations

AppBarLayout (android.support.design.widget.AppBarLayout)1 Fragment (android.support.v4.app.Fragment)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 FriendshipsShowResultBean (com.codez.collar.bean.FriendshipsShowResultBean)1 UserBean (com.codez.collar.bean.UserBean)1 StatusListFragment (com.codez.collar.fragment.StatusListFragment)1 UserAlbumFragment (com.codez.collar.fragment.UserAlbumFragment)1