More cleanup of view binding code.

This commit is contained in:
dosiecki 2015-05-16 22:14:45 -07:00
parent bbb1ebfa9c
commit 712f9f1bbf
2 changed files with 23 additions and 26 deletions

View file

@ -27,6 +27,9 @@ import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;
import butterknife.ButterKnife;
import butterknife.FindView;
import com.newsblur.R;
import com.newsblur.domain.Story;
import com.newsblur.fragment.ReadingItemFragment;
@ -73,11 +76,17 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
protected final Object STORIES_MUTEX = new Object();
protected Cursor stories;
private View contentView; // we use this a ton, so cache it
protected ViewPager pager;
protected Button overlayLeft, overlayRight;
protected ProgressBar overlayProgress, overlayProgressRight, overlayProgressLeft;
protected Button overlayText, overlaySend;
@FindView(android.R.id.content) View contentView; // we use this a ton, so cache it
@FindView(R.id.reading_overlay_left) Button overlayLeft;
@FindView(R.id.reading_overlay_right) Button overlayRight;
@FindView(R.id.reading_overlay_progress) ProgressBar overlayProgress;
@FindView(R.id.reading_overlay_progress_right) ProgressBar overlayProgressRight;
@FindView(R.id.reading_overlay_progress_left) ProgressBar overlayProgressLeft;
@FindView(R.id.reading_overlay_text) Button overlayText;
@FindView(R.id.reading_overlay_send) Button overlaySend;
ViewPager pager;
protected FragmentManager fragmentManager;
protected ReadingAdapter readingAdapter;
private boolean stopLoading;
@ -104,14 +113,7 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
super.onCreate(savedInstanceBundle);
setContentView(R.layout.activity_reading);
this.contentView = findViewById(android.R.id.content);
this.overlayLeft = (Button) findViewById(R.id.reading_overlay_left);
this.overlayRight = (Button) findViewById(R.id.reading_overlay_right);
this.overlayProgress = (ProgressBar) findViewById(R.id.reading_overlay_progress);
this.overlayProgressRight = (ProgressBar) findViewById(R.id.reading_overlay_progress_right);
this.overlayProgressLeft = (ProgressBar) findViewById(R.id.reading_overlay_progress_left);
this.overlayText = (Button) findViewById(R.id.reading_overlay_text);
this.overlaySend = (Button) findViewById(R.id.reading_overlay_send);
ButterKnife.bind(this);
fragmentManager = getFragmentManager();
@ -221,7 +223,7 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
}
private void setupPager() {
pager = (ViewPager) findViewById(R.id.reading_pager);
pager = (ViewPager) findViewById(R.id.reading_pager);
pager.setPageMargin(UIUtils.convertDPsToPixels(getApplicationContext(), 1));
if (PrefsUtils.isLightThemeSelected(this)) {
pager.setPageMarginDrawable(R.drawable.divider_light);

View file

@ -24,6 +24,9 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.FindView;
import com.newsblur.R;
import com.newsblur.activity.ItemsList;
import com.newsblur.database.DatabaseConstants;
@ -43,7 +46,7 @@ public abstract class ItemListFragment extends NbFragment implements OnScrollLis
public static int ITEMLIST_LOADER = 0x01;
protected ItemsList activity;
protected ListView itemList;
@FindView(R.id.itemlistfragment_list) ListView itemList;
protected StoryItemsAdapter adapter;
protected DefaultFeedView defaultFeedView;
protected StateFilter currentState;
@ -55,7 +58,7 @@ public abstract class ItemListFragment extends NbFragment implements OnScrollLis
// loading indicator for when stories are present and fresh (at bottom of list)
protected ProgressThrobber footerProgressView;
// loading indicator for when no stories are loaded yet (instead of list)
protected ProgressThrobber emptyProgressView;
@FindView(R.id.empty_view_loading_throb) ProgressThrobber emptyProgressView;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -68,8 +71,8 @@ public abstract class ItemListFragment extends NbFragment implements OnScrollLis
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_itemlist, null);
itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
emptyProgressView = (ProgressThrobber) v.findViewById(R.id.empty_view_loading_throb);
ButterKnife.bind(this, v);
emptyProgressView.setColors(getResources().getColor(R.color.refresh_1),
getResources().getColor(R.color.refresh_2),
getResources().getColor(R.color.refresh_3),
@ -148,10 +151,6 @@ public abstract class ItemListFragment extends NbFragment implements OnScrollLis
}
private void updateLoadingMessage() {
View v = this.getView();
if (v == null) return; // we might have beat construction?
ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
if (itemList == null) {
Log.w(this.getClass().getName(), "ItemListFragment does not have the expected ListView.");
return;
@ -168,10 +167,6 @@ public abstract class ItemListFragment extends NbFragment implements OnScrollLis
}
public void scrollToTop() {
View v = this.getView();
if (v == null) return; // we might have beat construction?
ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
if (itemList == null) {
Log.w(this.getClass().getName(), "ItemListFragment does not have the expected ListView.");
return;