Commit 8d3c6997 authored by Kevin Whitaker's avatar Kevin Whitaker

Fix some migration headers and add chapter value for campaigns.

parent c72c2884
......@@ -24,7 +24,7 @@ public class MiceAndMysticsApplication extends Application {
public void onCreate() {
super.onCreate();
singletonApplication = this;
realmConfig = new RealmConfiguration.Builder(this).schemaVersion(1).migration(new RealmMigrator()).build();
realmConfig = new RealmConfiguration.Builder(this).schemaVersion(2).migration(new RealmMigrator()).build();
singletonRealm = Realm.getInstance(realmConfig);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("ArchitectsDaughter.ttf")
......
package com.eyecreate.miceandmystics.miceandmystics;
import com.eyecreate.miceandmystics.miceandmystics.model.Campaign;
import io.realm.DynamicRealm;
import io.realm.RealmMigration;
import io.realm.RealmObject;
import io.realm.RealmResults;
public class RealmMigrator implements RealmMigration {
@Override
public void migrate(DynamicRealm dynamicRealm, long oldVersion, long newVersion) {
if(oldVersion == 0 && newVersion == 1) {
if(oldVersion == 0) {
//Nothing
oldVersion++;
}
if(oldVersion == 1) {
dynamicRealm.getSchema().get("Campaign")
.addField("campaignChapter",int.class);
oldVersion++;
}
}
}
......@@ -8,6 +8,7 @@ import java.util.UUID;
public class Ability extends RealmObject {
@PrimaryKey
@Required
private String uuid;
@Required
private String abilityName;
......
......@@ -8,6 +8,7 @@ import java.util.UUID;
public class Achievement extends RealmObject {
@PrimaryKey
@Required
private String uuid;
@Required
private String achievementName;
......
......@@ -7,6 +7,7 @@ import io.realm.annotations.Required;
public class BackpackItem extends RealmObject {
//TODO:Look into seeing if it's worth hard coding these instead of manual entry.
@PrimaryKey
@Required
private String uuid;
@Required
private String itemName;
......
......@@ -7,11 +7,13 @@ import io.realm.annotations.Required;
public class Campaign extends RealmObject {
@PrimaryKey
@Required
private String campaignName;
@Required
private String campaignType;
private RealmList<Character> currentCharacters;
private RealmList<Achievement> partyStoryAchievements;
private int campaignChapter;
public RealmList<Character> getCurrentCharacters() {
return currentCharacters;
......@@ -44,4 +46,12 @@ public class Campaign extends RealmObject {
public void setCampaignType(String campaignType) {
this.campaignType = campaignType;
}
public int getCampaignChapter() {
return campaignChapter;
}
public void setCampaignChapter(int campaignChapter) {
this.campaignChapter = campaignChapter;
}
}
......@@ -7,6 +7,7 @@ import io.realm.annotations.Required;
public class Character extends RealmObject {
@PrimaryKey
@Required
private String uuid;
@Required
private String characterName;
......
......@@ -2,12 +2,14 @@ package com.eyecreate.miceandmystics.miceandmystics.model;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import io.realm.annotations.Required;
import java.util.List;
import java.util.UUID;
public class Player extends RealmObject {
@PrimaryKey
@Required
private String playerName;
public Player() {}
......
package com.eyecreate.miceandmystics.miceandmystics.viewholders;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.eyecreate.miceandmystics.miceandmystics.MiceAndMysticsApplication;
import com.eyecreate.miceandmystics.miceandmystics.R;
import com.eyecreate.miceandmystics.miceandmystics.model.Campaign;
import com.eyecreate.miceandmystics.miceandmystics.model.Enums.CampaignType;
public class CampaignHeaderViewHolder extends RecyclerView.ViewHolder {
TextView campaignName,campaignType;
TextView campaignName,campaignType,campaignChapter;
EditText chapterEdit;
public CampaignHeaderViewHolder(View itemView) {
super(itemView);
campaignName = (TextView)itemView.findViewById(R.id.campaign_name);
campaignType = (TextView)itemView.findViewById(R.id.campaign_type);
campaignChapter = (TextView) itemView.findViewById(R.id.campaign_chapter);
chapterEdit = (EditText) itemView.findViewById(R.id.edit_chapter);
}
public void bindModel(Campaign campaign) {
public void bindModel(final Campaign campaign) {
campaignName.setText(campaign.getCampaignName());
campaignType.setText(CampaignType.valueOf(campaign.getCampaignType()).displayName());
campaignChapter.setText(campaignChapter.getResources().getText(R.string.campaign_chapter)+" : ");
chapterEdit.setText(String.valueOf(campaign.getCampaignChapter() == 0 ? 1:campaign.getCampaignChapter()));
chapterEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
try{
Integer.parseInt(editable.toString());
}
catch(NumberFormatException e) {
return;
}
MiceAndMysticsApplication.getRealmInstance().beginTransaction();
campaign.setCampaignChapter(Integer.parseInt(editable.toString()));
MiceAndMysticsApplication.getRealmInstance().commitTransaction();
}
});
}
}
......@@ -17,4 +17,22 @@
android:textColor="@color/parchment_yellow"
android:gravity="center_horizontal"
android:id="@+id/campaign_type"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/parchment_yellow"
android:text="Chapter: "
android:gravity="center_horizontal"
android:id="@+id/campaign_chapter"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:id="@+id/edit_chapter"/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -72,6 +72,7 @@
<string name="party_item_header">Party Achievements</string>
<string name="ability_item_header">Abilities</string>
<string name="campaign_activity">Campaigns</string>
<string name="campaign_chapter">Chapter</string>
<string name="campaign_name_request">Please give your new campaign a unique name:</string>
<string name="campaign_name_blank">Can not have blank name!</string>
<string name="character_activity">Character Details</string>
......
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