content: package com.anniezhang.textfromimage;
  
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import android.os.Bundle;
  import android.widget.Toast;
  
  import com.google.firebase.auth.FirebaseAuth;
  import com.google.firebase.auth.FirebaseUser;
  import com.google.firebase.database.DataSnapshot;
  import com.google.firebase.database.DatabaseError;
  import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;
  import com.google.firebase.database.ValueEventListener;
  
  import java.util.ArrayList;
  
  public class ScanHistory extends AppCompatActivity {
  
      private RecyclerView recyclerView;
      private ArrayList<Upload> list;
      private ImageAdapter adapter;
      private FirebaseAuth auth;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_scan_history);
  
          // Initialize Firebase Auth and get current user
          auth = FirebaseAuth.getInstance();
          FirebaseUser user = auth.getCurrentUser();
          if (user == null) {
              Toast.makeText(this, "User not authenticated", Toast.LENGTH_SHORT).show();
              finish();
              return;
          }
  
          // Get user ID and Firebase database reference
          String userID = user.getUid();
          String location = "images/users/" + userID;
          DatabaseReference root = FirebaseDatabase.getInstance().getReference(location);
  
          // Initialize RecyclerView
          recyclerView = findViewById(R.id.recycler_view);
          recyclerView.setHasFixedSize(true);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
  
          // Initialize list and adapter
          list = new ArrayList<>();
          adapter = new ImageAdapter(this, list);
          recyclerView.setAdapter(adapter);
  
          // Fetch data from Firebase and update RecyclerView
          root.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot snapshot) {
                  list.clear(); // Clear the list to avoid duplicates
                  for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
                      Upload model = dataSnapshot.getValue(Upload.class);
                      list.add(model);
                  }
                  adapter.notifyDataSetChanged();
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError error) {
                  Toast.makeText(ScanHistory.this, "Failed to retrieve data", Toast.LENGTH_SHORT).show();
              }
          });
      }
  }
  