|
|
@@ -1,5 +1,6 @@
|
|
|
package com.usai.redant.apexdrivers.Home;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
import android.app.ProgressDialog;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
@@ -11,6 +12,7 @@ import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
|
+import android.support.constraint.ConstraintLayout;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
@@ -29,6 +31,7 @@ import android.widget.TextView;
|
|
|
|
|
|
|
|
|
import com.usai.redant.apexdrivers.ApexDriverApplication;
|
|
|
+import com.usai.redant.apexdrivers.BadgeView.BadgeView;
|
|
|
import com.usai.redant.apexdrivers.Detail.DetailActivity;
|
|
|
import com.usai.redant.apexdrivers.R;
|
|
|
import com.usai.redant.rautils.Utils.Network;
|
|
|
@@ -45,6 +48,8 @@ public class HomeFragment extends Fragment {
|
|
|
public final static String HomeReloadBroadcastAction = "com.usai.redant.apexdriver.home_refresh";
|
|
|
private final static String HomeSaveDataKey = "HomeSaveDataKey";
|
|
|
|
|
|
+ private final static int REQUEST_MORE_CODE = 0;
|
|
|
+
|
|
|
private Context mCtx;
|
|
|
private HomeFragment self = this;
|
|
|
private ExpandableListView mListView;
|
|
|
@@ -98,6 +103,11 @@ public class HomeFragment extends Fragment {
|
|
|
mSelectedModel.setSelection(true);
|
|
|
}
|
|
|
|
|
|
+ if (orderModel.getBackendFlag()) {
|
|
|
+ orderModel.setBackendFlag(!orderModel.getBackendFlag());
|
|
|
+ sectionModel.setBackendFlagCount(--sectionModel.backendFlagCount);
|
|
|
+ }
|
|
|
+
|
|
|
Intent intent = DetailActivity.build(mCtx,orderModel.orderID,orderModel.status,orderModel.order_type2);
|
|
|
mCtx.startActivity(intent);
|
|
|
|
|
|
@@ -154,6 +164,24 @@ public class HomeFragment extends Fragment {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+
|
|
|
+ if (requestCode == REQUEST_MORE_CODE) {
|
|
|
+
|
|
|
+ if (requestCode == Activity.RESULT_OK && data != null) {
|
|
|
+
|
|
|
+ boolean reload = data.getBooleanExtra("reload",false);
|
|
|
+ if (reload) {
|
|
|
+ loadData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
@@ -210,13 +238,14 @@ public class HomeFragment extends Fragment {
|
|
|
for (int i = 0; i < sectionArr.length(); i++) {
|
|
|
|
|
|
JSONObject section = sectionArr.getJSONObject(i);
|
|
|
- HomeSectionModel model = new HomeSectionModel();
|
|
|
+ HomeSectionModel model = new HomeSectionModel(mCtx);
|
|
|
model.section = i;
|
|
|
|
|
|
model.type = section.optInt("type");
|
|
|
model.title = section.optString("title");
|
|
|
model.setOrders(section.optJSONArray("orders"));
|
|
|
model.totalCount = section.optInt("totalCount",0);
|
|
|
+ model.backendFlagCount = section.optInt("backendFlagCount");
|
|
|
|
|
|
mSectionArray.add(model);
|
|
|
}
|
|
|
@@ -356,15 +385,17 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
|
private class HomeListAdapter extends BaseExpandableListAdapter {
|
|
|
|
|
|
- private class SectionHeaderHolder implements View.OnClickListener{
|
|
|
+ private class SectionHeaderHolder implements View.OnClickListener,HomeSectionModel.SectionModelListener{
|
|
|
|
|
|
TextView titleTv;
|
|
|
+ BadgeView badgeView;
|
|
|
Button expandBtn;
|
|
|
WeakReference<HomeSectionModel> weakSectionModel;
|
|
|
|
|
|
SectionHeaderHolder(View view) {
|
|
|
|
|
|
titleTv = view.findViewById(R.id.header_title_tv);
|
|
|
+ badgeView = view.findViewById(R.id.header_badge_tv);
|
|
|
expandBtn = view.findViewById(R.id.section_switch_btn);
|
|
|
expandBtn.setOnClickListener(this);
|
|
|
expandBtn.setText("More");
|
|
|
@@ -373,14 +404,18 @@ public class HomeFragment extends Fragment {
|
|
|
}
|
|
|
|
|
|
void bindSectionModel(HomeSectionModel model) {
|
|
|
-
|
|
|
- titleTv.setText(model.title);
|
|
|
- if (model.hasMore()) {
|
|
|
- expandBtn.setVisibility(View.VISIBLE);
|
|
|
+ if (weakSectionModel != null && weakSectionModel.get() != null) {
|
|
|
+ weakSectionModel.get().listener = null;
|
|
|
+ }
|
|
|
+ if (model == null) {
|
|
|
+ weakSectionModel = null;
|
|
|
} else {
|
|
|
- expandBtn.setVisibility(View.GONE);
|
|
|
+ weakSectionModel = new WeakReference<>(model);
|
|
|
+ }
|
|
|
+ if (weakSectionModel != null) {
|
|
|
+ weakSectionModel.get().listener = this;
|
|
|
}
|
|
|
- weakSectionModel = new WeakReference<>(model);
|
|
|
+ refresh();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -389,7 +424,31 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
|
Intent intent = HomeMoreActivity.build(mCtx,sectionModel.type,sectionModel.title);
|
|
|
|
|
|
- startActivity(intent);
|
|
|
+ startActivityForResult(intent,REQUEST_MORE_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void refresh() {
|
|
|
+
|
|
|
+ HomeSectionModel model = null;
|
|
|
+ if (weakSectionModel != null) {
|
|
|
+ model = weakSectionModel.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (model != null) {
|
|
|
+ titleTv.setText(model.title);
|
|
|
+ badgeView.setBadgeCount(model.backendFlagCount);
|
|
|
+ if (model.hasMore()) {
|
|
|
+ expandBtn.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ expandBtn.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ titleTv.setText(null);
|
|
|
+ expandBtn.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -530,13 +589,34 @@ public class HomeFragment extends Fragment {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private class HomeSectionModel {
|
|
|
+ private static class HomeSectionModel {
|
|
|
+
|
|
|
+ public interface SectionModelListener {
|
|
|
+ void refresh();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
int type; // OrderStatus
|
|
|
ArrayList<HomeOrderModel> orders;
|
|
|
String title;
|
|
|
int section;
|
|
|
long totalCount;
|
|
|
+ int backendFlagCount;
|
|
|
+ SectionModelListener listener;
|
|
|
+
|
|
|
+ private Context mContext;
|
|
|
+ public HomeSectionModel(Context context) {
|
|
|
+ mContext = context;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setBackendFlagCount(int count) {
|
|
|
+ backendFlagCount = count;
|
|
|
+
|
|
|
+ if (listener != null) {
|
|
|
+ listener.refresh();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
int orderCount() {
|
|
|
if (orders == null) {
|
|
|
@@ -559,7 +639,7 @@ public class HomeFragment extends Fragment {
|
|
|
for (int i = 0; i < orders.length(); i++) {
|
|
|
JSONObject order = orders.optJSONObject(i);
|
|
|
if (order != null) {
|
|
|
- HomeOrderModel model = new HomeOrderModel(mCtx);
|
|
|
+ HomeOrderModel model = new HomeOrderModel(mContext);
|
|
|
model.status = order.optInt("status",0);
|
|
|
model.title = order.optString("title");
|
|
|
model.orderNo = order.optString("orderNo");
|
|
|
@@ -568,6 +648,7 @@ public class HomeFragment extends Fragment {
|
|
|
model.orderID = order.optString("orderID");
|
|
|
model.order_type2 = order.optString("order_type2");
|
|
|
model.setIconURL(order.optString("iconURL"));
|
|
|
+ model.setBackendFlag(order.optBoolean("backendFlag"));
|
|
|
|
|
|
orderArr.add(model);
|
|
|
}
|