|
|
@@ -4,6 +4,7 @@ import android.app.Activity;
|
|
|
import android.app.ProgressDialog;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.graphics.Color;
|
|
|
@@ -33,7 +34,11 @@ 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.MainActivity;
|
|
|
+import com.usai.redant.apexdrivers.Message.MessageActivity;
|
|
|
import com.usai.redant.apexdrivers.R;
|
|
|
+import com.usai.redant.apexdrivers.Setting.SettingActivity;
|
|
|
+import com.usai.redant.apexdrivers.Utils.OperationQueue;
|
|
|
import com.usai.redant.rautils.Utils.Network;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
@@ -43,7 +48,7 @@ import org.json.JSONObject;
|
|
|
import java.lang.ref.WeakReference;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
-public class HomeFragment extends Fragment {
|
|
|
+public class HomeFragment extends Fragment implements HomeHeaderView.HomeHeaderDelegate {
|
|
|
|
|
|
public final static String HomeReloadBroadcastAction = "com.usai.redant.apexdriver.home_refresh";
|
|
|
private final static String HomeSaveDataKey = "HomeSaveDataKey";
|
|
|
@@ -61,6 +66,7 @@ public class HomeFragment extends Fragment {
|
|
|
private JSONObject mJson;
|
|
|
private HomeOrderModel mSelectedModel;
|
|
|
private TextView mEmptyView;
|
|
|
+ private HomeHeaderView mHeaderView;
|
|
|
|
|
|
@Nullable
|
|
|
@Override
|
|
|
@@ -133,6 +139,11 @@ public class HomeFragment extends Fragment {
|
|
|
}
|
|
|
});
|
|
|
mListView.setEmptyView(view.findViewById(R.id.home_empty_view));
|
|
|
+
|
|
|
+ // header
|
|
|
+ mHeaderView = HomeHeaderView.headerView(mCtx);
|
|
|
+ mHeaderView.setDelegate(this);
|
|
|
+ mListView.addHeaderView(mHeaderView);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -268,6 +279,7 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
|
Message msg = new Message();
|
|
|
msg.what = HomeHandler.HomeActionReloadData;
|
|
|
+ msg.obj = json;
|
|
|
mHandler.sendMessage(msg);
|
|
|
}
|
|
|
|
|
|
@@ -343,6 +355,82 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void updateDriverAvailable(final boolean available) {
|
|
|
+
|
|
|
+ showProgressDialog();
|
|
|
+ ApexDriverApplication.sharedApplication().getNetworkQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
|
|
|
+ @Override
|
|
|
+ public Object operationDoInBackground() {
|
|
|
+
|
|
|
+ return com.usai.redant.apexdrivers.Network.Network.updateDriverAvailable(available);
|
|
|
+ }
|
|
|
+ }, new OperationQueue.OperationCompletionCallBack() {
|
|
|
+ @Override
|
|
|
+ public void operationCompletion(Object object) {
|
|
|
+
|
|
|
+ dismissProgressDialog();
|
|
|
+
|
|
|
+ JSONObject json = (JSONObject)object;
|
|
|
+
|
|
|
+ if (json != null) {
|
|
|
+
|
|
|
+ int result = json.optInt("result");
|
|
|
+ if (result == Network.RESULT_TRUE) {
|
|
|
+
|
|
|
+ mHeaderView.setAvailable(available);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ String errMsg = json.optString("err_msg");
|
|
|
+ if (errMsg == null || errMsg.length() == 0) {
|
|
|
+ errMsg = "Sorry,there is something wrong";
|
|
|
+ }
|
|
|
+ showWarningMsg(errMsg);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ String errMsg = "Sorry,there is something wrong";
|
|
|
+
|
|
|
+ showWarningMsg(errMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ },null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void signoutClick() {
|
|
|
+ ((MainActivity)getActivity()).logout();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void settingClick() {
|
|
|
+ SettingActivity.startSettingActivity(mCtx);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void availableClick() {
|
|
|
+
|
|
|
+ final boolean available = mHeaderView.isAvailable();
|
|
|
+ String msg = "are you sure to change status to " + (available ? "Unavailable" : "Available");
|
|
|
+ new AlertDialog.Builder(mCtx)
|
|
|
+ .setTitle("Warning")
|
|
|
+ .setMessage(msg)
|
|
|
+ .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ updateDriverAvailable(!available);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setNegativeButton("Cancel",null)
|
|
|
+ .show();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void messageClick() {
|
|
|
+ MessageActivity.startMessageActivity(mCtx);
|
|
|
+ }
|
|
|
+
|
|
|
private static final class HomeHandler extends Handler {
|
|
|
|
|
|
static final int HomeActionReloadData = 0;
|
|
|
@@ -376,6 +464,14 @@ public class HomeFragment extends Fragment {
|
|
|
}
|
|
|
|
|
|
fragment.mAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ JSONObject json = (JSONObject) msg.obj;
|
|
|
+ if (json != null) {
|
|
|
+ boolean driver_available = json.optBoolean("driver_available");
|
|
|
+ if (fragment.mHeaderView != null) {
|
|
|
+ fragment.mHeaderView.setAvailable(driver_available);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case HomeActionError: {
|