admin
2022-08-09 399ac289f80b7a40aa4210341db6b447cacdcf14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
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
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
190
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
package com.tejia.lijin.app.presenter;
 
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.wpc.library.util.NetUtils;
import com.wpc.library.util.common.StringUtils;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.contract.SelectionStoreHouse31Contract;
import com.tejia.lijin.app.entity.SelectionStoreHouse;
import com.tejia.lijin.app.model.SelectionStoreHouse31Model;
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
import com.tejia.lijin.app.ui.mine.SelectionStoreHouseActivity31;
import com.tejia.lijin.app.ui.mine.SelectionStoreHouseAdapter31;
 
import org.json.JSONObject;
 
import java.util.List;
 
/**
 * 分享库 presenter
 */
public class SelectionStoreHouse31Presenter extends BasePresenter<SelectionStoreHouse31Contract.SelectionStoreHouseView> {
    private Context mContext;
    private SelectionStoreHouse31Model model;
 
    public SelectionStoreHouse31Presenter(Context mContext) {
        this.mContext = mContext;
        this.model = new SelectionStoreHouse31Model();
    }
 
    /**
     * 小黄条
     */
    public void getAppPageNotification(String type) {
        model.getAppPageNotification(mContext, type, new SelectionStoreHouse31Contract.onStoreHouseCallBack() {
            @Override
            public void onSuccess(JSONObject jsonObject) {
                if (getView() != null) {
                    getView().onAppPageNotificationSuccess(jsonObject);
                }
            }
 
            @Override
            public void onFail(String errorInfo) {
                if (getView() != null) {
                    getView().onAppPageNotificationFail(errorInfo);
                }
            }
        });
    }
 
    /**
     * 分享库数据
     */
    public void getSelectioStoreHouseList(String page, Long uid, String goodsType) {
        model.getSelectioStoreHouseList(mContext, page, uid, goodsType, new SelectionStoreHouse31Contract.onStoreHouseCallBack() {
            @Override
            public void onSuccess(JSONObject jsonObject) {
                getView().onSelectioStoreHouseListSuccess(jsonObject);
            }
 
            @Override
            public void onFail(String errorInfo) {
                getView().onSelectioStoreHouseListFail(errorInfo);
            }
        });
    }
 
    /**
     * 删除分享库
     */
    public void deleteSelectStoreHouse(String ids, Long uid) {
        model.deleteSelectStoreHouse(mContext, ids, uid, new SelectionStoreHouse31Contract.onStoreHouseCallBack() {
            @Override
            public void onSuccess(JSONObject jsonObject) {
                getView().onDeleteSelectStoreHouseSuccess(jsonObject);
            }
 
            @Override
            public void onFail(String errorInfo) {
                getView().onDeleteSelectStoreHouseFail(errorInfo);
            }
        });
    }
 
    /**
     * 请求状态 0 数据正常展示;1 返回数据为空;2 网络请求失败;3 没有连接网络
     *
     * @param state
     */
    public void requestState(int state, LinearLayout ll_delete
            , LinearLayout ll_go_scan, LinearLayout ll_no_net, LinearLayout ll_request_failture, LinearLayout ll_content, ToggleButton tv_top_bar_right) {
        if (state != 0) {
            ll_delete.setVisibility(View.GONE);
        }
        ll_content.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
        tv_top_bar_right.setVisibility(state == 0 ? View.VISIBLE : View.INVISIBLE);
 
        ll_go_scan.setVisibility(state == 1 ? View.VISIBLE : View.GONE);
        ll_request_failture.setVisibility(state == 2 ? View.VISIBLE : View.GONE);
        ll_no_net.setVisibility(state == 3 ? View.VISIBLE : View.GONE);
    }
 
    /**
     * 分享数据 处理
     */
    public int setresult_list(JSONObject jsonObject, int page, List<SelectionStoreHouse> wList, SelectionStoreHouseAdapter31 adapter, int count,
                              View bottom, ImageView iv_loading, TextView tv_loading, LinearLayout ll_delete, LinearLayout ll_go_scan,
                              LinearLayout ll_no_net, LinearLayout ll_request_failture, LinearLayout ll_content,
                              ToggleButton tv_top_bar_right, int goodsType) {
        bottom.setVisibility(View.GONE);
        if (jsonObject.optString("code").equalsIgnoreCase("0")) {
//            Log.i("mResult", jsonObject.toString());
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<SelectionStoreHouse> list = gson.fromJson(jsonObject.optJSONObject("data").optJSONArray("result_list").toString(), new TypeToken<List<SelectionStoreHouse>>() {
            }.getType());
            if (page == 1 || deleteselect) {
                wList.clear();
                ((SelectionStoreHouseActivity31) mContext).SetnotifyDataSetChanged();
            }
            deleteselect = false;
//                    adapter.notifyItemRangeChanged(wList.size(), list.size());//倒序批量刷新列表
            wList.addAll(list);
            count = Integer.parseInt(jsonObject.optJSONObject("data").optString("count"));
            if (wList.size() == count) {
                bottom.setVisibility(View.VISIBLE);
                iv_loading.setVisibility(View.GONE);
                tv_loading.setText(mContext.getResources().getString(R.string.list_no_more));
            }
            requestState(wList.size() == 0 ? 1 : 0, ll_delete
                    , ll_go_scan, ll_no_net, ll_request_failture, ll_content, tv_top_bar_right);
 
//            adapter.init(list, page);
//            adapter.notifyDataSetChanged();
            return count;
        } else {
            if (wList.size() == 0)
                requestState(1, ll_delete
                        , ll_go_scan, ll_no_net, ll_request_failture, ll_content, tv_top_bar_right);
            return count;
        }
    }
 
    /**
     * 小黄条处理
     *
     * @param tv_notice_content
     * @param ll_notice
     * @param iv_close
     */
    public void setAppPageNotificationSuccess(JSONObject jsonObject, TextView tv_notice_content, final LinearLayout ll_notice, ImageView iv_close) {
        boolean isClose = jsonObject.optJSONObject("data").optBoolean("canClose");
        String content = jsonObject.optJSONObject("data").optString("content");
        final String contentUrl = jsonObject.optJSONObject("data").optString("contentUrl");
        final String md5 = jsonObject.optJSONObject("data").optString("md5");
 
        tv_notice_content.setText(content);
        final SharedPreferences sp = mContext.getSharedPreferences("notice", Context.MODE_PRIVATE);
        if (!sp.getBoolean(md5, false)) {//false 展示,true不展示
            ll_notice.setVisibility(View.VISIBLE);
        } else {
            ll_notice.setVisibility(View.GONE);
        }
        if (isClose) {
            iv_close.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_notice_close));
            iv_close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ll_notice.setVisibility(View.GONE);
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putBoolean(md5, true);
                    editor.apply();
                }
            });
        } else {
            iv_close.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_notice_input));
        }
        ll_notice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (StringUtils.isEmpty(contentUrl))
                    return;
                Intent intent = new Intent(mContext, ShareBrowserActivity.class);
                intent.putExtra("url", contentUrl);
                mContext.startActivity(intent);
            }
        });
    }
 
    private boolean deleteselect = false;//是否删除数据
 
    /**
     * 删除 分享数据成功处理
     *
     * @param jsonObject
     * @param wList
     * @param adapter
     * @param pd
     */
    public void setDeleteSelectStoreHouseSuccess(JSONObject jsonObject, List<SelectionStoreHouse> wList, SelectionStoreHouseAdapter31 adapter, ShapeLoadingDialog pd, LinearLayout ll_delete
            , LinearLayout ll_go_scan, LinearLayout ll_no_net, LinearLayout ll_request_failture, LinearLayout ll_content, ToggleButton tv_top_bar_right, int goodsType) {
        List<String> idList;
        if (goodsType == 1) {
            idList = adapter.selectList;
        } else if (goodsType == 2) {
            idList = adapter.selectListJD;
        } else {
            idList = adapter.selectListPDD;
        }
        int k = 0;
        for (int i = 0; i < wList.size(); i++) {
            if (idList.contains(wList.get(i).getStorageId())) {
//                wList.remove(i);
//                i--;
                k++;
            }
        }
        deleteselect = true;
        if (goodsType == 1 && deleteselect) {
            adapter.selectList.clear();
        } else if (goodsType == 2 && deleteselect) {
            adapter.selectListJD.clear();
        } else if (goodsType == 3 && deleteselect) {
            adapter.selectListPDD.clear();
        }
        Toast.makeText(mContext, "删除成功!", Toast.LENGTH_LONG).show();
        ((SelectionStoreHouseActivity31) mContext).setSelectedMode(false, goodsType);
        ((SelectionStoreHouseActivity31) mContext).updateView();
 
        if (k == wList.size()) {// if (wList.size() == 0) {
            ((SelectionStoreHouseActivity31) mContext).setData();
        } else {
            requestState(0, ll_delete
                    , ll_go_scan, ll_no_net, ll_request_failture, ll_content, tv_top_bar_right);
        }
        if (pd != null) {
            pd.dismiss();
        }
    }
 
    /**
     * 设置 淘宝 京东 拼多多 bar
     *
     * @param i
     * @param storehouse_tb
     * @param storehouse_jd
     * @param storehouse_pdd
     * @param storehouse_tbline
     * @param storehouse_jdline
     * @param storehouse_pddline
     */
    public void setBar(int i, TextView storehouse_tb, TextView storehouse_jd, TextView storehouse_pdd, View storehouse_tbline, View storehouse_jdline, View storehouse_pddline) {
        storehouse_tb.setTextColor(i == 1 ? mContext.getResources().getColor(R.color.main_text_color) : mContext.getResources().getColor(R.color.black));
        storehouse_tbline.setBackgroundColor(i == 1 ? mContext.getResources().getColor(R.color.main_text_color) : mContext.getResources().getColor(R.color.white));
        storehouse_jd.setTextColor(i == 2 ? mContext.getResources().getColor(R.color.main_text_color) : mContext.getResources().getColor(R.color.black));
        storehouse_jdline.setBackgroundColor(i == 2 ? mContext.getResources().getColor(R.color.main_text_color) : mContext.getResources().getColor(R.color.white));
        storehouse_pdd.setTextColor(i == 3 ? mContext.getResources().getColor(R.color.main_text_color) : mContext.getResources().getColor(R.color.black));
        storehouse_pddline.setBackgroundColor(i == 3 ? mContext.getResources().getColor(R.color.main_text_color) : mContext.getResources().getColor(R.color.white));
    }
 
    /**
     * 分享库 数据请求失败
     *
     * @param bottom
     * @param ll_delete
     * @param ll_go_scan
     * @param ll_no_net
     * @param ll_request_failture
     * @param ll_content
     * @param tv_top_bar_right
     * @param wList
     */
    public void setSelectioStoreHouseListFail(View bottom, LinearLayout ll_delete, LinearLayout ll_go_scan, LinearLayout ll_no_net, LinearLayout ll_request_failture, LinearLayout ll_content, ToggleButton tv_top_bar_right, List<SelectionStoreHouse> wList) {
        bottom.setVisibility(View.GONE);
        if (wList.size() == 0) {
            if (NetUtils.getNetworkState(mContext).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
                requestState(3, ll_delete
                        , ll_go_scan, ll_no_net, ll_request_failture, ll_content, tv_top_bar_right);
            } else {
                requestState(2, ll_delete
                        , ll_go_scan, ll_no_net, ll_request_failture, ll_content, tv_top_bar_right);
            }
        } else {
            if (NetUtils.getNetworkState(mContext).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
                Toast.makeText(mContext, "网络未连接,请检测网络设置", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mContext, "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
            }
        }
    }
}