From 89e08c282c660b2ec00c26f7ce4e9e39d9edc896 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 1 Jun 2016 19:15:14 +0200 Subject: [PATCH] make use of Butterknife --- .../gallery/activities/MainActivity.java | 8 +++-- .../gallery/activities/PhotosActivity.java | 8 +++-- .../gallery/activities/ViewPagerActivity.java | 31 ++++++++++--------- .../gallery/adapters/DirectoryAdapter.java | 13 ++++---- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index e5caa00c3..5f1a09873 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -40,12 +40,16 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import butterknife.BindView; +import butterknife.ButterKnife; + public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener, MediaScannerConnection.OnScanCompletedListener { + @BindView(R.id.directories_grid) GridView gridView; + private static final int STORAGE_PERMISSION = 1; private List dirs; - private GridView gridView; private int selectedItemsCnt; private Snackbar snackbar; private boolean isSnackbarShown; @@ -56,6 +60,7 @@ public class MainActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + ButterKnife.bind(this); } @Override @@ -115,7 +120,6 @@ public class MainActivity extends AppCompatActivity dirs = new ArrayList<>(getDirectories().values()); final DirectoryAdapter adapter = new DirectoryAdapter(this, dirs); - gridView = (GridView) findViewById(R.id.directories_grid); gridView.setAdapter(adapter); gridView.setOnItemClickListener(this); gridView.setMultiChoiceModeListener(this); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java index b8bb7fae5..bfcb64bd1 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java @@ -37,13 +37,17 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import butterknife.BindView; +import butterknife.ButterKnife; + public class PhotosActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, MediaScannerConnection.OnScanCompletedListener, GridView.OnTouchListener { + @BindView(R.id.photos_grid) GridView gridView; + private static final int STORAGE_PERMISSION = 1; private List photos; private int selectedItemsCnt; - private GridView gridView; private String path; private Snackbar snackbar; private boolean isSnackbarShown; @@ -54,6 +58,7 @@ public class PhotosActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_photos); + ButterKnife.bind(this); } @Override @@ -101,7 +106,6 @@ public class PhotosActivity extends AppCompatActivity return; final PhotosAdapter adapter = new PhotosAdapter(this, photos); - gridView = (GridView) findViewById(R.id.photos_grid); gridView.setAdapter(adapter); gridView.setOnItemClickListener(this); gridView.setMultiChoiceModeListener(this); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index 36392e9d4..4cc61d7ca 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -31,24 +31,30 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + public class ViewPagerActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, MediaScannerConnection.OnScanCompletedListener, ViewPager.OnTouchListener { + @BindView(R.id.undo_delete) View undoBtn; + @BindView(R.id.view_pager) MyViewPager pager; + private int pos; private boolean isFullScreen; private ActionBar actionbar; private List photos; - private MyViewPager pager; private String path; private String directory; private boolean isUndoShown; private String toBeDeleted; - private View undoBtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_photo); + ButterKnife.bind(this); pos = 0; isFullScreen = true; @@ -58,11 +64,8 @@ public class ViewPagerActivity extends AppCompatActivity path = getIntent().getStringExtra(Constants.PHOTO); MediaScannerConnection.scanFile(this, new String[]{path}, null, null); - undoBtn = findViewById(R.id.undo_delete); - undoBtn.setOnClickListener(undoDeletion); addUndoMargin(); directory = new File(path).getParent(); - pager = (MyViewPager) findViewById(R.id.view_pager); photos = getPhotos(); if (isDirEmpty()) return; @@ -78,6 +81,14 @@ public class ViewPagerActivity extends AppCompatActivity updateActionbarTitle(); } + @OnClick(R.id.undo_delete) + public void undoDeletion() { + isUndoShown = false; + toBeDeleted = ""; + undoBtn.setVisibility(View.GONE); + reloadViewPager(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.viewpager_menu, menu); @@ -141,16 +152,6 @@ public class ViewPagerActivity extends AppCompatActivity undoBtn.setVisibility(View.GONE); } - private View.OnClickListener undoDeletion = new View.OnClickListener() { - @Override - public void onClick(View v) { - isUndoShown = false; - toBeDeleted = ""; - undoBtn.setVisibility(View.GONE); - reloadViewPager(); - } - }; - private boolean isDirEmpty() { if (photos.size() <= 0) { deleteDirectoryIfEmpty(); diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java index 1ebf38202..834c3a1c4 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java @@ -14,6 +14,9 @@ import com.simplemobiletools.gallery.R; import java.util.List; +import butterknife.BindView; +import butterknife.ButterKnife; + public class DirectoryAdapter extends BaseAdapter { private final Context context; private final List dirs; @@ -66,14 +69,12 @@ public class DirectoryAdapter extends BaseAdapter { } static class ViewHolder { - TextView dirName; - TextView photoCnt; - ImageView dirThumbnail; + @BindView(R.id.dir_name) TextView dirName; + @BindView(R.id.photo_cnt) TextView photoCnt; + @BindView(R.id.dir_thumbnail) ImageView dirThumbnail; public ViewHolder(View view) { - dirName = (TextView) view.findViewById(R.id.dir_name); - photoCnt = (TextView) view.findViewById(R.id.photo_cnt); - dirThumbnail = (ImageView) view.findViewById(R.id.dir_thumbnail); + ButterKnife.bind(this, view); } } }