Skip to content

Commit

Permalink
codinguser#876 - Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanGarf committed Jun 14, 2020
1 parent 1f41df3 commit 511f889
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,15 @@ public int deleteAllRecords(){
* @throws IllegalArgumentException if the GUID does not exist in the database
*/
public long getID(@NonNull String uid){

Cursor cursor = mDb.query(mTableName,
new String[] {DatabaseSchema.CommonColumns._ID},
DatabaseSchema.CommonColumns.COLUMN_UID + " = ?",
new String[]{uid},
null, null, null);
new String[]{DatabaseSchema.CommonColumns._ID},
DatabaseSchema.CommonColumns.COLUMN_UID + " = ?",
new String[]{uid},
null, null, null);

long result = -1;

try{
if (cursor.moveToFirst()) {
result = cursor.getLong(cursor.getColumnIndexOrThrow(DatabaseSchema.CommonColumns._ID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PopupMenu;
Expand Down Expand Up @@ -484,27 +483,39 @@ public AccountViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

@Override
public void onBindViewHolderCursor(final AccountViewHolder holder, final Cursor cursor) {

final String accountUID = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.AccountEntry.COLUMN_UID));

mAccountsDbAdapter = AccountsDbAdapter.getInstance();
holder.accoundId = mAccountsDbAdapter.getID(accountUID);

holder.accoundId = mAccountsDbAdapter.getID(accountUID);
holder.accountName.setText(cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.AccountEntry.COLUMN_NAME)));

int subAccountCount = mAccountsDbAdapter.getSubAccountCount(accountUID);

if (subAccountCount > 0) {
holder.description.setVisibility(View.VISIBLE);
String text = getResources().getQuantityString(R.plurals.label_sub_accounts, subAccountCount, subAccountCount);
String text = getResources().getQuantityString(R.plurals.label_sub_accounts,
subAccountCount,
subAccountCount);
holder.description.setText(text);
} else

} else {
holder.description.setVisibility(View.GONE);
}

// add a summary of transactions to the account view

// Make sure the balance task is truly multithread
// Make sure the balance task is truly multithread
new AccountBalanceTask(holder.accountBalance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
accountUID);
accountUID);

String accountColor = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.AccountEntry.COLUMN_COLOR_CODE));
int colorCode = accountColor == null ? Color.TRANSPARENT : Color.parseColor(accountColor);

int colorCode = accountColor == null
? Color.TRANSPARENT
: Color.parseColor(accountColor);

holder.colorStripView.setBackgroundColor(colorCode);

boolean isPlaceholderAccount = mAccountsDbAdapter.isPlaceholderAccount(accountUID);
Expand All @@ -515,21 +526,30 @@ public void onBindViewHolderCursor(final AccountViewHolder holder, final Cursor

@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), FormActivity.class);

Intent intent = new Intent(getActivity(),
FormActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, accountUID);
intent.putExtra(UxArgument.FORM_TYPE, FormActivity.FormType.TRANSACTION.name());
intent.putExtra(UxArgument.SELECTED_ACCOUNT_UID,
accountUID);
intent.putExtra(UxArgument.FORM_TYPE,
FormActivity.FormType.TRANSACTION.name());
getActivity().startActivity(intent);
}
});
}

List<Budget> budgets = BudgetsDbAdapter.getInstance().getAccountBudgets(accountUID);
List<Budget> budgets = BudgetsDbAdapter.getInstance()
.getAccountBudgets(accountUID);
//TODO: include fetch only active budgets
if (budgets.size() == 1){
Budget budget = budgets.get(0);
Money balance = mAccountsDbAdapter.getAccountBalance(accountUID, budget.getStartofCurrentPeriod(), budget.getEndOfCurrentPeriod());
double budgetProgress = balance.divide(budget.getAmount(accountUID)).asBigDecimal().doubleValue() * 100;
if (budgets.size() == 1) {
Budget budget = budgets.get(0);
Money balance = mAccountsDbAdapter.getAccountBalance(accountUID,
budget.getStartofCurrentPeriod(),
budget.getEndOfCurrentPeriod());
double budgetProgress = balance.divide(budget.getAmount(accountUID))
.asBigDecimal()
.doubleValue() * 100;

holder.budgetIndicator.setVisibility(View.VISIBLE);
holder.budgetIndicator.setProgress((int) budgetProgress);
Expand All @@ -538,7 +558,7 @@ public void onClick(View v) {
}


if (mAccountsDbAdapter.isFavoriteAccount(accountUID)){
if (mAccountsDbAdapter.isFavoriteAccount(accountUID)) {
holder.favoriteStatus.setImageResource(R.drawable.ic_star_black_24dp);
} else {
holder.favoriteStatus.setImageResource(R.drawable.ic_star_border_black_24dp);
Expand All @@ -547,23 +567,29 @@ public void onClick(View v) {
holder.favoriteStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

boolean isFavoriteAccount = mAccountsDbAdapter.isFavoriteAccount(accountUID);

ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseSchema.AccountEntry.COLUMN_FAVORITE, !isFavoriteAccount);
mAccountsDbAdapter.updateRecord(accountUID, contentValues);

int drawableResource = !isFavoriteAccount ?
R.drawable.ic_star_black_24dp : R.drawable.ic_star_border_black_24dp;
contentValues.put(DatabaseSchema.AccountEntry.COLUMN_FAVORITE,
!isFavoriteAccount);
mAccountsDbAdapter.updateRecord(accountUID,
contentValues);

int drawableResource = !isFavoriteAccount
? R.drawable.ic_star_black_24dp
: R.drawable.ic_star_border_black_24dp;
holder.favoriteStatus.setImageResource(drawableResource);
if (mDisplayMode == DisplayMode.FAVORITES)
if (mDisplayMode == DisplayMode.FAVORITES) {
refresh();
}
}
});

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

onListItemClick(accountUID);
}
});
Expand Down

0 comments on commit 511f889

Please sign in to comment.