Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from Butterknife to View bindings #115

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ android {
}
}

buildFeatures {
viewBinding true
}

bundle {
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
Expand Down Expand Up @@ -194,10 +198,6 @@ dependencies {
implementation 'com.google.firebase:firebase-crashlytics:18.6.1'
implementation "com.jakewharton.timber:timber:5.0.1"

// Dependency Injection
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'

implementation('com.uservoice:uservoice-android-sdk:1.2.10') {
exclude module: 'commons-logging'
exclude module: 'httpcore'
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,18 @@

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.preference.PreferenceManager;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
import com.kobakei.ratethisapp.RateThisApp;

import org.gnucash.android.BuildConfig;
import org.gnucash.android.R;
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.databinding.ActivityAccountsBinding;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.adapter.AccountsDbAdapter;
import org.gnucash.android.db.adapter.BooksDbAdapter;
Expand All @@ -67,7 +65,6 @@
import org.gnucash.android.ui.wizard.FirstRunWizardActivity;
import org.gnucash.android.util.BackupManager;

import butterknife.BindView;
import timber.log.Timber;

/**
Expand Down Expand Up @@ -124,22 +121,14 @@ public class AccountsActivity extends BaseDrawerActivity implements OnAccountCli
*/
private SparseArray<Refreshable> mFragmentPageReferenceMap = new SparseArray<>();

/**
* 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;

/**
* Configuration for rating the app
*/
public static RateThisApp.Config rateAppConfig = new RateThisApp.Config(14, 100);
private AccountViewPagerAdapter mPagerAdapter;

private ActivityAccountsBinding mBinding;

/**
* Adapter for managing the sub-account and transaction fragment pages in the accounts view
*/
Expand Down Expand Up @@ -200,16 +189,17 @@ public int getCount() {
}

public AccountsListFragment getCurrentAccountListFragment() {
int index = mViewPager.getCurrentItem();
int index = mBinding.pager.getCurrentItem();
Fragment fragment = (Fragment) mFragmentPageReferenceMap.get(index);
if (fragment == null)
fragment = mPagerAdapter.getItem(index);
return (AccountsListFragment) fragment;
}

@Override
public int getContentView() {
return R.layout.activity_accounts;
public void inflateView() {
mBinding = ActivityAccountsBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());
}

@Override
Expand All @@ -234,13 +224,13 @@ public void onCreate(Bundle savedInstanceState) {

//show the simple accounts list
mPagerAdapter = new AccountViewPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mPagerAdapter);
mBinding.pager.setAdapter(mPagerAdapter);

mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
mBinding.pager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());
mBinding.pager.setCurrentItem(tab.getPosition());
}

@Override
Expand All @@ -256,7 +246,7 @@ public void onTabReselected(TabLayout.Tab tab) {

setCurrentTab();

mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
mBinding.fabCreateAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent addAccountIntent = new Intent(AccountsActivity.this, FormActivity.class);
Expand Down Expand Up @@ -303,7 +293,7 @@ protected void onNewIntent(Intent intent) {
setIntent(intent);
setCurrentTab();

int index = mViewPager.getCurrentItem();
int index = mBinding.pager.getCurrentItem();
Fragment fragment = (Fragment) mFragmentPageReferenceMap.get(index);
if (fragment != null)
((Refreshable) fragment).refresh();
Expand All @@ -318,7 +308,7 @@ public void setCurrentTab() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
int lastTabIndex = preferences.getInt(LAST_OPEN_TAB_INDEX, INDEX_TOP_LEVEL_ACCOUNTS_FRAGMENT);
int index = getIntent().getIntExtra(EXTRA_TAB_INDEX, lastTabIndex);
mViewPager.setCurrentItem(index);
mBinding.pager.setCurrentItem(index);
}

/**
Expand Down Expand Up @@ -352,7 +342,7 @@ private void init() {
protected void onDestroy() {
super.onDestroy();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
preferences.edit().putInt(LAST_OPEN_TAB_INDEX, mViewPager.getCurrentItem()).apply();
preferences.edit().putInt(LAST_OPEN_TAB_INDEX, mBinding.pager.getCurrentItem()).apply();
}

/**
Expand Down Expand Up @@ -550,4 +540,4 @@ public static void removeFirstRunFlag(Context context) {
editor.apply();
}

}
}
Loading