make use of Butterknife
This commit is contained in:
parent
d4978d0223
commit
89e08c282c
4 changed files with 35 additions and 25 deletions
|
@ -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<Directory> 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);
|
||||
|
|
|
@ -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<String> 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);
|
||||
|
|
|
@ -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<String> 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();
|
||||
|
|
|
@ -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<Directory> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue