Android 在安卓系统中,我们可以通过点击一个按钮删除一个子系统中的一个节点并更新另一个子系统中的另一个节点吗
我想为我的应用程序创建历史记录。我想要的是,当客户单击拒绝按钮时,请求活动中的数据应该被删除,并添加到拒绝的请求活动中。请帮帮我。 这是我的适配器类,我正在删除对驱动程序和停车场所有者的请求,但现在我想将其添加到拒绝请求活动中 公共类CustomAdapter扩展了ArrayAdapter{Android 在安卓系统中,我们可以通过点击一个按钮删除一个子系统中的一个节点并更新另一个子系统中的另一个节点吗,android,firebase,Android,Firebase,我想为我的应用程序创建历史记录。我想要的是,当客户单击拒绝按钮时,请求活动中的数据应该被删除,并添加到拒绝的请求活动中。请帮帮我。 这是我的适配器类,我正在删除对驱动程序和停车场所有者的请求,但现在我想将其添加到拒绝请求活动中 公共类CustomAdapter扩展了ArrayAdapter{ private DatabaseReference databaseReference; private Activity context; private List<parkingRequest&g
private DatabaseReference databaseReference;
private Activity context;
private List<parkingRequest> parkingRequestList;
private String send_email_driver;
private FirebaseAuth mAuth;
private DatabaseReference mAcceptedRequests, mRejectedRequests;
private String userId;
public CustomAdapter(Activity context, List<parkingRequest> parkingRequestList) {
super(context, R.layout.sample_layout, parkingRequestList);
this.context = context;
this.parkingRequestList = parkingRequestList;
mAuth = FirebaseAuth.getInstance();
userId = mAuth.getCurrentUser().getUid();
mAcceptedRequests = FirebaseDatabase.getInstance().getReference().child("History").child("AcceptedRequests").child(userId);
mRejectedRequests = FirebaseDatabase.getInstance().getReference().child("History").child("RejectedRequests").child(userId);
OneSignal.startInit(getContext())
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = context.getLayoutInflater();
View view = layoutInflater.inflate(R.layout.sample_layout, null, true);
final parkingRequest Request1 = parkingRequestList.get(position);
TextView t1 = view.findViewById(R.id.nameTxt);
TextView t2 = view.findViewById(R.id.phoneTxt);
TextView t3 = view.findViewById(R.id.carNoTxt);
TextView txtParkingLocation=view.findViewById(R.id.txtparkingLocation);
TextView pDate_time = view.findViewById(R.id.pdateTime);
final TextView driverEmail = view.findViewById(R.id.driverEmail);
final TextView DriverId = view.findViewById(R.id.driverid);
final Button reject = view.findViewById(R.id.RejectBtn);
final Button accept = view.findViewById(R.id.acceptBtn);
pDate_time.setText(Request1.getDate_time());
reject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id=FirebaseAuth.getInstance().getCurrentUser().getUid();
Toast.makeText(context,id,Toast.LENGTH_SHORT).show();
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("CurrentRequests").child(id).child(reject.getTag().toString());
ref.removeValue();
DatabaseReference refOwner=FirebaseDatabase.getInstance().getReference().child("CurrentRequests").child(DriverId.getTag().toString()).child(reject.getTag().toString());
refOwner.removeValue();
}
});
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(context, "Hello", Toast.LENGTH_SHORT).show();
send_email_driver = driverEmail.getTag().toString();
sendPushNotification();
}
});
t1.setText("Name: "+ Request1.getName());
t2.setText("Phone: "+ Request1.getPhone());
t3.setText("CarNo: "+ Request1.getCarNO());
txtParkingLocation.setText("Location: "+Request1.getParking_location());
reject.setTag(Request1.getReq_id());
DriverId.setTag(Request1.getUser_ID());
DriverId.setVisibility(View.INVISIBLE);
driverEmail.setTag(Request1.getDriver_email());
driverEmail.setVisibility(View.INVISIBLE);
return view;
}
private void sendPushNotification() {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
int SDK_INT = Build.VERSION.SDK_INT;
if(SDK_INT > 0){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
String jsonResponse;
URL url = new URL("https://onesignal.com/api/v1/notifications");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Authorization", "Basic OWFiYjg5ZDAtNzY0My00MDdkLThjMTAtZjEyMjJiZTU3MzI2");
con.setRequestMethod("POST");
String strJsonBody = "{"
+ "\"app_id\": \"f0b4bf7b-f76e-4d6b-91b9-dc09af30754c\","
+ "\"filters\": [{\"field\": \"tag\", \"key\": \"User_ID\", \"relation\": \"=\", \"value\": \"" + send_email_driver + "\"}],"
+ "\"data\": {\"foo\": \"bar\"},"
+ "\"headings\": {\"en\": \"Parking Reply\"},"
+ "\"contents\": {\"en\": \"Your request for a parking slot in the following parking is accepted.\"},"
+ "\"buttons\": [{\"id\":\"SeeMapBtn\",\"text\":\"See the Map\",\"icon\":\"\"}]"
+ "}";
System.out.println("strJsonBody:\n" + strJsonBody);
byte[] sendBytes = strJsonBody.getBytes("UTF-8");
con.setFixedLengthStreamingMode(sendBytes.length);
OutputStream outputStream = con.getOutputStream();
outputStream.write(sendBytes);
int httpResponse = con.getResponseCode();
System.out.println("httpResponse: " + httpResponse);
if (httpResponse >= HttpURLConnection.HTTP_OK
&& httpResponse < HttpURLConnection.HTTP_BAD_REQUEST) {
Scanner scanner = new Scanner(con.getInputStream(), "UTF-8");
jsonResponse = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
scanner.close();
} else {
Scanner scanner = new Scanner(con.getErrorStream(), "UTF-8");
jsonResponse = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
scanner.close();
}
System.out.println("jsonResponse:\n" + jsonResponse);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
私有数据库参考数据库参考;
私人活动语境;
私人列表停车请求列表;
私有字符串发送\电子邮件\驱动程序;
私人消防队;
私有数据库引用mAcceptedRequests、mRejectedRequests;
私有字符串用户标识;
公共CustomAdapter(活动上下文,列表parkingRequestList){
super(上下文、R.layout.sample_布局、parkingRequestList);
this.context=上下文;
this.parkingRequestList=parkingRequestList;
mAuth=FirebaseAuth.getInstance();
userId=mAuth.getCurrentUser().getUid();
mAcceptedRequests=FirebaseDatabase.getInstance().getReference().child(“历史”).child(“AcceptedRequests”).child(用户ID);
mRejectedRequests=FirebaseDatabase.getInstance().getReference().child(“历史”).child(“RejectedRequests”).child(用户ID);
OneSignal.startInit(getContext())
.inFocusDisplaying(OneSignal.osinfocusdisplayiption.Notification)
.取消订阅时通知被禁用(真)
.init();
}
@非空
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
LayoutInflater LayoutInflater=context.getLayoutInflater();
视图=布局更平坦。充气(R.layout.sample\u布局,null,true);
最终停车请求1=停车请求列表.get(位置);
TextView t1=view.findviewbyd(R.id.nameTxt);
TextView t2=view.findviewbyd(R.id.phoneTxt);
TextView t3=view.findViewById(R.id.carNoTxt);
TextView txtParkingLocation=view.findviewbyd(R.id.txtParkingLocation);
TextView pDate_time=view.findviewbyd(R.id.pdateTime);
final TextView driverEmail=view.findviewbyd(R.id.driverEmail);
final TextView DriverId=view.findviewbyd(R.id.DriverId);
最终按钮拒绝=view.findviewbyd(R.id.RejectBtn);
最终按钮接受=view.findviewbyd(R.id.acceptBtn);
pDate_time.setText(Request1.getDate_time());
拒绝.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
字符串id=FirebaseAuth.getInstance().getCurrentUser().getUid();
Toast.makeText(上下文、id、Toast.LENGTH_SHORT).show();
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child(“CurrentRequests”).child(id).child(reject.getTag().toString());
参考removeValue();
DatabaseReference Reowner=FirebaseDatabase.getInstance().getReference().child(“CurrentRequests”).child(DriverId.getTag().toString()).child(reject.getTag().toString());
Reowner.removeValue();
}
});
accept.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//Toast.makeText(上下文“Hello”,Toast.LENGTH_SHORT).show();
send_email_driver=driverEmail.getTag().toString();
sendPushNotification();
}
});
t1.setText(“Name:+Request1.getName());
t2.setText(“电话:+Request1.getPhone());
t3.setText(“CarNo:+Request1.getCarNO());
txtParkingLocation.setText(“位置:+Request1.getParking_Location());
拒绝.setTag(Request1.getReq_id());
setTag(Request1.getUser_ID());
DriverId.setVisibility(View.INVISIBLE);
setTag(Request1.getDriver_email());
设置可见性(视图不可见);
返回视图;
}
私有void sendPushNotification(){
AsyncTask.execute(新的Runnable(){
@凌驾
公开募捐{
int SDK_int=Build.VERSION.SDK_int;
如果(SDK_INT>0){
StrictMode.ThreadPolicy policy=新建StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(策略);
试一试{
字符串jsonResponse;
URL=新URL(“https://onesignal.com/api/v1/notifications");
HttpURLConnection con=(HttpURLConnection)url.openConnection();
con.setUseCaches(假);
con.设置输出(真);
con.setDoInput(真);
con.setRequestProperty(“内容类型”,“应用程序/json;字符集=UTF-8”);
con.setRequestProperty(“授权”、“基本OWFIYJG5ZDATNZY0MY00MDKlthJMTATZJEYMJZTU3MZI2”);
con.setRequestMethod(“POST”);
字符串strJsonBody=“{”
+“\“应用程序id\”:\“f0b4bf7b-f76e-4d6b-91b9-dc09af30754c\”,”
+“\”过滤器\“:[{\”字段\“:\”标记\“,\”键\“:\”用户ID \“,\”关系\“:\”=\”,\”值\“:\”+发送电子邮件\ \驱动程序+“\”}],”
+“\'data\':{\'foo\':\'bar\'”
+“\'headers\':{\'en\':\'Parking Reply\'”
+“\'contents\':{\'en\':\”您在以下停车场申请停车位的请求已被接受。\“}”
+“\”按钮\“:[{\”id\“:\”SeeMapBtn\”,\”文本\“:\”查看地图\“,\”图标\“:\”}]”
+ "}";
System.out.println(“strJsonBody:\n”+strJsonBody);
byte[]sendBytes=strJsonBody.getBytes(“UTF-8”);
con.setFixedLengthStreamingMode(sendBytes.length);
OutputStream OutputStream=con.getOutputStream();
outputStream.write(sendBytes);
int httpResponse=con.getResponseCode();