Commit 980a55b7 authored by Kevin Whitaker's avatar Kevin Whitaker

Implement party achievements being displayed and added.

parent dd0677c2
......@@ -13,6 +13,7 @@ import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import com.eyecreate.miceandmystics.miceandmystics.adapters.CampaignDetailsAdapter;
import com.eyecreate.miceandmystics.miceandmystics.model.Achievement;
import com.eyecreate.miceandmystics.miceandmystics.model.Campaign;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CharacterNames;
import com.eyecreate.miceandmystics.miceandmystics.model.Player;
......@@ -68,6 +69,7 @@ public class CampaignDetailsActivity extends RecyclerViewActivity {
startActivity(managePlayers);
return true;
} else if (id == R.id.action_add_party_achievement) {
newAchievementDialog();
return true;
}
......@@ -108,6 +110,36 @@ public class CampaignDetailsActivity extends RecyclerViewActivity {
getAdapter().notifyDataSetChanged();
}
public void newAchievementDialog() {
LayoutInflater inflator = (LayoutInflater)(new ContextThemeWrapper(this, R.style.dialogTheme)).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View dialogView = inflator.inflate(R.layout.dialog_new_achievement, null, false);
final Spinner achievementSpinner = ((Spinner)dialogView.findViewById(R.id.achievement_name));
achievementSpinner.setAdapter(new ArrayAdapter<com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement>(this, R.layout.simple_spinner_item, com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement.values()));
achievementSpinner.setSelection(0);
AlertDialog addDialog = new AlertDialog.Builder(this,R.style.dialogTheme)
.setMessage("Please select the achievement to add to party:")
.setView(dialogView)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
RealmResults<Achievement> currentPartyAchievements = MiceAndMysticsApplication.getRealmInstance().where(Achievement.class).findAll();
boolean hasAlready = false;
for (Achievement achievement:currentPartyAchievements) {
if(achievementSpinner.getSelectedItem().toString().equals(achievement.getAchievementName())){
hasAlready = true;
}
}
if (!hasAlready) {
((CampaignDetailsAdapter) getAdapter()).addPartyAchievement((com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement) achievementSpinner.getSelectedItem());
} else {
Toast.makeText(CampaignDetailsActivity.this, "Can not have more than one of same achievement.", Toast.LENGTH_LONG).show();
}
}
})
.create();
addDialog.show();
}
public void newCharacterDialog() {
LayoutInflater inflator = (LayoutInflater)(new ContextThemeWrapper(this, R.style.dialogTheme)).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View dialogView = inflator.inflate(R.layout.dialog_new_character, null, false);
......
......@@ -8,10 +8,12 @@ import android.widget.Toast;
import com.eyecreate.miceandmystics.miceandmystics.MiceAndMysticsApplication;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.model.*;
import com.eyecreate.miceandmystics.miceandmystics.model.Achievement;
import com.eyecreate.miceandmystics.miceandmystics.model.Character;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CharacterNames;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.*;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignDetailsViewHolder;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignHeaderViewHolder;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.PartyAchievementViewHolder;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.PartyAchievementsHeaderViewHolder;
import java.util.UUID;
......@@ -35,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 null;
return new PartyAchievementViewHolder(inflater.inflate(R.layout.item_party_achievement,parent,false));
}
}
......@@ -45,6 +47,8 @@ public class CampaignDetailsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
((CampaignHeaderViewHolder)holder).bindModel(currentCampaign);
} else if(holder instanceof CampaignDetailsViewHolder) {
((CampaignDetailsViewHolder)holder).bindModel(currentCampaign.getCurrentCharacters().get(position-1)); //Here's that one again making the position value related to characters again.
} else if(holder instanceof PartyAchievementViewHolder) {
((PartyAchievementViewHolder) holder).bindHolder(currentCampaign.getPartyStoryAchievements().get(position-2-currentCampaign.getCurrentCharacters().size())); //Here is more math that removes the headers and characters from the count.
}
}
......@@ -99,6 +103,16 @@ public class CampaignDetailsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
}
public void addPartyAchievement(com.eyecreate.miceandmystics.miceandmystics.model.Enums.Achievement achievement) {
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
Achievement realmAchievement = MiceAndMysticsApplication.getRealmInstance().createObject(Achievement.class);
realmAchievement.setUuid(UUID.randomUUID().toString());
realmAchievement.setAchievementName(achievement.displayName());
currentCampaign.getPartyStoryAchievements().add(realmAchievement);
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
fullRefresh();
}
@Override
public int getItemViewType(int position) {
if(position == 0) {
......@@ -114,6 +128,6 @@ public class CampaignDetailsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
@Override
public int getItemCount() {
return currentCampaign.getCurrentCharacters().size()+1+1; //The two plus ones are for the headers.
return currentCampaign.getCurrentCharacters().size()+1+1+currentCampaign.getPartyStoryAchievements().size(); //The two plus ones are for the headers.
}
}
......@@ -55,5 +55,5 @@ public enum Abilities {
public String displayName() { return displayName; }
@Override public String toString() { return displayName; }
public Abilities valueOfDisplayName(String valuedDisplayName) {return Abilities.valueOf(valuedDisplayName.replace(" ","_"));}
public static Abilities valueOfDisplayName(String valuedDisplayName) {return Abilities.valueOf(valuedDisplayName.replace(" ","_"));}
}
package com.eyecreate.miceandmystics.miceandmystics.model.Enums;
import com.eyecreate.miceandmystics.miceandmystics.R;
public enum Achievement {
Miz_Maggie("Miz Maggie"),
Vanestras_Brush("Vanestra's Brush"),
King("King"),
Cats_Horn_Claw("Cat's Horn Claw"),
Catnip("Catnip");
Miz_Maggie("Miz Maggie", R.mipmap.mizmaggie),
Vanestras_Brush("Vanestra's Brush",R.mipmap.vanbrush),
King("King",R.mipmap.king),
Cats_Horn_Claw("Cat's Horn Claw",R.mipmap.catclaw), //not sure if it matters this is the claw and not the horn side.
Catnip("Catnip",R.mipmap.catnip);
private String displayName;
private int displayResource;
Achievement(String displayName) {
Achievement(String displayName,int resource) {
this.displayName = displayName;
this.displayResource = resource;
}
public String displayName() { return displayName; }
public int getDisplayResource() { return displayResource; }
@Override public String toString() { return displayName; }
public Achievement valueOfDisplayName(String valuedDisplayName) {return Achievement.valueOf(valuedDisplayName.replace(" ","_").replace("'",""));}
public static Achievement valueOfDisplayName(String valuedDisplayName) {return Achievement.valueOf(valuedDisplayName.replace(" ","_").replace("'",""));}
}
......@@ -29,20 +29,6 @@ public class CampaignViewHolder extends RecyclerView.ViewHolder implements View.
characterGraph = (PieGraph) itemView.findViewById(R.id.campaign_characters_graph);
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
itemView.setOnTouchListener(new View.OnTouchListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onTouch(View v, MotionEvent event) {
v
.findViewById(R.id.campaign_content)
.getBackground()
.setHotspot(event.getX(), event.getY());
return(false);
}
});
}
}
@Override
......
package com.eyecreate.miceandmystics.miceandmystics.viewholders;
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.model.Achievement;
public class PartyAchievementViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener {
TextView achievementName;
ImageView achievementIcon;
public PartyAchievementViewHolder(View itemView) {
super(itemView);
achievementName = (TextView)itemView.findViewById(R.id.achievement_name);
achievementIcon = (ImageView)itemView.findViewById(R.id.achievement_icon);
itemView.setOnLongClickListener(this);
}
public void bindHolder(Achievement 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;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="12dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:layout_width="match_parent"
android:id="@+id/achievement_name"
android:layout_height="wrap_content"/>
</LinearLayout>
\ No newline at end of file
......@@ -4,7 +4,7 @@
android:orientation="vertical"
android:layout_width="match_parent"
app:cardUseCompatPadding="true"
app:cardElevation="0dp"
app:cardElevation="4dp"
android:foreground="?android:attr/selectableItemBackground"
android:layout_height="match_parent">
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
app:cardUseCompatPadding="true"
app:cardElevation="4dp"
android:foreground="?android:attr/selectableItemBackground"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:background="@color/parchment_yellow"
android:layout_height="wrap_content">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:id="@+id/achievement_icon"/>
<LinearLayout
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/achievement_name"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
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