Wednesday, April 1, 2015

MyNotes: Pass the Butter

I recently posted an entry about incorporating Roboguice.  Well, I changed my mind about that and decided to swap it for ButterKnife after all.   After doing some UI work, it became apparent that Roboguice was overkill for MyNotes and wasn't going to work really well in the CommonLibrary.

After some thought, I decided that ButterKnife was a better fit.  Here are the steps I used for swapping out the libraries:

Step 1: Undo the RoboGuice Integration.

I just reversed the steps from the blog entry to return to a clean slate.

Step 2: Bring in ButterKnife

Update the MyNotes gradle.build file with the following:

   release {
     // Library specific proguard files
     ...
     proguardFiles 'proguard-butterknife.pro'
   }
   ....

   dependencies {
      ....  
      compile 'com.jakewharton:butterknife:6.1.0'
    }
Add proguard-butterknife.pro to the project with the following content:
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}
Incorporate it into the MainActivity:
    /**
     * UI element to display the note data.
     */
    @InjectView(R.id.activity_main_notes_recycler_view)
    RecyclerView mCardsRecyclerView;


    /**
     * UI element to allow a user to create a new note.
     */
    @InjectView(R.id.activity_main_add_view)
    View mAddView;


    /**
     * The adapter to manage the display of cards in {@link #mCardsRecyclerView}.
     */
    CardAdapter mCardAdapter;


    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);

Commits:

No comments :

Post a Comment