SelecTopicActivity.java 6.73 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8
package com.yidianling.dynamic.publishTrend;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

konghaorui committed
9
import com.ydl.ydlcommon.base.BaseActivity;
konghaorui committed
10
import com.ydl.ydlcommon.bean.StatusBarOptions;
konghaorui committed
11 12
import com.ydl.ydlcommon.view.widgets.RecyclerViewForScrollView;
import com.yidianling.common.tools.ToastUtil;
konghaorui committed
13 14 15 16 17 18 19
import com.yidianling.dynamic.R;
import com.yidianling.dynamic.adapter.SelectTopicAdapter;
import com.yidianling.dynamic.common.net.DynamicApiUtils;
import com.yidianling.dynamic.common.view.FullyLinearLayoutManager;
import com.yidianling.dynamic.model.Command;
import com.yidianling.dynamic.model.RecommendTopic;

konghaorui committed
20 21
import org.jetbrains.annotations.NotNull;

konghaorui committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
import java.util.ArrayList;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;


/**
 * 选择话题
 */
public class SelecTopicActivity extends BaseActivity {

    private TextView Cancletv;
    private RecyclerViewForScrollView focus_rcv, recommend_rcv;
    private List<RecommendTopic> mDatasR, mDatasF;
    SelectTopicAdapter adapterR, adapterF;
    RelativeLayout select_topic_focus_hint_rel, select_topic_recommend_hint_rel;

konghaorui committed
40 41 42 43 44 45
    @NotNull
    @Override
    public StatusBarOptions getStatusViewOptions() {
        return new StatusBarOptions(true,true);
    }

konghaorui committed
46 47 48
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
konghaorui committed
49
        setContentView(R.layout.dynamic_activity_selec_topic);
konghaorui committed
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
        Cancletv = (TextView) findViewById(R.id.select_topic_cancel_tv);
        focus_rcv = (RecyclerViewForScrollView) findViewById(R.id.select_topic_focus_rcv);
        recommend_rcv = (RecyclerViewForScrollView) findViewById(R.id.select_topic_recommend_rcv);
        select_topic_focus_hint_rel = (RelativeLayout) findViewById(R.id.select_topic_focus_hint_rel);
        select_topic_recommend_hint_rel = (RelativeLayout) findViewById(R.id.select_topic_recommend_hint_rel);
        mDatasR = new ArrayList<RecommendTopic>();
        mDatasF = new ArrayList<RecommendTopic>();
        Cancletv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(SelecTopicActivity.this, PublishTrendActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("type", "back");
                intent.putExtra("bundle", bundle);
                setResult(RESULT_OK, intent);
                finish();
            }
        });

        if (adapterR == null) {
            adapterR = new SelectTopicAdapter(mDatasR, this);
        } else {
            adapterR.notifyDataSetChanged();
        }
        if (adapterF == null) {
            adapterF = new SelectTopicAdapter(mDatasF, this);
        } else {
            adapterF.notifyDataSetChanged();
        }
        FullyLinearLayoutManager linearLayoutManager = new FullyLinearLayoutManager(this, FullyLinearLayoutManager.VERTICAL, false);
        FullyLinearLayoutManager linearLayoutManager1 = new FullyLinearLayoutManager(this, FullyLinearLayoutManager.VERTICAL, false);
        focus_rcv.setLayoutManager(linearLayoutManager);
        focus_rcv.setAdapter(adapterF);
        recommend_rcv.setLayoutManager(linearLayoutManager1);
        recommend_rcv.setAdapter(adapterR);
        adapterR.setOnItemClickLister(new SelectTopicAdapter.OnItemClickLister() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent();
                intent.setClass(SelecTopicActivity.this, PublishTrendActivity.class);
                intent.putExtra("type", "topic_select");
                Bundle bd = new Bundle();
                bd.putString("topic_id", mDatasR.get(position).getTopic_id());
                bd.putString("topic_title", mDatasR.get(position).getTopic_title());
                intent.putExtra("bundle", bd);
                setResult(RESULT_OK, intent);
                click_event();
                finish();
            }

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

            }
        });
        adapterF.setOnItemClickLister(new SelectTopicAdapter.OnItemClickLister() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent();
                intent.setClass(SelecTopicActivity.this, PublishTrendActivity.class);
                intent.putExtra("type", "topic_select");
                Bundle bd = new Bundle();
                bd.putString("topic_id", mDatasF.get(position).getTopic_id());
                bd.putString("topic_title", mDatasF.get(position).getTopic_title());
                intent.putExtra("bundle", bd);
                setResult(RESULT_OK, intent);
                click_event();
                finish();
            }

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

            }
        });
        showProgressDialog("");
        initDatas();
    }

    private void click_event() {
    }

    private void initDatas() {
        Command.AllTopicCmd cmd = new Command.AllTopicCmd("1", "1");
        DynamicApiUtils.fetchTopicList(cmd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(response -> {
                    if (response.code == 0) {
                        mDatasF.addAll(response.data.my);
                        mDatasR.addAll(response.data.list);
                        if (mDatasF.size() > 0) {
                            select_topic_focus_hint_rel.setVisibility(View.VISIBLE);
                        } else {
                            select_topic_focus_hint_rel.setVisibility(View.GONE);
                        }
                        if (mDatasR.size() > 0) {
                            select_topic_recommend_hint_rel.setVisibility(View.VISIBLE);
                        } else {
                            select_topic_recommend_hint_rel.setVisibility(View.GONE);
                        }
                        adapterR.notifyDataSetChanged();
                        adapterF.notifyDataSetChanged();
                    } else {
konghaorui committed
155
                        ToastUtil.toastShort(SelecTopicActivity.this, response.msg);
konghaorui committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                    }
                    dismissProgressDialog();
                }, throwable -> {
                    dismissProgressDialog();
                    DynamicApiUtils.handleError(SelecTopicActivity.this, throwable);
                });
    }

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

    @Override
    protected void initDataAndEvent() {

    }
}