Browse Source

完成话题详情页数据交互逻辑

hy 3 years ago
parent
commit
ccb3b915f4

+ 67 - 4
app/src/main/java/com/electric/chargingpile/activity/SelectTopicActivity.java

1
package com.electric.chargingpile.activity;
1
package com.electric.chargingpile.activity;
2
2
3
import android.content.Context;
3
import android.app.Activity;
4
import android.content.Intent;
4
import android.content.Intent;
5
import android.os.Bundle;
5
import android.os.Bundle;
6
import android.view.View;
6
import android.view.View;
7
import android.widget.TextView;
7
import android.widget.TextView;
8
import android.widget.Toast;
8
9
9
import androidx.annotation.Nullable;
10
import androidx.annotation.Nullable;
10
import androidx.appcompat.app.AppCompatActivity;
11
import androidx.appcompat.app.AppCompatActivity;
11
import androidx.recyclerview.widget.LinearLayoutManager;
12
import androidx.recyclerview.widget.LinearLayoutManager;
12
import androidx.recyclerview.widget.RecyclerView;
13
import androidx.recyclerview.widget.RecyclerView;
13
14
15
import com.blankj.utilcode.util.EmptyUtils;
14
import com.electric.chargingpile.R;
16
import com.electric.chargingpile.R;
15
import com.electric.chargingpile.adapter.CommentTopicAdapter;
17
import com.electric.chargingpile.adapter.CommentTopicAdapter;
18
import com.electric.chargingpile.application.MainApplication;
19
import com.electric.chargingpile.data.TopicBean;
16
import com.electric.chargingpile.util.BarColorUtil;
20
import com.electric.chargingpile.util.BarColorUtil;
21
import com.electric.chargingpile.util.JsonUtils;
22
import com.electric.chargingpile.util.LoadingDialog;
23
import com.google.gson.Gson;
24
import com.google.gson.reflect.TypeToken;
25
import com.zhy.http.okhttp.OkHttpUtils;
26
import com.zhy.http.okhttp.callback.StringCallback;
27
28
import java.util.ArrayList;
29
30
import okhttp3.Call;
17
31
18
public class SelectTopicActivity  extends AppCompatActivity {
32
public class SelectTopicActivity  extends AppCompatActivity {
19
33
20
    private RecyclerView mRecyclerView;
34
    private RecyclerView mRecyclerView;
21
    private TextView noDataText;
35
    private TextView noDataText;
22
    private CommentTopicAdapter mAdapter;
36
    private CommentTopicAdapter mAdapter;
37
    private LoadingDialog dialog = null;
38
    private final Gson mGson =new Gson();
39
    public static   final int REESULT_CODE =112;
23
40
24
    @Override
41
    @Override
25
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
42
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
27
        setContentView(R.layout.activity_slelect_topic);
44
        setContentView(R.layout.activity_slelect_topic);
28
        BarColorUtil.initStatusBarColor(this);
45
        BarColorUtil.initStatusBarColor(this);
29
        initView();
46
        initView();
47
        requestTopicList();
30
    }
48
    }
31
49
32
    private void initView() {
50
    private void initView() {
51
        dialog=new LoadingDialog(this);
52
        dialog.setCanceledOnTouchOutside(false);
53
33
        findViewById(R.id.iv_back).setOnClickListener(v->{
54
        findViewById(R.id.iv_back).setOnClickListener(v->{
34
            finish();
55
            finish();
35
        });
56
        });
38
        noDataText = findViewById(R.id.noDataText);
59
        noDataText = findViewById(R.id.noDataText);
39
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
60
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
40
        mAdapter = new CommentTopicAdapter();
61
        mAdapter = new CommentTopicAdapter();
62
        mAdapter.setListener(pos -> {
63
            TopicBean bean = mAdapter.getDatas().get(pos);
64
65
            Intent intent=new Intent();
66
            intent.putExtra("topicBean",mGson.toJson(bean));
67
            setResult(REESULT_CODE,intent);//2. setResult()方法,用于携带数据进行回传
68
            finish();
69
        });
41
        mRecyclerView.setAdapter(mAdapter);
70
        mRecyclerView.setAdapter(mAdapter);
42
71
43
        noDataText.setVisibility(View.GONE);
72
        noDataText.setVisibility(View.GONE);
44
        mRecyclerView.setVisibility(View.VISIBLE);
73
        mRecyclerView.setVisibility(View.VISIBLE);
45
    }
74
    }
46
75
47
    public static void actionStart(Context context){
48
        Intent intent = new Intent(context, SelectTopicActivity.class);
49
        context.startActivity(intent);
76
    public void requestTopicList(){
77
        String url = MainApplication.url + "/zhannew/basic/web/index.php/theme/getlist";
78
        OkHttpUtils.get().url(url).build().connTimeOut(5000).readTimeOut(5000).execute(new StringCallback() {
79
80
            @Override
81
            public void onError(Call call, Exception e) {
82
                Toast.makeText(getApplicationContext(), "网络不给力,请检查网络状态", Toast.LENGTH_SHORT).show();
83
            }
84
85
            @Override
86
            public void onResponse(String response) {
87
                if (null != response) {
88
                    String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
89
                    if (EmptyUtils.isNotEmpty(rtnCode)&& rtnCode .equals("01")) {
90
                        String data = JsonUtils.getKeyResult(response, "data");
91
92
93
                        ArrayList<TopicBean> list = mGson.fromJson(data, new TypeToken<ArrayList<TopicBean>>() {
94
                        }.getType());
95
                        if (list!=null && list.size()>0){
96
                            mAdapter.setDatas(list);
97
                            mRecyclerView.setVisibility(View.VISIBLE);
98
                            noDataText.setVisibility(View.GONE);
99
                        }else{
100
                            mRecyclerView.setVisibility(View.GONE);
101
                            noDataText.setVisibility(View.VISIBLE);
102
                        }
103
                    }
104
                }
105
106
            }
107
        });
108
    }
109
110
    public static void actionStart(Activity activity,int requestCode){
111
        Intent intent = new Intent(activity, SelectTopicActivity.class);
112
        activity.startActivityForResult(intent,requestCode);
50
    }
113
    }
51
}
114
}

+ 10 - 1
app/src/main/java/com/electric/chargingpile/activity/ZhanCommentActivity.java

52
import com.electric.chargingpile.data.CommentsBean;
52
import com.electric.chargingpile.data.CommentsBean;
53
import com.electric.chargingpile.data.MyOtto;
53
import com.electric.chargingpile.data.MyOtto;
54
import com.electric.chargingpile.data.RObject;
54
import com.electric.chargingpile.data.RObject;
55
import com.electric.chargingpile.data.TopicBean;
55
import com.electric.chargingpile.engine.GlideEngine;
56
import com.electric.chargingpile.engine.GlideEngine;
56
import com.electric.chargingpile.util.BarColorUtil;
57
import com.electric.chargingpile.util.BarColorUtil;
57
import com.electric.chargingpile.util.Bimp;
58
import com.electric.chargingpile.util.Bimp;
74
import com.electric.chargingpile.view.REditText;
75
import com.electric.chargingpile.view.REditText;
75
import com.electric.chargingpile.view.RatingBarView;
76
import com.electric.chargingpile.view.RatingBarView;
76
77
78
import com.google.gson.Gson;
77
import com.luck.picture.lib.PictureSelector;
79
import com.luck.picture.lib.PictureSelector;
78
import com.luck.picture.lib.animators.AnimationType;
80
import com.luck.picture.lib.animators.AnimationType;
79
import com.luck.picture.lib.config.PictureConfig;
81
import com.luck.picture.lib.config.PictureConfig;
148
    private static final int PHOTO_REQUEST_CAMERA = 1;
150
    private static final int PHOTO_REQUEST_CAMERA = 1;
149
    private static final int PHOTO_REQUEST_GALLERY = 2;
151
    private static final int PHOTO_REQUEST_GALLERY = 2;
150
    private static final int PHOTO_REQUEST_CUT = 3;
152
    private static final int PHOTO_REQUEST_CUT = 3;
153
    private static final int REQUEST_TOPIC_CODE = 102;
151
    public static android.view.animation.Animation animation;
154
    public static android.view.animation.Animation animation;
152
    public static TextView textView;
155
    public static TextView textView;
153
    public static RelativeLayout relativeLayout;
156
    public static RelativeLayout relativeLayout;
155
    private InputMethodManager imm = null;
158
    private InputMethodManager imm = null;
156
    private static final int RC_ALBUM_PERM = 123;
159
    private static final int RC_ALBUM_PERM = 123;
157
    public static final int REQUEST_CODE_CHOOSE = 336;
160
    public static final int REQUEST_CODE_CHOOSE = 336;
161
    private final Gson mGson=new Gson();
158
    Handler handler = new Handler() {
162
    Handler handler = new Handler() {
159
        public void handleMessage(Message msg) {
163
        public void handleMessage(Message msg) {
160
            switch (msg.what) {
164
            switch (msg.what) {
452
        });
456
        });
453
        topicText.setOnClickListener(v->{
457
        topicText.setOnClickListener(v->{
454
            //跳转至话题页
458
            //跳转至话题页
455
            SelectTopicActivity.actionStart(this);
459
            SelectTopicActivity.actionStart(this,REQUEST_TOPIC_CODE);
456
        });
460
        });
457
    }
461
    }
458
462
521
                    insertImagesSync(data);
525
                    insertImagesSync(data);
522
                }
526
                }
523
            }
527
            }
528
        }else if  (requestCode==REQUEST_TOPIC_CODE && resultCode == SelectTopicActivity.REESULT_CODE){
529
            String name=data.getStringExtra("topicBean");
530
            TopicBean bean = mGson.fromJson(name, TopicBean.class);
531
            topicText.setText(bean.getMeg());
524
        }
532
        }
533
525
    }
534
    }
526
535
527
    /**
536
    /**

+ 17 - 2
app/src/main/java/com/electric/chargingpile/adapter/CommentTopicAdapter.java

9
import androidx.recyclerview.widget.RecyclerView;
9
import androidx.recyclerview.widget.RecyclerView;
10
10
11
import com.electric.chargingpile.R;
11
import com.electric.chargingpile.R;
12
import com.electric.chargingpile.data.TopicBean;
12
13
13
import org.jetbrains.annotations.NotNull;
14
import org.jetbrains.annotations.NotNull;
14
import org.w3c.dom.Text;
15
import org.w3c.dom.Text;
15
16
17
import java.util.ArrayList;
18
16
public class CommentTopicAdapter extends RecyclerView.Adapter<CommentTopicAdapter.ViewHolder> {
19
public class CommentTopicAdapter extends RecyclerView.Adapter<CommentTopicAdapter.ViewHolder> {
17
20
18
    private OnItemClickListener mListener;
21
    private OnItemClickListener mListener;
22
    private ArrayList<TopicBean> mDatas=new ArrayList<>();
23
24
    public ArrayList<TopicBean> getDatas() {
25
        return mDatas;
26
    }
27
28
    public void setDatas(ArrayList<TopicBean> mDatas) {
29
        this.mDatas = mDatas;
30
        notifyDataSetChanged();
31
    }
19
32
20
    public OnItemClickListener getListener() {
33
    public OnItemClickListener getListener() {
21
        return mListener;
34
        return mListener;
39
52
40
    @Override
53
    @Override
41
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
54
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
42
        holder.title.setText("标题"+position);
55
        TopicBean data = mDatas.get(position);
56
57
        holder.title.setText(data.getMeg());
43
        holder.participateText.setText("内容够"+position+"参与");
58
        holder.participateText.setText("内容够"+position+"参与");
44
        holder.onlookersText.setText("标题"+position+"围观");
59
        holder.onlookersText.setText("标题"+position+"围观");
45
        holder.itemView.setOnClickListener(v->{
60
        holder.itemView.setOnClickListener(v->{
50
65
51
    @Override
66
    @Override
52
    public int getItemCount() {
67
    public int getItemCount() {
53
        return 20;
68
        return mDatas.size();
54
    }
69
    }
55
70
56
    public static class ViewHolder extends RecyclerView.ViewHolder {
71
    public static class ViewHolder extends RecyclerView.ViewHolder {

+ 32 - 0
app/src/main/java/com/electric/chargingpile/data/TopicBean.java

1
package com.electric.chargingpile.data;
2
3
4
public class TopicBean {
5
    private String id;
6
    private String meg;
7
    private String icon;
8
9
    public String getId() {
10
        return id;
11
    }
12
13
    public void setId(String id) {
14
        this.id = id;
15
    }
16
17
    public String getMeg() {
18
        return meg;
19
    }
20
21
    public void setMeg(String meg) {
22
        this.meg = meg;
23
    }
24
25
    public String getIcon() {
26
        return icon;
27
    }
28
29
    public void setIcon(String icon) {
30
        this.icon = icon;
31
    }
32
}

+ 6 - 2
app/src/main/res/layout/activity_zhan_comment.xml

200
200
201
201
202
            <TextView
202
            <TextView
203
                android:paddingEnd="11dp"
204
                android:paddingStart="11dp"
205
                android:paddingBottom="6dp"
206
                android:paddingTop="6dp"
203
                android:layout_marginBottom="13dp"
207
                android:layout_marginBottom="13dp"
204
                android:id="@+id/topicText"
208
                android:id="@+id/topicText"
205
                android:background="@drawable/bg_topic_tab"
209
                android:background="@drawable/bg_topic_tab"
206
                android:layout_width="66dp"
207
                android:layout_height="28dp"
210
                android:layout_width="wrap_content"
211
                android:layout_height="wrap_content"
208
                android:layout_marginStart="15dp"
212
                android:layout_marginStart="15dp"
209
                android:gravity="center"
213
                android:gravity="center"
210
                android:text="╋  话题"
214
                android:text="╋  话题"