package com.example.finddonor; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import com.google.android.gms.tasks.OnFailureListener; import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import java.util.HashMap; public class SerachActivity extends AppCompatActivity { EditText location; EditText district; EditText name; EditText medical; EditText blood; CheckBox checkBox; Button submitButton; Button updateButton; Button deleteButton; FirebaseDatabase firebaseDatabase; DatabaseReference databaseReference; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_serach); firebaseDatabase = FirebaseDatabase.getInstance(); databaseReference = firebaseDatabase.getReference(); location = findViewById(R.id.location); district = findViewById(R.id.district); name = findViewById(R.id.name); medical = findViewById(R.id.medical); blood = findViewById(R.id.blood); checkBox = findViewById(R.id.checkBox); submitButton = findViewById(R.id.submitButton); updateButton = findViewById(R.id.updateButton); deleteButton = findViewById(R.id. deleteButton); submitButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String getlocation = location.getText().toString(); String getdistrict = district.getText().toString(); String getname = name.getText().toString(); String getmedical = medical.getText().toString(); String getblood = blood.getText().toString(); String getcheckBox = checkBox.getText().toString(); HashMap hashMap = new HashMap<>(); hashMap.put("location",getlocation); hashMap.put("district",getdistrict); hashMap.put("name",getname); hashMap.put("medical",getmedical); hashMap.put("blood",getblood); hashMap.put("checkBox",getcheckBox); databaseReference.child("Users") .child(getname) .setValue(hashMap) .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void aVoid) { Toast.makeText(SerachActivity.this, "Submited", Toast.LENGTH_SHORT).show(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Toast.makeText(SerachActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show(); } }); } }); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String getlocation = location.getText().toString(); String getdistrict = district.getText().toString(); String getname = name.getText().toString(); String getmedical = medical.getText().toString(); String getblood = blood.getText().toString(); HashMap hashMap = new HashMap<>(); hashMap.put("location",getlocation); hashMap.put("district",getdistrict); hashMap.put("name",getname); hashMap.put("medical",getmedical); hashMap.put("blood",getblood); databaseReference.child("Users") .child(getname) .setValue(hashMap) .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void aVoid) { Toast.makeText(SerachActivity.this, "deleted", Toast.LENGTH_SHORT).show(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Toast.makeText(SerachActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show(); } }); } }); updateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String getlocation = location.getText().toString(); String getdistrict = district.getText().toString(); String getname = name.getText().toString(); String getmedical = medical.getText().toString(); String getblood = blood.getText().toString(); String getcheckBox = checkBox.getText().toString(); HashMap hashMap = new HashMap<>(); hashMap.put("location",getlocation); hashMap.put("district",getdistrict); hashMap.put("name",getname); hashMap.put("medical",getmedical); hashMap.put("blood",getblood); hashMap.put("checkBox",getcheckBox); databaseReference.child("Users") .child(getname) .setValue(hashMap) .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void aVoid) { Toast.makeText(SerachActivity.this, "updated", Toast.LENGTH_SHORT).show(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Toast.makeText(SerachActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show(); } }); } }); BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView); bottomNavigationView.setSelectedItemId(R.id.bottom_Search); bottomNavigationView.setOnItemSelectedListener(item -> { switch (item.getItemId()) { case R.id.bottom_home: startActivity(new Intent(getApplicationContext(), MainActivity.class)); overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left); finish(); return true; case R.id.bottom_Search: return true; case R.id.bottom_settings: startActivity(new Intent(getApplicationContext(), SettingActivity.class)); overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left); finish(); return true; case R.id.bottom_profile: startActivity(new Intent(getApplicationContext(),ProfileActivity.class)); overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left); finish(); return true; } return false; }); } }