Skip to content

Commit

Permalink
Merge pull request #60 from Carifio24/add-spells-v3
Browse files Browse the repository at this point in the history
Implement homebrew spells and use Android navigation graph
  • Loading branch information
Carifio24 authored Apr 7, 2024
2 parents 4b3fe8b + 4fb2a40 commit b8c6ac2
Show file tree
Hide file tree
Showing 140 changed files with 4,355 additions and 1,800 deletions.
36 changes: 36 additions & 0 deletions Icons/cauldron-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 30 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'placeholder-resolver'
apply plugin: 'com.likethesalad.stem'

android {
signingConfigs {
Expand All @@ -21,8 +21,8 @@ android {
signingConfig signingConfigs.release
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
buildTypes {
release {
Expand All @@ -39,29 +39,38 @@ android {
viewBinding true
dataBinding true
}
stringXmlReference {
keepResolvedFiles = true
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
lint {
abortOnError false
}
namespace 'dnd.jon.spellbook'
}

dependencies {
implementation 'androidx.navigation:navigation-runtime:2.5.2'
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
because 'align all versions of Kotlin transitive dependencies'
}
}
def nav_version = "2.6.0"

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.core:core:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.fragment:fragment:1.4.0'
implementation 'androidx.lifecycle:lifecycle-livedata:2.3.1'
implementation 'androidx.core:core:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.fragment:fragment:1.6.1'
implementation 'androidx.lifecycle:lifecycle-livedata:2.6.2'
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"

//implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.1'
implementation 'com.google.android.material:material:1.9.0'
implementation "androidx.gridlayout:gridlayout:1.0.0"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'com.github.deano2390:MaterialShowcaseView:1.3.4'
Expand All @@ -72,13 +81,17 @@ dependencies {
implementation 'com.github.kizitonwose.colorpreference:support:1.1.0'
implementation 'com.github.skydoves:colorpickerview:2.2.4'
implementation 'io.github.cdimascio:dotenv-java:2.2.4'
implementation "com.leinardi.android:speed-dial:3.3.0"
//implementation 'org.sufficientlysecure:html-textview:4.0'

testImplementation 'junit:junit:4.13.1'
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'androidx.test:core:1.5.0'
testImplementation 'com.google.truth:truth:1.1.2'
testImplementation 'org.robolectric:robolectric:4.4'
testImplementation 'org.json:json:20180813'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation files('libs/commons-lang3-3.8.jar')
}


Binary file added app/release/app-release.aab
Binary file not shown.
11 changes: 11 additions & 0 deletions app/src/debug/res/drawable-anydpi/ic_add_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FFFFFF"
android:alpha="0.8">
<path
android:fillColor="@android:color/white"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
11 changes: 11 additions & 0 deletions app/src/debug/res/drawable-anydpi/ic_close_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FFFFFF"
android:alpha="0.8">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
11 changes: 11 additions & 0 deletions app/src/debug/res/drawable-anydpi/ic_delete.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FFFFFF"
android:alpha="0.8">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>
Binary file added app/src/debug/res/drawable-hdpi/ic_add_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-hdpi/ic_close_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-hdpi/ic_delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-mdpi/ic_add_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-mdpi/ic_close_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-mdpi/ic_delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-xhdpi/ic_add_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-xhdpi/ic_close_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-xhdpi/ic_delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-xxhdpi/ic_add_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-xxhdpi/ic_close_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/debug/res/drawable-xxhdpi/ic_delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dnd.jon.spellbook">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/dnd/jon/spellbook/AndroidUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dnd.jon.spellbook;

import android.app.Activity;
import android.util.DisplayMetrics;

import org.javatuples.Pair;

class AndroidUtils {
static Pair<Integer,Integer> screenDimensions(Activity activity) {
final DisplayMetrics displayMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
return new Pair<>(displayMetrics.widthPixels, displayMetrics.heightPixels);
}
}
28 changes: 16 additions & 12 deletions app/src/main/java/dnd/jon/spellbook/CastingTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public static CastingTimeType fromInternalName(String name) {

// Convenience constructors
CastingTime(CastingTimeType type, float value, TimeUnit unit, String str) { super(type, value, unit, str); }
CastingTime(CastingTimeType type, float value, TimeUnit unit) { super(type, value, unit); }
CastingTime(CastingTimeType type, float value) { super(type, value, TimeUnit.SECOND); }
CastingTime(CastingTimeType type) { this(type, 1); }
CastingTime() { this(CastingTimeType.ACTION, 1, TimeUnit.SECOND, ""); }

// For Parcelable
Expand All @@ -83,17 +86,13 @@ private CastingTime(Parcel in) {
String makeString(boolean useStored, Function<CastingTimeType,String> typeNameGetter, Function<TimeUnit,String> unitSingularNameGetter, Function<TimeUnit,String> unitPluralNameGetter) {
if (useStored && !str.isEmpty()) { return str; }
final String name = typeNameGetter.apply(type);
final String valueString = DisplayUtils.DECIMAL_FORMAT.format(value);
if (type == CastingTimeType.TIME) {
final String valueString = DisplayUtils.DECIMAL_FORMAT.format(value);
final Function<TimeUnit,String> unitNameGetter = (value == 1) ? unitSingularNameGetter : unitPluralNameGetter;
final String unitStr = unitNameGetter.apply(unit);
return valueString + " " + unitStr;
} else {
String typeStr = name;
if (value != 1) {
typeStr += "s";
}
return valueString + " " + typeStr;
return name;
}
}

Expand All @@ -108,22 +107,27 @@ String internalString() {
// Create a range from a string
static CastingTime fromString(String s, Function<CastingTimeType,String> typeNameGetter, Function<String, TimeUnit> timeUnitMaker, boolean useForStr) {
try {

String[] sSplit = s.split(" ", 2);
final float value = Float.parseFloat(sSplit[0]);
final String typeStr = sSplit[1];
//System.out.println("sSplit0: " + sSplit[0]);
//System.out.println("sSplit1: " + sSplit[1]);
float value = 1;
String typeStr = "";
try {
value = Float.parseFloat(sSplit[0]);
typeStr = sSplit[1];
} catch (NumberFormatException e) {
e.printStackTrace();
}

// If the type is one of the action types
CastingTimeType type = null;
for (CastingTimeType ct : CastingTimeType.actionTypes) {
if (typeStr.startsWith(typeNameGetter.apply(ct))) {
final String typeName = typeNameGetter.apply(ct);
if (s.startsWith(typeName) || typeStr.startsWith(typeName)) {
type = ct;
break;
}
}
if (type != null) {
//final int inRounds = value * SECONDS_PER_ROUND;
final String str = useForStr ? s : "";
return new CastingTime(type, 1, TimeUnit.SECOND, str);
}
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/dnd/jon/spellbook/CenterReveal.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
public class CenterReveal {

private final View view;
private final View container;
private ObjectAnimator viewTranslation;
private ObjectAnimator viewAlpha;
private ObjectAnimator viewScale;
private ObjectAnimator containerAlpha;
private final ObjectAnimator viewTranslation;
private final ObjectAnimator viewAlpha;
private final ObjectAnimator viewScale;
private final ObjectAnimator containerAlpha;

private static final long duration = 150L;

CenterReveal(View view, View container) {
this.view = view;
this.container = container;
final ViewGroup parent = (ViewGroup) view.getParent();
final ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
final float cX = marginLayoutParams.getMarginEnd() + view.getWidth() / 2f - parent.getWidth() / 2f;
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/dnd/jon/spellbook/CharacterAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupMenu;
Expand All @@ -20,6 +21,10 @@

public class CharacterAdapter extends NamedItemAdapter<CharacterAdapter.CharacterRowHolder> {

private static final String confirmDeleteTag = "confirmDeleteCharacter";
private static final String duplicateTag = "duplicateCharacter";
private static final String renameTag = "changeCharacterName";

CharacterAdapter(FragmentActivity fragmentActivity) {
super(fragmentActivity, SpellbookViewModel::currentCharacterNames);
}
Expand Down Expand Up @@ -47,26 +52,30 @@ public void bind(String name) {
binding.optionsButton.setOnClickListener((View v) -> {
final PopupMenu popupMenu = new PopupMenu(activity, binding.optionsButton);
popupMenu.inflate(R.menu.options_menu);
final MenuItem updateItem = popupMenu.getMenu().findItem(R.id.options_update);
if (updateItem != null) {
updateItem.setTitle(R.string.rename);
}
popupMenu.setOnMenuItemClickListener((menuItem) -> {
final int itemID = menuItem.getItemId();
if (itemID == R.id.options_rename) {
if (itemID == R.id.options_update) {
final Bundle args = new Bundle();
args.putString(NameChangeDialog.nameKey, binding.getName());
final CharacterNameChangeDialog dialog = new CharacterNameChangeDialog();
dialog.setArguments(args);
dialog.show(activity.getSupportFragmentManager(), "changeCharacterName");
dialog.show(activity.getSupportFragmentManager(), renameTag);
} else if (itemID == R.id.options_duplicate) {
final Bundle args = new Bundle();
args.putParcelable(CreateCharacterDialog.PROFILE_KEY, viewModel.getProfileByName(binding.getName()));
final CreateCharacterDialog dialog = new CreateCharacterDialog();
dialog.setArguments(args);
dialog.show(activity.getSupportFragmentManager(), "duplicateCharacter");
dialog.show(activity.getSupportFragmentManager(), duplicateTag);
} else if (itemID == R.id.options_delete) {
final Bundle args = new Bundle();
args.putString(DeleteCharacterDialog.NAME_KEY, binding.getName());
final DeleteCharacterDialog dialog = new DeleteCharacterDialog();
dialog.setArguments(args);
dialog.show(activity.getSupportFragmentManager(), "confirmDeleteCharacter");
dialog.show(activity.getSupportFragmentManager(), confirmDeleteTag);
} else if (itemID == R.id.options_export) {
// String permissionNeeded;
// if (GlobalInfo.ANDROID_VERSION >= Build.VERSION_CODES.R) {
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/dnd/jon/spellbook/CharacterProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ public JSONObject toJSON() throws JSONException {
// Construct a profile from a JSON object
// Basically the inverse to toJSON
static CharacterProfile fromJSON(JSONObject json) throws JSONException {
//System.out.println(json.toString(4));
if (json.has(versionCodeKey)) {
final String versionCode = json.getString(versionCodeKey);
final Version version = SpellbookUtils.coalesce(Version.fromString(versionCode), GlobalInfo.VERSION);
Expand Down Expand Up @@ -356,7 +355,7 @@ private static CharacterProfile fromJSONNew(JSONObject json, Version version) th

final EnumSet<CasterClass> visibleCasterClasses = visibleSetFromLegacyJSON(json, CasterClass.class);
final EnumSet<School> visibleSchools = visibleSetFromLegacyJSON(json, School.class);
final Set<Source> visibleSources = visibleSetFromLegacyJSON(json, Source.class, Source.values());
final Set<Source> visibleSources = visibleSetFromLegacyJSON(json, Source.class, Source.sourcebooks());
final EnumSet<CastingTimeType> visibleCastingTimeTypes = visibleSetFromLegacyJSON(json, CastingTimeType.class);
final EnumSet<DurationType> visibleDurationTypes = visibleSetFromLegacyJSON(json, DurationType.class);
final EnumSet<RangeType> visibleRangeTypes = visibleSetFromLegacyJSON(json, RangeType.class);
Expand Down Expand Up @@ -463,7 +462,7 @@ private static CharacterProfile fromJSONPre2_10(JSONObject json) throws JSONExce

final EnumSet<CasterClass> visibleCasterClasses = visibleSetFromLegacyJSON(json, CasterClass.class);
final EnumSet<School> visibleSchools = visibleSetFromLegacyJSON(json, School.class);
final Set<Source> visibleSources = visibleSetFromLegacyJSON(json, Source.class, Source.values());
final Set<Source> visibleSources = visibleSetFromLegacyJSON(json, Source.class, Source.sourcebooks());
final EnumSet<CastingTimeType> visibleCastingTimeTypes = visibleSetFromLegacyJSON(json, CastingTimeType.class);
final EnumSet<DurationType> visibleDurationTypes = visibleSetFromLegacyJSON(json, DurationType.class);
final EnumSet<RangeType> visibleRangeTypes = visibleSetFromLegacyJSON(json, RangeType.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private View getSpinnerRow(int position, ViewGroup parent) {
int itemIndex(T item) {
final String itemName = textFunction.apply(context, item);
final int index = itemStrings.indexOf(itemName);
return (index == -1) ? index : 0;
return (index != -1) ? index : 0;
}

T[] getData() {
Expand Down
Loading

0 comments on commit b8c6ac2

Please sign in to comment.