Adds speeds to monster card.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package com.majinnaibu.monstercards.helpers;
|
package com.majinnaibu.monstercards.helpers;
|
||||||
|
|
||||||
@SuppressWarnings({"BooleanMethodIsAlwaysInverted", "RedundantIfStatement"})
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@SuppressWarnings({"RedundantIfStatement"})
|
||||||
public final class StringHelper {
|
public final class StringHelper {
|
||||||
public static boolean isNullOrEmpty(CharSequence value) {
|
public static boolean isNullOrEmpty(CharSequence value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@@ -13,4 +15,24 @@ public final class StringHelper {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String join(String delimiter, Collection<String> strings) {
|
||||||
|
int length = strings.size();
|
||||||
|
if (length < 1) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
boolean isFirst = true;
|
||||||
|
for (String element : strings) {
|
||||||
|
if (!isFirst) {
|
||||||
|
sb.append(delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(element);
|
||||||
|
|
||||||
|
isFirst = false;
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,5 +338,98 @@ public class Monster {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String mSpeed;
|
||||||
|
public String getSpeed() {
|
||||||
|
return mSpeed;
|
||||||
|
}
|
||||||
|
public void setSpeed(String value) {
|
||||||
|
mSpeed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mBurrowSpeed;
|
||||||
|
public String getBurrowSpeed() {
|
||||||
|
return mBurrowSpeed;
|
||||||
|
}
|
||||||
|
public void setBurrowSpeed(String value) {
|
||||||
|
mBurrowSpeed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mClimbSpeed;
|
||||||
|
public String getClimbSpeed() {
|
||||||
|
return mClimbSpeed;
|
||||||
|
}
|
||||||
|
public void setClimbSpeed(String value) {
|
||||||
|
mClimbSpeed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mFlySpeed;
|
||||||
|
public String getFlySpeed() {
|
||||||
|
return mFlySpeed;
|
||||||
|
}
|
||||||
|
public void setFlySpeed(String value) {
|
||||||
|
mFlySpeed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean mHover;
|
||||||
|
public boolean getHover() {
|
||||||
|
return mHover;
|
||||||
|
}
|
||||||
|
public void setHover(boolean value) {
|
||||||
|
mHover = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mSwimSpeed;
|
||||||
|
public String getSwimSpeed() {
|
||||||
|
return mSwimSpeed;
|
||||||
|
}
|
||||||
|
public void setSwimSpeed(String value) {
|
||||||
|
mSwimSpeed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean mCustomSpeed;
|
||||||
|
public boolean getCustomSpeed() {
|
||||||
|
return mCustomSpeed;
|
||||||
|
}
|
||||||
|
public void setCustomSpeed(boolean value) {
|
||||||
|
mCustomSpeed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mSpeedDescription;
|
||||||
|
public String getSpeedDescription() {
|
||||||
|
return mSpeedDescription;
|
||||||
|
}
|
||||||
|
public void setSpeedDescription(String value) {
|
||||||
|
mSpeedDescription = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSpeedText() {
|
||||||
|
if (getCustomSpeed()) {
|
||||||
|
return getSpeedDescription();
|
||||||
|
} else {
|
||||||
|
ArrayList<String> speedParts = new ArrayList<>();
|
||||||
|
speedParts.add(String.format("%s ft.", getSpeed()));
|
||||||
|
String burrowSpeed = getBurrowSpeed();
|
||||||
|
if (!StringHelper.isNullOrEmpty(burrowSpeed) && !"0".equals(burrowSpeed)) {
|
||||||
|
speedParts.add(String.format("burrow %s ft.", burrowSpeed));
|
||||||
|
}
|
||||||
|
|
||||||
|
String climbSpeed = getClimbSpeed();
|
||||||
|
if (!StringHelper.isNullOrEmpty(climbSpeed) && !"0".equals(climbSpeed)) {
|
||||||
|
speedParts.add(String.format("climb %s ft.", climbSpeed));
|
||||||
|
}
|
||||||
|
|
||||||
|
String flySpeed = getFlySpeed();
|
||||||
|
if (!StringHelper.isNullOrEmpty(flySpeed) && !"0".equals(flySpeed)) {
|
||||||
|
speedParts.add(String.format("fly %s ft.%s", flySpeed, getHover() ? " (hover)" : ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
String swimSpeed = getSwimSpeed();
|
||||||
|
if (!StringHelper.isNullOrEmpty(swimSpeed) && !"0".equals(swimSpeed)) {
|
||||||
|
speedParts.add(String.format("swim %s ft.", swimSpeed));
|
||||||
|
}
|
||||||
|
|
||||||
|
return StringHelper.join(", ", speedParts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,14 @@ public class MonsterFragment extends Fragment {
|
|||||||
monster.setHitDice(1);
|
monster.setHitDice(1);
|
||||||
monster.setCustomHP(false);
|
monster.setCustomHP(false);
|
||||||
monster.setHPText("11 (2d8 + 2)");
|
monster.setHPText("11 (2d8 + 2)");
|
||||||
|
monster.setSpeed("10");
|
||||||
|
monster.setBurrowSpeed("0");
|
||||||
|
monster.setClimbSpeed("0");
|
||||||
|
monster.setFlySpeed("30");
|
||||||
|
monster.setHover(false);
|
||||||
|
monster.setSwimSpeed("0");
|
||||||
|
monster.setCustomSpeed(false);
|
||||||
|
monster.setSpeedDescription("30 ft., swim 30 ft.");
|
||||||
|
|
||||||
// END remove block
|
// END remove block
|
||||||
monsterViewModel = new ViewModelProvider(this).get(MonsterViewModel.class);
|
monsterViewModel = new ViewModelProvider(this).get(MonsterViewModel.class);
|
||||||
@@ -80,6 +88,14 @@ public class MonsterFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final TextView monsterSpeed = root.findViewById(R.id.speed);
|
||||||
|
monsterViewModel.getSpeed().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(String speed) {
|
||||||
|
monsterSpeed.setText(Html.fromHtml("<b>Speed</b> " + speed));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
mArmorClass.setValue("");
|
mArmorClass.setValue("");
|
||||||
mHitPoints = new MutableLiveData<>();
|
mHitPoints = new MutableLiveData<>();
|
||||||
mHitPoints.setValue("");
|
mHitPoints.setValue("");
|
||||||
|
mSpeed = new MutableLiveData<>();
|
||||||
|
mSpeed.setValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private MutableLiveData<String> mName;
|
private MutableLiveData<String> mName;
|
||||||
@@ -36,6 +38,10 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
public LiveData<String> getHitPoints() {
|
public LiveData<String> getHitPoints() {
|
||||||
return mHitPoints;
|
return mHitPoints;
|
||||||
}
|
}
|
||||||
|
private MutableLiveData<String> mSpeed;
|
||||||
|
public LiveData<String> getSpeed() {
|
||||||
|
return mSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
private Monster mMonster;
|
private Monster mMonster;
|
||||||
public void setMonster(Monster monster) {
|
public void setMonster(Monster monster) {
|
||||||
@@ -44,5 +50,6 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
mMeta.setValue(mMonster.getMeta());
|
mMeta.setValue(mMonster.getMeta());
|
||||||
mArmorClass.setValue(mMonster.getArmorClass());
|
mArmorClass.setValue(mMonster.getArmorClass());
|
||||||
mHitPoints.setValue(mMonster.getHitPoints());
|
mHitPoints.setValue(mMonster.getHitPoints());
|
||||||
|
mSpeed.setValue(mMonster.getSpeedText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,5 +82,18 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/armor_class"
|
app:layout_constraintTop_toBottomOf="@+id/armor_class"
|
||||||
tools:text="Hit Points 1 (1d4 - 1)" />
|
tools:text="Hit Points 1 (1d4 - 1)" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/speed"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/hit_points"
|
||||||
|
tools:text="10 ft., fly 30 ft." />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
Reference in New Issue
Block a user