Skip to content

Commit

Permalink
reFormat code
Browse files Browse the repository at this point in the history
replace Editor.commit() to apply()
  • Loading branch information
John-Yu committed May 21, 2020
1 parent a68e933 commit 41c745c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.preference.PreferenceManager;
import androidx.viewpager.widget.ViewPager;

import butterknife.BindView;

/**
Expand Down Expand Up @@ -145,7 +146,6 @@ public class AccountsActivity extends BaseDrawerActivity implements OnAccountCli
private final Runnable mResetDoubleBackPressedStatusRunnable = new Runnable() {
@Override
public void run() {

// BackPress button is not more considered pressed recently
mDoubleBackButtonPressedOnce = false;
}
Expand All @@ -159,12 +159,9 @@ public void run() {
/**
* ViewPager which manages the different tabs
*/
@BindView(R.id.pager)
ViewPager mViewPager;
@BindView(R.id.fab_create_account)
FloatingActionButton mFloatingActionButton;
@BindView(R.id.coordinatorLayout)
CoordinatorLayout mCoordinatorLayout;
@BindView(R.id.pager) ViewPager mViewPager;
@BindView(R.id.fab_create_account) FloatingActionButton mFloatingActionButton;
@BindView(R.id.coordinatorLayout) CoordinatorLayout mCoordinatorLayout;

/**
* Configuration for rating the app
Expand All @@ -178,7 +175,7 @@ public void run() {
private class AccountViewPagerAdapter extends FragmentPagerAdapter {

public AccountViewPagerAdapter(FragmentManager fm) {
super(fm, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
super(fm);
}

@NonNull
Expand Down Expand Up @@ -231,6 +228,7 @@ public CharSequence getPageTitle(int position) {
public int getCount() {
return DEFAULT_NUM_PAGES;
}

}

public AccountsListFragment getCurrentAccountListFragment() {
Expand Down Expand Up @@ -305,8 +303,7 @@ public void onTabReselected(TabLayout.Tab tab) {
Toast.LENGTH_SHORT);

// Align-Center text inside the Toast
TextView toastTextView = mToast.getView()
.findViewById(android.R.id.message);
TextView toastTextView = mToast.getView().findViewById(android.R.id.message);
if (toastTextView != null) {
toastTextView.setGravity(Gravity.CENTER);
}
Expand Down Expand Up @@ -379,8 +376,7 @@ public void setCurrentTab() {
private void init() {

PreferenceManager.setDefaultValues(this,
BooksDbAdapter.getInstance()
.getActiveBookUID(),
BooksDbAdapter.getInstance().getActiveBookUID(),
Context.MODE_PRIVATE,
R.xml.fragment_transaction_preferences,
true);
Expand Down Expand Up @@ -434,7 +430,7 @@ protected void onDestroy() {

mHandler.removeCallbacks(mResetDoubleBackPressedStatusRunnable);
}

mFragmentPageReferenceMap.clear();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SearchView;
import androidx.core.view.MenuItemCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
Expand All @@ -43,6 +37,19 @@
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SearchView;
import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.Fragment;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.gnucash.android.R;
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.DatabaseCursorLoader;
Expand All @@ -61,13 +68,8 @@
import org.gnucash.android.util.BackupManager;

import java.util.List;
import java.util.Objects;

import androidx.fragment.app.Fragment;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

Expand Down Expand Up @@ -480,6 +482,7 @@ public AccountRecyclerAdapter(Cursor cursor){
super(cursor);
}

@NonNull
@Override
public AccountViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
Expand Down Expand Up @@ -516,16 +519,12 @@ public void onBindViewHolderCursor(final AccountViewHolder holder, final Cursor
if (isPlaceholderAccount) {
holder.createTransaction.setVisibility(View.GONE);
} else {
holder.createTransaction.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
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());
getActivity().startActivity(intent);
}
holder.createTransaction.setOnClickListener(v -> {
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());
Objects.requireNonNull(getActivity()).startActivity(intent);
});
}

Expand All @@ -549,29 +548,21 @@ public void onClick(View v) {
holder.favoriteStatus.setImageResource(R.drawable.ic_star_border_black_24dp);
}

holder.favoriteStatus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isFavoriteAccount = mAccountsDbAdapter.isFavoriteAccount(accountUID);
holder.favoriteStatus.setOnClickListener(v -> {
boolean isFavoriteAccount = mAccountsDbAdapter.isFavoriteAccount(accountUID);

ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseSchema.AccountEntry.COLUMN_FAVORITE, !isFavoriteAccount);
mAccountsDbAdapter.updateRecord(accountUID, contentValues);
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;
holder.favoriteStatus.setImageResource(drawableResource);
if (mDisplayMode == DisplayMode.FAVORITES)
refresh();
}
int drawableResource = !isFavoriteAccount ?
R.drawable.ic_star_black_24dp : R.drawable.ic_star_border_black_24dp;
holder.favoriteStatus.setImageResource(drawableResource);
if (mDisplayMode == DisplayMode.FAVORITES)
refresh();
});

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onListItemClick(accountUID);
}
});
holder.itemView.setOnClickListener(v -> onListItemClick(accountUID));
}


Expand All @@ -592,15 +583,12 @@ public AccountViewHolder(View itemView) {

ButterKnife.bind(this, itemView);

optionsMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popup = new PopupMenu(getActivity(), v);
popup.setOnMenuItemClickListener(AccountViewHolder.this);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.account_context_menu, popup.getMenu());
popup.show();
}
optionsMenu.setOnClickListener(v -> {
PopupMenu popup = new PopupMenu(getActivity(), v);
popup.setOnMenuItemClickListener(AccountViewHolder.this);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.account_context_menu, popup.getMenu());
popup.show();
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

/**
* Fragment for general preferences. Currently caters to the passcode and reporting preferences
*
* @author Oleksandr Tyshkovets <[email protected]>
*/
public class GeneralPreferenceFragment extends PreferenceFragmentCompat implements
Expand Down Expand Up @@ -67,6 +68,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
assert actionBar != null;
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.title_general_prefs);
Expand All @@ -78,7 +80,8 @@ public void onResume() {

final Intent intent = new Intent(getActivity(), PasscodePreferenceActivity.class);

mCheckBoxPreference = (CheckBoxPreference) findPreference(getString(R.string.key_enable_passcode));
mCheckBoxPreference = findPreference(getString(R.string.key_enable_passcode));
assert mCheckBoxPreference != null;
mCheckBoxPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Expand Down Expand Up @@ -115,84 +118,60 @@ public boolean onPreferenceChange(Preference preference,
//
// Preference : key_use_double_back_button_press_to_quit
//

if (preference.getKey()
.equals(getString(R.string.key_use_double_back_button_press_to_quit))) {
if (preference.getKey().equals(getString(R.string.key_use_double_back_button_press_to_quit))) {

// Store the new value of the Preference
getPreferenceManager().getSharedPreferences()
.edit()
.putBoolean(getString(R.string.key_use_double_back_button_press_to_quit),
Boolean.parseBoolean(newValue.toString()))
.commit();
.edit()
.putBoolean(getString(R.string.key_use_double_back_button_press_to_quit), Boolean.parseBoolean(newValue.toString()))
.apply();
}

//
// Set Preference : key_shall_open_keyboard_in_account_searchable_spinner
//

if (preference.getKey()
.equals(getString(R.string.key_shall_open_keyboard_in_account_searchable_spinner))) {
if (preference.getKey().equals(getString(R.string.key_shall_open_keyboard_in_account_searchable_spinner))) {

// Store the new value of the Preference
getPreferenceManager().getSharedPreferences()
.edit()
.putBoolean(getString(R.string.key_shall_open_keyboard_in_account_searchable_spinner),
Boolean.parseBoolean(newValue.toString()))
.commit();
.edit()
.putBoolean(getString(R.string.key_shall_open_keyboard_in_account_searchable_spinner), Boolean.parseBoolean(newValue.toString()))
.apply();
}

//
// Set Preference : key_use_color_in_account_list
//

if (preference.getKey()
.equals(getString(R.string.key_use_color_in_account_list))) {
if (preference.getKey().equals(getString(R.string.key_use_color_in_account_list))) {

// Store the new value of the Preference
getPreferenceManager().getSharedPreferences()
.edit()
.putBoolean(getString(R.string.key_use_color_in_account_list),
Boolean.parseBoolean(newValue.toString()))
.commit();
.edit()
.putBoolean(getString(R.string.key_use_color_in_account_list), Boolean.parseBoolean(newValue.toString()))
.apply();
}

//
// Set Preference : enable_passcode
//

if (preference.getKey()
.equals(getString(R.string.key_enable_passcode))) {

if (preference.getKey().equals(getString(R.string.key_enable_passcode))) {
if ((Boolean) newValue) {

startActivityForResult(new Intent(getActivity(),
PasscodePreferenceActivity.class),
GeneralPreferenceFragment.PASSCODE_REQUEST_CODE);

startActivityForResult(new Intent(getActivity(), PasscodePreferenceActivity.class), GeneralPreferenceFragment.PASSCODE_REQUEST_CODE);
} else {

Intent passIntent = new Intent(getActivity(),
PasscodeLockScreenActivity.class);
passIntent.putExtra(UxArgument.DISABLE_PASSCODE,
UxArgument.DISABLE_PASSCODE);
startActivityForResult(passIntent,
GeneralPreferenceFragment.REQUEST_DISABLE_PASSCODE);
Intent passIntent = new Intent(getActivity(), PasscodeLockScreenActivity.class);
passIntent.putExtra(UxArgument.DISABLE_PASSCODE, UxArgument.DISABLE_PASSCODE);
startActivityForResult(passIntent, GeneralPreferenceFragment.REQUEST_DISABLE_PASSCODE);
}
}

//
// Set Preference : use_color_in_reports
//

if (preference.getKey()
.equals(getString(R.string.key_use_account_color))) {

if (preference.getKey().equals(getString(R.string.key_use_account_color))) {
getPreferenceManager().getSharedPreferences()
.edit()
.putBoolean(getString(R.string.key_use_account_color),
Boolean.parseBoolean(newValue.toString()))
.commit();
.edit()
.putBoolean(getString(R.string.key_use_account_color), Boolean.parseBoolean(newValue.toString()))
.apply();
}

return true;
Expand All @@ -202,7 +181,7 @@ public boolean onPreferenceChange(Preference preference,
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (mEditor == null){
if (mEditor == null) {
mEditor = getPreferenceManager().getSharedPreferences().edit();
}

Expand Down Expand Up @@ -231,7 +210,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
break;
}
mEditor.commit();
mEditor.apply();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -459,21 +459,14 @@ public void onChanged() {
});

// On item click listener
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
getListView().setOnItemClickListener((parent, view, position, id) -> {

@Override
public void onItemClick(AdapterView<?> parent,
View view,
int position,
long id) {

dismissDialog();
dismissDialog();

final T_ITEM item = (T_ITEM) getListViewAdapter().getItem(position);
final T_ITEM item = (T_ITEM) getListViewAdapter().getItem(position);

// Call Listener
getOnSearchableListItemClickedListener().onSearchableListItemClicked(item);
}
// Call Listener
getOnSearchableListItemClickedListener().onSearchableListItemClicked(item);
});

//
Expand Down

0 comments on commit 41c745c

Please sign in to comment.