make use of Butterknife

This commit is contained in:
tibbi 2016-06-01 19:15:14 +02:00
parent d4978d0223
commit 89e08c282c
4 changed files with 35 additions and 25 deletions

View File

@ -40,12 +40,16 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity public class MainActivity extends AppCompatActivity
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener, implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener,
MediaScannerConnection.OnScanCompletedListener { MediaScannerConnection.OnScanCompletedListener {
@BindView(R.id.directories_grid) GridView gridView;
private static final int STORAGE_PERMISSION = 1; private static final int STORAGE_PERMISSION = 1;
private List<Directory> dirs; private List<Directory> dirs;
private GridView gridView;
private int selectedItemsCnt; private int selectedItemsCnt;
private Snackbar snackbar; private Snackbar snackbar;
private boolean isSnackbarShown; private boolean isSnackbarShown;
@ -56,6 +60,7 @@ public class MainActivity extends AppCompatActivity
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ButterKnife.bind(this);
} }
@Override @Override
@ -115,7 +120,6 @@ public class MainActivity extends AppCompatActivity
dirs = new ArrayList<>(getDirectories().values()); dirs = new ArrayList<>(getDirectories().values());
final DirectoryAdapter adapter = new DirectoryAdapter(this, dirs); final DirectoryAdapter adapter = new DirectoryAdapter(this, dirs);
gridView = (GridView) findViewById(R.id.directories_grid);
gridView.setAdapter(adapter); gridView.setAdapter(adapter);
gridView.setOnItemClickListener(this); gridView.setOnItemClickListener(this);
gridView.setMultiChoiceModeListener(this); gridView.setMultiChoiceModeListener(this);

View File

@ -37,13 +37,17 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import butterknife.BindView;
import butterknife.ButterKnife;
public class PhotosActivity extends AppCompatActivity public class PhotosActivity extends AppCompatActivity
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, MediaScannerConnection.OnScanCompletedListener, implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, MediaScannerConnection.OnScanCompletedListener,
GridView.OnTouchListener { GridView.OnTouchListener {
@BindView(R.id.photos_grid) GridView gridView;
private static final int STORAGE_PERMISSION = 1; private static final int STORAGE_PERMISSION = 1;
private List<String> photos; private List<String> photos;
private int selectedItemsCnt; private int selectedItemsCnt;
private GridView gridView;
private String path; private String path;
private Snackbar snackbar; private Snackbar snackbar;
private boolean isSnackbarShown; private boolean isSnackbarShown;
@ -54,6 +58,7 @@ public class PhotosActivity extends AppCompatActivity
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photos); setContentView(R.layout.activity_photos);
ButterKnife.bind(this);
} }
@Override @Override
@ -101,7 +106,6 @@ public class PhotosActivity extends AppCompatActivity
return; return;
final PhotosAdapter adapter = new PhotosAdapter(this, photos); final PhotosAdapter adapter = new PhotosAdapter(this, photos);
gridView = (GridView) findViewById(R.id.photos_grid);
gridView.setAdapter(adapter); gridView.setAdapter(adapter);
gridView.setOnItemClickListener(this); gridView.setOnItemClickListener(this);
gridView.setMultiChoiceModeListener(this); gridView.setMultiChoiceModeListener(this);

View File

@ -31,24 +31,30 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class ViewPagerActivity extends AppCompatActivity public class ViewPagerActivity extends AppCompatActivity
implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, MediaScannerConnection.OnScanCompletedListener, implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, MediaScannerConnection.OnScanCompletedListener,
ViewPager.OnTouchListener { ViewPager.OnTouchListener {
@BindView(R.id.undo_delete) View undoBtn;
@BindView(R.id.view_pager) MyViewPager pager;
private int pos; private int pos;
private boolean isFullScreen; private boolean isFullScreen;
private ActionBar actionbar; private ActionBar actionbar;
private List<String> photos; private List<String> photos;
private MyViewPager pager;
private String path; private String path;
private String directory; private String directory;
private boolean isUndoShown; private boolean isUndoShown;
private String toBeDeleted; private String toBeDeleted;
private View undoBtn;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo); setContentView(R.layout.activity_photo);
ButterKnife.bind(this);
pos = 0; pos = 0;
isFullScreen = true; isFullScreen = true;
@ -58,11 +64,8 @@ public class ViewPagerActivity extends AppCompatActivity
path = getIntent().getStringExtra(Constants.PHOTO); path = getIntent().getStringExtra(Constants.PHOTO);
MediaScannerConnection.scanFile(this, new String[]{path}, null, null); MediaScannerConnection.scanFile(this, new String[]{path}, null, null);
undoBtn = findViewById(R.id.undo_delete);
undoBtn.setOnClickListener(undoDeletion);
addUndoMargin(); addUndoMargin();
directory = new File(path).getParent(); directory = new File(path).getParent();
pager = (MyViewPager) findViewById(R.id.view_pager);
photos = getPhotos(); photos = getPhotos();
if (isDirEmpty()) if (isDirEmpty())
return; return;
@ -78,6 +81,14 @@ public class ViewPagerActivity extends AppCompatActivity
updateActionbarTitle(); updateActionbarTitle();
} }
@OnClick(R.id.undo_delete)
public void undoDeletion() {
isUndoShown = false;
toBeDeleted = "";
undoBtn.setVisibility(View.GONE);
reloadViewPager();
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.viewpager_menu, menu); getMenuInflater().inflate(R.menu.viewpager_menu, menu);
@ -141,16 +152,6 @@ public class ViewPagerActivity extends AppCompatActivity
undoBtn.setVisibility(View.GONE); 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() { private boolean isDirEmpty() {
if (photos.size() <= 0) { if (photos.size() <= 0) {
deleteDirectoryIfEmpty(); deleteDirectoryIfEmpty();

View File

@ -14,6 +14,9 @@ import com.simplemobiletools.gallery.R;
import java.util.List; import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class DirectoryAdapter extends BaseAdapter { public class DirectoryAdapter extends BaseAdapter {
private final Context context; private final Context context;
private final List<Directory> dirs; private final List<Directory> dirs;
@ -66,14 +69,12 @@ public class DirectoryAdapter extends BaseAdapter {
} }
static class ViewHolder { static class ViewHolder {
TextView dirName; @BindView(R.id.dir_name) TextView dirName;
TextView photoCnt; @BindView(R.id.photo_cnt) TextView photoCnt;
ImageView dirThumbnail; @BindView(R.id.dir_thumbnail) ImageView dirThumbnail;
public ViewHolder(View view) { public ViewHolder(View view) {
dirName = (TextView) view.findViewById(R.id.dir_name); ButterKnife.bind(this, view);
photoCnt = (TextView) view.findViewById(R.id.photo_cnt);
dirThumbnail = (ImageView) view.findViewById(R.id.dir_thumbnail);
} }
} }
} }