Skip to content

Commit

Permalink
#441 Updated tokenautocomplete
Browse files Browse the repository at this point in the history
Used synchronous methods to clear tokens when they're otherwise persisted

Replaced modified 'com.splitwise:tokenautocomplete:2.0.8' with actual 'com.splitwise:tokenautocomplete:3.0.0-alpha'
  • Loading branch information
AEFeinstein committed Nov 30, 2018
1 parent 30dd6cf commit bdcd48f
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 2,066 deletions.
2 changes: 1 addition & 1 deletion mobile/build.gradle
Expand Up @@ -158,7 +158,7 @@ dependencies {
exclude module: 'support-v4'
}
implementation 'org.jsoup:jsoup:1.11.3'
// implementation 'com.splitwise:tokenautocomplete:2.0.8'
implementation 'com.splitwise:tokenautocomplete:3.0.0-alpha'
implementation 'com.google.code.findbugs:annotations:3.0.1', {
// Need to exclude these, or build is broken by:
// com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull
Expand Down
Expand Up @@ -61,6 +61,7 @@
import com.gelakinetic.mtgfam.helpers.database.FamiliarDbException;
import com.gelakinetic.mtgfam.helpers.database.FamiliarDbHandle;
import com.gelakinetic.mtgfam.helpers.model.Comparison;
import com.gelakinetic.mtgfam.helpers.view.ATokenTextView;
import com.gelakinetic.mtgfam.helpers.view.ComparisonSpinner;
import com.gelakinetic.mtgfam.helpers.view.CompletionView;
import com.gelakinetic.mtgfam.helpers.view.ManaCostTextView;
Expand Down Expand Up @@ -489,10 +490,10 @@ public String getItem(int position) {
public void onPause() {
super.onPause();
// Save the search criteria
if(PreferenceAdapter.getPersistSearchOptions(getContext())) {
// TODO also clear all tokens
if (PreferenceAdapter.getPersistSearchOptions(getContext())) {
try {
PreferenceAdapter.setSearchViewCriteria(getContext(), parseForm());
clear();
} catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
/* Eat it */
}
Expand All @@ -511,7 +512,7 @@ public void onResume() {
mSetSpinner.setSelection(consolidate ? CardDbAdapter.MOST_RECENT_PRINTING : CardDbAdapter.ALL_PRINTINGS);

// Load the saved criteria
if(PreferenceAdapter.getPersistSearchOptions(getContext())) {
if (PreferenceAdapter.getPersistSearchOptions(getContext())) {
setFieldsFromCriteria(PreferenceAdapter.getSearchViewCriteria(getContext()));
}
}
Expand Down Expand Up @@ -789,14 +790,14 @@ private SearchCriteria parseForm() throws ArrayIndexOutOfBoundsException, NullPo
*/
private void clear() {
mNameField.setText("");
mSupertypeField.clearTextAndTokens();
mSubtypeField.clearTextAndTokens();
clearTextAndTokens(mSupertypeField);
clearTextAndTokens(mSubtypeField);
mTextField.setText("");
mArtistField.setText("");
mWatermarkField.setText("");
mFlavorField.setText("");
mCollectorsNumberField.setText("");
mSetField.clearTextAndTokens();
clearTextAndTokens(mSetField);

mCheckboxW.setChecked(false);
mCheckboxU.setChecked(false);
Expand Down Expand Up @@ -825,7 +826,7 @@ private void clear() {
mCmcLogic.setSelection(0);
mCmcLogic.setSelection(1); /* CMC should default to < */
mCmcChoice.setSelection(0);
mManaCostTextView.clearTextAndTokens();
clearTextAndTokens(mManaCostTextView);
mManaComparisonSpinner.setSelection(Comparison.EMPTY.ordinal());

if (mSetCheckedIndices != null) {
Expand All @@ -838,6 +839,20 @@ private void clear() {
checkDialogButtonColors();
}

/**
* This helper function clears all tokens and text from an ATokenTextView
*
* @param field The ATokenTextView to clear everything from
*/
private void clearTextAndTokens(ATokenTextView field) {
while (!field.getObjects().isEmpty()) {
field.removeObjectSync(field.getObjects().get(0));
}
field.clearCompletionText();
field.clearComposingText();
field.clearListSelection();
}

/**
* This function saves the current search options into a file, so the user can have a default search
*/
Expand Down Expand Up @@ -879,17 +894,17 @@ private void setFieldsFromCriteria(SearchCriteria criteria) {
/* Set type fields */
if (null != criteria.superTypes && criteria.superTypes.size() > 0) {
for (String supertype : criteria.superTypes) {
mSupertypeField.addObject(supertype);
mSupertypeField.addObjectSync(supertype);
}
} else {
mSupertypeField.clearTextAndTokens();
clearTextAndTokens(mSupertypeField);
}
if (null != criteria.subTypes && criteria.subTypes.size() > 0) {
for (String subtype : criteria.subTypes) {
mSubtypeField.addObject(subtype);
mSubtypeField.addObjectSync(subtype);
}
} else {
mSubtypeField.clearTextAndTokens();
clearTextAndTokens(mSubtypeField);
}
mTypeSpinner.setSelection(criteria.typeLogic);

Expand Down Expand Up @@ -984,10 +999,10 @@ else if (t == CardDbAdapter.INFINITY)
/* Set mana fields */
if (criteria.manaCost != null && criteria.manaCost.size() > 0) {
for (String mana : criteria.manaCost) {
mManaCostTextView.addObject(mana);
mManaCostTextView.addObjectSync(mana);
}
} else {
mManaCostTextView.clearTextAndTokens();
clearTextAndTokens(mManaCostTextView);
}
if (null != criteria.manaCostLogic) {
mManaComparisonSpinner.setSelection(criteria.manaCostLogic.ordinal());
Expand Down Expand Up @@ -1019,10 +1034,10 @@ else if (t == CardDbAdapter.INFINITY)
if (criteria.sets != null && criteria.sets.size() > 0) {
/* Get a list of the persisted sets */
for (String set : criteria.sets) {
mSetField.addObject(set);
mSetField.addObjectSync(set);
}
} else {
mSetField.clearTextAndTokens();
clearTextAndTokens(mSetField);
}
mSetSpinner.setSelection(criteria.setLogic);

Expand Down
Expand Up @@ -34,6 +34,10 @@ public class CompletionView extends ATokenTextView {
public CompletionView(Context context, AttributeSet attrs) {
super(context, attrs);
this.allowDuplicates(false);
this.preventFreeFormText(true);
this.setTokenClickStyle(TokenClickStyle.Delete);
this.performBestGuess(true);
this.allowCollapse(true);
}

@Override
Expand Down
75 changes: 0 additions & 75 deletions mobile/src/main/java/com/tokenautocomplete/CharacterTokenizer.java

This file was deleted.

29 changes: 0 additions & 29 deletions mobile/src/main/java/com/tokenautocomplete/CountSpan.java

This file was deleted.

142 changes: 0 additions & 142 deletions mobile/src/main/java/com/tokenautocomplete/FilteredArrayAdapter.java

This file was deleted.

0 comments on commit bdcd48f

Please sign in to comment.