Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
feat: set custom title
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiselrahman committed May 5, 2020
1 parent 5ed384d commit 9f50a90
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void onClick(View v) {
.setShowAudios(true)
.setSingleChoiceMode(true)
.setSelectedMediaFile(file)
.setTitle("Select an audio")
.build());
startActivityForResult(intent, FILE_REQUEST_CODE);
}
Expand All @@ -118,6 +119,7 @@ public void onClick(View v) {
.enableImageCapture(true)
.setIgnoreHiddenFile(false)
.setMaxSelection(10)
.setTitle("Select a file")
.build());
startActivityForResult(intent, FILE_REQUEST_CODE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

if (configs.getTitle() != null)
setTitle(configs.getTitle());

int spanCount;
if (getResources().getConfiguration().orientation
== Configuration.ORIENTATION_LANDSCAPE) {
Expand All @@ -138,7 +141,8 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(Dir dir) {
Intent intent = new Intent(DirSelectActivity.this, FilePickerActivity.class)
.putExtra(FilePickerActivity.CONFIGS, configs)
.putExtra(FilePickerActivity.DIR_ID, dir.getId());
.putExtra(FilePickerActivity.DIR_ID, dir.getId())
.putExtra(FilePickerActivity.DIR_TITLE, dir.getName());
startActivityForResult(intent, REQUEST_FILE);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@
import java.io.File;
import java.util.ArrayList;

@SuppressLint("StringFormatMatches")
public class FilePickerActivity extends AppCompatActivity
implements OnSelectionListener<FileGalleryAdapter.ViewHolder>, OnCameraClickListener {
public static final String MEDIA_FILES = "MEDIA_FILES";
public static final String SELECTED_MEDIA_FILES = "SELECTED_MEDIA_FILES";
public static final String CONFIGS = "CONFIGS";
public static final String DIR_ID = "DIR_ID";
public static final String DIR_TITLE = "DIR_TITLE";
public static final String TAG = "FilePicker";
private static final String PATH = "PATH";
private static final String URI = "URI";
Expand All @@ -71,6 +73,8 @@ public class FilePickerActivity extends AppCompatActivity
private FileGalleryAdapter fileGalleryAdapter;
private int maxCount;
private Long dirId = null;
private String title = null;
private int title_res = R.string.selection_count;

private FileResultCallback fileResultCallback = new FileResultCallback() {
@Override
Expand Down Expand Up @@ -121,6 +125,14 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

if (getIntent().hasExtra(DIR_TITLE))
title = getIntent().getStringExtra(DIR_TITLE);
else if (configs.getTitle() != null)
title = configs.getTitle();

if (title != null)
title_res = R.string.selection_count_title;

int spanCount;
if (getResources().getConfiguration().orientation
== Configuration.ORIENTATION_LANDSCAPE) {
Expand Down Expand Up @@ -166,7 +178,7 @@ public boolean isAutoMeasureEnabled() {

maxCount = configs.getMaxSelection();
if (maxCount > 0) {
setTitle(getResources().getString(R.string.selection_count, fileGalleryAdapter.getSelectedItemCount(), maxCount));
setTitle(getResources().getString(title_res, fileGalleryAdapter.getSelectedItemCount(), maxCount, title));
}
}

Expand Down Expand Up @@ -336,14 +348,14 @@ public void onSelectionBegin() {
@Override
public void onSelected(FileGalleryAdapter.ViewHolder viewHolder, int position) {
if (maxCount > 0) {
setTitle(getResources().getString(R.string.selection_count, fileGalleryAdapter.getSelectedItemCount(), maxCount));
setTitle(getResources().getString(title_res, fileGalleryAdapter.getSelectedItemCount(), maxCount, title));
}
}

@Override
public void onUnSelected(FileGalleryAdapter.ViewHolder viewHolder, int position) {
if (maxCount > 0) {
setTitle(getResources().getString(R.string.selection_count, fileGalleryAdapter.getSelectedItemCount(), maxCount));
setTitle(getResources().getString(title_res, fileGalleryAdapter.getSelectedItemCount(), maxCount, title));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

public class DirListAdapter extends RecyclerView.Adapter<DirListAdapter.ViewHolder> implements ListUpdateCallback {
public static final int CAPTURE_IMAGE_VIDEO = 1;
// private ArrayList<Dir> mediaDirs;
private Activity activity;
private RequestManager glideRequest;
private OnClickListener onClickListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public Configurations[] newArray(int size) {
private Matcher[] ignorePathMatchers;
private final boolean ignoreNoMedia;
private final boolean ignoreHiddenFile;
private final String title;

private Configurations(Builder builder) {
this.imageCaptureEnabled = builder.imageCapture;
Expand All @@ -79,6 +80,7 @@ private Configurations(Builder builder) {
setIgnorePathMatchers(builder.ignorePaths);
this.ignoreNoMedia = builder.ignoreNoMedia;
this.ignoreHiddenFile = builder.ignoreHiddenFile;
this.title = builder.title;
}

protected Configurations(Parcel in) {
Expand All @@ -102,6 +104,7 @@ protected Configurations(Parcel in) {
setIgnorePathMatchers(in.createStringArray());
ignoreNoMedia = in.readByte() != 0;
ignoreHiddenFile = in.readByte() != 0;
title = in.readString();
}

public boolean isShowVideos() {
Expand Down Expand Up @@ -150,6 +153,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeStringArray(getIgnorePaths());
dest.writeByte((byte) (ignoreNoMedia ? 1 : 0));
dest.writeByte((byte) (ignoreHiddenFile ? 1 : 0));
dest.writeString(title);
}

@Override
Expand Down Expand Up @@ -234,6 +238,10 @@ private String[] getIgnorePaths() {
return null;
}

public String getTitle() {
return title;
}

public static class Builder {
private boolean imageCapture = false, videoCapture = false,
checkPermission = false, showImages = true, showVideos = true,
Expand All @@ -253,6 +261,7 @@ public static class Builder {
private String[] ignorePaths = null;
private boolean ignoreNoMedia = true;
private boolean ignoreHiddenFile = true;
private String title = null;

public Builder setSingleClickSelection(boolean singleClickSelection) {
this.singleClickSelection = singleClickSelection;
Expand Down Expand Up @@ -366,6 +375,11 @@ public Builder setIgnoreHiddenFile(boolean ignoreHiddenFile) {
return this;
}

public Builder setTitle(String title) {
this.title = title;
return this;
}

public Configurations build() {
return new Configurations(this);
}
Expand Down
1 change: 1 addition & 0 deletions filepicker/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<string name="file_thumbnail">File Thumbnail</string>
<string name="open_camera">Open Camera</string>
<string name="done">Done</string>
<string name="selection_count_title">%3$s (%1$d/%2$d)</string>
<string name="selection_count">%1$d/%2$d</string>
<string name="permission_not_given">Permission not given</string>
</resources>

0 comments on commit 9f50a90

Please sign in to comment.