Skip to content

Commit

Permalink
Some refactoring (Fixes codinguser#467 and fixes codinguser#464).
Browse files Browse the repository at this point in the history
  • Loading branch information
alceurneto committed Feb 6, 2016
1 parent 904f301 commit f5e8cac
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected SQLiteStatement compileReplaceStatement(@NonNull final Account account
mReplaceStatement.bindLong(7, account.isFavorite() ? 1 : 0);
mReplaceStatement.bindString(8, account.getFullName());
mReplaceStatement.bindLong(9, account.isPlaceholderAccount() ? 1 : 0);
mReplaceStatement.bindString(10, TimestampHelper.getUtcStringForTimestamp(account.getCreatedTimestamp()));
mReplaceStatement.bindString(10, TimestampHelper.getUtcStringFromTimestamp(account.getCreatedTimestamp()));
mReplaceStatement.bindLong(11, account.isHidden() ? 1 : 0);
Commodity commodity = account.getCommodity();
if (commodity == null)
Expand Down Expand Up @@ -530,7 +530,7 @@ public List<Account> getExportableAccounts(Timestamp lastExportTimeStamp){
SplitEntry.COLUMN_ACCOUNT_UID,
new String[]{AccountEntry.TABLE_NAME + ".*"},
TransactionEntry.TABLE_NAME + "." + TransactionEntry.COLUMN_MODIFIED_AT + " > ?",
new String[]{TimestampHelper.getUtcStringForTimestamp(lastExportTimeStamp)},
new String[]{TimestampHelper.getUtcStringFromTimestamp(lastExportTimeStamp)},
AccountEntry.TABLE_NAME + "." + AccountEntry.COLUMN_UID,
null,
null
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/gnucash/android/db/DatabaseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public List<Model> getAllRecords(){
*/
protected ContentValues populateBaseModelAttributes(@NonNull ContentValues contentValues, @NonNull Model model){
contentValues.put(CommonColumns.COLUMN_UID, model.getUID());
contentValues.put(CommonColumns.COLUMN_CREATED_AT, TimestampHelper.getUtcStringForTimestamp(model.getCreatedTimestamp()));
contentValues.put(CommonColumns.COLUMN_CREATED_AT, TimestampHelper.getUtcStringFromTimestamp(model.getCreatedTimestamp()));
//there is a trigger in the database for updated the modified_at column
/* Due to the use of SQL REPLACE syntax, we insert the created_at values each time
* (maintain the original creation time and not the time of creation of the replacement)
Expand All @@ -321,8 +321,8 @@ protected void populateBaseModelAttributes(Cursor cursor, BaseModel model){
String modified= cursor.getString(cursor.getColumnIndexOrThrow(CommonColumns.COLUMN_MODIFIED_AT));

model.setUID(uid);
model.setCreatedTimestamp(TimestampHelper.getTimestampForUtcString(created));
model.setModifiedTimestamp(TimestampHelper.getTimestampForUtcString(modified));
model.setCreatedTimestamp(TimestampHelper.getTimestampFromUtcString(created));
model.setModifiedTimestamp(TimestampHelper.getTimestampFromUtcString(modified));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/org/gnucash/android/db/MigrationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ static int upgradeDbToVersion8(SQLiteDatabase db) {
//================================ END TABLE MIGRATIONS ================================

// String timestamp to be used for all new created entities in migration
String timestamp = TimestampHelper.getUtcStringForTimestamp(TimestampHelper.getTimestampForNow());
String timestamp = TimestampHelper.getUtcStringFromTimestamp(TimestampHelper.getTimestampFromNow());

//ScheduledActionDbAdapter scheduledActionDbAdapter = new ScheduledActionDbAdapter(db);
//SplitsDbAdapter splitsDbAdapter = new SplitsDbAdapter(db);
Expand Down Expand Up @@ -698,7 +698,7 @@ static int upgradeDbToVersion8(SQLiteDatabase db) {
while (cursor.moveToNext()){
contentValues.clear();
Timestamp timestampT = new Timestamp(cursor.getLong(cursor.getColumnIndexOrThrow(TransactionEntry.COLUMN_TIMESTAMP)));
contentValues.put(TransactionEntry.COLUMN_CREATED_AT, TimestampHelper.getUtcStringForTimestamp(timestampT));
contentValues.put(TransactionEntry.COLUMN_CREATED_AT, TimestampHelper.getUtcStringFromTimestamp(timestampT));
long transactionId = cursor.getLong(cursor.getColumnIndexOrThrow(TransactionEntry._ID));
db.update(TransactionEntry.TABLE_NAME, contentValues, TransactionEntry._ID + "=" + transactionId, null);

Expand Down Expand Up @@ -1096,7 +1096,7 @@ static int upgradeDbToVersion10(SQLiteDatabase db){

boolean exportAll = Boolean.parseBoolean(tokens[2]);
if (exportAll){
params.setExportStartTime(TimestampHelper.getTimestampForEpochZero());
params.setExportStartTime(TimestampHelper.getTimestampFromEpochZero());
} else {
Timestamp timestamp = PreferencesHelper.getLastExportTime();
params.setExportStartTime(timestamp);
Expand Down Expand Up @@ -1143,9 +1143,9 @@ static int upgradeDbToVersion11(SQLiteDatabase db){
String tag = cursor.getString(cursor.getColumnIndexOrThrow(ScheduledActionEntry.COLUMN_TAG));
String[] tokens = tag.split(";");
try {
Timestamp timestamp = TimestampHelper.getTimestampForUtcString(tokens[2]);
Timestamp timestamp = TimestampHelper.getTimestampFromUtcString(tokens[2]);
} catch (IllegalArgumentException ex) {
tokens[2] = TimestampHelper.getUtcStringForTimestamp(PreferencesHelper.getLastExportTime());
tokens[2] = TimestampHelper.getUtcStringFromTimestamp(PreferencesHelper.getLastExportTime());
} finally {
tag = TextUtils.join(";", tokens);
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/gnucash/android/db/PricesDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected SQLiteStatement compileReplaceStatement(@NonNull final Price price) {
mReplaceStatement.bindString(1, price.getUID());
mReplaceStatement.bindString(2, price.getCommodityUID());
mReplaceStatement.bindString(3, price.getCurrencyUID());
mReplaceStatement.bindString(4, TimestampHelper.getUtcStringForTimestamp(price.getDate()));
mReplaceStatement.bindString(4, TimestampHelper.getUtcStringFromTimestamp(price.getDate()));
if (price.getSource() != null) {
mReplaceStatement.bindString(5, price.getSource());
}
Expand All @@ -70,7 +70,7 @@ public Price buildModelInstance(@NonNull final Cursor cursor) {
long valueDenom = cursor.getLong(cursor.getColumnIndexOrThrow(PriceEntry.COLUMN_VALUE_DENOM));

Price price = new Price(commodityUID, currencyUID);
price.setDate(TimestampHelper.getTimestampForUtcString(dateString));
price.setDate(TimestampHelper.getTimestampFromUtcString(dateString));
price.setSource(source);
price.setType(type);
price.setValueNum(valueNum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected SQLiteStatement compileReplaceStatement(@NonNull final ScheduledAction
mReplaceStatement.bindLong(6, schedxAction.getLastRun());
mReplaceStatement.bindLong(7, schedxAction.getPeriod());
mReplaceStatement.bindLong(8, schedxAction.isEnabled() ? 1 : 0);
mReplaceStatement.bindString(9, TimestampHelper.getUtcStringForTimestamp(schedxAction.getCreatedTimestamp()));
mReplaceStatement.bindString(9, TimestampHelper.getUtcStringFromTimestamp(schedxAction.getCreatedTimestamp()));
if (schedxAction.getTag() == null)
mReplaceStatement.bindNull(10);
else
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/gnucash/android/db/SplitsDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void addRecord(@NonNull final Split split){

//modifying a split means modifying the accompanying transaction as well
updateRecord(TransactionEntry.TABLE_NAME, transactionId,
TransactionEntry.COLUMN_MODIFIED_AT, TimestampHelper.getUtcStringForTimestamp(TimestampHelper.getTimestampForNow()));
TransactionEntry.COLUMN_MODIFIED_AT, TimestampHelper.getUtcStringFromTimestamp(TimestampHelper.getTimestampFromNow()));
}

@Override
Expand Down Expand Up @@ -107,7 +107,7 @@ protected SQLiteStatement compileReplaceStatement(@NonNull final Split split) {
mReplaceStatement.bindLong(5, split.getValue().getDenominator());
mReplaceStatement.bindLong(6, split.getQuantity().getNumerator());
mReplaceStatement.bindLong(7, split.getQuantity().getDenominator());
mReplaceStatement.bindString(8, TimestampHelper.getUtcStringForTimestamp(split.getCreatedTimestamp()));
mReplaceStatement.bindString(8, TimestampHelper.getUtcStringFromTimestamp(split.getCreatedTimestamp()));
mReplaceStatement.bindString(9, split.getAccountUID());
mReplaceStatement.bindString(10, split.getTransactionUID());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected SQLiteStatement compileReplaceStatement(@NonNull final Transaction tra
commodity = CommoditiesDbAdapter.getInstance().getCommodity(transaction.getCurrencyCode());

mReplaceStatement.bindString(7, commodity.getUID());
mReplaceStatement.bindString(8, TimestampHelper.getUtcStringForTimestamp(transaction.getCreatedTimestamp()));
mReplaceStatement.bindString(8, TimestampHelper.getUtcStringFromTimestamp(transaction.getCreatedTimestamp()));

if (transaction.getScheduledActionUID() == null)
mReplaceStatement.bindNull(9);
Expand Down Expand Up @@ -644,11 +644,11 @@ public Timestamp getTimestampOfLastModification(){
new String[]{"MAX(" + TransactionEntry.COLUMN_MODIFIED_AT + ")"},
null, null, null, null, null);

Timestamp timestamp = TimestampHelper.getTimestampForNow();
Timestamp timestamp = TimestampHelper.getTimestampFromNow();
if (cursor.moveToFirst()){
String timeString = cursor.getString(0);
if (timeString != null){ //in case there were no transactions in the XML file (account structure only)
timestamp = TimestampHelper.getTimestampForUtcString(timeString);
timestamp = TimestampHelper.getTimestampFromUtcString(timeString);
}
}
cursor.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum ExportTarget {SD_CARD, SHARING, DROPBOX, GOOGLE_DRIVE }
/**
* All transactions created after this date will be exported
*/
private Timestamp mExportStartTime = TimestampHelper.getTimestampForEpochZero();
private Timestamp mExportStartTime = TimestampHelper.getTimestampFromEpochZero();

/**
* Flag to determine if all transactions should be deleted after exporting is complete
Expand Down Expand Up @@ -134,7 +134,7 @@ public void setExportTarget(ExportTarget mExportTarget) {

@Override
public String toString() {
return "Export all transactions created since " + TimestampHelper.getUtcStringForTimestamp(mExportStartTime) + " UTC"
return "Export all transactions created since " + TimestampHelper.getUtcStringFromTimestamp(mExportStartTime) + " UTC"
+ " as "+ mExportFormat.name() + " to " + mExportTarget.name();
}

Expand All @@ -147,7 +147,7 @@ public String toCsv(){
String separator = ";";

return mExportFormat.name() + separator + mExportTarget.name() + separator
+ TimestampHelper.getUtcStringForTimestamp(mExportStartTime) + separator
+ TimestampHelper.getUtcStringFromTimestamp(mExportStartTime) + separator
+ Boolean.toString(mDeleteTransactionsAfterExport);
}

Expand All @@ -160,7 +160,7 @@ public static ExportParams parseCsv(String csvParams){
String[] tokens = csvParams.split(";");
ExportParams params = new ExportParams(ExportFormat.valueOf(tokens[0]));
params.setExportTarget(ExportTarget.valueOf(tokens[1]));
params.setExportStartTime(TimestampHelper.getTimestampForUtcString(tokens[2]));
params.setExportStartTime(TimestampHelper.getTimestampFromUtcString(tokens[2]));
params.setDeleteTransactionsAfterExport(Boolean.parseBoolean(tokens[3]));

return params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private String generateOfxExport() throws ExporterException {
boolean useXmlHeader = PreferenceManager.getDefaultSharedPreferences(mContext)
.getBoolean(mContext.getString(R.string.key_xml_ofx_header), false);

PreferencesHelper.setLastExportTime(TimestampHelper.getTimestampForNow());
PreferencesHelper.setLastExportTime(TimestampHelper.getTimestampFromNow());

StringWriter stringWriter = new StringWriter();
//if we want SGML OFX headers, write first to string and then prepend header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<String> generateExport() throws ExporterException {
final String newLine = "\n";
TransactionsDbAdapter transactionsDbAdapter = mTransactionsDbAdapter;
try {
String lastExportTimeStamp = TimestampHelper.getUtcStringForTimestamp(mExportParams.getExportStartTime());
String lastExportTimeStamp = TimestampHelper.getUtcStringFromTimestamp(mExportParams.getExportStartTime());
Cursor cursor = transactionsDbAdapter.fetchTransactionsWithSplitsWithTransactionAccount(
new String[]{
TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_UID + " AS trans_uid",
Expand Down Expand Up @@ -216,7 +216,7 @@ public List<String> generateExport() throws ExporterException {
transactionsDbAdapter.updateTransaction(contentValues, null, null);

/// export successful
PreferencesHelper.setLastExportTime(TimestampHelper.getTimestampForNow());
PreferencesHelper.setLastExportTime(TimestampHelper.getTimestampFromNow());
return splitQIF(file);
} catch (IOException e) {
throw new ExporterException(mExportParams, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private void exportTransactions(XmlSerializer xmlSerializer, boolean exportTempl
xmlSerializer.endTag(null, GncXmlHelper.TAG_DATE_POSTED);

// date entered, time when the transaction was actually created
Timestamp timeEntered = TimestampHelper.getTimestampForUtcString(cursor.getString(cursor.getColumnIndexOrThrow("trans_date_posted")));
Timestamp timeEntered = TimestampHelper.getTimestampFromUtcString(cursor.getString(cursor.getColumnIndexOrThrow("trans_date_posted")));
String dateEntered = GncXmlHelper.formatDate(timeEntered.getTime());
xmlSerializer.startTag(null, GncXmlHelper.TAG_DATE_ENTERED);
xmlSerializer.startTag(null, GncXmlHelper.TAG_TS_DATE);
Expand Down Expand Up @@ -539,7 +539,7 @@ private void exportScheduledTransactions(XmlSerializer xmlSerializer) throws IOE

//start date
String createdTimestamp = cursor.getString(cursor.getColumnIndexOrThrow(ScheduledActionEntry.COLUMN_CREATED_AT));
long scheduleStartTime = TimestampHelper.getTimestampForUtcString(createdTimestamp).getTime();
long scheduleStartTime = TimestampHelper.getTimestampFromUtcString(createdTimestamp).getTime();
serializeDate(xmlSerializer, GncXmlHelper.TAG_SX_START, scheduleStartTime);

long lastRunTime = cursor.getLong(cursor.getColumnIndexOrThrow(ScheduledActionEntry.COLUMN_LAST_RUN));
Expand Down Expand Up @@ -659,7 +659,7 @@ private void exportPrices(XmlSerializer xmlSerializer) throws IOException {
xmlSerializer.endTag(null, GncXmlHelper.TAG_COMMODITY_ID);
xmlSerializer.endTag(null, GncXmlHelper.TAG_PRICE_CURRENCY);
// time
String strDate = GncXmlHelper.formatDate(TimestampHelper.getTimestampForUtcString(cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.PriceEntry.COLUMN_DATE))).getTime());
String strDate = GncXmlHelper.formatDate(TimestampHelper.getTimestampFromUtcString(cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.PriceEntry.COLUMN_DATE))).getTime());
xmlSerializer.startTag(null, GncXmlHelper.TAG_PRICE_TIME);
xmlSerializer.startTag(null, GncXmlHelper.TAG_TS_DATE);
xmlSerializer.text(strDate);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/gnucash/android/model/BaseModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public abstract class BaseModel {
* A unique ID will be generated on demand with a call to {@link #getUID()}</p>
*/
public BaseModel(){
mCreatedTimestamp = TimestampHelper.getTimestampForNow();
mModifiedTimestamp = TimestampHelper.getTimestampForNow();
mCreatedTimestamp = TimestampHelper.getTimestampFromNow();
mModifiedTimestamp = TimestampHelper.getTimestampFromNow();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/gnucash/android/model/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Price extends BaseModel {
public static final String SOURCE_USER = "user:xfer-dialog";

public Price(){
mDate = TimestampHelper.getTimestampForNow();
mDate = TimestampHelper.getTimestampFromNow();
}

/**
Expand All @@ -34,7 +34,7 @@ public Price(){
public Price(String commodityUID, String currencyUID){
this.mCommodityUID = commodityUID;
this.mCurrencyUID = currencyUID;
mDate = TimestampHelper.getTimestampForNow();
mDate = TimestampHelper.getTimestampFromNow();
}

public String getCommodityUID() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private void startExport(){
ExportParams exportParameters = new ExportParams(mExportFormat);

if (mExportAllSwitch.isChecked()){
exportParameters.setExportStartTime(TimestampHelper.getTimestampForEpochZero());
exportParameters.setExportStartTime(TimestampHelper.getTimestampFromEpochZero());
} else {
exportParameters.setExportStartTime(new Timestamp(mExportStartCalendar.getTimeInMillis()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private PreferencesHelper() {}
* @param lastExportTime the last export time to set.
*/
public static void setLastExportTime(Timestamp lastExportTime) {
final String utcString = TimestampHelper.getUtcStringForTimestamp(lastExportTime);
final String utcString = TimestampHelper.getUtcStringFromTimestamp(lastExportTime);
Log.d(LOG_TAG, "Storing '" + utcString + "' as lastExportTime in Android Preferences.");
PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext())
.edit()
Expand All @@ -66,6 +66,6 @@ public static Timestamp getLastExportTime() {
.getString(PREFERENCE_LAST_EXPORT_TIME_KEY, PREFERENCE_LAST_EXPORT_TIME_DEFAULT_VALUE);
Log.d(LOG_TAG, "Retrieving '" + utcString + "' as lastExportTime from Android Preferences.");
return PREFERENCE_LAST_EXPORT_TIME_DEFAULT_VALUE.equals(utcString) ?
TimestampHelper.getTimestampForEpochZero() : TimestampHelper.getTimestampForUtcString(utcString);
TimestampHelper.getTimestampFromEpochZero() : TimestampHelper.getTimestampFromUtcString(utcString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ private TimestampHelper() {}
* @param timestamp The {@link Timestamp} to format.
* @return The formatted {@link String}.
*/
public static String getUtcStringForTimestamp(Timestamp timestamp) {
public static String getUtcStringFromTimestamp(Timestamp timestamp) {
return UTC_DATE_WITH_MILLISECONDS_FORMAT.withZone(UTC_TIME_ZONE).print(timestamp.getTime());
}

/**
* @return A {@link Timestamp} with time in milliseconds equals to zero.
*/
public static Timestamp getTimestampForEpochZero() {
public static Timestamp getTimestampFromEpochZero() {
return new Timestamp(0);
}

Expand All @@ -68,7 +68,7 @@ public static Timestamp getTimestampForEpochZero() {
* @param utcString A {@link String} in UTC.
* @return A {@link Timestamp} for given utcString.
*/
public static Timestamp getTimestampForUtcString(String utcString) {
public static Timestamp getTimestampFromUtcString(String utcString) {
DateTime dateTime;
try {

Expand All @@ -93,7 +93,7 @@ public static Timestamp getTimestampForUtcString(String utcString) {
/**
* @return A {@link Timestamp} initialized with the system current time.
*/
public static Timestamp getTimestampForNow() {
public static Timestamp getTimestampFromNow() {
return new Timestamp(System.currentTimeMillis());
}
}
Loading

0 comments on commit f5e8cac

Please sign in to comment.