From 481c04ca01e2b602b6ae7b35a3e222b20fda783f Mon Sep 17 00:00:00 2001 From: Ahmed Eltaher Date: Sun, 26 Feb 2017 16:44:38 +0100 Subject: [PATCH] Update ButterKnife . Adding configuration gradle file . Improve build gradle file . --- app/app.iml | 187 ------------------ app/build.gradle | 63 +++--- app/configuration.gradle | 20 ++ .../java/com/task/ui/base/BaseActivity.java | 28 +-- .../java/com/task/ui/base/BaseFragment.java | 9 +- .../ui/component/details/DetailsActivity.java | 12 +- .../task/ui/component/news/HomeActivity.java | 31 +-- .../ui/component/news/NewsViewHolder.java | 10 +- build.gradle | 5 + 9 files changed, 109 insertions(+), 256 deletions(-) delete mode 100644 app/app.iml create mode 100644 app/configuration.gradle diff --git a/app/app.iml b/app/app.iml deleted file mode 100644 index 87d675f..0000000 --- a/app/app.iml +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 63efcb8..9513af3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,18 +1,22 @@ apply plugin: 'com.android.application' -//Daggar +//Dagger apply plugin: 'com.neenbedankt.android-apt' +//ButterKnife +apply plugin: 'com.jakewharton.butterknife' //lamda apply plugin: 'com.jakewharton.hugo' apply plugin: 'me.tatarka.retrolambda' +apply from: 'configuration.gradle' + android { - compileSdkVersion 24 - buildToolsVersion "24.0.1" + compileSdkVersion project.compileSdkVersion + buildToolsVersion project.buildToolsVersion defaultConfig { applicationId 'com.eltaher.task' - minSdkVersion 16 - targetSdkVersion 24 - versionCode 1 - versionName "1.0" + minSdkVersion project.minSdkVersion + targetSdkVersion project.targetSdkVersion + versionCode project.versionCode + versionName project.versionName multiDexEnabled true } buildTypes { @@ -44,70 +48,71 @@ repositories { } configurations.all { resolutionStrategy { - force 'com.android.support:support-annotations:24.2.1' + force "com.android.support:support-annotations:${supportLibraryVersion}" } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') //android support & recyclerview - compile 'com.android.support:recyclerview-v7:24.2.1' - compile 'com.android.support:appcompat-v7:24.2.1' - compile 'com.android.support:design:24.2.1' + compile "com.android.support:recyclerview-v7:${supportLibraryVersion}" + compile "com.android.support:appcompat-v7:${supportLibraryVersion}" + compile "com.android.support:design:${supportLibraryVersion}" //Dagger - compile 'com.google.dagger:dagger:2.0.2' - apt 'com.google.dagger:dagger-compiler:2.0.2' + compile "com.google.dagger:dagger:${daggerVersion}" + apt "com.google.dagger:dagger-compiler:${daggerVersion}" //Butter knife - compile 'com.jakewharton:butterknife:7.0.1' + compile "com.jakewharton:butterknife:${butterKnifeVersion}" + apt "com.jakewharton:butterknife-compiler:${butterKnifeVersion}" //event bus compile 'com.squareup:otto:1.3.8' //Logging - compile 'com.squareup.okhttp3:logging-interceptor:3.3.0' + compile "com.squareup.okhttp3:logging-interceptor:${okhttpVersion}" compile 'com.orhanobut:logger:1.15' // retrofit - compile 'com.squareup.retrofit2:retrofit:2.1.0' - compile 'com.squareup.retrofit2:converter-gson:2.1.0' - compile 'com.squareup.okhttp3:okhttp:3.3.0' + compile "com.squareup.retrofit2:retrofit:${retrofitVersion}" + compile "com.squareup.retrofit2:converter-gson:${retrofitVersion}" + compile "com.squareup.okhttp3:okhttp:${okhttpVersion}" //picasso compile 'com.squareup.picasso:picasso:2.5.2' //MultiDex compile 'com.android.support:multidex:+' //ParcelablePlease - compile 'com.hannesdorfmann.parcelableplease:parent:1.0.2' - compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2' - compile 'com.hannesdorfmann.parcelableplease:processor:1.0.2' + compile "com.hannesdorfmann.parcelableplease:parent:${parcelablepleaseVersion}" + compile "com.hannesdorfmann.parcelableplease:annotation:${parcelablepleaseVersion}" + compile "com.hannesdorfmann.parcelableplease:processor:${parcelablepleaseVersion}" //Android RX compile 'io.reactivex:rxandroid:1.2.1' compile 'io.reactivex:rxjava:1.1.6' - compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' + compile "com.squareup.retrofit2:adapter-rxjava:${retrofitVersion}" // espresso , junit for testing testCompile 'junit:junit:4.12' - compile("com.android.support.test:rules:0.5") { + compile('com.android.support.test:rules:0.5') { exclude group: "javax.inject", module: "javax.inject" exclude group: 'com.android.support', module: 'support-annotations' } - compile("com.android.support.test:runner:0.5") { + compile('com.android.support.test:runner:0.5') { exclude group: "javax.inject", module: "javax.inject" exclude group: 'com.android.support', module: 'support-annotations' } - compile("com.android.support.test.espresso:espresso-core:2.2.2") { + compile("com.android.support.test.espresso:espresso-core:${espressoVersion}") { exclude group: "javax.inject", module: "javax.inject" exclude group: "com.squareup", module: "javawriter" exclude group: 'com.android.support', module: 'support-annotations' } - compile("com.android.support.test.espresso:espresso-contrib:2.2.2") { + compile("com.android.support.test.espresso:espresso-contrib:${espressoVersion}") { exclude module: "recyclerview-v7" exclude module: "support-v4" exclude group: "javax.inject", module: "javax.inject" exclude group: 'com.android.support', module: 'support-annotations' } - compile("com.android.support.test.espresso:espresso-intents:2.2.1") { + compile('com.android.support.test.espresso:espresso-intents:2.2.1') { exclude group: "javax.inject", module: "javax.inject" exclude group: 'com.android.support', module: 'support-annotations' } - compile("com.android.support.test.espresso:espresso-idling-resource:2.2.2") { + compile("com.android.support.test.espresso:espresso-idling-resource:${espressoVersion}") { exclude module: "recyclerview-v7" exclude module: "support-v4" exclude group: "javax.inject", module: "javax.inject" exclude group: 'com.android.support', module: 'support-annotations' } -} +} \ No newline at end of file diff --git a/app/configuration.gradle b/app/configuration.gradle new file mode 100644 index 0000000..69c5b8c --- /dev/null +++ b/app/configuration.gradle @@ -0,0 +1,20 @@ +ext { + //App name + versionCode = 1 + versionName = "1.0" + + //Compilation + minSdkVersion = 16 + compileSdkVersion = 24 + targetSdkVersion = 24 + + //Libraries + buildToolsVersion = '24.0.1' + supportLibraryVersion = '24.2.1' + daggerVersion = '2.0.2' + parcelablepleaseVersion = '1.0.2' + espressoVersion = '2.2.2' + retrofitVersion = '2.2.0' + okhttpVersion = '3.3.0' + butterKnifeVersion = '8.5.1' +} \ No newline at end of file diff --git a/app/src/main/java/com/task/ui/base/BaseActivity.java b/app/src/main/java/com/task/ui/base/BaseActivity.java index fe541a3..db9b2b4 100644 --- a/app/src/main/java/com/task/ui/base/BaseActivity.java +++ b/app/src/main/java/com/task/ui/base/BaseActivity.java @@ -11,8 +11,9 @@ import android.widget.TextView; import com.task.R; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.Unbinder; import static android.view.View.GONE; import static android.view.View.VISIBLE; @@ -21,25 +22,28 @@ import static android.view.View.VISIBLE; * Created by AhmedEltaher on 5/12/2016 */ -@SuppressWarnings("ConstantConditions") -public abstract class BaseActivity extends AppCompatActivity implements Presenter.View, ActionBarView { + +public abstract class BaseActivity extends AppCompatActivity implements Presenter.View, + ActionBarView { protected Presenter presenter; @Nullable - @Bind(R.id.toolbar) + @BindView(R.id.toolbar) Toolbar toolbar; @Nullable - @Bind(R.id.ic_toolbar_setting) + @BindView(R.id.ic_toolbar_setting) ImageView icSettings; @Nullable - @Bind(R.id.ic_toolbar_refresh) + @BindView(R.id.ic_toolbar_refresh) protected ImageView icHome; + private Unbinder unbinder; + protected abstract void initializeDagger(); protected abstract void initializePresenter(); @@ -50,7 +54,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Presente protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getLayoutId()); - initializeButterKnife(); + unbinder = ButterKnife.bind(this); initializeDagger(); initializePresenter(); initializeToolbar(); @@ -81,10 +85,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Presente } } - private void initializeButterKnife() { - ButterKnife.bind(this); - } - protected void initializeToolbar() { if (toolbar != null) { setSupportActionBar(toolbar); @@ -141,4 +141,10 @@ public abstract class BaseActivity extends AppCompatActivity implements Presente } return super.onOptionsItemSelected(item); } + + @Override + protected void onDestroy() { + super.onDestroy(); + unbinder.unbind(); + } } diff --git a/app/src/main/java/com/task/ui/base/BaseFragment.java b/app/src/main/java/com/task/ui/base/BaseFragment.java index 6668061..a5797fe 100644 --- a/app/src/main/java/com/task/ui/base/BaseFragment.java +++ b/app/src/main/java/com/task/ui/base/BaseFragment.java @@ -15,6 +15,7 @@ import android.widget.TextView; import com.task.R; import butterknife.ButterKnife; +import butterknife.Unbinder; /** * Created by AhmedEltaher on 5/12/2016 @@ -35,6 +36,7 @@ public abstract class BaseFragment extends Fragment implements Presenter.View { private View view; + private Unbinder unbinder; private String toolbarTitleKey; @@ -48,9 +50,10 @@ public abstract class BaseFragment extends Fragment implements Presenter.View { @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { view = inflater.inflate(getLayoutId(), container, false); - ButterKnife.bind(this, view); + unbinder = ButterKnife.bind(this, view); if (presenter != null) { presenter.initialize(getArguments()); } @@ -76,7 +79,7 @@ public abstract class BaseFragment extends Fragment implements Presenter.View { @Override public void onDestroyView() { super.onDestroyView(); - ButterKnife.unbind(this); + unbinder.unbind(); } public void setTitle(String title) { diff --git a/app/src/main/java/com/task/ui/component/details/DetailsActivity.java b/app/src/main/java/com/task/ui/component/details/DetailsActivity.java index aa83fce..d65bbf2 100644 --- a/app/src/main/java/com/task/ui/component/details/DetailsActivity.java +++ b/app/src/main/java/com/task/ui/component/details/DetailsActivity.java @@ -1,5 +1,7 @@ package com.task.ui.component.details; +import static android.text.TextUtils.isEmpty; + import android.widget.ImageView; import android.widget.TextView; @@ -12,9 +14,7 @@ import com.task.ui.base.BaseActivity; import javax.inject.Inject; -import butterknife.Bind; - -import static android.text.TextUtils.isEmpty; +import butterknife.BindView; /** * Created by AhmedEltaher on 11/12/16. @@ -25,11 +25,11 @@ public class DetailsActivity extends BaseActivity implements DetailsView { @Inject DetailsPresenter presenter; - @Bind(R.id.tv_title) + @BindView(R.id.tv_title) TextView tvTitle; - @Bind(R.id.iv_news_main_Image) + @BindView(R.id.iv_news_main_Image) ImageView ivMainImage; - @Bind(R.id.tv_description) + @BindView(R.id.tv_description) TextView tvDescription; @Override diff --git a/app/src/main/java/com/task/ui/component/news/HomeActivity.java b/app/src/main/java/com/task/ui/component/news/HomeActivity.java index 6db7bb9..6e7b849 100644 --- a/app/src/main/java/com/task/ui/component/news/HomeActivity.java +++ b/app/src/main/java/com/task/ui/component/news/HomeActivity.java @@ -1,5 +1,14 @@ package com.task.ui.component.news; +import static android.support.design.widget.Snackbar.LENGTH_SHORT; +import static android.view.View.GONE; +import static android.view.View.VISIBLE; + +import static com.task.utils.Constants.NEWS_ITEM_KEY; +import static com.task.utils.EspressoIdlingResource.decrement; +import static com.task.utils.EspressoIdlingResource.getIdlingResource; +import static com.task.utils.EspressoIdlingResource.increment; + import android.content.Intent; import android.os.Bundle; import android.support.annotation.VisibleForTesting; @@ -24,17 +33,9 @@ import java.util.List; import javax.inject.Inject; -import butterknife.Bind; +import butterknife.BindView; import butterknife.OnClick; -import static android.support.design.widget.Snackbar.LENGTH_SHORT; -import static android.view.View.GONE; -import static android.view.View.VISIBLE; -import static com.task.utils.Constants.NEWS_ITEM_KEY; -import static com.task.utils.EspressoIdlingResource.decrement; -import static com.task.utils.EspressoIdlingResource.getIdlingResource; -import static com.task.utils.EspressoIdlingResource.increment; - /** * Created by AhmedEltaher on 5/12/2016 */ @@ -42,17 +43,17 @@ import static com.task.utils.EspressoIdlingResource.increment; public class HomeActivity extends BaseActivity implements HomeView { @Inject HomePresenter presenter; - @Bind(R.id.rv_news_list) + @BindView(R.id.rv_news_list) RecyclerView rvNews; - @Bind(R.id.pb_loading) + @BindView(R.id.pb_loading) ProgressBar pbLoading; - @Bind(R.id.tv_no_data) + @BindView(R.id.tv_no_data) TextView tvNoData; - @Bind(R.id.rl_news_list) + @BindView(R.id.rl_news_list) RelativeLayout rlNewsList; - @Bind(R.id.btn_search) + @BindView(R.id.btn_search) ImageButton btnSearch; - @Bind(R.id.et_search) + @BindView(R.id.et_search) EditText editTextSearch; @Override diff --git a/app/src/main/java/com/task/ui/component/news/NewsViewHolder.java b/app/src/main/java/com/task/ui/component/news/NewsViewHolder.java index 45b63ed..4c76651 100644 --- a/app/src/main/java/com/task/ui/component/news/NewsViewHolder.java +++ b/app/src/main/java/com/task/ui/component/news/NewsViewHolder.java @@ -11,7 +11,7 @@ import com.task.R; import com.task.data.remote.dto.NewsItem; import com.task.ui.base.listeners.RecyclerItemListener; -import butterknife.Bind; +import butterknife.BindView; import butterknife.ButterKnife; import static android.text.TextUtils.isEmpty; @@ -26,13 +26,13 @@ public class NewsViewHolder extends RecyclerView.ViewHolder { private RecyclerItemListener onItemClickListener; - @Bind(R.id.tv_caption) + @BindView(R.id.tv_caption) TextView tvCaption; - @Bind(R.id.tv_title) + @BindView(R.id.tv_title) TextView tvTitle; - @Bind(R.id.rl_news_item) + @BindView(R.id.rl_news_item) RelativeLayout newsItemLayout; - @Bind(R.id.iv_news_item_image) + @BindView(R.id.iv_news_item_image) ImageView newsImage; diff --git a/build.gradle b/build.gradle index 9a7356d..33431be 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ buildscript { repositories { jcenter() + mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' @@ -11,8 +12,12 @@ buildscript { //lamda classpath 'me.tatarka:gradle-retrolambda:3.2.5' classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1' + //ButterKnife + classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1' + // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files + } }