Commit 8103e300 authored by Kevin Whitaker's avatar Kevin Whitaker

I somehow missed that all similar class objects are stored in the same db....

I somehow missed that all similar class objects are stored in the same db. This means I needed to add a more unique id. Renamed classes to make easier to read. Fix typo in spelling. Fill out initial header and UI for character details.
parent f0753180
......@@ -53,7 +53,7 @@ public class CampaignActivity extends RecyclerViewActivity {
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
((CampaignAdapter) getAdapter()).addItem(((EditText) dialogView.findViewById(R.id.campagin_name)).getText().toString(), CampaignType.valueOfDisplayName(typeSpinner.getSelectedItem().toString()));
((CampaignAdapter) getAdapter()).addItem(((EditText) dialogView.findViewById(R.id.campaign_name)).getText().toString(), CampaignType.valueOfDisplayName(typeSpinner.getSelectedItem().toString()));
}
})
.create();
......
......@@ -4,6 +4,7 @@ import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.Menu;
import android.view.MenuItem;
import com.eyecreate.miceandmystics.miceandmystics.adapters.CampaignDetailsAdapter;
import com.eyecreate.miceandmystics.miceandmystics.model.Campaign;
......@@ -17,6 +18,7 @@ public class CampaignDetailsActivity extends RecyclerViewActivity {
setTitle(getIntent().getStringExtra("campaignName"));
campaign = MiceAndMysticsApplication.getRealmInstance().where(Campaign.class).equalTo("campaignName",getIntent().getStringExtra("campaignName")).findFirst();
setLayoutManager(new LinearLayoutManager(this));
setAdapter(new CampaignDetailsAdapter(campaign));
}
......
......@@ -7,10 +7,10 @@ import android.view.ViewGroup;
import com.eyecreate.miceandmystics.miceandmystics.MiceAndMysticsApplication;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CampaignType;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.Campaign;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignViewHolder;
import io.realm.RealmResults;
public class CampaignAdapter extends RecyclerView.Adapter<Campaign> {
public class CampaignAdapter extends RecyclerView.Adapter<CampaignViewHolder> {
LayoutInflater inflater;
RealmResults<com.eyecreate.miceandmystics.miceandmystics.model.Campaign> campaigns;
......@@ -20,13 +20,13 @@ public class CampaignAdapter extends RecyclerView.Adapter<Campaign> {
}
@Override
public Campaign onCreateViewHolder(ViewGroup parent, int viewType) {
public CampaignViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if(inflater == null) inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return new Campaign(inflater.inflate(R.layout.item_campaign,parent,false),this);
return new CampaignViewHolder(inflater.inflate(R.layout.item_campaign,parent,false),this);
}
@Override
public void onBindViewHolder(Campaign holder, int position) {
public void onBindViewHolder(CampaignViewHolder holder, int position) {
holder.bindModel(campaigns.get(position));
}
......
package com.eyecreate.miceandmystics.miceandmystics.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignDetails;
import com.eyecreate.miceandmystics.miceandmystics.MiceAndMysticsApplication;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.model.*;
import com.eyecreate.miceandmystics.miceandmystics.model.Character;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CharacterNames;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CharacterType;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignDetailsViewHolder;
import com.eyecreate.miceandmystics.miceandmystics.viewholders.CampaignHeaderViewHolder;
import java.util.UUID;
public class CampaignDetailsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
LayoutInflater inflater;
Campaign currentCampaign;
public CampaignDetailsAdapter(Campaign currentCampaign) {
this.currentCampaign = currentCampaign;
}
public class CampaignDetailsAdapter extends RecyclerView.Adapter<CampaignDetails> {
@Override
public CampaignDetails onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if(inflater == null) inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(viewType==R.id.campaignDetailMainHeader) {
return new CampaignHeaderViewHolder(inflater.inflate(R.layout.item_campaign_header,parent,false));
} else {
return new CampaignDetailsViewHolder(inflater.inflate(R.layout.item_campaign_details,parent,false),this);
}
}
@Override
public void onBindViewHolder(CampaignDetails holder, int position) {
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if(holder instanceof CampaignHeaderViewHolder) {
((CampaignHeaderViewHolder)holder).bindModel(currentCampaign);
} else {
((CampaignDetailsViewHolder)holder).bindModel(currentCampaign.getCurrentCharacters().get(position-1)); //Here's that one again making the position value related to characters again.
}
}
public void fullRefresh() {
notifyDataSetChanged();
}
public void addCharacter(CharacterNames name, Player player) {
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
Character character = MiceAndMysticsApplication.getRealmInstance().createObject(Character.class);
character.setUuid(UUID.randomUUID().toString());
character.setCharacterName(name.name());
character.setControllingPlayer(player);
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
fullRefresh();
}
public void removeCharacter(Character character) {
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
character.removeFromRealm();
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
fullRefresh();
}
@Override
public int getItemViewType(int position) {
if(position == 0) {
return R.id.campaignDetailMainHeader;
} else {
return R.id.campaignDetailItem;
}
}
@Override
public int getItemCount() {
return 0;
return currentCampaign.getCurrentCharacters().size()+1; //The plus one if for header. May expand this for other kinds of details.
}
}
......@@ -3,13 +3,16 @@ package com.eyecreate.miceandmystics.miceandmystics.model;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import java.util.UUID;
public class Ability extends RealmObject {
@PrimaryKey
private String uuid;
private String abilityName;
public Ability() {}
public Ability(String abilityName) {setAbilityName(abilityName);}
public Ability(String abilityName) {setAbilityName(abilityName);setUuid(UUID.randomUUID().toString());}
public String getAbilityName() {
return abilityName;
......@@ -18,4 +21,12 @@ public class Ability extends RealmObject {
public void setAbilityName(String abilityName) {
this.abilityName = abilityName;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
......@@ -3,13 +3,16 @@ package com.eyecreate.miceandmystics.miceandmystics.model;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import java.util.UUID;
public class Achievement extends RealmObject {
@PrimaryKey
private String uuid;
private String achievementName;
public Achievement() {}
public Achievement(String achievementName) {setAchievementName(achievementName);}
public Achievement(String achievementName) {setAchievementName(achievementName);setUuid(UUID.randomUUID().toString());}
public String getAchievementName() {
return achievementName;
......@@ -18,4 +21,12 @@ public class Achievement extends RealmObject {
public void setAchievementName(String achievementName) {
this.achievementName = achievementName;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
......@@ -6,6 +6,7 @@ import io.realm.annotations.PrimaryKey;
public class BackpackItem extends RealmObject {
//TODO:Look into seeing if it's worth hard coding these instead of manual entry.
@PrimaryKey
private String uuid;
private String itemName;
public BackpackItem() {}
......@@ -19,4 +20,12 @@ public class BackpackItem extends RealmObject {
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
......@@ -6,6 +6,7 @@ import io.realm.annotations.PrimaryKey;
public class Character extends RealmObject {
@PrimaryKey
private String uuid;
private String characterName;
private RealmList<Ability> abilities;
private RealmList<BackpackItem> storedItems; //Not sure why I made this a list when rulebook says you can only have one xD
......@@ -42,4 +43,12 @@ public class Character extends RealmObject {
public void setControllingPlayer(Player controllingPlayer) {
this.controllingPlayer = controllingPlayer;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
......@@ -3,13 +3,16 @@ package com.eyecreate.miceandmystics.miceandmystics.model;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import java.util.UUID;
public class Player extends RealmObject {
@PrimaryKey
private String uuid;
private String playerName;
public Player() {}
public Player(String playerName) {setPlayerName(playerName);}
public Player(String playerName) {setPlayerName(playerName);setUuid(UUID.randomUUID().toString());}
public String getPlayerName() {
return playerName;
......@@ -18,4 +21,12 @@ public class Player extends RealmObject {
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
package com.eyecreate.miceandmystics.miceandmystics.viewholders;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class CampaignDetails extends RecyclerView.ViewHolder {
public CampaignDetails(View itemView) {
super(itemView);
}
}
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.Character;
public class CampaignDetailsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener {
TextView characterName,playerName;
ImageView characterIcon;
CampaignDetailsAdapter adapter;
Character boundCharacter;
public CampaignDetailsViewHolder(View itemView,CampaignDetailsAdapter adapter) {
super(itemView);
this.adapter = adapter;
characterName = (TextView)itemView.findViewById(R.id.character_name);
playerName = (TextView)itemView.findViewById(R.id.character_player);
characterIcon = (ImageView)itemView.findViewById(R.id.character_icon);
}
public void bindModel(Character character) {
boundCharacter = character;
characterName.setText(character.getCharacterName());
playerName.setText(character.getControllingPlayer().getPlayerName());
//TODO:implement character icons one in project.
}
@Override
public void onClick(View view) {
//TODO:implement character edit screen.
}
@Override
public boolean onLongClick(View view) {
AlertDialog removeDialog = new AlertDialog.Builder(view.getContext(),R.style.dialogTheme)
.setMessage("Do you want to remove character: "+characterName.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.removeCharacter(boundCharacter);
}
})
.create();
removeDialog.show();
return true;
}
}
package com.eyecreate.miceandmystics.miceandmystics.viewholders;
public class CampaignHeader {
}
package com.eyecreate.miceandmystics.miceandmystics.viewholders;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.model.Campaign;
public class CampaignHeaderViewHolder extends RecyclerView.ViewHolder {
TextView campaignName,campaignType;
public CampaignHeaderViewHolder(View itemView) {
super(itemView);
campaignName = (TextView)itemView.findViewById(R.id.campaign_name);
campaignType = (TextView)itemView.findViewById(R.id.campaign_type);
}
public void bindModel(Campaign campaign) {
campaignName.setText(campaign.getCampaignName());
campaignType.setText(campaign.getCampaignType());
}
}
......@@ -14,13 +14,13 @@ import com.eyecreate.miceandmystics.miceandmystics.CampaignDetailsActivity;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.adapters.CampaignAdapter;
public class Campaign extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener {
public class CampaignViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,View.OnLongClickListener {
CampaignAdapter adapter;
TextView campaignName;
PieGraph characterGraph;
public Campaign(View itemView,CampaignAdapter adapter) {
public CampaignViewHolder(View itemView, CampaignAdapter adapter) {
super(itemView);
this.adapter = adapter;
campaignName = (TextView) itemView.findViewById(R.id.campagin_name);
......
......@@ -6,7 +6,7 @@
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/campagin_name"/>
android:id="@+id/campaign_name"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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="0dp"
android:foreground="?android:attr/selectableItemBackground"
android:layout_height="match_parent">
</LinearLayout>
\ No newline at end of file
<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:id="@+id/character_icon"/>
<LinearLayout
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/character_name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/character_player"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
......@@ -2,13 +2,19 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="@color/dark_red"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="@color/parchment_yellow"
android:gravity="center_horizontal"
android:id="@+id/campaign_name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/parchment_yellow"
android:gravity="center_horizontal"
android:id="@+id/campaign_type"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="campaignDetailMainHeader"/>
<item type="id" name="campaignDetailItem"/>
</resources>
\ 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