загрузка всех данных RecyclerView из MainActivity в firebase - PullRequest
0 голосов
/ 09 сентября 2018

Я обрабатываю некоторые изображения и добавляю данные из процесса в список массивов в RecyclerView. Теперь я хочу вставить все данные в базу данных firebase, проверив, соответствует ли объект из списка дочернему элементу базы данных firebase, а затем вставить второй объект в дочерний элемент совпадающего дочернего элемента firebase один за другим. Как добиться этого с помощью одной кнопки из основной деятельности, а не RecyclerView.

вот как я вставляю данные в RecyclerView с ModelClass.

if (fileDirectory.isDirectory()) {
        listCroppedImages.clear();
        EmptyViewCroppedImage.setVisibility(View.GONE);
        RVCroppedImages.setVisibility(View.VISIBLE);
        listCroppedImages.clear();
        String PhotoPath[] = new String[100];
        final String StudentMatric[] = new String[100];
        final String AttendanceRecord[] = new String[100];

        for (int i = 1; i <= fileDirectory.listFiles().length; i++) {
            PhotoPath[i] = croppedImageDirectory + i + ".jpg";

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            Bitmap croppedimageold = BitmapFactory.decodeFile(PhotoPath[i], options);
            Bitmap croppedimagenew = Bitmap.createScaledBitmap(croppedimageold, 460, 66, true);

            StudentMatric[i] = TextImageProcess(croppedimagenew);
            AttendanceRecord[i]=CircleDetection(croppedimagenew, StudentMatric[i]);
            listCroppedImages.add(new CroppedImageModel(String.valueOf(i), PhotoPath[i], StudentMatric[i], AttendanceRecord[i]));
        }
    } else {
        EmptyViewCroppedImage.setVisibility(View.VISIBLE);
        RVCroppedImages.setVisibility(View.GONE);
    }
 -------------------------
 }
 public String TextImageProcess(Bitmap image){
 ----------------
   return String x;
 };

 public String CircleDetection(Bitmap image, String y){
 ----------------------
   return String z;

 } 

что хотите, это

 btnUploadData.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
       for(i=1; i=listCroppedImages.size(); i++)
       if(StudentMatric[i].isequalto(firbasedataRef.getKey())){
           DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child(StudentMatric[i]).child("Attendance Record");
           Map newPost = new HashMap();
           newPost.put("Attendance", Attendance[i]);                         
           current_user_db.updateChildren(newPost);

       }

 });

Моя проблема теперь, как получить данные (Student [i], Attendance [i]) в btnUploadData.setOnclickliastener и сопоставить первый элемент списка массива с ключом firebase и вставить следующий в дочерний элемент ключа ? я застрял здесь на несколько дней. любое предложение будет очень ценным. Заранее спасибо

1 Ответ

0 голосов
/ 10 сентября 2018

я не понял, что ответ был настолько прост .. вот что я сделал

 if (fileDirectory.isDirectory()) {
        listCroppedImages.clear();
        EmptyViewCroppedImage.setVisibility(View.GONE);
        RVCroppedImages.setVisibility(View.VISIBLE);
        listCroppedImages.clear();
        String PhotoPath[] = new String[100];
        final String StudentMatric[] = new String[100];
        final String AttendanceRecord[] = new String[100];

        for (int i = 1; i <= fileDirectory.listFiles().length; i++) {
            PhotoPath[i] = croppedImageDirectory + i + ".jpg";

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            Bitmap croppedimageold = BitmapFactory.decodeFile(PhotoPath[i], options);
            Bitmap croppedimagenew = Bitmap.createScaledBitmap(croppedimageold, 460, 66, true);

            StudentMatric[i] = TextImageProcess(croppedimagenew);
            AttendanceRecord[i] = CircleDetection(croppedimagenew, StudentMatric[i]);
            listCroppedImages.add(new CroppedImageModel(String.valueOf(i), PhotoPath[i], StudentMatric[i], AttendanceRecord[i]));

            btnUploadAttendance.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {


                    for (int x = 1; x <= listCroppedImages.size(); x++) {
                        UploadData(StudentMatric[x], AttendanceRecord[x], x);
                    }
                }
            });


        }
    } else {
        EmptyViewCroppedImage.setVisibility(View.VISIBLE);
        RVCroppedImages.setVisibility(View.GONE);
    }

    -----------------------------------------------------------------------

    public void UploadData(final String StudentMatric, final String AttendanceRecord, final int x) {
         ProgressUploadAttendance.setVisibility(View.VISIBLE);

        Query query = StudentsRef.orderByKey().equalTo(StudentMatric);
        query.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              if (dataSnapshot.exists()) {
                  int progress = x / listCroppedImages.size() * 100;
                  DatabaseReference StudentMatricRef = StudentsRef.child(StudentMatric).child("Attendance").push();
                  StudentMatricRef.child("Status").setValue(AttendanceRecord);
                  StudentMatricRef.child("Date").setValue(getCurrentDate());
                  ProgressUploadAttendance.setProgress(progress);
              } else {
                  Toast.makeText(TextExtractionActivity.this, "Could not Find " + StudentMatric, Toast.LENGTH_LONG).show();
              }

          }

          @Override
          public void onCancelled(DatabaseError databaseError) {
              throw databaseError.toException(); // don't ignore errors
          }
      });

  }
...