MembersActivity.java 40.7 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
package com.yidianling.dynamic.members;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

23 24 25 26 27
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

konghaorui committed
28 29 30 31 32
import com.google.gson.internal.LinkedTreeMap;
import com.ydl.ydl_image.module.GlideApp;
import com.ydl.ydlcommon.base.BaseActivity;
import com.ydl.ydlcommon.base.config.YDLConstants;
import com.ydl.ydlcommon.data.http.RxUtils;
33
import com.ydl.ydlcommon.ui.ParcelableImage;
konghaorui committed
34
import com.ydl.ydlcommon.utils.StatusBarUtils;
konghaorui committed
35 36 37 38 39
import com.ydl.ydlcommon.view.dialog.ListDialog;
import com.ydl.ydlcommon.view.widgets.BorderCircleImageView;
import com.ydl.ydlcommon.view.widgets.MyNestedScrollView;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.dynamic.R;
40
import com.yidianling.dynamic.bean.DynamicConstants;
konghaorui committed
41 42 43 44 45
import com.yidianling.dynamic.common.browsePictures.BrowsePicturesActivity;
import com.yidianling.dynamic.common.net.DynamicApiUtils;
import com.yidianling.dynamic.dialog.CancelFocusDialog;
import com.yidianling.dynamic.event.BlackEvent;
import com.yidianling.dynamic.event.LoginStateEvent;
霍志良 committed
46
import com.yidianling.dynamic.event.dynamicFocusEvent;
konghaorui committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
import com.yidianling.dynamic.model.Command;
import com.yidianling.dynamic.model.MemberInfoBean;
import com.yidianling.dynamic.router.DynamicIn;
import com.yidianling.dynamic.trendList.TrendListInFragment;
import com.yidianling.user.api.event.UserLoginEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import de.greenrobot.event.EventBus;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;



/**
 * 会员主页
 */
public class MembersActivity extends BaseActivity implements View.OnClickListener, MyNestedScrollView.ScrollViewListener, SwipeRefreshLayout.OnRefreshListener {

    private MyNestedScrollView members_myScrov;
    String mem_id;
    private ImageView members_title_back_iv, members_title_top_right_tv, members_top_bg_iv, members_top_user_gender_iv, members_top_user_focus_iv;
    private BorderCircleImageView members_top_head_iv;
    private TextView members_title_top_tv, members_top_user_tv, members_top_user_visit_num_tv, members_top_user_fensi_num_tv, members_top_user_zan_num_tv, members_top_user_focus_ortion_tv,
            members_trend_tv, members_trend_hint_tv, members_information_tv, members_information_hint_tv;
    private RelativeLayout members_title_rel, members_top_head_rel, members_trend_rel, members_information_rel, members_top_user_focus_ortion_rel;

    LinearLayout members_type_lin;
    private TrendListInFragment trendlisfragment;
    private MemberFragment memberfragment;

    List<String> reportReasonsId;//举报内容id
    List<String> reportReasons;//举报内容列表

    private FragmentManager fragmentManager;
    String age, emotional_state, job, address, introduction;
    String focus_state;//关注状态
    boolean zan_state;

    String zan_count, fans_count;//赞数和粉丝数
//    private View members_top_view;

    //顶部渐变
    private int height;
    String name;
    protected int DIS = 0;
    protected int title_rel_bottom;

    boolean shielding = false;//屏蔽状态
    private SwipeRefreshLayout member_swrl;
    private Handler mHandler1;
    int select_tab;//当前动态列表的标示
    String tab;
    boolean is_first_refreh;
    String head;//头像

    private CancelFocusDialog cancelFocusDialog = null;

    private static final String USER_ID = "user_id";

konghaorui committed
111 112


konghaorui committed
113 114 115 116 117 118 119 120 121 122 123
    public static Intent newIntent(Activity activity, String userId) {
        Intent intent = new Intent(activity, MembersActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString(USER_ID, userId);
        intent.putExtra(YDLConstants.BUNDLE, bundle);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
konghaorui committed
124
        setContentView(R.layout.dynamic_activity_members);
konghaorui committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
        EventBus.getDefault().register(this);
//        mem_id = getIntent().getStringExtra("user_id");
        Bundle bundle = getIntent().getBundleExtra(YDLConstants.BUNDLE);
        mem_id = bundle.getString(USER_ID);
        if (!"".equals(mem_id) && mem_id != null) {
            if (mem_id.equals(DynamicIn.INSTANCE.getUserInfo().getUid() + "")) {
                focus_state = "4";
            }
        }
        fragmentManager = getSupportFragmentManager();
        initView();
//        initWindows();
        initEvent();
        initListeners();
//        initDatas();
        setTabSelection(0);
fengquan committed
141
        StatusBarUtils.Companion.setCustomStatusViewForMembers(this,members_title_rel,true);
konghaorui committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    }

    private void initEvent() {
        members_title_back_iv.setOnClickListener(this);
        members_title_top_right_tv.setOnClickListener(this);
        members_trend_rel.setOnClickListener(this);
        members_information_rel.setOnClickListener(this);
        members_top_user_focus_ortion_rel.setOnClickListener(this);
        members_top_user_focus_iv.setOnClickListener(this);
        members_top_head_iv.setOnClickListener(this);
    }

    private void initView() {
        member_swrl = (SwipeRefreshLayout) findViewById(R.id.member_swrl);
        members_title_top_tv = (TextView) findViewById(R.id.members_title_top_tv);
        members_myScrov = (MyNestedScrollView) findViewById(R.id.members_myScrov);
//        members_top_view = (View) findViewById(R.id.members_top_view);
        members_top_head_rel = (RelativeLayout) findViewById(R.id.members_top_head_rel);
        members_title_rel = (RelativeLayout) findViewById(R.id.members_title_rel);
        members_title_back_iv = (ImageView) findViewById(R.id.members_title_back_iv);
        members_title_top_right_tv = (ImageView) findViewById(R.id.members_title_top_right_tv);
        members_top_bg_iv = (ImageView) findViewById(R.id.members_top_bg_iv);
        members_top_user_gender_iv = (ImageView) findViewById(R.id.members_top_user_gender_iv);
//        members_top_user_focus_ortion_hint_iv=(ImageView)findViewById(members_top_user_focus_ortion_hint_iv);
        members_top_user_focus_iv = (ImageView) findViewById(R.id.members_top_user_focus_iv);
        members_top_head_iv = (BorderCircleImageView) findViewById(R.id.members_top_head_iv);
        members_top_user_tv = (TextView) findViewById(R.id.members_top_user_tv);
        members_top_user_visit_num_tv = (TextView) findViewById(R.id.members_top_user_visit_num_tv);
        members_top_user_fensi_num_tv = (TextView) findViewById(R.id.members_top_user_fensi_num_tv);
        members_top_user_zan_num_tv = (TextView) findViewById(R.id.members_top_user_zan_num_tv);
        members_top_user_focus_ortion_tv = (TextView) findViewById(R.id.members_top_user_focus_ortion_tv);
        members_trend_tv = (TextView) findViewById(R.id.members_trend_tv);
        members_trend_hint_tv = (TextView) findViewById(R.id.members_trend_hint_tv);
        members_information_tv = (TextView) findViewById(R.id.members_information_tv);
        members_information_hint_tv = (TextView) findViewById(R.id.members_information_hint_tv);
        members_trend_rel = (RelativeLayout) findViewById(R.id.members_trend_rel);
        members_information_rel = (RelativeLayout) findViewById(R.id.members_information_rel);
        members_type_lin = (LinearLayout) findViewById(R.id.members_type_lin);
        members_top_user_focus_ortion_rel = (RelativeLayout) findViewById(R.id.members_top_user_focus_ortion_rel);

        initLoadMore();
    }

    /**
     * 加载更多初始化
     */
    private void initLoadMore() {
        member_swrl.setOnRefreshListener(this);
190
        member_swrl.setColorSchemeResources(R.color.platform_main_theme);
konghaorui committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
        member_swrl.post(new Runnable() {
            @Override
            public void run() {
                member_swrl.setProgressViewOffset(false, 0, 100);
                member_swrl.setRefreshing(true);
                onRefresh();
            }
        });
    }

    /**
     * 获取顶部图片高度后,设置滚动监听
     */
    private void initListeners() {

        ViewTreeObserver vto = members_top_head_rel.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                members_title_rel.getViewTreeObserver().removeGlobalOnLayoutListener(
                        this);
                height = members_top_head_rel.getHeight();

                members_myScrov.setScrollViewListener(MembersActivity.this);
            }
        });
    }


    private void initDatas() {
        Command.MemberInfoCmd cmd = new Command.MemberInfoCmd(mem_id);
        DynamicApiUtils.getMemberInfo(cmd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(resp-> {
                        if (resp.code == 0) {
                            MemberInfoBean.MemberInfo person = resp.data.person;
                            name = person.name;
                            String gender = person.gender + "";
                            head = person.head;
                            String visit_count = person.visit_count + "";
                            zan_count = person.zan_count + "";
                            fans_count = person.fans_count + "";
                            String is_focused = person.is_focused + "";
                            String is_zan = person.is_zan + "";
                            String is_black = person.is_black + "";
                            age = person.age + "";
                            emotional_state = person.marriage;
                            job = person.profession;
                            address = person.address;
                            introduction = person.description;
                            String bg = person.bg;
                            GlideApp.with(MembersActivity.this)
                                    .load(head)
konghaorui committed
245
                                    .error(R.drawable.dynamic_head_place_hold_pic)
konghaorui committed
246 247 248
                                    .into(members_top_head_iv);
                            GlideApp.with(MembersActivity.this)
                                    .load(bg)
konghaorui committed
249 250
                                    .placeholder(R.drawable.dynamic_default_img)
                                    .error(R.drawable.dynamic_default_img)
konghaorui committed
251 252 253 254
                                    .centerCrop()
                                    .into(members_top_bg_iv);
                            members_top_user_tv.setText(name);
                            if ("1".equals(gender)) {//1男2女
konghaorui committed
255
                                members_top_user_gender_iv.setImageResource(R.drawable.dynamic_male);
konghaorui committed
256
                            } else if ("2".equals(gender)) {
konghaorui committed
257
                                members_top_user_gender_iv.setImageResource(R.drawable.dynamic_female);
konghaorui committed
258 259 260 261 262 263 264
                            }
                            members_top_user_visit_num_tv.setText("访客 " + visit_count);
                            members_top_user_fensi_num_tv.setText("粉丝 " + fans_count);
                            members_top_user_zan_num_tv.setText("温暖 " + zan_count);
                            if (!"4".equals(focus_state)) {
                                members_top_user_focus_iv.setVisibility(View.VISIBLE);
                                if ("1".equals(is_black)) { //黑名单关系,1已加入黑名单,2未入黑名单
konghaorui committed
265
                                    members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_focused_topic_detail_bg);
konghaorui committed
266 267 268 269 270 271
                                    members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, null, null);
                                    members_top_user_focus_iv.setVisibility(View.GONE);
                                    members_top_user_focus_ortion_tv.setText("已屏蔽");
                                    shielding = true;
                                } else {
                                    shielding = false;
konghaorui committed
272
                                    members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_focus_topic_detail_bg);
konghaorui committed
273 274
                                    members_top_user_focus_iv.setVisibility(View.VISIBLE);
                                    if ("1".equals(is_focused)) {//关注:1已关注,2未关注
konghaorui committed
275
                                        members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_has_focus_bg);
konghaorui committed
276
                                        Drawable drawable = getResources().getDrawable(R.drawable.dynamic_ic_expand);
konghaorui committed
277 278 279 280 281 282
                                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                                        members_top_user_focus_ortion_tv.setCompoundDrawablePadding(20);
                                        members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, drawable, null);

//                                    members_top_user_focus_ortion_hint_iv.setVisibility(View.VISIBLE);
                                        members_top_user_focus_ortion_tv.setText("已关注");
283
                                        members_top_user_focus_ortion_tv.setTextColor(getResources().getColor(R.color.platform_main_theme));
konghaorui committed
284 285
                                        focus_state = "1";
                                    } else {
konghaorui committed
286
                                        members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_focus_topic_detail_bg);
konghaorui committed
287 288 289 290 291 292 293
                                        members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, null, null);
                                        members_top_user_focus_ortion_tv.setText("+ 关注");
                                        members_top_user_focus_ortion_tv.setTextColor(Color.parseColor("#ffffff"));
                                        focus_state = "2";
                                    }

                                    if ("1".equals(is_zan)) {//1赞,2未赞
konghaorui committed
294
                                        members_top_user_focus_iv.setImageResource(R.drawable.dynamic_newsfeed_like_sel);
konghaorui committed
295 296
                                        zan_state = true;
                                    } else {
konghaorui committed
297
                                        members_top_user_focus_iv.setImageResource(R.drawable.dynamic_newsfeed_like);
konghaorui committed
298 299 300 301 302 303 304
                                        zan_state = false;
                                    }
                                }
                            }
                            members_top_user_focus_ortion_rel.setVisibility(View.VISIBLE);
                            members_top_user_focus_iv.setVisibility(View.VISIBLE);
                        } else {
konghaorui committed
305
                            ToastUtil.toastShort(MembersActivity.this, resp.msg);
konghaorui committed
306 307 308 309 310 311 312 313 314 315 316 317 318
                        }
                }, throwable ->{
                    DynamicApiUtils.handleError(MembersActivity.this, throwable);
                });

    }


    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.members_title_back_iv){
            onBackPressed();
        }else if (v.getId()==R.id.members_title_top_right_tv){
319
            if (DynamicIn.INSTANCE.loginByOneKeyLogin(this, true)) {
konghaorui committed
320 321 322 323 324 325 326
                RightSet();
            }
        }else if (v.getId()==R.id.members_trend_rel){
            setTabSelection(0);
        }else if (v.getId()==R.id.members_information_rel){
            setTabSelection(1);
        }else if (v.getId()==R.id.members_top_user_focus_ortion_rel){
327
            if (DynamicIn.INSTANCE.loginByOneKeyLogin(this, true)) {
konghaorui committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
                if (shielding == false) {
                    if ("1".equals(focus_state)) {//1已关注,2未关注,4代表自己
                        String phone = DynamicIn.INSTANCE.getUserInfo().getPhone();
                        // 弹框提示是否取消关注
                        if (cancelFocusDialog == null) {
                            cancelFocusDialog = new CancelFocusDialog(this, () -> Focus());
                        }
                        cancelFocusDialog.show();
                    } else if ("2".equals(focus_state)) {
                        //关注
                        Focus();
                    } else if ("4".equals(focus_state)) {
                        JumpToPersonInfo();
                    } else {
                        //屏蔽状态,点击无反应
                    }

                }
            }
        }else if (v.getId()==R.id.members_top_user_focus_iv){
348
            if (DynamicIn.INSTANCE.loginByOneKeyLogin(this,true)) {
konghaorui committed
349 350 351 352 353 354
                Zan();
            }
        }else if (v.getId()== R.id.members_top_head_iv){
            Intent intent = new Intent();
            intent.putExtra("browse_type", "member");
            Bundle bd = new Bundle();
355 356
            List<ParcelableImage> images = new ArrayList<ParcelableImage>();
            ParcelableImage image = new ParcelableImage(head);
konghaorui committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
            images.add(image);
            bd.putParcelableArrayList("allTrendImages", (ArrayList<? extends Parcelable>) images);
            intent.putExtra("allTrendImages_bd", bd);
            intent.setClass(MembersActivity.this, BrowsePicturesActivity.class);
            startActivity(intent);
        }
    }

    /**
     * 点赞
     */
    private void Zan() {
        members_top_user_focus_iv.setEnabled(false);
        Command.ZanAction cmd = new Command.ZanAction("1", mem_id);
        DynamicApiUtils.zanAction(cmd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(resp -> {
                    members_top_user_focus_iv.setEnabled(true);
                    if (resp.code == 0) {
                        int zan_numi = Integer.valueOf(zan_count);
                        switch (resp.data.status) {
                            case 1: {
konghaorui committed
380
                                members_top_user_focus_iv.setImageResource(R.drawable.dynamic_newsfeed_like_sel);
konghaorui committed
381 382 383 384 385 386 387 388 389 390 391 392
                                ObjectAnimator animator1 = ObjectAnimator.ofFloat(members_top_user_focus_iv, "scaleX", 1f, 1.5f, 1f);
                                ObjectAnimator animator2 = ObjectAnimator.ofFloat(members_top_user_focus_iv, "scaleY", 1f, 1.5f, 1f);
                                AnimatorSet set = new AnimatorSet();
                                set.setDuration(500);
                                set.playTogether(animator1, animator2);
                                set.start();
                                zan_state = true;
                                zan_count = (zan_numi + 1) + "";
                                members_top_user_zan_num_tv.setText("温暖 " + zan_count);
                                break;
                            }
                            case 2: {
konghaorui committed
393
                                members_top_user_focus_iv.setImageResource(R.drawable.dynamic_newsfeed_like);
konghaorui committed
394 395 396 397 398 399 400 401 402 403 404 405 406
                                ObjectAnimator animator1 = ObjectAnimator.ofFloat(members_top_user_focus_iv, "scaleX", 1f, 1.5f, 1f);
                                ObjectAnimator animator2 = ObjectAnimator.ofFloat(members_top_user_focus_iv, "scaleY", 1f, 1.5f, 1f);
                                AnimatorSet set = new AnimatorSet();
                                set.setDuration(500);
                                set.playTogether(animator1, animator2);
                                set.start();
                                zan_state = false;
                                zan_count = (zan_numi - 1) + "";
                                members_top_user_zan_num_tv.setText("温暖 " + zan_count);
                                break;
                            }
                        }
                    } else {
konghaorui committed
407
                        ToastUtil.toastShort(MembersActivity.this, resp.msg);
konghaorui committed
408 409 410 411 412 413 414 415 416 417 418 419 420
                    }

                }, throwable -> {
                    members_top_user_focus_iv.setEnabled(true);
                    DynamicApiUtils.handleError(MembersActivity.this, throwable);
                });
    }

    /**
     * 跳转修改个人资料
     */
    private void JumpToPersonInfo() {
//        OuterEmptyImp.jumpToPersonInfoActivity(MembersActivity.this);
konghaorui committed
421
        DynamicIn.INSTANCE.personalInfoIntent(this);
konghaorui committed
422 423 424 425 426
    }

    /**
     *
     */
霍志良 committed
427
    @SuppressLint("CheckResult")
konghaorui committed
428
    private void Focus() {
霍志良 committed
429

konghaorui committed
430 431 432 433 434 435 436 437 438 439 440 441
        showProgressDialog("");
        Command.FocusCmd cmd = new Command.FocusCmd(mem_id, "1");
        DynamicApiUtils.focus(cmd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(resp -> {
                    if (resp.code == 0) {
                        //关注成功
                        dismissProgressDialog();
                        int fans_counti = Integer.valueOf(fans_count);
                        String status = String.valueOf(resp.data.status);//1关注,2取消关注
                        if ("1".equals(status)) {
konghaorui committed
442
                            members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_has_focus_bg);
konghaorui committed
443 444 445
                            fans_count = (fans_counti + 1) + "";
                            members_top_user_fensi_num_tv.setText("粉丝 " + fans_count);
                            focus_state = "1";
霍志良 committed
446
                            EventBus.getDefault().post(new dynamicFocusEvent(focus_state));
konghaorui committed
447
                            Drawable drawable = getResources().getDrawable(R.drawable.dynamic_ic_expand);
konghaorui committed
448 449 450 451
                            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                            members_top_user_focus_ortion_tv.setCompoundDrawablePadding(20);
                            members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, drawable, null);
                            members_top_user_focus_ortion_tv.setText("已关注");
452
                            members_top_user_focus_ortion_tv.setTextColor(getResources().getColor(R.color.platform_main_theme));
konghaorui committed
453
                        } else {
konghaorui committed
454
                            members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_focus_topic_detail_bg);
konghaorui committed
455 456 457
                            fans_count = (fans_counti - 1) + "";
                            members_top_user_fensi_num_tv.setText("粉丝 " + fans_count);
                            focus_state = "2";
霍志良 committed
458
                            EventBus.getDefault().post(new dynamicFocusEvent(focus_state));
konghaorui committed
459 460
                            members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, null, null);
                            members_top_user_focus_ortion_tv.setText("+ 关注");
konghaorui committed
461
                            members_top_user_focus_ortion_tv.setTextColor(getResources().getColor(R.color.dynamic_white));
konghaorui committed
462 463 464
                        }
                    } else {
                        String msg = resp.msg;
konghaorui committed
465
                        ToastUtil.toastShort(MembersActivity.this, msg);
konghaorui committed
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
                        dismissProgressDialog();
                    }
                }, throwable -> {
                    dismissProgressDialog();
                    DynamicApiUtils.handleError(MembersActivity.this, throwable);
                });
    }

    /**
     * 右上角按钮
     */
    private void RightSet() {

        final List<String> dialog_datas = new ArrayList<String>();
        if (shielding == false) {
            dialog_datas.add("屏蔽ta");
        } else {
            dialog_datas.add("解除屏蔽");
        }
        dialog_datas.add("举报");
konghaorui committed
486
        int itemTextColor = getResources().getColor(R.color.dynamic_black);
konghaorui committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
        ListDialog.Builder builder1 = new ListDialog.Builder(MembersActivity.this, dialog_datas, itemTextColor);
        builder1.SetLastStr("取消");
        builder1.SetLastButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder1.SetOnItemClickLister(new ListDialog.Builder.OnItemClickLister() {
            @Override
            public void onItemClick(Dialog dialog, View view, int position) {
                if (dialog_datas.size() == 2) {//不含取消关注
                    switch (position) {
                        case 0:
                            if (shielding == false) {
                                shieldHint();
                            } else {
                                RemoveShielding();
                            }
                            break;
                        case 1:
                            report();
                            break;
                    }
                }
                dialog.dismiss();
            }


            @Override
            public void onItemLongClick(Dialog dialog, View view, int position) {

            }
        });
        builder1.create().show();

    }


    /**
     * 解除屏蔽
     */
    private void RemoveShielding() {
        showProgressDialog("");
        Command.RmBlack cmd = new Command.RmBlack(mem_id);
        DynamicApiUtils.rmBlack(cmd)
                .subscribeOn(Schedulers.io())
                .compose(RxUtils.INSTANCE.resultData())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(resp -> {
                    members_top_user_focus_iv.setVisibility(View.VISIBLE);
                    if ("1".equals(focus_state)) {//关注:1已关注,2未关注
konghaorui committed
539
                        members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_has_focus_bg);
konghaorui committed
540
                        Drawable drawable = getResources().getDrawable(R.drawable.dynamic_ic_expand);
konghaorui committed
541 542 543 544
                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                        members_top_user_focus_ortion_tv.setCompoundDrawablePadding(20);
                        members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, drawable, null);
                        members_top_user_focus_ortion_tv.setText("已关注");
545
                        members_top_user_focus_ortion_tv.setTextColor(getResources().getColor(R.color.platform_main_theme));
konghaorui committed
546
                    } else {
konghaorui committed
547
                        members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_focus_topic_detail_bg);
konghaorui committed
548 549
                        members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, null, null);
                        members_top_user_focus_ortion_tv.setText("+ 关注");
konghaorui committed
550
                        members_top_user_focus_ortion_tv.setTextColor(getResources().getColor(R.color.dynamic_white));
konghaorui committed
551 552
                    }
                    if (zan_state == true) {//1赞,2未赞
konghaorui committed
553
                        members_top_user_focus_iv.setImageResource(R.drawable.dynamic_newsfeed_like_sel);
konghaorui committed
554
                    } else {
konghaorui committed
555
                        members_top_user_focus_iv.setImageResource(R.drawable.dynamic_newsfeed_like);
konghaorui committed
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
                    }
                    members_top_user_focus_iv.setVisibility(View.VISIBLE);
                    shielding = false;
                    dismissProgressDialog();
                    ToastUtil.toastShort("解除屏蔽成功");
                    BlackEvent changeEvent = new BlackEvent(true);
                    EventBus.getDefault().post(changeEvent);
                }, throwable -> {
                    dismissProgressDialog();
                    DynamicApiUtils.handleError(MembersActivity.this, throwable);
                });

    }

    /**
     * 屏蔽提示
     */
    private void shieldHint() {
        AlertDialog.Builder builder = new AlertDialog.Builder(MembersActivity.this);
        builder.setTitle("提示");
        builder.setMessage("屏蔽之后将收不到对方的任何消息,并且看不到ta的动态");
        builder.setPositiveButton("确定屏蔽",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Shielding();
                        dialog.dismiss();
                    }
                });
        builder.setNegativeButton("放弃",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        if (!MembersActivity.this.isFinishing()){
            builder.create().show();
        }
    }

    /**
     * 屏蔽
     */
    private void Shielding() {
        showProgressDialog("");
        Command.SetBlackCall cmd = new Command.SetBlackCall(mem_id);
        DynamicApiUtils.setBlackCall(cmd)
                .subscribeOn(Schedulers.io())
                .compose(RxUtils.INSTANCE.resultData())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(resp -> {
konghaorui committed
608
                        members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_focused_topic_detail_bg);
konghaorui committed
609 610 611
                        members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, null, null);
                        members_top_user_focus_iv.setVisibility(View.GONE);
                        members_top_user_focus_ortion_tv.setText("已屏蔽");
konghaorui committed
612
                        members_top_user_focus_ortion_tv.setTextColor(getResources().getColor(R.color.dynamic_white));
konghaorui committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
                        ToastUtil.toastShort("已屏蔽");
                        BlackEvent changeEvent = new BlackEvent(true);
                        EventBus.getDefault().post(changeEvent);
                        focus_state = "2";
                        shielding = true;
                        dismissProgressDialog();
                }, throwable -> {
                    dismissProgressDialog();
                    DynamicApiUtils.handleError(MembersActivity.this, throwable);
                });

    }

    /**
     * //获取举报的内容列表
     */
    public void report() {
        if (reportReasons == null) {
            Command.GetReportReason cmd = new Command.GetReportReason();
            DynamicApiUtils.getReportReason(cmd)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(resp -> {
                        if (resp.code!=0){
                            ToastUtil.toastShort(resp.msg);
                            return;
                        }
                        LinkedTreeMap<String, String> reportReasonsmaps =
                                (LinkedTreeMap<String, String>) resp.data;
                        if (reportReasonsmaps == null)
                            return;
                        reportReasonsId = new ArrayList<>();
                        reportReasons = new ArrayList<>();
                        for (Map.Entry<String, String> entry : reportReasonsmaps.entrySet()) {
                            reportReasonsId.add(entry.getKey());
                            reportReasons.add(entry.getValue());
                        }
                        showReportReason();
                    }, throwable -> DynamicApiUtils.handleError(MembersActivity.this, throwable));
        } else {
            showReportReason();
        }
    }

    /**
     * 举报
     */
    public void showReportReason() {
        if (reportReasons == null || reportReasons.size() <= 0) return;
        int itemTextColor = Color.RED;
        ListDialog.Builder builder1 = new ListDialog.Builder(this, reportReasons, itemTextColor);
        builder1.SetLastStr("取消");
        builder1.SetLastButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder1.SetOnItemClickLister(new ListDialog.Builder.OnItemClickLister() {
            @Override
            public void onItemClick(Dialog dialog, View view, int position) {
                dialog.dismiss();
675
                if (!DynamicIn.INSTANCE.loginByOneKeyLogin(MembersActivity.this,true)) {
konghaorui committed
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
                    return;
                }
                Command.ReportWorry cmd = new Command.ReportWorry(Integer.valueOf(mem_id), Integer.valueOf(reportReasonsId.get(position)), 0, reportReasons.get(position), 2);
                DynamicApiUtils.reportWorry(cmd)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .doOnSubscribe(new Consumer<Disposable>() {
                            @Override
                            public void accept(Disposable disposable) throws Exception {
                                showProgressDialog("");
                            }
                        })
                        .doAfterTerminate(() -> dismissProgressDialog())
                        .subscribe(resp -> {
                            if (resp.code == 0) {
konghaorui committed
691
                                ToastUtil.toastShort(MembersActivity.this, "举报成功");
konghaorui committed
692
                            } else {
konghaorui committed
693
                                ToastUtil.toastShort(MembersActivity.this, resp.msg);
konghaorui committed
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
                            }

                        }, throwable -> DynamicApiUtils.handleError(MembersActivity.this, throwable));
            }

            @Override
            public void onItemLongClick(Dialog dialog, View view, int position) {

            }
        });
        builder1.create().show();
    }

    private void setTabSelection(int index) {
        // 重置按钮
        resetText();
        // 开启一个Fragment事务
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        // 先隐藏掉所有的Fragment,以防止有多个Fragment显示在界面上的情况
        hideFragments(transaction);
        switch (index) {
            case 0:
716 717
                members_trend_tv.setTextColor(getResources().getColor(R.color.platform_main_theme));
                members_trend_hint_tv.setBackgroundColor(getResources().getColor(R.color.platform_main_theme));
konghaorui committed
718 719 720 721 722 723 724 725 726 727

                if (trendlisfragment == null) {
                    trendlisfragment = TrendListInFragment.newInstance("3", "0", "member_trend", mem_id);
                    transaction.add(R.id.members_content_frm, trendlisfragment);
                } else {
                    transaction.show(trendlisfragment);
                }
                select_tab = 0;
                break;
            case 1:
728 729
                members_information_tv.setTextColor(getResources().getColor(R.color.platform_main_theme));
                members_information_hint_tv.setBackgroundColor(getResources().getColor(R.color.platform_main_theme));
konghaorui committed
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
                if (memberfragment == null) {
                    memberfragment = MemberFragment.newInstance(age, emotional_state, job, address, introduction);
                    transaction.add(R.id.members_content_frm, memberfragment);
                } else {
                    transaction.show(memberfragment);
                }
                select_tab = 1;
                break;

        }
        transaction.commit();
    }

    private void hideFragments(FragmentTransaction transaction) {
        if (trendlisfragment != null) {
            transaction.hide(trendlisfragment);
        }
        if (memberfragment != null) {
            transaction.hide(memberfragment);
        }

    }

    private void resetText() {
konghaorui committed
754 755 756 757
        members_trend_tv.setTextColor(getResources().getColor(R.color.dynamic_text_gray));
        members_trend_hint_tv.setBackgroundColor(getResources().getColor(R.color.dynamic_white));
        members_information_tv.setTextColor(getResources().getColor(R.color.dynamic_text_gray));
        members_information_hint_tv.setBackgroundColor(getResources().getColor(R.color.dynamic_white));
konghaorui committed
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
    }

    @Override
    public void onScrollChanged(MyNestedScrollView scrollView, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

        if (DIS == 0) {
            DIS = members_type_lin.getTop();
            title_rel_bottom = members_title_rel.getBottom();
        }
        int y = members_myScrov.getScrollY();
        if (y < DIS - title_rel_bottom) {
            members_type_lin.setTranslationY(-y);
        } else {
            members_type_lin.setTranslationY(title_rel_bottom - DIS);
        }

        if (scrollY <= 0) {   //设置标题的背景颜色
konghaorui committed
775
            members_title_top_tv.setTextColor(getResources().getColor(R.color.dynamic_trend_transparent));
konghaorui committed
776
            members_title_top_tv.setText("");
konghaorui committed
777 778 779 780
            members_title_back_iv.setImageResource(R.drawable.dynamic_titlebar_back2);
            members_title_top_right_tv.setImageResource(R.drawable.dynamic_more_green2);
            members_title_rel.setBackgroundColor(getResources().getColor(R.color.dynamic_trend_transparent));
//            members_top_view.setBackgroundColor(getResources().getColor(R.color.dynamic_trend_transparent));
konghaorui committed
781
        } else if (scrollY > 0 && scrollY <= height - 55) { //滑动距离小于banner图的高度时,设置背景和字体颜色颜色透明度渐变
konghaorui committed
782
            members_title_top_tv.setTextColor(getResources().getColor(R.color.dynamic_trend_transparent));
konghaorui committed
783
            members_title_top_tv.setText("");
konghaorui committed
784 785 786 787
            members_title_back_iv.setImageResource(R.drawable.dynamic_titlebar_back2);
            members_title_top_right_tv.setImageResource(R.drawable.dynamic_more_green2);
//            members_top_view.setBackgroundColor(getResources().getColor(R.color.dynamic_trend_transparent));
            members_title_rel.setBackgroundColor(getResources().getColor(R.color.dynamic_trend_transparent));
konghaorui committed
788
        } else {    //滑动到banner下面设置普通颜色
konghaorui committed
789
            members_title_top_tv.setTextColor(getResources().getColor(R.color.dynamic_black));
konghaorui committed
790
            members_title_top_tv.setText(name);
konghaorui committed
791
            members_title_back_iv.setImageResource(R.drawable.platform_common_back);
konghaorui committed
792
            members_title_top_right_tv.setImageResource(R.drawable.platform_common_notice_more_un);
konghaorui committed
793 794
//            members_top_view.setBackgroundColor(getResources().getColor(R.color.dynamic_black));
            members_title_rel.setBackgroundDrawable(getResources().getDrawable(R.drawable.dynamic_layout_border));
konghaorui committed
795 796 797 798 799 800 801 802 803 804 805
        }

    }

    @SuppressLint("WrongConstant")
    @Override
    protected void onResume() {
        super.onResume();
        if (mem_id.equals(DynamicIn.INSTANCE.getUserInfo().getUid() + "")) {
            focus_state = "4";
//            members_top_user_focus_ortion_rel.setVisibility(View.VISIBLE);
konghaorui committed
806
            members_top_user_focus_ortion_rel.setBackgroundResource(R.drawable.dynamic_focused_topic_detail_bg);
konghaorui committed
807 808 809 810
//             members_top_user_focus_ortion_hint_iv.setVisibility(View.GONE);
            members_top_user_focus_ortion_tv.setCompoundDrawables(null, null, null, null);
            members_top_user_focus_iv.setVisibility(View.GONE);
            members_top_user_focus_ortion_tv.setText("修改资料");
konghaorui committed
811
            members_top_user_focus_ortion_tv.setTextColor(getResources().getColor(R.color.dynamic_text_trend_black));
konghaorui committed
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
            members_title_top_right_tv.setVisibility(View.GONE);
            members_top_user_focus_iv.setVisibility(View.GONE);
        }
    }

    public void setHandler(Handler handler, String tab) {
        this.tab = tab;
        if ("3".equals(tab)) {//TrendListInFragment.newInstance("3", "0", "member_trend", mem_id);
            mHandler1 = handler;
        }
    }

    @Override
    public void onRefresh() {
        initDatas();
        if (is_first_refreh) {
            if (0 == select_tab && "3".equals(tab)) {
                Message msg = new Message();
                msg.what = DynamicConstants.MEMBER_REFRESH;
                msg.obj = mem_id;
                mHandler1.sendMessage(msg);
            }
        }
        member_swrl.setRefreshing(false);
        is_first_refreh = true;
    }

    public void onEvent(LoginStateEvent event) {
        if ("login".equals(event.getLogin_state())) {
            initDatas();
        }
    }

    public void onEvent(UserLoginEvent event) {
        if ("login".equals(event.getLogin_state())) {
            initDatas();
        }
    }

    @Override
    public void onBackPressed() {
        getIntent().putExtra("focus", focus_state);
        setResult(-1, getIntent());
        finish();
    }

    @Override
    protected int layoutResId() {
        return 0;
    }

    @Override
    protected void initDataAndEvent() {

    }
}