Commit 91615dbd authored by Kevin Whitaker's avatar Kevin Whitaker

Implement party achievements being removable.

parent 980a55b7
......@@ -37,7 +37,7 @@ public class CampaignDetailsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
} else if(viewType == R.id.campaignPartyAchievementsHeader){
return new PartyAchievementsHeaderViewHolder(inflater.inflate(R.layout.item_partyachievements_header,parent,false));
} else {
return new PartyAchievementViewHolder(inflater.inflate(R.layout.item_party_achievement,parent,false));
return new PartyAchievementViewHolder(inflater.inflate(R.layout.item_party_achievement,parent,false),this);
}
}
......@@ -113,6 +113,13 @@ public class CampaignDetailsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
fullRefresh();
}
public void removeAchievement(Achievement achievement) {
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
achievement.removeFromRealm();
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
fullRefresh();
}
@Override
public int getItemViewType(int position) {
if(position == 0) {
......
package com.eyecreate.miceandmystics.miceandmystics.viewholders;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.adapters.CampaignDetailsAdapter;
import com.eyecreate.miceandmystics.miceandmystics.model.Achievement;
public class PartyAchievementViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener {
TextView achievementName;
ImageView achievementIcon;
CampaignDetailsAdapter adapter;
Achievement boundAchievement;
public PartyAchievementViewHolder(View itemView) {
public PartyAchievementViewHolder(View itemView, CampaignDetailsAdapter adapter) {
super(itemView);
this.adapter = adapter;
achievementName = (TextView)itemView.findViewById(R.id.achievement_name);
achievementIcon = (ImageView)itemView.findViewById(R.id.achievement_icon);
itemView.setOnLongClickListener(this);
}
public void bindHolder(Achievement achievement) {
this.boundAchievement = achievement;
achievementName.setText(achievement.getAchievementName());
achievementIcon.setImageResource(com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement.valueOfDisplayName(achievement.getAchievementName()).getDisplayResource());
}
@Override
public boolean onLongClick(View view) {
//TODO:implement removing
return false;
AlertDialog removeDialog = new AlertDialog.Builder(view.getContext(),R.style.dialogTheme)
.setMessage("Do you want to remove achievement: "+achievementName.getText()+"?")
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
adapter.removeAchievement(boundAchievement);
}
})
.create();
removeDialog.show();
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment