|
|
@@ -16,6 +16,7 @@ import android.support.constraint.ConstraintLayout;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.View;
|
|
|
import android.widget.TextView;
|
|
|
@@ -26,6 +27,7 @@ import com.blankj.utilcode.util.ActivityUtils;
|
|
|
import com.blankj.utilcode.util.AppUtils;
|
|
|
import com.blankj.utilcode.util.SPUtils;
|
|
|
import com.blankj.utilcode.util.ZipUtils;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.mtp2.tcplibs.tools.LogUtils;
|
|
|
import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
import com.zhy.http.okhttp.callback.Callback;
|
|
|
@@ -34,8 +36,14 @@ import com.zhy.http.okhttp.callback.StringCallback;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import io.reactivex.Observable;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.disposables.Disposable;
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
import mtp.polymer.com.ActivityManager;
|
|
|
import mtp.polymer.com.AddressConfig;
|
|
|
import mtp.polymer.com.EntryActivity_BAK;
|
|
|
@@ -54,6 +62,7 @@ import mtp.polymer.com.businesslayer.models.login.marketQueryBase.MarketsInfoDat
|
|
|
import mtp.polymer.com.businesslayer.models.notices.NoticeData;
|
|
|
import mtp.polymer.com.businesslayer.models.queryCommon.opeData.TradeSummaryData;
|
|
|
import mtp.polymer.com.businesslayer.models.queryCommon.qryPositionBase.DeliveryHolder;
|
|
|
+import mtp.polymer.com.businesslayer.models.queryCommon.qryPositionBase.HnMessageData;
|
|
|
import mtp.polymer.com.futures.ManageFuturesFragment;
|
|
|
import mtp.polymer.com.global.Config;
|
|
|
import mtp.polymer.com.global.Constent;
|
|
|
@@ -91,6 +100,7 @@ import mtp.polymer.com.zy_module.zymarketings.ZYMarketingFragment;
|
|
|
import okhttp3.Call;
|
|
|
import okhttp3.OkHttpClient;
|
|
|
import okhttp3.Response;
|
|
|
+import q.rorbin.badgeview.QBadgeView;
|
|
|
|
|
|
import static mtp.polymer.com.tools.TouristorToolsKt.touristorCheck;
|
|
|
|
|
|
@@ -140,6 +150,8 @@ public class MainActivity extends MyAppCompatActivity implements View.OnClickLis
|
|
|
|
|
|
private ConstraintLayout p_bottom; //底部栏
|
|
|
private View p_line; //底部栏上面的view
|
|
|
+ private Timer noticeTimer; //公告的计时器
|
|
|
+ private QBadgeView qBadgeView ;
|
|
|
//endregion
|
|
|
|
|
|
//region 数据
|
|
|
@@ -164,7 +176,7 @@ public class MainActivity extends MyAppCompatActivity implements View.OnClickLis
|
|
|
initListener();
|
|
|
initQuery();
|
|
|
getNetIp();
|
|
|
-
|
|
|
+ timeLoop();
|
|
|
}
|
|
|
|
|
|
private void getNetIp(){
|
|
|
@@ -225,6 +237,151 @@ public class MainActivity extends MyAppCompatActivity implements View.OnClickLis
|
|
|
PolApplication.myAppCompatActivity = this;
|
|
|
}
|
|
|
|
|
|
+ private static final int PERIOD = 10 * 1000;
|
|
|
+ private static final int DELAY = 100;
|
|
|
+ private Disposable mDisposable;
|
|
|
+ /**
|
|
|
+ * 定时循环任务
|
|
|
+ */
|
|
|
+ private void timeLoop() {
|
|
|
+ mDisposable = Observable.interval(DELAY, PERIOD, TimeUnit.MILLISECONDS)
|
|
|
+ .map((aLong -> aLong + 1))
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(aLong -> queryNotice());//getUnreadCount()执行的任务
|
|
|
+ }
|
|
|
+//关闭定时任务
|
|
|
+//if (mDisposable != null) mDisposable.dispose();
|
|
|
+
|
|
|
+ private void startQueryNotice(){
|
|
|
+ com.blankj.utilcode.util.LogUtils.eTag("dasjdklajdsklasd","3");
|
|
|
+ if (noticeTimer != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ noticeTimer = new Timer();
|
|
|
+ try {
|
|
|
+ int delay = PolApplication.getInstance().getNoticeRandom() * 1000;
|
|
|
+ int perId = PolApplication.getInstance().getNoticeRandom() * 1000;
|
|
|
+ noticeTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ com.blankj.utilcode.util.LogUtils.eTag("dasjdklajdsklasd","1");
|
|
|
+ queryNotice();
|
|
|
+ }
|
|
|
+ },delay, perId);
|
|
|
+ } catch (Exception e ) {
|
|
|
+ com.blankj.utilcode.util.LogUtils.eTag("dasjdklajdsklasd",e);
|
|
|
+ e.printStackTrace();
|
|
|
+ noticeTimer = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void queryNotice(){
|
|
|
+ com.blankj.utilcode.util.LogUtils.eTag("dasjdklajdsklasd","2");
|
|
|
+ String loginid = "0";
|
|
|
+ if (GlobalDataCollention.getInstance().isTouristor()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ loginid = SPUtils.getInstance().getString(Constent.LOGINID);
|
|
|
+ ArrayList<HnMessageData.dataList> hnmessageList = GlobalDataCollention.getInstance().getHnmessageDataList();
|
|
|
+
|
|
|
+ if (hnmessageList.isEmpty()){
|
|
|
+ OkHttpUtils.get()
|
|
|
+ .url(AddressConfig.AUTH_GO_URL + "/Common/QueryNotice?")
|
|
|
+ .addParams("loginID",loginid)
|
|
|
+ .addHeader("Authorization", SPUtils.getInstance().getString("token"))
|
|
|
+ .build()
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(String response, int id) {
|
|
|
+ com.blankj.utilcode.util.LogUtils.eTag("dasjdklajdsklasd",response);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ HnMessageData data = gson.fromJson(response,HnMessageData.class);
|
|
|
+ ArrayList<HnMessageData.dataList> hnmessageList = GlobalDataCollention.getInstance().getHnmessageDataList();
|
|
|
+ hnmessageList.clear();
|
|
|
+ hnmessageList.addAll(data.getData());
|
|
|
+ Message message = handlermessage.obtainMessage();
|
|
|
+ message.what = 0;
|
|
|
+ message.sendToTarget();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ String lastID = hnmessageList.get(hnmessageList.size() - 1).getAutoid();
|
|
|
+ com.blankj.utilcode.util.LogUtils.eTag("dasjdklajdsklasdlastID",lastID);
|
|
|
+ OkHttpUtils.get()
|
|
|
+ .url(AddressConfig.AUTH_GO_URL + "/Common/QueryNotice?")
|
|
|
+ .addParams("loginID",loginid)
|
|
|
+ .addHeader("Authorization", SPUtils.getInstance().getString("token"))
|
|
|
+ .addParams("lastID",lastID)
|
|
|
+ .build()
|
|
|
+ .execute(new StringCallback() {
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(String response, int id) {
|
|
|
+ com.blankj.utilcode.util.LogUtils.eTag("dasjdklajdsklasd",response);
|
|
|
+ Gson gson = new Gson();
|
|
|
+ HnMessageData data = gson.fromJson(response,HnMessageData.class);
|
|
|
+ if (!data.getData().isEmpty()){
|
|
|
+ //反正只是暂存的公告
|
|
|
+ ArrayList<HnMessageData.dataList> hnmessageList = GlobalDataCollention.getInstance().getHnmessageDataList();
|
|
|
+ hnmessageList.addAll(data.getData());
|
|
|
+ refrashNotice();
|
|
|
+ Message message = handlermessage.obtainMessage();
|
|
|
+ message.what = 0;
|
|
|
+ message.sendToTarget();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Handler handlermessage = new Handler(Looper.myLooper()) {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ switch (msg.what) {
|
|
|
+ case 0:
|
|
|
+ showNoReadNotice();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ super.handleMessage(msg);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void showNoReadNotice(){
|
|
|
+ ArrayList<HnMessageData.dataList> hnmessageList = GlobalDataCollention.getInstance().getHnmessageDataList();
|
|
|
+ Boolean hasUnRead = false;
|
|
|
+ for (int j=0;j<hnmessageList.size();j++){
|
|
|
+ if (!hnmessageList.get(j).getReaded()){
|
|
|
+ hasUnRead = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hasUnRead){
|
|
|
+ qBadgeView.setVisibility(View.VISIBLE);
|
|
|
+ }else {
|
|
|
+ qBadgeView.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ if (mDisposable != null) {
|
|
|
+ mDisposable.dispose();
|
|
|
+ mDisposable = null; //noticeTimer释放
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// endregion
|
|
|
|
|
|
//region 功能函数
|
|
|
@@ -273,6 +430,9 @@ public class MainActivity extends MyAppCompatActivity implements View.OnClickLis
|
|
|
p_optionquery = findViewById(R.id.p_optionquery);
|
|
|
p_shoppssssing = findViewById(R.id.p_shoppssssing);
|
|
|
p_open = findViewById(R.id.p_open);
|
|
|
+ qBadgeView = new QBadgeView(this);
|
|
|
+ qBadgeView.bindTarget(p_query).setBadgeBackground(getDrawable(R.drawable.hn_main_cercle_red_bg)).setBadgeGravity(Gravity.TOP | Gravity.END).setGravityOffset(80,0,false).setBadgeText("");
|
|
|
+ qBadgeView.setVisibility(View.GONE);
|
|
|
if (Config.ZYSTATE) {
|
|
|
p_warehouse_receipt.setText(R.string.p_marketing);
|
|
|
// 中远显示期权单据,改字为定货
|
|
|
@@ -1228,7 +1388,10 @@ public class MainActivity extends MyAppCompatActivity implements View.OnClickLis
|
|
|
loadHnGoodsFragment(select);
|
|
|
}
|
|
|
|
|
|
- public void toNotice(){
|
|
|
- loadHnMessageFragment();
|
|
|
+ public void refrashNotice(){
|
|
|
+
|
|
|
+ if (messageFragment != null) {
|
|
|
+ messageFragment.refrashList();
|
|
|
+ }
|
|
|
}
|
|
|
}
|