@Override public boolean onLongClick(View v) { int position = ((RecyclerView.ViewHolder) v.getTag()).getAdapterPosition(); Team newTeam = realm.where(Team.class).equalTo("teamId", 0).findFirst(); if (saveMonsterListRecycler.getItem(position).getMonsterId() == 0 && monsterPosition == 0) { if (toast != null) { toast.cancel(); } toast = Toast.makeText(getActivity(), "Leader cannot be empty", Toast.LENGTH_SHORT); toast.show(); } else { if (replaceAll) { ArrayList<Team> teamList = new ArrayList<>(); RealmResults results = realm.where(Team.class).findAll(); teamList.addAll(results); for (int i = 0; i < teamList.size(); i++) { for (int j = 0; j < teamList.get(i).getMonsters().size(); j++) { if (teamList.get(i).getMonsters().get(j).getMonsterId() == replaceMonsterId) { realm.beginTransaction(); teamList.get(i).setMonsters(j, saveMonsterListRecycler.getItem(position)); realm.commitTransaction(); } } } } else { realm.beginTransaction(); Monster monster = realm.copyToRealmOrUpdate(saveMonsterListRecycler.getItem(position)); switch (monsterPosition) { case 0: newTeam.setLead(monster); break; case 1: newTeam.setSub1(monster); break; case 2: newTeam.setSub2(monster); break; case 3: newTeam.setSub3(monster); break; case 4: newTeam.setSub4(monster); break; case 5: newTeam.setHelper(monster); break; } realm.commitTransaction(); } getActivity().getSupportFragmentManager().popBackStack(MonsterListFragment.TAG, 0); } return true; }
@Override public void onClick(View v) { int position = (int) v.getTag(R.string.index); Team newTeam = realm.where(Team.class).equalTo("teamId", 0).findFirst(); if (saveMonsterListRecycler.getItem(position).getMonsterId() == 0 && monsterPosition == 0) { if (toast != null) { toast.cancel(); } toast = Toast.makeText(getActivity(), "Leader cannot be empty", Toast.LENGTH_SHORT); toast.show(); } else { if (replaceAll) { ArrayList<Team> teamList = new ArrayList<>(); RealmResults results = realm.where(Team.class).findAll(); teamList.addAll(results); for (int i = 0; i < teamList.size(); i++) { for (int j = 0; j < teamList.get(i).getMonsters().size(); j++) { if (teamList.get(i).getMonsters().get(j).getMonsterId() == replaceMonsterId) { realm.beginTransaction(); teamList.get(i).setMonsters(j, saveMonsterListRecycler.getItem(position)); realm.commitTransaction(); } } } } else { realm.beginTransaction(); Monster monster = realm.copyToRealmOrUpdate(saveMonsterListRecycler.getItem(position)); switch (monsterPosition) { case 0: newTeam.setLead(monster); break; case 1: newTeam.setSub1(monster); break; case 2: newTeam.setSub2(monster); break; case 3: newTeam.setSub3(monster); break; case 4: newTeam.setSub4(monster); break; case 5: newTeam.setHelper(monster); break; } realm.commitTransaction(); } // Intent intent = new Intent(); // Bundle bundle = new Bundle(); // bundle.putParcelable("monster", // saveMonsterListRecycler.getItem(position)); // bundle.putLong("monsterId", // saveMonsterListRecycler.getItem(position).getMonsterId()); // intent.putExtras(bundle); // intent.putExtra("monster", saveMonsterListRecycler.getItem(position)); // intent.putExtra("monsterId", // saveMonsterListRecycler.getItem(position).getMonsterId()); // Log.d("SaveMonsterList", "monster is: " + // intent.getParcelableExtra("monster") + " extra is: " + intent.getExtras()); // getActivity().setResult(Activity.RESULT_OK, intent); // getActivity().finish(); getActivity().getSupportFragmentManager().popBackStack(MonsterListFragment.TAG, 0); Parcelable monsterParcel = Parcels.wrap(saveMonsterListRecycler.getItem(position)); ((MainActivity) getActivity()) .switchFragment( MonsterPageFragment.newInstance( saveMonsterListRecycler.getItem(position).getMonsterId(), monsterPosition, monsterParcel), MonsterPageFragment.TAG, "good"); } }