Skip to content

Commit b7482ba

Browse files
committed
completed
1 parent 56eda94 commit b7482ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+702
-457
lines changed

SmartFileBrowser/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ android {
3131
}
3232
}
3333
group = 'ir.smartdevelopers'
34-
version = '1.0.0'
34+
version = '1.1.8'
3535
task sourcesJar(type: Jar) {
3636
archiveClassifier.set("sources")
3737
from android.sourceSets.main.java.srcDirs
@@ -57,6 +57,7 @@ dependencies {
5757
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
5858
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
5959
implementation "androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_version"
60+
implementation 'com.github.iamutkarshtiwari:Ananas:1.2.4'
6061
}
6162
afterEvaluate{
6263
publishing {

SmartFileBrowser/src/main/java/ir/smartdevelopers/smartfilebrowser/acitivties/FileBrowserMainActivity.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import android.content.Intent;
1515
import android.content.res.TypedArray;
1616
import android.os.Bundle;
17+
import android.text.TextUtils;
18+
import android.util.Log;
1719
import android.util.TypedValue;
1820
import android.view.LayoutInflater;
1921
import android.view.MotionEvent;
@@ -37,6 +39,8 @@
3739
import java.io.FileFilter;
3840
import java.util.List;
3941

42+
import iamutkarshtiwari.github.io.ananas.editimage.EditImageActivity;
43+
import iamutkarshtiwari.github.io.ananas.editimage.ImageEditorIntentBuilder;
4044
import ir.smartdevelopers.smartfilebrowser.R;
4145
import ir.smartdevelopers.smartfilebrowser.adapters.AlbumAdapter;
4246
import ir.smartdevelopers.smartfilebrowser.models.FileModel;
@@ -58,6 +62,7 @@
5862
public class FileBrowserMainActivity extends AppCompatActivity {
5963

6064
public static final String EXTRA_RESULT = "file_browser_result";
65+
private static final int REQ_CODE_EDIT_IMAGE = 258;
6166
private GalleryFragment mGalleryFragment;
6267
private FileBrowserFragment mFileBrowserFragment;
6368
private AppBarLayout mAppBarLayout;
@@ -107,7 +112,8 @@ public class FileBrowserMainActivity extends AppCompatActivity {
107112
private boolean mShowFilesTab = true;
108113
private boolean mShowAudioTab = true;
109114
private boolean mShowGalleryTab = true;
110-
115+
private String mEditedImagePath;
116+
private int mEditedImagePosition;
111117

112118
private void getDataFromIntent() {
113119
mShowVideosInGallery = getIntent().getBooleanExtra("mShowVideosInGallery", true);
@@ -337,6 +343,9 @@ public void onItemClicked(GalleryModel model, int position) {
337343
sendBackResult(model);
338344
} else {
339345
//Todo manage on item click for user
346+
if (model.getType()==FileUtil.TYPE_IMAGE){
347+
openImageEditor(model,position);
348+
}
340349
}
341350
}
342351
};
@@ -356,6 +365,32 @@ public void onVisibilityChanged(boolean isShowing) {
356365

357366
}
358367

368+
private void openImageEditor(GalleryModel model, int position) {
369+
try {
370+
mEditedImagePath=FileUtil.getImageTempFile(getApplicationContext()).getPath();
371+
mEditedImagePosition=position;
372+
Intent intent = new ImageEditorIntentBuilder(this,
373+
model.getPath()
374+
,mEditedImagePath)
375+
.withAddText() // Add the features you need
376+
.withPaintFeature()
377+
378+
// .withFilterFeature()
379+
.withRotateFeature()
380+
.withCropFeature()
381+
// .withBrightnessFeature()
382+
// .withSaturationFeature()
383+
// .withBeautyFeature()
384+
.withStickerFeature()
385+
// Add this to force portrait mode (It's set to false by default)
386+
.build();
387+
388+
EditImageActivity.start(this, intent, REQ_CODE_EDIT_IMAGE);
389+
} catch (Exception e) {
390+
Log.e("ttt", e.getMessage()); // This could throw if either `sourcePath` or `outputPath` is blank or Null
391+
}
392+
}
393+
359394
private boolean mFileBrowserEnabled = true;
360395

361396
private void setFileBrowserEnabled(boolean enabled) {
@@ -521,7 +556,13 @@ private void sendBackResult(FileModel model) {
521556
resultFiles = new File[]{model.getCurrentFile()};
522557
}
523558
}
524-
result.putExtra(EXTRA_RESULT, resultFiles);
559+
String[] filesPath=new String[resultFiles.length];
560+
for (int i=0;i<resultFiles.length;i++){
561+
filesPath[i]=resultFiles[i].getPath();
562+
}
563+
Bundle bundle=new Bundle();
564+
bundle.putStringArray(EXTRA_RESULT,filesPath);
565+
result.putExtras(bundle);
525566

526567
setResult(RESULT_OK, result);
527568
finish();
@@ -993,6 +1034,12 @@ public void onBackPressed() {
9931034
return;
9941035
}
9951036
}
1037+
if (!TextUtils.isEmpty(mEditedImagePath)){
1038+
File editedImageTempFile=new File(mEditedImagePath);
1039+
if (editedImageTempFile.exists()){
1040+
editedImageTempFile.delete();
1041+
}
1042+
}
9961043
setResult(RESULT_CANCELED);
9971044
super.onBackPressed();
9981045
}
@@ -1038,5 +1085,17 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
10381085
mGalleryFragment.onActivityResult(requestCode, resultCode, data);
10391086
}
10401087
}
1088+
if (requestCode==REQ_CODE_EDIT_IMAGE){
1089+
if (mGalleryFragment!=null){
1090+
if (data != null) {
1091+
boolean isImageEdit = data.getBooleanExtra("is_image_edited", false);
1092+
String sourcePath = data.getStringExtra("source_path");
1093+
String newFilePath = data.getStringExtra("output_path");
1094+
if (isImageEdit){
1095+
mGalleryFragment.imageUpdated(sourcePath,newFilePath,mEditedImagePosition);
1096+
}
1097+
}
1098+
}
1099+
}
10411100
}
10421101
}

SmartFileBrowser/src/main/java/ir/smartdevelopers/smartfilebrowser/adapters/GalleryAdapter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ public GalleryAdapter setOnItemChooseListener(OnItemChooseListener onItemChooseL
160160
return this;
161161
}
162162

163+
public GalleryModel getItem(int editedImagePosition) {
164+
return mGalleryModels.get(editedImagePosition);
165+
}
166+
163167
class CameraViewHolder extends RecyclerView.ViewHolder {
164168
AppCompatImageView mImageView;
165169
public CameraViewHolder(@NonNull View itemView) {

SmartFileBrowser/src/main/java/ir/smartdevelopers/smartfilebrowser/customClasses/FileUtil.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.os.Environment;
99
import android.os.storage.StorageManager;
1010
import android.provider.MediaStore;
11+
import android.text.TextUtils;
1112
import android.util.Log;
1213
import android.webkit.MimeTypeMap;
1314

@@ -92,7 +93,17 @@ public static String getMimeTypeFromPath(String path){
9293
}
9394
public static String getFileExtensionFromPath(String path){
9495
String uri=Uri.encode(path);
95-
return MimeTypeMap.getFileExtensionFromUrl(uri);
96+
String extension= MimeTypeMap.getFileExtensionFromUrl(uri);
97+
if (TextUtils.isEmpty(extension)){
98+
int index = uri.lastIndexOf(".");
99+
if (index!=-1) {
100+
extension = uri.substring(index + 1);
101+
}
102+
if (TextUtils.isEmpty(extension)){
103+
extension="";
104+
}
105+
}
106+
return extension;
96107
}
97108
public static boolean isDirectory(File file){
98109
if (file==null){
@@ -104,6 +115,13 @@ public static File getImageFile(Context context) throws IOException {
104115
File folder= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
105116
DateFormat dateFormat=new SimpleDateFormat("yyyyMMdd-HHmmss",new Locale("en"));
106117
String name="JPEG_"+dateFormat.format(new Date());
118+
// return File.createTempFile(name,".jpg",folder);
119+
return new File(folder,name+".jpg");
120+
}
121+
public static File getImageTempFile(Context context) {
122+
File folder= context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
123+
DateFormat dateFormat=new SimpleDateFormat("yyyyMMdd-HHmmss",new Locale("en"));
124+
String name="JPEG_"+dateFormat.format(new Date());
107125
// return File.createTempFile(name,".jpg",folder);
108126
return new File(folder,name+".jpg");
109127
}

SmartFileBrowser/src/main/java/ir/smartdevelopers/smartfilebrowser/customClasses/SFBCheckBox.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import androidx.annotation.NonNull;
99
import androidx.annotation.Nullable;
10+
import androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat;
1011
import androidx.appcompat.widget.AppCompatCheckBox;
1112
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
1213

@@ -29,17 +30,17 @@ public SFBCheckBox(@NonNull Context context, @Nullable AttributeSet attrs, int d
2930
}
3031
void init(@NonNull Context context, @Nullable AttributeSet attrs){
3132
// if (Build.VERSION.SDK_INT>=21){
32-
// AnimatedStateListDrawableCompat animatedStateListDrawableCompat=
33-
// AnimatedStateListDrawableCompat.create(context,R.drawable.check_box_drawable_without_tick,context.getTheme());
34-
// setButtonDrawable(animatedStateListDrawableCompat);
33+
AnimatedStateListDrawableCompat animatedStateListDrawableCompat=
34+
AnimatedStateListDrawableCompat.create(context,R.drawable.sfb_check_box_drawable_without_tick,context.getTheme());
35+
setButtonDrawable(animatedStateListDrawableCompat);
3536
// }else {
36-
StateListDrawable stateListDrawable=new StateListDrawable();
37-
Drawable checkedDrawable= VectorDrawableCompat.create(getResources(),R.drawable.sfb_check_box_checked_without_tick,context.getTheme());
38-
Drawable uncheckedDrawable= VectorDrawableCompat.create(getResources(),R.drawable.sfb_chech_box_unchecked_without_tick,context.getTheme());
39-
stateListDrawable.addState(new int[]{android.R.attr.state_checked},checkedDrawable);
40-
stateListDrawable.addState(new int[]{},uncheckedDrawable);
41-
42-
setButtonDrawable(stateListDrawable);
37+
// StateListDrawable stateListDrawable=new StateListDrawable();
38+
// Drawable checkedDrawable= VectorDrawableCompat.create(getResources(),R.drawable.sfb_check_box_checked_without_tick,context.getTheme());
39+
// Drawable uncheckedDrawable= VectorDrawableCompat.create(getResources(),R.drawable.sfb_chech_box_unchecked_without_tick,context.getTheme());
40+
// stateListDrawable.addState(new int[]{android.R.attr.state_checked},checkedDrawable);
41+
// stateListDrawable.addState(new int[]{},uncheckedDrawable);
42+
//
43+
// setButtonDrawable(stateListDrawable);
4344
// }
4445

4546
}

SmartFileBrowser/src/main/java/ir/smartdevelopers/smartfilebrowser/customClasses/SFBCheckBoxWithTick.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import androidx.annotation.NonNull;
99
import androidx.annotation.Nullable;
10+
import androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat;
1011
import androidx.appcompat.widget.AppCompatCheckBox;
1112
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
1213

@@ -29,17 +30,17 @@ public SFBCheckBoxWithTick(@NonNull Context context, @Nullable AttributeSet attr
2930
}
3031
void init(@NonNull Context context, @Nullable AttributeSet attrs){
3132
// if (Build.VERSION.SDK_INT>=21){
32-
//// AnimatedStateListDrawableCompat animatedStateListDrawableCompat=
33-
//// AnimatedStateListDrawableCompat.create(context,R.drawable.check_box_drawable_with_tick,context.getTheme());
34-
// setButtonDrawable(R.drawable.check_box_drawable_with_tick);
33+
AnimatedStateListDrawableCompat animatedStateListDrawableCompat=
34+
AnimatedStateListDrawableCompat.create(context,R.drawable.sfb_check_box_drawable_with_tick,context.getTheme());
35+
setButtonDrawable(animatedStateListDrawableCompat);
3536
// }else {
36-
StateListDrawable stateListDrawable=new StateListDrawable();
37-
Drawable checkedDrawable= VectorDrawableCompat.create(getResources(),R.drawable.sfb_check_box_checked,context.getTheme());
38-
Drawable uncheckedDrawable= VectorDrawableCompat.create(getResources(),R.drawable.sfb_chech_box_unchecked,context.getTheme());
39-
stateListDrawable.addState(new int[]{android.R.attr.state_checked},checkedDrawable);
40-
stateListDrawable.addState(new int[]{},uncheckedDrawable);
41-
42-
setButtonDrawable(stateListDrawable);
37+
// StateListDrawable stateListDrawable=new StateListDrawable();
38+
// Drawable checkedDrawable= VectorDrawableCompat.create(getResources(),R.drawable.sfb_check_box_checked,context.getTheme());
39+
// Drawable uncheckedDrawable= VectorDrawableCompat.create(getResources(),R.drawable.sfb_chech_box_unchecked,context.getTheme());
40+
// stateListDrawable.addState(new int[]{android.R.attr.state_checked},checkedDrawable);
41+
// stateListDrawable.addState(new int[]{},uncheckedDrawable);
42+
//
43+
// setButtonDrawable(stateListDrawable);
4344
// }
4445

4546
}

SmartFileBrowser/src/main/java/ir/smartdevelopers/smartfilebrowser/customClasses/SmartFileBrowser.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.graphics.drawable.StateListDrawable;
6+
import android.os.Bundle;
57

68
import androidx.annotation.Nullable;
79

@@ -10,8 +12,10 @@
1012
import java.util.List;
1113

1214
import ir.smartdevelopers.smartfilebrowser.acitivties.FileBrowserMainActivity;
15+
import ir.smartdevelopers.smartfilebrowser.models.GalleryModel;
1316

1417
public class SmartFileBrowser {
18+
public static OnItemClickListener<GalleryModel> sOnGalleryModelClickListener;
1519
public static class IntentBuilder{
1620
private SFBFileFilter mFileFilter;
1721
private boolean showVideosInGallery=true;
@@ -62,6 +66,10 @@ public IntentBuilder setShowGalleryTab(boolean showGalleryTab) {
6266
this.showGalleryTab = showGalleryTab;
6367
return this;
6468
}
69+
public IntentBuilder setOnGalleryItemClickListener(OnItemClickListener<GalleryModel> onGalleryModelClickListener){
70+
sOnGalleryModelClickListener=onGalleryModelClickListener;
71+
return this;
72+
}
6573
public Intent build(Context context){
6674
Intent filePickerIntent=new Intent(context, FileBrowserMainActivity.class);
6775
filePickerIntent.putExtra("mShowVideosInGallery",showVideosInGallery);
@@ -87,6 +95,19 @@ public static File[] getResult(Intent data){
8795
if (data==null){
8896
return null;
8997
}
90-
return (File[]) data.getSerializableExtra(FileBrowserMainActivity.EXTRA_RESULT);
98+
Bundle bundle=data.getExtras();
99+
if (bundle==null){
100+
return null;
101+
}
102+
String[] filesPath=bundle.getStringArray(FileBrowserMainActivity.EXTRA_RESULT);
103+
if (filesPath != null) {
104+
File[] files=new File[filesPath.length];
105+
for (int i=0;i<filesPath.length;i++){
106+
files[i]=new File(filesPath[i]);
107+
}
108+
return files;
109+
}
110+
return null;
111+
91112
}
92113
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package ir.smartdevelopers.smartfilebrowser.customClasses;
2+
3+
import androidx.core.content.FileProvider;
4+
5+
public class SmartFileProvider extends FileProvider {
6+
}

0 commit comments

Comments
 (0)