Skip to content

Commit

Permalink
移除ButtferKnife
Browse files Browse the repository at this point in the history
  • Loading branch information
woshidasusu committed Apr 10, 2017
1 parent 711b9a9 commit b09db75
Show file tree
Hide file tree
Showing 19 changed files with 128 additions and 145 deletions.
9 changes: 4 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Properties properties = new Properties();
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
compileSdkVersion 24
compileSdkVersion 25
buildToolsVersion '25.0.2'

defaultConfig {
Expand Down Expand Up @@ -86,7 +86,6 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:5.1.1'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.picasso:picasso:2.5.2'
Expand All @@ -95,9 +94,9 @@ dependencies {
compile 'org.greenrobot:greendao-generator:3.1.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.github.chrisbanes:PhotoView:1.3.0'
debugCompile 'com.facebook.stetho:stetho:1.3.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class NetBroadcastReceiver extends BroadcastReceiver {
*/
public static final String NET_CHANGED_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
/**
* 支持并发读
* 支持并发读,为什么选择使用这个,因为这个支持在读的过程中对 list 进行修改,
* 它是线程安全的
*/
private static CopyOnWriteArrayList<NetStateListener> mListeners = new CopyOnWriteArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import com.dasu.gank.R;
import com.dasu.gank.ui.base.BaseActivity;

Expand All @@ -17,25 +15,20 @@ public class DayGankDetailActivity extends BaseActivity {

private static final String TAG = DayGankDetailActivity.class.getSimpleName();

@InjectView(R.id.rv_day_detail)
RecyclerView mDayDetaiView;
private RecyclerView mDayDetaiView;

@Override
public int provideContentView() {
return R.layout.activity_day_gank_detail;
}


// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreae(savedInstanceState);
// ButterKnife.inject(this);
// }


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.inject(this);
findView();
}

private void findView() {
mDayDetaiView = (RecyclerView) findViewById(R.id.rv_day_detail);
}
}
23 changes: 11 additions & 12 deletions app/src/main/java/com/dasu/gank/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,22 @@
import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class MainActivity extends SwipeRefreshActivity {

private static final String TAG = MainActivity.class.getSimpleName();

private GankPagerFragmentAdapter mFragmentAdapter;
private List<GankDataFragment> mFragmentList;

@InjectView(R.id.main_tab_layout)
TabLayout mTabLayout;
@InjectView(R.id.main_content_viewpager)
ViewPager mViewPager;
@InjectView(R.id.layout_content)
ViewGroup mContentLayout;
private TabLayout mTabLayout;
private ViewPager mViewPager;
private ViewGroup mContentLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.inject(this);

initVariable();
findView();
bindWidgets();
UpdateController.checkUpdate(this, new UpdateDialog(this));
addNoNetworkTipView(mContentLayout);
Expand All @@ -51,7 +44,7 @@ public int provideContentView() {
return R.layout.activity_main;
}

public void initVariable() {
private void initVariable() {
mFragmentList = new ArrayList<>();
GankDataFragmentFactory factory = new GankDataFragmentFactory();
for (FragmentKey key: FragmentKey.values()) {
Expand All @@ -61,6 +54,12 @@ public void initVariable() {

}

private void findView() {
mTabLayout = (TabLayout) findViewById(R.id.main_tab_layout);
mViewPager = (ViewPager) findViewById(R.id.main_content_viewpager);
mContentLayout = (ViewGroup) findViewById(R.id.layout_content);
}

public void bindWidgets() {
mViewPager.setAdapter(mFragmentAdapter);
mTabLayout.setupWithViewPager(mViewPager);
Expand Down
21 changes: 8 additions & 13 deletions app/src/main/java/com/dasu/gank/ui/adapter/AndroidDataAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SizeReadyCallback;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import com.dasu.gank.R;
import com.dasu.gank.mode.entity.Data;
import com.dasu.gank.ui.base.OnItemClickListener;
import com.dasu.gank.utils.TimeUtils;
import com.dasu.gank.ui.view.RatioImageView;
import com.dasu.gank.utils.TimeUtils;

import java.util.List;

/**
* Created by dasu on 2016/9/28.
Expand Down Expand Up @@ -79,24 +76,22 @@ public void setOnItemClickListener(OnItemClickListener listener) {

class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

@InjectView(R.id.android_item_image)
RatioImageView mItemImage;
@InjectView(R.id.android_item_title)
TextView mItemTitle;
@InjectView(R.id.android_item_publish_time)
TextView mItemPublishTime;
@InjectView(R.id.android_item_author)
TextView mItemAuthor;
@InjectView(R.id.android_item_type)
TextView mItemType;

View mItemView;
Data mData;

public ViewHolder(View itemView) {
super(itemView);
mItemView = itemView;
ButterKnife.inject(this, itemView);
mItemImage = (RatioImageView) itemView.findViewById(R.id.android_item_image);
mItemTitle = (TextView) itemView.findViewById(R.id.android_item_title);
mItemPublishTime = (TextView) itemView.findViewById(R.id.android_item_publish_time);
mItemAuthor = (TextView) itemView.findViewById(R.id.android_item_author);
mItemType = (TextView) itemView.findViewById(R.id.android_item_type);
itemView.setOnClickListener(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.Collections;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
Expand Down Expand Up @@ -173,18 +171,17 @@ public interface OnItemClickListener{

class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

@InjectView(R.id.day_gank_img)
RatioImageView mDayGankImg;
@InjectView(R.id.day_gank_title)
TextView mDayGankTitle;

DayGank mData;
View mItemView;

public ViewHolder(View itemView) {
super(itemView);
ButterKnife.inject(this, itemView);
mItemView = itemView;
mDayGankImg = (RatioImageView) itemView.findViewById(R.id.day_gank_img);
mDayGankTitle = (TextView) itemView.findViewById(R.id.day_gank_title);
mItemView.setOnClickListener(this);
mDayGankImg.setOnClickListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import butterknife.ButterKnife;
import com.dasu.gank.R;
import com.dasu.gank.mode.entity.Data;

import java.util.List;

/**
* Created by dasu on 2016/10/9.
* ttps://github.com/woshidasusu/Meizi
Expand Down Expand Up @@ -67,15 +66,13 @@ class VideoViewHolder extends RecyclerView.ViewHolder{

public VideoViewHolder(View itemView) {
super(itemView);
ButterKnife.inject(this, itemView);
}
}

class DataViewHolder extends RecyclerView.ViewHolder{

public DataViewHolder(View itemView) {
super(itemView);
ButterKnife.inject(this, itemView);
}
}

Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/com/dasu/gank/ui/adapter/MeiziWallAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SizeReadyCallback;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import com.dasu.gank.R;
import com.dasu.gank.mode.entity.Data;
import com.dasu.gank.ui.base.OnItemClickListener;
import com.dasu.gank.ui.view.RatioImageView;

import java.util.List;

/**
* Created by sxq on 2016/9/10.
*/
Expand Down Expand Up @@ -70,18 +67,17 @@ public void setOnItemClickListener(OnItemClickListener itemClickListener) {

class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

@InjectView(R.id.meizhi_img)
RatioImageView meizhiImg;
@InjectView(R.id.meizhi_tv)
TextView meizhiText;

View mItemView;
Data mMeizhi;

public ViewHolder(View itemView) {
super(itemView);
ButterKnife.inject(this, itemView);
mItemView = itemView;
meizhiImg = (RatioImageView) itemView.findViewById(R.id.meizhi_img);
meizhiText = (TextView) itemView.findViewById(R.id.meizhi_tv);
mItemView.setOnClickListener(this);
meizhiImg.setOnClickListener(this);
meizhiImg.setOriginSize(50, 50);
Expand Down
33 changes: 21 additions & 12 deletions app/src/main/java/com/dasu/gank/ui/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.WindowManager;

import com.dasu.gank.R;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
* Created by dasu on 2016/8/25.
* https://github.com/woshidasusu/Meizi
Expand All @@ -21,16 +18,15 @@ public abstract class BaseActivity extends AppCompatActivity {

private long mFirstClickTime;

@InjectView(R.id.toolbar)
public Toolbar mToolbar;
@InjectView(R.id.collaps_toolbar)
public CollapsingToolbarLayout mCollapsToolbar;
protected Toolbar mToolbar;
protected CollapsingToolbarLayout mCollapsToolbar;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(provideContentView());
ButterKnife.inject(this);
findView();
bindWidgets();
//透明状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
mCollapsToolbar.setTitle(getString(R.string.app_name));
Expand All @@ -44,8 +40,21 @@ protected void onDestroy() {
ActivityStack.getInstance().popActivity(this);
}

@OnClick(R.id.toolbar)
public void onToolbarClickListener() {
private void findView() {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mCollapsToolbar = (CollapsingToolbarLayout) findViewById(R.id.collaps_toolbar);
}

private void bindWidgets() {
mToolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onToolbarClick();
}
});
}

protected void onToolbarClick() {
long secClick = System.currentTimeMillis();
if ((secClick - mFirstClickTime) < 1000) {
onToolbarDoubleClick();
Expand All @@ -56,6 +65,6 @@ public void onToolbarClickListener() {
protected void onToolbarDoubleClick() {
}

public abstract int provideContentView();
protected abstract int provideContentView();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import com.dasu.gank.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
* Created by dasu on 2016/10/1.
* https://github.com/woshidasusu/Meizi
Expand All @@ -17,16 +14,19 @@ public abstract class SwipeRefreshActivity extends NetworkListenerActivity imple

private static final String TAG = SwipeRefreshActivity.class.getSimpleName();

@InjectView(R.id.refresh_layout)
SwipeRefreshLayout mSwipeRefreshLayout;
private SwipeRefreshLayout mSwipeRefreshLayout;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.inject(this);
findView();
initSwipeRefresh();
}

private void findView() {
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
}

private void initSwipeRefresh() {
if (mSwipeRefreshLayout != null) {
mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.deeppink),
Expand Down
Loading

0 comments on commit b09db75

Please sign in to comment.