Я хочу создать историю для своего приложения. То, что я хочу, - это когда клиент нажимает кнопку отклонения, поэтому данные из действия запроса должны быть удалены и добавлены в действие отклоненных запросов. Пожалуйста, помогите мне кто-нибудь. Это мой класс адаптера, в котором я удаляю запросы как для водителя, так и для владельца парковки, но теперь я хочу добавить в него активность отклоненных запросов.
publi c Класс CustomAdapter расширяет ArrayAdapter {
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();
}
}
}
});
}
}