Skip to content

Commit

Permalink
fixed issue with electron volt conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pshadlyn committed Sep 30, 2015
1 parent 9a1b6c4 commit f7dda39
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId "com.physphil.android.unitconverterultimate"
minSdkVersion 14
targetSdkVersion 22
versionCode 40002
versionName '4.0.2'
versionCode 40003
versionName '4.0.3'
}

signingConfigs{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.physphil.android.unitconverterultimate.models.Conversion;
import com.physphil.android.unitconverterultimate.models.ConversionState;
import com.physphil.android.unitconverterultimate.models.Unit;

/**
* Extension of SQLiteOpenHelper to access SQLite database
Expand Down Expand Up @@ -133,6 +134,14 @@ public ConversionState getConversionState(@Conversion.id int conversionId)
c.getInt(c.getColumnIndex(COLUMN_CONVERSION_STATE_TO_ID)));

c.close();

if(isInvalidState(cs))
{
// Using electron volt which was included in error, delete and return empty state
deleteInvalidState();
return new ConversionState(conversionId);
}

return cs;
}
else
Expand All @@ -142,4 +151,32 @@ public ConversionState getConversionState(@Conversion.id int conversionId)
return new ConversionState(conversionId);
}
}

/**
* Checks to see if the returned conversion state is invalid in any way
* @param cs ConversionState object
* @return if the state is invalid
*/
private boolean isInvalidState(ConversionState cs)
{
// Invalid if using ElectronVolt, which was included in error
return cs.getFromId() == Unit.ELECTRON_VOLT || cs.getToId() == Unit.ELECTRON_VOLT;
}

/**
* Remove any invalid state from database
*/
private void deleteInvalidState()
{
// Delete any state that includes 207 (electron volt, oops)
String sql =
"DELETE FROM " +
TABLE_CONVERSION_STATE + " " +
"WHERE " +
COLUMN_CONVERSION_STATE_FROM_ID + " = 207 " +
"OR " +
COLUMN_CONVERSION_STATE_TO_ID + " = 207 ";

mDb.execSQL(sql);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ private void getEnergyConversions()
units.add(new Unit(FT_LBF, R.string.ft_lbF, 1.3558179483314004, 0.7375621494575464935503));
units.add(new Unit(IN_LBF, R.string.in_lbF, 0.1129848290276167, 8.850745793490557922604));
units.add(new Unit(KILOWATT_HOUR, R.string.kilowatt_hour, 3600000.0, 0.0000002777777777777777777778));
units.add(new Unit(ELECTRON_VOLT, R.string.electron_volt, 6241509479607718382.9424839, 0.000000000000000000160217653));
addConversion(Conversion.ENERGY, new Conversion(Conversion.ENERGY, R.string.energy, units));
}

Expand Down Expand Up @@ -235,7 +234,6 @@ private void getPowerConversions()
units.add(new Unit(CALORIE_S, R.string.calorie_s, 4.1868, 0.23884589662749594));
units.add(new Unit(BTU_S, R.string.btu_s, 1055.05585262, 0.0009478171203133172));
units.add(new Unit(KVA, R.string.kva, 1000.0, 0.001));
units.add(new Unit(ELECTRON_VOLT, R.string.electron_volt, 6241509479607718382.9424839, 0.000000000000000000160217653));
addConversion(Conversion.POWER, new Conversion(Conversion.POWER, R.string.power, units));
}

Expand Down

0 comments on commit f7dda39

Please sign in to comment.