Adds saving throws to monster card.
This commit is contained in:
@@ -14,7 +14,9 @@ import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.majinnaibu.monstercards.R;
|
||||
import com.majinnaibu.monstercards.helpers.StringHelper;
|
||||
import com.majinnaibu.monstercards.models.Monster;
|
||||
import com.majinnaibu.monstercards.models.SavingThrow;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
public class MonsterFragment extends Fragment {
|
||||
@@ -57,7 +59,18 @@ public class MonsterFragment extends Fragment {
|
||||
monster.setIntelligenceScore(Integer.parseInt("10"));
|
||||
monster.setWisdomScore(Integer.parseInt("14"));
|
||||
monster.setCharismaScore(Integer.parseInt("15"));
|
||||
// Saving Throws
|
||||
monster.addSavingThrow(new SavingThrow("str", 0));
|
||||
monster.addSavingThrow(new SavingThrow("dex", 1));
|
||||
monster.addSavingThrow(new SavingThrow("con", 2));
|
||||
monster.addSavingThrow(new SavingThrow("int", 3));
|
||||
monster.addSavingThrow(new SavingThrow("wis", 4));
|
||||
monster.addSavingThrow(new SavingThrow("cha", 5));
|
||||
|
||||
// Challenge Rating
|
||||
monster.setChallengeRating("*");
|
||||
monster.setCustomChallengeRating("Infinite (0XP)");
|
||||
monster.setCustomProficiencyBonus(4);
|
||||
// END remove block
|
||||
monsterViewModel = new ViewModelProvider(this).get(MonsterViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_monster, container, false);
|
||||
@@ -151,6 +164,19 @@ public class MonsterFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
final TextView monsterSavingThrows = root.findViewById(R.id.saving_throws);
|
||||
monsterViewModel.getSavingThrows().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(String savingThrows) {
|
||||
if (StringHelper.isNullOrEmpty(savingThrows)) {
|
||||
monsterSavingThrows.setVisibility(View.GONE);
|
||||
} else {
|
||||
monsterSavingThrows.setVisibility(View.VISIBLE);
|
||||
}
|
||||
monsterSavingThrows.setText(Html.fromHtml("<b>Saving Throws</b> " + savingThrows));
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ public class MonsterViewModel extends ViewModel {
|
||||
mWisdom.setValue("");
|
||||
mCharisma = new MutableLiveData<>();
|
||||
mCharisma.setValue("");
|
||||
mSavingThrows = new MutableLiveData<>();
|
||||
mSavingThrows.setValue("");
|
||||
}
|
||||
|
||||
private MutableLiveData<String> mName;
|
||||
@@ -78,6 +80,10 @@ public class MonsterViewModel extends ViewModel {
|
||||
public LiveData<String> getCharisma() {
|
||||
return mCharisma;
|
||||
}
|
||||
private MutableLiveData<String> mSavingThrows;
|
||||
public LiveData<String> getSavingThrows() {
|
||||
return mSavingThrows;
|
||||
}
|
||||
|
||||
private Monster mMonster;
|
||||
public void setMonster(Monster monster) {
|
||||
@@ -93,5 +99,6 @@ public class MonsterViewModel extends ViewModel {
|
||||
mIntelligence.setValue(monster.getIntelligenceDescription());
|
||||
mWisdom.setValue(monster.getWisdomDescription());
|
||||
mCharisma.setValue(monster.getCharismaDescription());
|
||||
mSavingThrows.setValue(monster.getSavingThrowsDescription());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user