From d9693d58742d6f55e34873e7aad6811ce131b490 Mon Sep 17 00:00:00 2001 From: ZLAA <72907523+zlaazlaa@users.noreply.github.com> Date: Sat, 24 Sep 2022 19:09:38 +0800 Subject: [PATCH] =?UTF-8?q?1.5=20=E6=94=B9=E7=89=88=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=EF=BC=8C=E8=BF=94=E5=9B=9E=E7=9C=9F=E5=AE=9E?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=8F=82=E6=95=B0=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/gradle.xml | 3 +- .idea/misc.xml | 5 +- app/src/main/AndroidManifest.xml | 3 + .../java/com/example/meiyong/GPSGetClass.kt | 2 +- .../java/com/example/meiyong/MainActivity.kt | 4 +- .../java/com/example/meiyong/ManageOrders.kt | 24 +- .../com/example/meiyong/NewNobodyCarOrder.kt | 146 +++++++++++ .../OrderCancelReturn/OrderCancelReturn.kt | 7 + .../OrderCreateReturn/OrderCreateReturn.kt | 7 + .../java/com/example/meiyong/SendExpress.kt | 6 +- .../java/com/example/meiyong/data/Data.kt | 73 ++++-- .../example/meiyong/data/LoginDataSource.kt | 1 + .../example/meiyong/ui/home/HomeFragment.kt | 7 +- app/src/main/java/http/OkHttp.kt | 3 +- .../layout/activity_new_nobody_car_order.xml | 236 ++++++++++++++++++ .../main/res/layout/activity_send_express.xml | 2 +- app/src/main/res/values/colors.xml | 1 + 17 files changed, 488 insertions(+), 42 deletions(-) create mode 100644 app/src/main/java/com/example/meiyong/NewNobodyCarOrder.kt create mode 100644 app/src/main/java/com/example/meiyong/ReturnDataClass/OrderCancelReturn/OrderCancelReturn.kt create mode 100644 app/src/main/java/com/example/meiyong/ReturnDataClass/OrderCreateReturn/OrderCreateReturn.kt create mode 100644 app/src/main/res/layout/activity_new_nobody_car_order.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index e9969a1..6e5389e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -7,14 +7,13 @@ - diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b67fce..46d6bbc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,9 +12,10 @@ + - + @@ -33,7 +34,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b6dc18a..26ffc16 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,9 @@ android:supportsRtl="true" android:theme="@style/Theme.Meiyong" android:usesCleartextTraffic="true"> + diff --git a/app/src/main/java/com/example/meiyong/GPSGetClass.kt b/app/src/main/java/com/example/meiyong/GPSGetClass.kt index 5a79db0..242672d 100644 --- a/app/src/main/java/com/example/meiyong/GPSGetClass.kt +++ b/app/src/main/java/com/example/meiyong/GPSGetClass.kt @@ -46,7 +46,7 @@ class GPSGetClass { .add("coorType", "bd09ll")//BaiduMap // .add("coorType", "GCJ02")//GoogleMap // .add("token", GPSLoginInformation.data.token) - .add("token", "8e1f56bf0e78669fdf774c91c55ed0f147047d1eb4b2ecf7284c90924c0b30ff") + .add("token", GPSLoginInformation.data.token) .build() http.GPSOkHttp.post("/locator-app/redis/getGps", GetGPSFormBody, object : Callback { override fun onFailure(call: Call, e: IOException) { diff --git a/app/src/main/java/com/example/meiyong/MainActivity.kt b/app/src/main/java/com/example/meiyong/MainActivity.kt index 1747981..4fe9d36 100644 --- a/app/src/main/java/com/example/meiyong/MainActivity.kt +++ b/app/src/main/java/com/example/meiyong/MainActivity.kt @@ -54,8 +54,8 @@ class MainActivity : AppCompatActivity() { setupActionBarWithNavController(navController, appBarConfiguration) navView.setupWithNavController(navController) -// val GPSSSS = GPSGetClass() -// GPSSSS.LoginGPS() + val GPSSSS = GPSGetClass() + GPSSSS.LoginGPS() // GetAMapWrapper().getAMapWrapper(this) diff --git a/app/src/main/java/com/example/meiyong/ManageOrders.kt b/app/src/main/java/com/example/meiyong/ManageOrders.kt index 5b4e468..12eda3a 100644 --- a/app/src/main/java/com/example/meiyong/ManageOrders.kt +++ b/app/src/main/java/com/example/meiyong/ManageOrders.kt @@ -17,6 +17,7 @@ import android.widget.Toast import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.example.meiyong.MyApplication.Companion.context +import com.example.meiyong.ReturnDataClass.OrderCancelReturn.OrderCancelReturn import com.example.meiyong.ReturnDataClass.OrderListReturn.OrderListReturn import com.example.meiyong.ReturnDataClass.OrderReturn.Body import com.google.android.material.button.MaterialButton @@ -87,11 +88,14 @@ class ManageOrders : AppCompatActivity() { val view = LayoutInflater.from(parent.context) .inflate(R.layout.order_information_card, parent, false) val viewHolder = ViewHolder(view) + viewHolder.cuiOrder.setOnClickListener { + Toast.makeText(context, "催促成功,将优先安排配送", Toast.LENGTH_LONG).show() + } viewHolder.cancelOrder.setOnClickListener { val jsonObject = JSONObject() val id = viewHolder.orderId.text.toString().toLong() val status = viewHolder.orderStatus.text.toString() - if (status.toInt() <= 3) { + if (status.toInt() <= -1) { Toast.makeText(context, "订单未在派送", Toast.LENGTH_LONG).show() } else { jsonObject @@ -103,11 +107,23 @@ class ManageOrders : AppCompatActivity() { } override fun onResponse(call: Call, response: Response) { - val responseData = response.body.toString() + val responseData = response.body?.string() Looper.prepare() - Toast.makeText(context, responseData, Toast.LENGTH_LONG).show() + val gson = Gson() + + if (responseData != null) { + val orderCancelReturn = + gson.fromJson(responseData, OrderCancelReturn::class.java) + var text = "" + if (orderCancelReturn.status == 200) { + text = "取消成功" + } else { + text = "订单当前状态不允许取消" + } + Toast.makeText(context, text, Toast.LENGTH_LONG).show() + Log.e("OKHTTP_CANCEL_ORDER", responseData) + } Looper.loop() - Log.e("OKHTTP_CANCEL_ORDER", responseData) } }) diff --git a/app/src/main/java/com/example/meiyong/NewNobodyCarOrder.kt b/app/src/main/java/com/example/meiyong/NewNobodyCarOrder.kt new file mode 100644 index 0000000..3b46528 --- /dev/null +++ b/app/src/main/java/com/example/meiyong/NewNobodyCarOrder.kt @@ -0,0 +1,146 @@ +package com.example.meiyong + +import android.annotation.SuppressLint +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.os.Looper +import android.util.Log +import android.widget.ImageButton +import android.widget.LinearLayout +import android.widget.TextView +import android.widget.Toast +import androidx.appcompat.app.AlertDialog +import com.example.meiyong.MyApplication.Companion.context +import com.example.meiyong.ReturnDataClass.OrderCancelReturn.OrderCancelReturn +import com.example.meiyong.ReturnDataClass.OrderCreateReturn.OrderCreateReturn +import com.example.meiyong.ReturnDataClass.OrderListReturn.OrderListReturn +import com.google.android.material.button.MaterialButton +import com.google.gson.Gson +import http.OkHttp +import okhttp3.Call +import okhttp3.Callback +import okhttp3.Response +import org.json.JSONObject +import org.w3c.dom.Text +import java.io.IOException + +class NewNobodyCarOrder : AppCompatActivity() { + private val item_address = + arrayOf("梅苑", "兰苑", "竹苑", "菊苑", "桃苑", "李苑", "柳苑", "桂苑", "荷苑", "樱苑", "青教") + + private val item_time = + arrayOf("9:00-11:00", "11:00-13:00", "13:00-15:00", "15:00-17:00", "17:00-19:00") + + @SuppressLint("CutPasteId") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_new_nobody_car_order) + findViewById(R.id.detail_address_textview).text = item_address[0] + findViewById(R.id.set_time_linear).setOnClickListener { + setTime() + } + findViewById(R.id.detail_address).setOnClickListener { + alertDialogListen() + } + findViewById(R.id.set_adress).setOnClickListener { + alertDialogListen() + } + findViewById(R.id.confirm_address).setOnClickListener { + val receiveName = findViewById(R.id.name).text + val receivePhone = findViewById(R.id.phone_number_to_send).text + val packagePos = + findViewById(R.id.Pos1).text.toString() + "-" + findViewById(R.id.Pos2).text.toString() + "-" + findViewById( + R.id.Pos3 + ).text.toString() + val jsonObjects = JSONObject() + jsonObjects + .put("userId", UserInformation.userId) + .put("expectedTime", findViewById(R.id.time_set_is).text.toString()) + .put("deliveryAddress", 2) + .put("receiverName", receiveName.toString()) + .put("phone", receivePhone.toString().toLong()) +// .put("deliveryAddress", 1) + .put("packagePos", packagePos) + .put("stationId", 2) + .put("status", 1) + OkHttp.post("/Order", jsonObjects, object : Callback { + override fun onFailure(call: Call, e: IOException) { + Toast.makeText(context, "网络连接错误,请检查本地网络连接", Toast.LENGTH_LONG).show() + Log.e("OKHTTP_NEW_ORDER", e.toString()) + } + + override fun onResponse(call: Call, response: Response) { + Looper.prepare() + val responseData = response.body?.string() + val gson = Gson() + if (responseData != null) { + Log.e("OKHTTP_NEW_ORDER", responseData) + val returnData = gson.fromJson(responseData, OrderCreateReturn::class.java) + if (returnData.status == 500) { + Toast.makeText(context, "驿站正在休息,请稍后再试", Toast.LENGTH_LONG).show() + } else { + Toast.makeText(context, "订单创建成功", Toast.LENGTH_LONG).show() + finish() + } + } + Looper.loop() + } + }) + } + } + + fun alertDialogListen() { + val txt = findViewById(R.id.detail_address_textview) + var nowNumber = 0 + for ((i, e) in item_address.withIndex()) + if (e == txt.text) { + nowNumber = i + break + } + val alertDialog = AlertDialog.Builder(this) + .setTitle("请选择") //默认为0表示选中第一个项目 + .setSingleChoiceItems( + item_address, nowNumber + ) { dialog, which -> + txt.text = item_address[which] +// Toast.makeText(this@SendExpress, "你单选了" + item[which], Toast.LENGTH_LONG).show() + } + .setPositiveButton( + "确认" + ) { dialog, which -> +// txt.setText(item[which]) + } + .setNegativeButton("取消") { dialog, which -> + txt.text = item_address[nowNumber] + } + .create() + alertDialog.show() + } + + private fun setTime() { + val txt = findViewById(R.id.time_set_is) + var nowNumber = 0 + for ((i, e) in item_time.withIndex()) + if (e == txt.text) { + nowNumber = i + break + } + val alertDialog = android.app.AlertDialog.Builder(this) + .setTitle("请选择") //默认为0表示选中第一个项目 + .setSingleChoiceItems( + item_time, nowNumber + ) { dialog, which -> + txt.text = item_time[which] +// Toast.makeText(this@SendExpress, "你单选了" + item[which], Toast.LENGTH_LONG).show() + } + .setPositiveButton( + "确认" + ) { dialog, which -> + } + .setNegativeButton("取消") { dialog, which -> + txt.text = item_time[nowNumber] + } + .create() + alertDialog.show() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/meiyong/ReturnDataClass/OrderCancelReturn/OrderCancelReturn.kt b/app/src/main/java/com/example/meiyong/ReturnDataClass/OrderCancelReturn/OrderCancelReturn.kt new file mode 100644 index 0000000..6861f0d --- /dev/null +++ b/app/src/main/java/com/example/meiyong/ReturnDataClass/OrderCancelReturn/OrderCancelReturn.kt @@ -0,0 +1,7 @@ +package com.example.meiyong.ReturnDataClass.OrderCancelReturn + +class OrderCancelReturn( + val status: Int, + val err: String?, + val body: String? +) \ No newline at end of file diff --git a/app/src/main/java/com/example/meiyong/ReturnDataClass/OrderCreateReturn/OrderCreateReturn.kt b/app/src/main/java/com/example/meiyong/ReturnDataClass/OrderCreateReturn/OrderCreateReturn.kt new file mode 100644 index 0000000..93d9c68 --- /dev/null +++ b/app/src/main/java/com/example/meiyong/ReturnDataClass/OrderCreateReturn/OrderCreateReturn.kt @@ -0,0 +1,7 @@ +package com.example.meiyong.ReturnDataClass.OrderCreateReturn + +class OrderCreateReturn( + val status: Int, + val err: String?, + val body: Int? +) \ No newline at end of file diff --git a/app/src/main/java/com/example/meiyong/SendExpress.kt b/app/src/main/java/com/example/meiyong/SendExpress.kt index 17c643f..eec588b 100644 --- a/app/src/main/java/com/example/meiyong/SendExpress.kt +++ b/app/src/main/java/com/example/meiyong/SendExpress.kt @@ -59,18 +59,18 @@ class SendExpress : AppCompatActivity() { val jsonObjects = JSONObject() jsonObjects - .put("userId", UserInformation.userId.toString()) + .put("userId", UserInformation.userId) .put("expectedTime", findViewById(R.id.time_set_is).text.toString()) .put("deliveryAddress", 2) .put("receiverName", receiveName.toString()) - .put("phone", receivePhone.toString()) + .put("phone", receivePhone.toString().toInt()) // .put("deliveryAddress", 1) .put("packagePos", "25-5-4") .put("stationId", 2) .put("status",1) OkHttp.post("/Order", jsonObjects, object : Callback { override fun onFailure(call: Call, e: IOException) { - TODO("Not yet implemented") +// TODO("Not yet implemented") Log.e("OKHTTP_NEW_ORDER", e.toString()) } diff --git a/app/src/main/java/com/example/meiyong/data/Data.kt b/app/src/main/java/com/example/meiyong/data/Data.kt index 8775f7e..e1d526d 100644 --- a/app/src/main/java/com/example/meiyong/data/Data.kt +++ b/app/src/main/java/com/example/meiyong/data/Data.kt @@ -1,8 +1,14 @@ package com.example.meiyong.data +import android.os.Looper import android.util.Log -import com.example.meiyong.ReceiveClass.StudyjsonData +import android.widget.Toast +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.example.meiyong.MyApplication +import com.example.meiyong.R import com.example.meiyong.ReceiveClass.StudyjsonExpressData +import com.example.meiyong.ReturnDataClass.OrderListReturn.OrderListReturn import com.google.gson.Gson import http.OkHttp import okhttp3.Call @@ -19,28 +25,57 @@ class Data { "http://123.56.232.18:8080/serverdemo/tag/queryTagList?offset=1231321&pageCount=10&tagId=3&tagType=all&userId=33" fun updateExpressData() { - expressList.clear() - OkHttp.sendOkHttpRequestGET(StudyAPIurl, object : Callback { + OkHttp.get("/Order/1/100", object : Callback { + override fun onFailure(call: Call, e: IOException) { + Log.e("OKHTTP_ORDER", e.toString()) + } + override fun onResponse(call: Call, response: Response) { - val gson = Gson() - val responseData = response.body?.string() -// val typeOf = object : TypeToken>() {}.type - Log.e("OKHTTP", "$responseData") - val express_list = gson.fromJson(responseData, StudyjsonData::class.java) - expressList.clear() - for ((cnt, ex) in express_list.data.data.withIndex()) { - expressList.add(cnt, ex) - } - -// val express_list = gson.fromJson(responseData, queryOrder::class.java) -// for ((cnt, ex) in express_list) { -// expressList.add(cnt, ex) +// val responseData = response.body?.string() +// val gson = Gson() +// val orderReturn = gson.fromJson(responseData, OrderListReturn::class.java) +// Log.e("OKHTTP_GSON", "$responseData") +// if (orderReturn.status == 200) { +// expressList = orderReturn.body!! +// val recyclerView = findViewById(R.id.orders_list) +// recyclerView.layoutManager = LinearLayoutManager(MyApplication.context) +// recyclerView.adapter = OrderListAdapter() +// } else { +// Looper.prepare(); +// Toast.makeText(MyApplication.context, "用户未登录", Toast.LENGTH_LONG).show() +// finish() +// Looper.loop() +// // } } - override fun onFailure(call: Call, e: IOException) { - Log.e("OKHTTP", "ERROR") - } }) } + + +// fun updateExpressData() { +// expressList.clear() +// OkHttp.sendOkHttpRequestGET(StudyAPIurl, object : Callback { +// override fun onResponse(call: Call, response: Response) { +// val gson = Gson() +// val responseData = response.body?.string() +//// val typeOf = object : TypeToken>() {}.type +// Log.e("OKHTTP", "$responseData") +// val express_list = gson.fromJson(responseData, OrderListReturn::class.java) +// expressList.clear() +// for ((cnt, ex) in express_list.data.data.withIndex()) { +// expressList.add(cnt, ex) +// } +// +//// val express_list = gson.fromJson(responseData, queryOrder::class.java) +//// for ((cnt, ex) in express_list) { +//// expressList.add(cnt, ex) +//// } +// } +// +// override fun onFailure(call: Call, e: IOException) { +// Log.e("OKHTTP", "ERROR") +// } +// }) +// } } \ No newline at end of file diff --git a/app/src/main/java/com/example/meiyong/data/LoginDataSource.kt b/app/src/main/java/com/example/meiyong/data/LoginDataSource.kt index bce22f9..e58cc8d 100644 --- a/app/src/main/java/com/example/meiyong/data/LoginDataSource.kt +++ b/app/src/main/java/com/example/meiyong/data/LoginDataSource.kt @@ -41,6 +41,7 @@ class LoginDataSource { if (loginReturn.status == 200) { tag = 1 // TODO("添加userID") + UserInformation.userId = loginReturn.body.userId } else { tag = 0 } diff --git a/app/src/main/java/com/example/meiyong/ui/home/HomeFragment.kt b/app/src/main/java/com/example/meiyong/ui/home/HomeFragment.kt index 1b22902..c5b83c8 100644 --- a/app/src/main/java/com/example/meiyong/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/example/meiyong/ui/home/HomeFragment.kt @@ -30,11 +30,6 @@ class HomeFragment : Fragment() { val StudyAPIurl = "http://123.56.232.18:8080/serverdemo/tag/queryTagList?offset=1231321&pageCount=10&tagId=3&tagType=all&userId=33" - val SunAPIurl = "http://192.168.0.127:80/Order" - - val PanAPIurl = "http://192.168.0.114:8081/api/tbSendOrder/list" - - val YuAPIurl = "http://192.168.0.112:8081/api/tbPickOrder/list" private var expressList = ArrayList() private var _binding: FragmentHomeBinding? = null @@ -303,7 +298,7 @@ class HomeFragment : Fragment() { } view?.findViewById(R.id.btn2)?.setOnClickListener { - val intent = Intent(activity, SendExpress::class.java) + val intent = Intent(activity, NewNobodyCarOrder::class.java) startActivity(intent) } } diff --git a/app/src/main/java/http/OkHttp.kt b/app/src/main/java/http/OkHttp.kt index 3a0c0da..8e01df7 100644 --- a/app/src/main/java/http/OkHttp.kt +++ b/app/src/main/java/http/OkHttp.kt @@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit object OkHttp { - private const val BASE_URL = "http://192.168.0.140:80" + private const val BASE_URL = "http://zlaaa.top:8088" // private const val BASE_URL = "http://192.168.0.114:8081" private var url1: String = "" @@ -143,6 +143,5 @@ object OkHttp { client.newCall(request).enqueue(callback) } - } diff --git a/app/src/main/res/layout/activity_new_nobody_car_order.xml b/app/src/main/res/layout/activity_new_nobody_car_order.xml new file mode 100644 index 0000000..743e233 --- /dev/null +++ b/app/src/main/res/layout/activity_new_nobody_car_order.xml @@ -0,0 +1,236 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_send_express.xml b/app/src/main/res/layout/activity_send_express.xml index d555524..33d2419 100644 --- a/app/src/main/res/layout/activity_send_express.xml +++ b/app/src/main/res/layout/activity_send_express.xml @@ -424,7 +424,7 @@ #FF000000 #FFFFFFFF #02C39A + #808080 \ No newline at end of file