增加 - 通知跳转查询数据

master
wangh 6 months ago
parent ecdd0d15a9
commit 6d749568ef

@ -10,8 +10,8 @@ android {
applicationId "com.example.aucma_mes" applicationId "com.example.aucma_mes"
minSdk 24 minSdk 24
targetSdk 33 targetSdk 33
versionCode 11 versionCode 12
versionName "1.11" versionName "1.12"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

@ -5,7 +5,6 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application <application
@ -20,10 +19,15 @@
android:theme="@style/Theme.Aucmames" android:theme="@style/Theme.Aucmames"
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name=".InfoListActivity"
android:exported="false"
android:label="降级信息查询" />
<service <service
android:name=".service.MyService" android:name=".service.MyService"
android:enabled="true" android:enabled="true"
android:exported="true"/> android:exported="true" />
<activity <activity
android:name=".UnbindActivity" android:name=".UnbindActivity"

@ -0,0 +1,70 @@
package com.example.aucma_mes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import com.example.aucma_mes.adapter.RecordAdapter;
import com.example.aucma_mes.base.BaseActivity;
import com.example.aucma_mes.databinding.ActivityInfoListBinding;
import com.example.aucma_mes.entity.RecordExceptionProcess;
import com.example.aucma_mes.entity.Result;
import com.example.aucma_mes.utils.MyRecultCall;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import java.util.List;
public class InfoListActivity extends BaseActivity {
private ActivityInfoListBinding binding;
private RecordAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_info_list);
adapter=new RecordAdapter(this);
binding.setAdapter(adapter);
infoSelect( "2" );
}
@Override
protected void sanInfo(String code) {
}
public void infoSelect(View view) {
var s = binding.infoSpinner.getSelectedItem().toString();
infoSelect(s.equals("否") ? "2" : "1");
}
private void infoSelect(String inspectionUserFlag) {
OkGo.<Result>post(url + "/api/downgradeQuery")
.tag(this)
.params("inspectionUserFlag",inspectionUserFlag )
.execute(new MyRecultCall(dialog, this) {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onSuccess(Response<Result> response) {
super.onSuccess(response);
var body = response.body();
if (body.getCode()==200){
List<RecordExceptionProcess> list=gson.fromJson(gson.toJson(body.getData()),new TypeToken< List<RecordExceptionProcess>>(){}.getType());
adapter.setList(list);
adapter.notifyDataSetChanged();
if (list==null||list.isEmpty()){
binding.setListNumbre(0);
return;
}
binding.setListNumbre(list.size());
}
}
});
}
}

@ -125,10 +125,10 @@ public class MainActivity extends BaseActivity {
// 登录 // 登录
public void login(View view) { public void login(View view) {
if (!loginState) { // if (!loginState) {
Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show(); // Toast.makeText(this, "设备未注册,不允许登录", Toast.LENGTH_SHORT).show();
return; // return;
} // }
String teamCode = user.getTeamCode(); String teamCode = user.getTeamCode();
if (teamCode==null||teamCode.isEmpty()) return; if (teamCode==null||teamCode.isEmpty()) return;
dialog.show(); dialog.show();

@ -0,0 +1,75 @@
package com.example.aucma_mes.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.example.aucma_mes.BR;
import com.example.aucma_mes.R;
import com.example.aucma_mes.databinding.ItemInfoBinding;
import com.example.aucma_mes.databinding.ItemRepairBinding;
import com.example.aucma_mes.entity.DefectBeen;
import com.example.aucma_mes.entity.RecordExceptionProcess;
import java.util.List;
/**
* @author wanghao
* @date 2023/11/17 17:15
*/
public class RecordAdapter extends RecyclerView.Adapter<RecordAdapter.CheckAdapterVH> {
private Context context;
private List<RecordExceptionProcess> list;
private LayoutInflater from;
public RecordAdapter(Context context) {
this.context = context;
from = LayoutInflater.from(context);
}
public void setList(List<RecordExceptionProcess> list) {
this.list = list;
}
@NonNull
@Override
public CheckAdapterVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemInfoBinding inflate1 = DataBindingUtil.inflate(from, R.layout.item_info, parent, false);
return new CheckAdapterVH(inflate1);
}
@Override
public void onBindViewHolder(@NonNull CheckAdapterVH holder, int position) {
var defectBeen = list.get(position);
var databing = holder.getInflate1();
databing.setVariable(BR.item, defectBeen);
databing.executePendingBindings();
}
@Override
public int getItemCount() {
return list == null ? 0 : list.size();
}
static class CheckAdapterVH extends RecyclerView.ViewHolder {
private final ItemInfoBinding inflate1;
public ItemInfoBinding getInflate1() {
return inflate1;
}
public CheckAdapterVH(ItemInfoBinding inflate1) {
super(inflate1.getRoot());
this.inflate1 = inflate1;
}
}
}

@ -26,8 +26,8 @@ import okhttp3.MediaType;
public abstract class BaseActivity extends AppCompatActivity { public abstract class BaseActivity extends AppCompatActivity {
private MyBroad receiver; private MyBroad receiver;
// public static String url="http://192.168.137.1:8080"; public static String url="http://192.168.137.1:8080";
public static String url = "http://10.100.72.10:8080"; // public static String url = "http://10.100.72.10:8080";
public ProgressDialog dialog; public ProgressDialog dialog;
public Gson gson; public Gson gson;
public MediaType JSON = MediaType.parse("application/json; charset=utf-8"); public MediaType JSON = MediaType.parse("application/json; charset=utf-8");

@ -0,0 +1,35 @@
package com.example.aucma_mes.entity;
/**
* @author wanghao
* @date 2024/5/9 16:50
*/
public class RecordExceptionProcess {
// 箱体码:boxBarcode型号:materialModel班组:teamName
private String boxBarcode, materialModel, teamName;
public String getBoxBarcode() {
return boxBarcode;
}
public void setBoxBarcode(String boxBarcode) {
this.boxBarcode = boxBarcode;
}
public String getMaterialModel() {
return materialModel;
}
public void setMaterialModel(String materialModel) {
this.materialModel = materialModel;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String teamName) {
this.teamName = teamName;
}
}

@ -2,6 +2,7 @@ package com.example.aucma_mes.service;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -11,6 +12,7 @@ import android.util.Log;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import com.example.aucma_mes.InfoListActivity;
import com.example.aucma_mes.R; import com.example.aucma_mes.R;
import com.example.aucma_mes.base.BaseActivity; import com.example.aucma_mes.base.BaseActivity;
import com.example.aucma_mes.entity.Result; import com.example.aucma_mes.entity.Result;
@ -85,12 +87,16 @@ public class MyService extends Service {
NotificationChannel channel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT); NotificationChannel channel = new NotificationChannel("channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);
} }
// 创建跳转Intent
Intent intent = new Intent(this, InfoListActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// 创建通知 // 创建通知
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id") NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id")
.setSmallIcon(R.mipmap.logo2) .setSmallIcon(R.mipmap.logo2)
.setContentTitle(title) .setContentTitle(title)
.setContentText(content) .setContentText(content)
.setContentIntent(pendingIntent) // 设置点击通知后跳转的Intent
// .setStyle(new NotificationCompat.BigTextStyle() // .setStyle(new NotificationCompat.BigTextStyle()
// .bigText("这里是非常长的文本内容,可以显示多行文本。")) // .bigText("这里是非常长的文本内容,可以显示多行文本。"))
.setAutoCancel(true); .setAutoCancel(true);

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/blue" />
<corners android:radius="10dp" />
</shape>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#74DEE3E6" />
<corners android:radius="5dp" />
<stroke android:width="1dp"/>
</shape>

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="adapter"
type="com.example.aucma_mes.adapter.RecordAdapter" />
<variable
name="listNumbre"
type="int" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/grey"
tools:context=".InfoListActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="43dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
android:background="@color/white"
android:orientation="horizontal">
<TextView
style="@style/text_style1"
android:layout_width="120dp"
android:layout_height="match_parent"
android:background="@color/grey"
android:text="是否已降级:" />
<Spinner
android:id="@+id/info_spinner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:entries="@array/yn"
android:spinnerMode="dropdown"
android:layout_weight="1"
android:textAlignment="center" />
<Button
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="@drawable/button_1"
android:textColor="@color/white"
android:textSize="18sp"
android:onClick="infoSelect"
android:text="查询" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:textColor="@color/blue"
android:text='@{"待降级数量:"+listNumbre}' />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:adapter="@{adapter}"
android:padding="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:background="@color/white" />
</LinearLayout>
</layout>

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="item"
type="com.example.aucma_mes.entity.RecordExceptionProcess" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/item_1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="1dp"
android:orientation="horizontal">
<TextView
style="@style/item_text_style"
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="箱体码" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/white" />
<TextView
style="@style/item_text_style"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@{item.boxBarcode}" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="@color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="1dp"
android:orientation="horizontal">
<TextView
style="@style/item_text_style"
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="型号" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/white" />
<TextView
style="@style/item_text_style"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@{item.materialModel}" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="@color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="1dp"
android:orientation="horizontal">
<TextView
style="@style/item_text_style"
android:layout_width="80dp"
android:layout_height="match_parent"
android:text="班组" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/white" />
<TextView
style="@style/item_text_style"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@{item.teamName}" />
</LinearLayout>
</LinearLayout>
</layout>

@ -10,4 +10,5 @@
<item></item> <item></item>
</string-array> </string-array>
</resources> </resources>
Loading…
Cancel
Save