مشکل بسته شدن کانکشن دیتابیس در اندروید

تعرفه تبلیغات در سایت
عنوان عکس
عنوان عکس
عنوان عکس
عنوان عکس
عنوان عکس

جستجوگر

امکانات وب

آرشیو مطالب

برچسب ها

#1

26-08-1396، 02:44 ب.ظ
با سلام
من برنامم رو منتشر کردم و لاگ ها رو از طریف فایربیس میخونم
یکی از ارور هایی که داشتم اینه که کانکشن به دیتابیس توی یه صفحه ای بسته هست ظاهرا
public class ScoreAdapter extends RecyclerView.Adapter<ScoreAdapter.ViewHolder> {
   private Context context;
   private List<ItemSession> list;
   private DatabaseHelper databaseHelper;
   private AdapterClickListener listener;
   private int historyID, turn = 1;
   private int Score, Posotion1;
   private boolean checkClicked1, checkClicked2, checkClicked3, checkClicked4, checkClicked5;
   ScoreAdapter(Context context, int historyID, List<ItemSession> list, DatabaseHelper databaseHelper, AdapterClickListener listener) {
       this.context = context;
       this.historyID = historyID;
       this.list = list;
       this.databaseHelper = databaseHelper;
       this.listener = listener;
   }
   @Override
   public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_score_list, parent, false);
       return new ViewHolder(view);
   }
   @SuppressLint("SetTextI18n")
   @Override
   public void onBindViewHolder(ViewHolder holder, int position) {
       if (list.get(position).sessionPosition == 0) {
           holder.person.setBackgroundResource(R.drawable.ic_user_green);
           holder.leftColor.setBackgroundColor(Color.parseColor("#079f0f"));
           holder.rightColor.setBackgroundColor(Color.parseColor("#079f0f"));
       } else if (list.get(position).sessionPosition == 1) {
           holder.person.setBackgroundResource(R.drawable.ic_user_purple);
           holder.leftColor.setBackgroundColor(Color.parseColor("#9231d5"));
           holder.rightColor.setBackgroundColor(Color.parseColor("#9231d5"));
       } else if (list.get(position).sessionPosition == 2) {
           holder.person.setBackgroundResource(R.drawable.ic_user_yellow);
           holder.leftColor.setBackgroundColor(Color.parseColor("#9e9f25"));
           holder.rightColor.setBackgroundColor(Color.parseColor("#9e9f25"));
       } else if (list.get(position).sessionPosition == 3) {
           holder.person.setBackgroundResource(R.drawable.ic_user_red);
           holder.leftColor.setBackgroundColor(Color.parseColor("#bd0a51"));
           holder.rightColor.setBackgroundColor(Color.parseColor("#bd0a51"));
       } else if (list.get(position).sessionPosition == 4) {
           holder.person.setBackgroundResource(R.drawable.ic_user_sky_blue);
           holder.leftColor.setBackgroundColor(Color.parseColor("#289682"));
           holder.rightColor.setBackgroundColor(Color.parseColor("#289682"));
       }
       holder.editTeamName.setVisibility(View.GONE);
       holder.teamName.setVisibility(View.VISIBLE);
       holder.teamName.setTypeface(AppConfiguration.setFont(context));
       holder.score.setTypeface(AppConfiguration.setFont(context));
       holder.editTeamName.setTypeface(AppConfiguration.setFont(context));
       holder.score.setText(AppConfiguration.getNumber(list.get(position).sessionScore));
       holder.teamName.setText(list.get(position).sessionTeamName);
       holder.editSave.setBackgroundResource(R.drawable.ic_edit);
       holder.play.setBackgroundResource(R.drawable.ic_play);
       holder.play.setVisibility(View.INVISIBLE);
       holder.numberTeam.setTypeface(AppConfiguration.setFont(context));
       new Thread(() -> {
           try {
               databaseHelper.openDataBase();
           } catch (Exception e) {
               e.printStackTrace();
           }
           int state = databaseHelper.getRealStateHistory(historyID);
           databaseHelper.close();
           new Handler(Looper.getMainLooper()).post(() -> {
               if (state == 1) {
                   if (turn <= 5) {
                       if (list.get(position).sessionState == 1) {
                           holder.play.setVisibility(View.VISIBLE);
                       }
                   } else {
                       try {
                           databaseHelper.openDataBase();
                       } catch (Exception e) {
                           e.printStackTrace();
                       }
                       databaseHelper.updateClosedStateHistory(historyID);
                       databaseHelper.close();
                   }
               } else {
                   try {
                       databaseHelper.openDataBase();
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
                   int[] highScore = databaseHelper.getHighScore(historyID);
                   if (list.size() == 2) {
                       if (databaseHelper.getPositionHighScore(historyID, highScore[list.size() - 1]) == position) {
                           holder.play.setVisibility(View.VISIBLE);
                           holder.play.setEnabled(false);
                           holder.play.setBackgroundResource(R.drawable.ic_trophy_gold);
                           holder.numberTeam.setVisibility(View.VISIBLE);
                           holder.numberTeam.setTypeface(AppConfiguration.setFont(context));
                           holder.numberTeam.setText("1");
                       } else if (databaseHelper.getPositionHighScore(historyID, highScore[list.size() - 2]) == position) {
                           holder.play.setVisibility(View.VISIBLE);
                           holder.play.setEnabled(false);
                           holder.play.setBackgroundResource(R.drawable.ic_trophy_silver);
                           holder.numberTeam.setVisibility(View.VISIBLE);
                           holder.numberTeam.setTypeface(AppConfiguration.setFont(context));
                           holder.numberTeam.setText("2");
                       }
                   } else {
                       if (databaseHelper.getPositionHighScore(historyID, highScore[list.size() - 1]) == position) {
                           holder.play.setVisibility(View.VISIBLE);
                           holder.play.setEnabled(false);
                           holder.play.setBackgroundResource(R.drawable.ic_trophy_gold);
                           holder.numberTeam.setVisibility(View.VISIBLE);
                           holder.numberTeam.setTypeface(AppConfiguration.setFont(context));
                           holder.numberTeam.setText("1");
                       } else if (databaseHelper.getPositionHighScore(historyID, highScore[list.size() - 2]) == position) {
                           holder.play.setVisibility(View.VISIBLE);
                           holder.numberTeam.setTypeface(AppConfiguration.setFont(context));
                           holder.play.setEnabled(false);
                           holder.play.setBackgroundResource(R.drawable.ic_trophy_silver);
                           holder.numberTeam.setVisibility(View.VISIBLE);
                           holder.numberTeam.setText("2");
                       } else if (databaseHelper.getPositionHighScore(historyID, highScore[list.size() - 3]) == position) {
                           holder.play.setVisibility(View.VISIBLE);
                           holder.play.setEnabled(false);
                           holder.play.setBackgroundResource(R.drawable.ic_trophy_bronze);
                           holder.numberTeam.setVisibility(View.VISIBLE);
                           holder.numberTeam.setTypeface(AppConfiguration.setFont(context));
                           holder.numberTeam.setText("3");
                       }
                   }
                   databaseHelper.close();
               }
           });
       }).start();
       holder.framelayout_edit.setOnClickListener(view -> {
           try {
               databaseHelper.openDataBase();
           } catch (Exception e) {
               e.printStackTrace();
           }
           if (position == 0) {
               if (!checkClicked1) {
                   holder.editSave.setBackgroundResource(R.drawable.ic_check_box);
                   checkClicked1 = true;
                   holder.editTeamName.setVisibility(View.VISIBLE);
                   holder.editTeamName.setText(holder.teamName.getText().toString());
                   holder.teamName.setVisibility(View.GONE);
               } else {
                   holder.editSave.setBackgroundResource(R.drawable.ic_edit);
                   checkClicked1 = false;
                   holder.editTeamName.setVisibility(View.GONE);
                   holder.teamName.setVisibility(View.VISIBLE);
                   holder.teamName.setText(holder.editTeamName.getText().toString());
                   databaseHelper.updateTeamName(holder.editTeamName.getText().toString().trim(), list.get(position).sessionID);
               }
           } else if (position == 1) {
               if (!checkClicked2) {
                   holder.editSave.setBackgroundResource(R.drawable.ic_check_box);
                   checkClicked2 = true;
                   holder.editTeamName.setVisibility(View.VISIBLE);
                   holder.editTeamName.setText(holder.teamName.getText().toString());
                   holder.teamName.setVisibility(View.GONE);
               } else {
                   holder.editSave.setBackgroundResource(R.drawable.ic_edit);
                   checkClicked2 = false;
                   holder.editTeamName.setVisibility(View.GONE);
                   holder.teamName.setVisibility(View.VISIBLE);
                   holder.teamName.setText(holder.editTeamName.getText().toString());
                   databaseHelper.updateTeamName(holder.editTeamName.getText().toString(), list.get(position).sessionID);
               }
           } else if (position == 2) {
               if (!checkClicked3) {
                   holder.editSave.setBackgroundResource(R.drawable.ic_check_box);
                   checkClicked3 = true;
                   holder.editTeamName.setVisibility(View.VISIBLE);
                   holder.editTeamName.setText(holder.teamName.getText().toString());
                   holder.teamName.setVisibility(View.GONE);
               } else {
                   holder.editSave.setBackgroundResource(R.drawable.ic_edit);
                   checkClicked3 = false;
                   holder.editTeamName.setVisibility(View.GONE);
                   holder.teamName.setVisibility(View.VISIBLE);
                   holder.teamName.setText(holder.editTeamName.getText().toString());
                   databaseHelper.updateTeamName(holder.editTeamName.getText().toString(), list.get(position).sessionID);
               }
           } else if (position == 3) {
               if (!checkClicked4) {
                   holder.editSave.setBackgroundResource(R.drawable.ic_check_box);
                   checkClicked4 = true;
                   holder.editTeamName.setVisibility(View.VISIBLE);
                   holder.editTeamName.setText(holder.teamName.getText().toString());
                   holder.teamName.setVisibility(View.GONE);
               } else {
                   holder.editSave.setBackgroundResource(R.drawable.ic_edit);
                   checkClicked4 = false;
                   holder.editTeamName.setVisibility(View.GONE);
                   holder.teamName.setVisibility(View.VISIBLE);
                   holder.teamName.setText(holder.editTeamName.getText().toString());
                   databaseHelper.updateTeamName(holder.editTeamName.getText().toString(), list.get(position).sessionID);
               }
           } else if (position == 4) {
               if (!checkClicked5) {
                   holder.editSave.setBackgroundResource(R.drawable.ic_check_box);
                   checkClicked5 = true;
                   holder.editTeamName.setVisibility(View.VISIBLE);
                   holder.editTeamName.setText(holder.teamName.getText().toString());
                   holder.teamName.setVisibility(View.GONE);
               } else {
                   holder.editSave.setBackgroundResource(R.drawable.ic_edit);
                   checkClicked5 = false;
                   holder.editTeamName.setVisibility(View.GONE);
                   holder.teamName.setVisibility(View.VISIBLE);
                   holder.teamName.setText(holder.editTeamName.getText().toString());
                   databaseHelper.updateTeamName(holder.editTeamName.getText().toString(), list.get(position).sessionID);
               }
           }
           databaseHelper.close();
       });
       holder.play.setOnClickListener(view -> {
           try {
               databaseHelper.openDataBase();
           } catch (Exception e) {
               e.printStackTrace();
           }
           databaseHelper.updateClosedStateSession(position, historyID);
           databaseHelper.updateCounterState(historyID);
           turn = databaseHelper.getPositionCounter();
           databaseHelper.close();
           if (listener != null)
               listener.onButtonClick(position);
       });
   }
   @Override
   public int getItemCount() {
       return list.size();
   }
   public interface AdapterClickListener {
       void onButtonClick(int id);
   }
   class ViewHolder extends RecyclerView.ViewHolder {
       TextView score, teamName, numberTeam;
       EditText editTeamName;
       ImageView person, editSave, play;
       FrameLayout framelayout_edit;
       LinearLayout leftColor, rightColor;
       ViewHolder(View itemView) {
           super(itemView);
           person = itemView.findViewById(R.id.person_image);
           teamName = itemView.findViewById(R.id.team_name);
           editTeamName = itemView.findViewById(R.id.team_name_editText);
           editSave = itemView.findViewById(R.id.edit_button);
           framelayout_edit = itemView.findViewById(R.id.framelayout_edit);
           play = itemView.findViewById(R.id.play);
           score = itemView.findViewById(R.id.score);
           numberTeam = itemView.findViewById(R.id.number_team);
           leftColor = itemView.findViewById(R.id.leftColor);
           rightColor = itemView.findViewById(R.id.rightColor);
       }
   }
}
فایل‌های پیوست تصاویر بندانگشتی
   

ارسال‌ها

پاسخ

تشکر شده توسط:

نویسنده : خنجی بازدید : 1 تاريخ : يکشنبه 5 آذر 1396 ساعت: 15:19
برچسب‌ها : دیتابیس,اندروید,
اخبار و رسانه هاهنر و ادبیاترایانه و اینترنتعلم و فن آوریتجارت و اقتصاداندیشه و مذهبفوتو بلاگوبلاگ و وبلاگ نویسیفرهنگ و تاریخجامعه و سیاستورزشسرگرمی و طنزشخصیخانواده و زندگیسفر و توریسمفارسی زبان در دیگر کشورها