Skip to content

Commit d95b5ae

Browse files
committed
Extract code from BooksCursorAdapter.bindView into new methods.
1 parent 1c5f928 commit d95b5ae

1 file changed

Lines changed: 29 additions & 23 deletions

File tree

app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -161,29 +161,8 @@ public void bindView(View view, final Context context, Cursor cursor) {
161161

162162
final String bookUID = cursor.getString(cursor.getColumnIndexOrThrow(BookEntry.COLUMN_UID));
163163

164-
Timestamp lastSyncTime = PreferencesHelper.getLastExportTime(bookUID);
165-
TextView lastSyncText = (TextView) view.findViewById(R.id.last_sync_time);
166-
if (lastSyncTime.equals(new Timestamp(0)))
167-
lastSyncText.setText(R.string.last_export_time_never);
168-
else
169-
lastSyncText.setText(lastSyncTime.toString());
170-
171-
TextView labelLastSync = (TextView) view.findViewById(R.id.label_last_sync);
172-
labelLastSync.setText(R.string.label_last_export_time);
173-
174-
//retrieve some book statistics
175-
DatabaseHelper dbHelper = new DatabaseHelper(GnuCashApplication.getAppContext(), bookUID);
176-
SQLiteDatabase db = dbHelper.getReadableDatabase();
177-
TransactionsDbAdapter trnAdapter = new TransactionsDbAdapter(db, new SplitsDbAdapter(db));
178-
int transactionCount = (int) trnAdapter.getRecordsCount();
179-
String transactionStats = getResources().getQuantityString(R.plurals.book_transaction_stats, transactionCount, transactionCount);
180-
181-
AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(db, trnAdapter);
182-
int accountsCount = (int) accountsDbAdapter.getRecordsCount();
183-
String accountStats = getResources().getQuantityString(R.plurals.book_account_stats, accountsCount, accountsCount);
184-
String stats = accountStats + ", " + transactionStats;
185-
TextView statsText = (TextView) view.findViewById(R.id.secondary_text);
186-
statsText.setText(stats);
164+
setLastExportedText(view, bookUID);
165+
setStatisticsText(view, bookUID);
187166

188167
ImageView optionsMenu = (ImageView) view.findViewById(R.id.options_menu);
189168
optionsMenu.setOnClickListener(new View.OnClickListener() {
@@ -254,6 +233,33 @@ public void onClick(View v) {
254233
}
255234
});
256235
}
236+
237+
private void setLastExportedText(View view, String bookUID) {
238+
TextView labelLastSync = (TextView) view.findViewById(R.id.label_last_sync);
239+
labelLastSync.setText(R.string.label_last_export_time);
240+
241+
Timestamp lastSyncTime = PreferencesHelper.getLastExportTime(bookUID);
242+
TextView lastSyncText = (TextView) view.findViewById(R.id.last_sync_time);
243+
if (lastSyncTime.equals(new Timestamp(0)))
244+
lastSyncText.setText(R.string.last_export_time_never);
245+
else
246+
lastSyncText.setText(lastSyncTime.toString());
247+
}
248+
249+
private void setStatisticsText(View view, String bookUID) {
250+
DatabaseHelper dbHelper = new DatabaseHelper(GnuCashApplication.getAppContext(), bookUID);
251+
SQLiteDatabase db = dbHelper.getReadableDatabase();
252+
TransactionsDbAdapter trnAdapter = new TransactionsDbAdapter(db, new SplitsDbAdapter(db));
253+
int transactionCount = (int) trnAdapter.getRecordsCount();
254+
String transactionStats = getResources().getQuantityString(R.plurals.book_transaction_stats, transactionCount, transactionCount);
255+
256+
AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(db, trnAdapter);
257+
int accountsCount = (int) accountsDbAdapter.getRecordsCount();
258+
String accountStats = getResources().getQuantityString(R.plurals.book_account_stats, accountsCount, accountsCount);
259+
String stats = accountStats + ", " + transactionStats;
260+
TextView statsText = (TextView) view.findViewById(R.id.secondary_text);
261+
statsText.setText(stats);
262+
}
257263
}
258264

259265
/**

0 commit comments

Comments
 (0)