当用户提交空值的费率时,如何使该费率函数拒绝其值?

时间:2018-12-25 12:49:37

标签: android-studio-3.0

  private void Submit_Rating_Detail() {
    final AlertDialog waiting_dialog=new SpotsDialog(Rate_Driver.this);
    waiting_dialog.show();
    Rate rate=new Rate();
    rate.setRates(String.valueOf(rating_stars));
    rate.setComments(comment.getText().toString());
    rating_detail_ref.child(Commons.driver_id).push().setValue(rate).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            rating_detail_ref.child(Commons.driver_id).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    double average_stars=0.0;
                    int count=0;
                    for(DataSnapshot postsnapshot:dataSnapshot.getChildren()){
                        Rate rate=postsnapshot.getValue(Rate.class);
                        average_stars+=Double.parseDouble(rate.getRates());
                        count++;
                    }
                    final double final_average_stars=average_stars/count;
                    DecimalFormat df=new DecimalFormat("#.#");
                    final String value_update=df.format(final_average_stars);
                    Map<String,Object> driver_rating_update=new HashMap<>();
                    driver_rating_update.put("rates",value_update);

                    Driverinformationref.child(Commons.driver_id).updateChildren(driver_rating_update).addOnCompleteListener(new OnCompleteListener<Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {
                            if(task.isSuccessful()) {
                                waiting_dialog.dismiss();
                                finish();
                            }



                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            waiting_dialog.dismiss();
                            Toast.makeText(Rate_Driver.this,e.getMessage(),Toast.LENGTH_LONG).show();
                        }
                    });
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            waiting_dialog.dismiss();
            Toast.makeText(Rate_Driver.this,e.getMessage(),Toast.LENGTH_LONG).show();

        }
    });
}

我的问题是当用户单击空值的提交速率时,因为此评分功能使用平均计算,这意味着如果先前的速率为5星(最大值),则当用户提交空值时,新速率将变为2.5星。

0 个答案:

没有答案