Adds monster meta (size, type, subtype/tag, and alignment) to monster cards.
This commit is contained in:
@@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
import com.majinnaibu.monstercards.R;
|
||||
import com.majinnaibu.monstercards.models.Monster;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
public class MonsterFragment extends Fragment {
|
||||
|
||||
private MonsterViewModel monsterViewModel;
|
||||
@@ -24,7 +25,13 @@ public class MonsterFragment extends Fragment {
|
||||
|
||||
// TODO: remove this block make the monster ID a parameter to the view and get the monster from saved data (sqlite)
|
||||
Monster monster = new Monster();
|
||||
// Name
|
||||
monster.setName("Pixie");
|
||||
// Meta
|
||||
monster.setSize("tiny");
|
||||
monster.setType("fey");
|
||||
monster.setTag("");
|
||||
monster.setAlignment("neutral good");
|
||||
// END remove block
|
||||
monsterViewModel = new ViewModelProvider(this).get(MonsterViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_monster, container, false);
|
||||
@@ -38,6 +45,14 @@ public class MonsterFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
final TextView monsterMeta = root.findViewById(R.id.meta);
|
||||
monsterViewModel.getMeta().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
monsterMeta.setText(s);
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,17 +12,23 @@ public class MonsterViewModel extends ViewModel {
|
||||
mMonster = null;
|
||||
mName = new MutableLiveData<>();
|
||||
mName.setValue("");
|
||||
|
||||
mMeta = new MutableLiveData<>();
|
||||
mMeta.setValue("");
|
||||
}
|
||||
|
||||
private MutableLiveData<String> mName;
|
||||
public LiveData<String> getName() {
|
||||
return mName;
|
||||
}
|
||||
private MutableLiveData<String> mMeta;
|
||||
public LiveData<String> getMeta() {
|
||||
return mMeta;
|
||||
}
|
||||
|
||||
private Monster mMonster;
|
||||
public void setMonster(Monster monster) {
|
||||
mMonster = monster;
|
||||
mName.setValue(mMonster.getName());
|
||||
mMeta.setValue(mMonster.getMeta());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user