This repository has been archived by the owner on Sep 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added simple FileExplorer to copy, move and delete items
- Bug fixes
- Loading branch information
1 parent
cb3857f
commit 66452a2
Showing
22 changed files
with
1,400 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
app/src/main/java/us/koller/cameraroll/adapter/fileExplorer/RecyclerViewAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
package us.koller.cameraroll.adapter.fileExplorer; | ||
|
||
import android.content.ActivityNotFoundException; | ||
import android.content.Intent; | ||
import android.os.Handler; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import us.koller.cameraroll.R; | ||
import us.koller.cameraroll.adapter.fileExplorer.ViewHolder.FileHolder; | ||
import us.koller.cameraroll.data.Album; | ||
import us.koller.cameraroll.data.AlbumItem; | ||
import us.koller.cameraroll.data.File_POJO; | ||
import us.koller.cameraroll.ui.ItemActivity; | ||
|
||
public class RecyclerViewAdapter extends RecyclerView.Adapter { | ||
|
||
public static final int NORMAL_MODE = 0; | ||
public static final int SELECTOR_MODE = 1; | ||
public static final int PICK_TARGET_MODE = 2; | ||
|
||
|
||
public interface Callback { | ||
void onSelectorModeEnter(); | ||
|
||
void onSelectorModeExit(File_POJO[] selected_items); | ||
|
||
void onItemSelected(int count); | ||
|
||
void onPickTargetModeEnter(); | ||
|
||
void onPickTargetModeExit(); | ||
|
||
void onDataChanged(); | ||
} | ||
|
||
private File_POJO files; | ||
|
||
private int mode = NORMAL_MODE; | ||
private boolean[] selected_items; | ||
|
||
private Callback callback; | ||
|
||
public RecyclerViewAdapter(Callback callback) { | ||
this.callback = callback; | ||
} | ||
|
||
public RecyclerViewAdapter setFiles(File_POJO files) { | ||
this.files = files; | ||
selected_items = new boolean[files.getChildren().size()]; | ||
return this; | ||
} | ||
|
||
public File_POJO getFiles() { | ||
return files; | ||
} | ||
|
||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.file_cover, parent, false); | ||
return new FileHolder(v); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { | ||
final File_POJO file = files.getChildren().get(position); | ||
|
||
((FileHolder) holder).setFile(file); | ||
|
||
((FileHolder) holder).setSelected(selected_items[position]); | ||
|
||
holder.itemView.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
if (mode == SELECTOR_MODE) { | ||
onItemSelect(file); | ||
} else if (file.isMedia) { | ||
|
||
int index = file.getPath().lastIndexOf("/"); | ||
String path = file.getPath().substring(0, index); | ||
|
||
//load Album | ||
final Album album = new Album().setPath(path); | ||
AlbumItem albumItem = AlbumItem.getInstance(holder.itemView.getContext(), file.getPath()); | ||
if (albumItem != null) { | ||
album.getAlbumItems() | ||
.add(albumItem); | ||
} | ||
|
||
//create intent | ||
Intent intent = new Intent(holder.itemView.getContext(), ItemActivity.class) | ||
.putExtra(ItemActivity.ALBUM_ITEM, albumItem) | ||
.putExtra(ItemActivity.ALBUM, album) | ||
.putExtra(ItemActivity.VIEW_ONLY, true) | ||
.putExtra(ItemActivity.ITEM_POSITION, album.getAlbumItems().indexOf(albumItem)) | ||
.putExtra(ItemActivity.FINISH_AFTER, false); | ||
|
||
try { | ||
holder.itemView.getContext().startActivity(intent); | ||
} catch (ActivityNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
} else { | ||
//to keep the ripple animation | ||
new Handler().postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
RecyclerViewAdapter.this.setFiles(file); | ||
RecyclerViewAdapter.this.notifyDataSetChanged(); | ||
|
||
if (callback != null) { | ||
callback.onDataChanged(); | ||
} | ||
} | ||
}, 300); | ||
} | ||
} | ||
}); | ||
|
||
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() { | ||
@Override | ||
public boolean onLongClick(View view) { | ||
onItemSelect(file); | ||
return true; | ||
} | ||
}); | ||
|
||
//clicking on folder icons also selects this item | ||
holder.itemView.findViewById(R.id.folder_indicator).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
onItemSelect(file); | ||
} | ||
}); | ||
} | ||
|
||
private void onItemSelect(File_POJO file) { | ||
if (mode == NORMAL_MODE) { | ||
mode = SELECTOR_MODE; | ||
selected_items = new boolean[files.getChildren().size()]; | ||
if (callback != null) { | ||
callback.onSelectorModeEnter(); | ||
} | ||
} | ||
|
||
int position = files.getChildren().indexOf(file); | ||
selected_items[position] = !selected_items[position]; | ||
notifyItemChanged(position); | ||
|
||
if (callback != null) { | ||
callback.onItemSelected(getSelectedCount()); | ||
} | ||
|
||
checkSelectorMode(); | ||
} | ||
|
||
public boolean isModeActive() { | ||
return mode == SELECTOR_MODE; | ||
} | ||
|
||
public int getMode() { | ||
return mode; | ||
} | ||
|
||
private int getSelectedCount() { | ||
int selected_items_count = 0; | ||
for (int i = 0; i < selected_items.length; i++) { | ||
selected_items_count += selected_items[i] ? 1 : 0; | ||
} | ||
return selected_items_count; | ||
} | ||
|
||
private void checkSelectorMode() { | ||
int selected_items_count = getSelectedCount(); | ||
if (selected_items_count == 0) { | ||
cancelMode(); | ||
} | ||
} | ||
|
||
public void cancelMode() { | ||
if (mode == SELECTOR_MODE) { | ||
mode = NORMAL_MODE; | ||
if (callback != null) { | ||
File_POJO[] files = new File_POJO[getSelectedCount()]; | ||
int index = 0; | ||
for (int i = 0; i < selected_items.length; i++) { | ||
if (selected_items[i]) { | ||
files[index] = this.files.getChildren().get(i); | ||
index++; | ||
} | ||
} | ||
callback.onSelectorModeExit(files); | ||
} | ||
selected_items = new boolean[files.getChildren().size()]; | ||
} else if (mode == PICK_TARGET_MODE) { | ||
mode = NORMAL_MODE; | ||
if (callback != null) { | ||
callback.onPickTargetModeExit(); | ||
} | ||
} | ||
notifyDataSetChanged(); | ||
} | ||
|
||
public void pickTarget() { | ||
mode = PICK_TARGET_MODE; | ||
if (callback != null) { | ||
callback.onPickTargetModeEnter(); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return files.getChildren().size(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/us/koller/cameraroll/adapter/fileExplorer/ViewHolder/FileHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package us.koller.cameraroll.adapter.fileExplorer.ViewHolder; | ||
|
||
import android.graphics.drawable.Drawable; | ||
import android.support.v4.content.ContextCompat; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import java.io.File; | ||
|
||
import us.koller.cameraroll.R; | ||
import us.koller.cameraroll.data.File_POJO; | ||
import us.koller.cameraroll.util.MediaType; | ||
|
||
public class FileHolder extends RecyclerView.ViewHolder { | ||
|
||
private File_POJO file; | ||
|
||
public FileHolder(View itemView) { | ||
super(itemView); | ||
} | ||
|
||
public void setFile(File_POJO file) { | ||
this.file = file; | ||
|
||
ImageView folderIndicator = (ImageView) itemView.findViewById(R.id.folder_indicator); | ||
if (!file.isMedia) { | ||
folderIndicator.setImageResource(R.drawable.ic_folder_white_24dp); | ||
} else if (MediaType.isVideo(folderIndicator.getContext(), file.getPath())) { | ||
folderIndicator.setImageResource(R.drawable.ic_videocam_white_24dp); | ||
} else { | ||
folderIndicator.setImageResource(R.drawable.ic_photo_white_24dp); | ||
} | ||
|
||
TextView textView = (TextView) itemView.findViewById(R.id.text); | ||
textView.setText(file.getName()); | ||
} | ||
|
||
public void setSelected(boolean selected) { | ||
itemView.setBackgroundColor( | ||
ContextCompat.getColor(itemView.getContext(), | ||
selected ? R.color.colorAccent_translucent : | ||
android.R.color.transparent)); | ||
|
||
TextView textView = (TextView) itemView.findViewById(R.id.text); | ||
textView.setTextColor(ContextCompat.getColor(itemView.getContext(), | ||
selected ? R.color.grey_900_translucent : R.color.white_translucent1)); | ||
|
||
ImageView folderIndicator = (ImageView) itemView.findViewById(R.id.folder_indicator); | ||
Drawable d = folderIndicator.getDrawable().mutate(); | ||
d.setTint(ContextCompat.getColor(itemView.getContext(), | ||
selected ? R.color.grey_900_translucent : R.color.white)); | ||
folderIndicator.setImageDrawable(d); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.