Procházet zdrojové kódy

download info in main header

hanjing před 6 roky
rodič
revize
803701a779

+ 32 - 0
app/src/main/java/com/sheep/gamegroup/module/home/fragment/FgtMainHeader.java

@@ -11,6 +11,7 @@ import android.widget.TextView;
 
 import com.kfzs.duanduan.utils.NumberFormatUtils;
 import com.sheep.gamegroup.event.BigEvent;
+import com.sheep.gamegroup.greendao.download.DownLoadInfo;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.MessageUnReadEntity;
 import com.sheep.gamegroup.model.entity.UserEntity;
@@ -19,6 +20,7 @@ import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.Jump2View;
+import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.view.activity.ActMsg;
 import com.sheep.gamegroup.view.dialog.DialogNotificationOfArrival;
@@ -29,10 +31,12 @@ import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.base.BaseFragment;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
+import com.sheep.gamegroup.util.DownloadUtil;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 
+import java.util.List;
 import java.util.Locale;
 
 import butterknife.BindView;
@@ -50,6 +54,8 @@ public class FgtMainHeader extends BaseFragment {
     TextView tv_user_asset;
     @BindView(R.id.tv_msg_count)
     TextView tv_msg_count;
+    @BindView(R.id.tv_download_count)
+    TextView tv_download_count;
     @BindView(R.id.iv_flag_vip)
     ImageView iv_flag_vip;
     @BindView(R.id.v_red_dot)
@@ -92,6 +98,7 @@ public class FgtMainHeader extends BaseFragment {
     public void onViewCreated() {
         getUnReadMessageCounts();
         ViewUtil.setVisibility(v_red_dot, SpUtils.isVoucherFirst());
+        showDownloadInfo();
     }
 
     @Override
@@ -176,6 +183,22 @@ public class FgtMainHeader extends BaseFragment {
                 });
     }
 
+    public void showDownloadInfo() {
+        List<DownLoadInfo> infos = new DownloadUtil().getAllDownloadTasks();
+        int runningCount = 0;
+        for (DownLoadInfo info : infos) {
+            if (info.getMStatus() == 2) {
+                runningCount++;
+            }
+        }
+        if (runningCount > 0) {
+            ViewUtil.setText(tv_download_count, runningCount + "");
+            ViewUtil.setVisibility(tv_download_count, true);
+        } else {
+            ViewUtil.setVisibility(tv_download_count, false);
+        }
+    }
+
     @Subscribe
     public void onEventMainThread(BigEvent event) {
         switch (event.getEventTypes()) {
@@ -184,6 +207,15 @@ public class FgtMainHeader extends BaseFragment {
                     getActivity().runOnUiThread(() -> getUnReadMessageCounts());
                 }
                 break;
+            case DOWNLOAD_START:
+            case DOWNLOAD_RUNNING:
+            case DOWNLOAD_STOP:
+            case DOWNLOAD_COMPLETE:
+            case DOWNLOAD_FAIL:
+            case DOWNLOAD_CANCEL:
+                LogUtil.logI(event.getData().toString());
+                showDownloadInfo();
+                break;
         }
     }
 

+ 17 - 0
app/src/main/res/layout/fgt_main_header.xml

@@ -2,6 +2,7 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
+    android:background="@color/blue_34a6e7"
     android:layout_height="40dp">
 
     <ImageView
@@ -101,6 +102,22 @@
         android:textColor="@color/white"
         android:textSize="9sp" />
 
+    <TextView
+        android:id="@+id/tv_download_count"
+        android:layout_width="wrap_content"
+        android:layout_height="14dp"
+        android:layout_alignParentEnd="true"
+        android:layout_marginTop="8dp"
+        android:layout_marginEnd="50dp"
+        android:background="@drawable/shape_f81b5f_rec_7"
+        android:gravity="center"
+        android:minWidth="14dp"
+        android:paddingStart="4dp"
+        android:paddingEnd="4dp"
+        android:text="0"
+        android:textColor="@color/white"
+        android:textSize="9sp" />
+
     <ImageView
         android:id="@+id/iv_download"
         android:layout_width="40dp"