Skip to content

Commit 98b4afc

Browse files
Merge pull request #4 from smartdevelopers-ir/changes_for_android_11
Changes for android 11
2 parents ddc85d3 + 9e9f634 commit 98b4afc

File tree

9 files changed

+238
-21
lines changed

9 files changed

+238
-21
lines changed

.idea/misc.xml

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SmartFileBrowser/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ android {
3131
}
3232
}
3333
group = 'ir.smartdevelopers'
34-
version = '1.4.0'
34+
version = '1.4.1'
3535
task sourcesJar(type: Jar) {
3636
archiveClassifier.set("sources")
3737
from android.sourceSets.main.java.srcDirs
@@ -42,9 +42,9 @@ task javadocJar2(type: Jar) {
4242
}
4343
dependencies {
4444

45-
implementation 'androidx.appcompat:appcompat:1.4.0'
46-
implementation 'com.google.android.material:material:1.4.0'
47-
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
45+
implementation 'androidx.appcompat:appcompat:1.4.1'
46+
implementation 'com.google.android.material:material:1.5.0'
47+
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
4848
implementation 'com.github.bumptech.glide:glide:4.12.0'
4949

5050
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

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

Lines changed: 124 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import androidx.annotation.NonNull;
44
import androidx.annotation.Nullable;
55
import androidx.appcompat.app.AppCompatActivity;
6-
import androidx.appcompat.widget.AppCompatImageButton;
76
import androidx.appcompat.widget.AppCompatTextView;
87
import androidx.constraintlayout.widget.Group;
9-
import androidx.coordinatorlayout.widget.CoordinatorLayout;
108
import androidx.core.app.ActivityCompat;
119
import androidx.core.app.ActivityOptionsCompat;
1210
import androidx.core.app.SharedElementCallback;
@@ -25,6 +23,7 @@
2523
import android.animation.ValueAnimator;
2624
import android.annotation.SuppressLint;
2725
import android.app.Activity;
26+
import android.content.ClipData;
2827
import android.content.Intent;
2928
import android.content.pm.PackageManager;
3029
import android.content.pm.ResolveInfo;
@@ -44,9 +43,11 @@
4443
import android.view.View;
4544
import android.view.ViewGroup;
4645
import android.view.ViewPropertyAnimator;
46+
import android.view.ViewStub;
4747
import android.view.ViewTreeObserver;
4848
import android.view.Window;
4949
import android.view.animation.OvershootInterpolator;
50+
import android.widget.Button;
5051
import android.widget.FrameLayout;
5152
import android.widget.ImageButton;
5253
import android.widget.ImageView;
@@ -63,6 +64,7 @@
6364
import java.io.File;
6465
import java.io.FileFilter;
6566
import java.io.IOException;
67+
import java.util.ArrayList;
6668
import java.util.Collections;
6769
import java.util.List;
6870
import java.util.Map;
@@ -76,7 +78,7 @@
7678
import ir.smartdevelopers.smartfilebrowser.customClasses.OnItemLongClickListener;
7779
import ir.smartdevelopers.smartfilebrowser.customClasses.OnSearchListener;
7880
import ir.smartdevelopers.smartfilebrowser.customClasses.ResultListener;
79-
import ir.smartdevelopers.smartfilebrowser.customClasses.SmartFileBrowser;
81+
import ir.smartdevelopers.smartfilebrowser.customClasses.Utils;
8082
import ir.smartdevelopers.smartfilebrowser.models.FileModel;
8183
import ir.smartdevelopers.smartfilebrowser.customClasses.FileUtil;
8284
import ir.smartdevelopers.smartfilebrowser.customClasses.OnItemChooseListener;
@@ -99,6 +101,7 @@ public class FileBrowserMainActivity extends AppCompatActivity {
99101
private static final int REQ_CODE_EDIT_IMAGE = 258;
100102
public static final int REQ_CODE_TACK_PICTURE = 303;
101103
public static final int REQ_CODE_PICK_BY_GALLEY = 305;
104+
private static final int REQ_CODE_SYSTEM_FILE_BROWSER = 6354;
102105
private AppBarLayout mAppBarLayout;
103106
private RoundViewGroup mBottomSheetRoot;
104107
private MyBehavior<View> mBottomSheetBehavior;
@@ -168,17 +171,22 @@ public class FileBrowserMainActivity extends AppCompatActivity {
168171
private OnItemLongClickListener<GalleryModel> mOnGalleryItemLongClickListener;
169172
private OnItemClickListener<GalleryModel> mOnZoomOutClickListener;
170173
private String tackingPictureFilePath;
174+
private View mSystemBrowserButtonView;
171175
//</editor-fold>
172176

173177
private void getDataFromIntent() {
174178
mShowVideosInGallery = getIntent().getBooleanExtra("mShowVideosInGallery", true);
175179
mShowCamera = getIntent().getBooleanExtra("mShowCamera", true);
176180
mCanSelectMultipleInGallery = getIntent().getBooleanExtra("mCanSelectMultipleInGallery", true);
177181
mCanSelectMultipleInFiles = getIntent().getBooleanExtra("mCanSelectMultipleInFiles", true);
178-
mShowPDFTab = getIntent().getBooleanExtra("mShowPDFTab", true);
182+
179183
mShowFilesTab = getIntent().getBooleanExtra("mShowFilesTab", true);
180-
mShowAudioTab = getIntent().getBooleanExtra("mShowAudioTab", true);
181184
mShowGalleryTab = getIntent().getBooleanExtra("mShowGalleryTab", true);
185+
186+
mShowPDFTab = getIntent().getBooleanExtra("mShowPDFTab", true);
187+
mShowAudioTab = getIntent().getBooleanExtra("mShowAudioTab", true);
188+
189+
182190
mShowPickFromSystemGalleryMenuButton = getIntent().getBooleanExtra("mShowPickFromSystemGalleryMenuButton", true);
183191
SFBFileFilter sfbFileFilter = (SFBFileFilter) getIntent().getSerializableExtra("mFileTabFileFilter");
184192
if (sfbFileFilter != null) {
@@ -789,9 +797,9 @@ private void sendBackResult(FileModel model) {
789797
Bundle bundle = new Bundle();
790798
bundle.putStringArray(EXTRA_RESULT, filesPath);
791799
bundle.putParcelableArray(EXTRA_RESULT_URIS, filesUri);
792-
Bundle sfbExtra=getIntent().getBundleExtra("sfb_extra");
793-
if (sfbExtra!=null){
794-
bundle.putBundle("sfb_extra",sfbExtra);
800+
Bundle sfbExtra = getIntent().getBundleExtra("sfb_extra");
801+
if (sfbExtra != null) {
802+
bundle.putBundle("sfb_extra", sfbExtra);
795803
}
796804
result.putExtras(bundle);
797805

@@ -835,6 +843,13 @@ private void showSuitableToolbar(PageType type) {
835843
}
836844
}
837845

846+
private boolean shouldShowSystemFileBrowser() {
847+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
848+
return mPageType == PageType.TYPE_PDF || mPageType == PageType.TYPE_FILE_BROWSER;
849+
}
850+
return false;
851+
}
852+
838853
private boolean isShowingFileBrowser() {
839854
return mFileBrowserContainer.getVisibility() == View.VISIBLE;
840855
}
@@ -906,18 +921,25 @@ private void showFileBrowserToolbar(String toolbarTitle) {
906921
if (txtToolbarTitle != null) {
907922
txtToolbarTitle.setText(toolbarTitle);
908923
}
924+
ImageView btnSearch = findViewById(R.id.fileBrowser_activity_main_btnSearch);
925+
if (!shouldShowSystemFileBrowser()) {
926+
btnSearch.setVisibility(View.VISIBLE);
927+
} else {
928+
btnSearch.setVisibility(View.GONE);
929+
}
909930
}
910931

911932
private void initFileBrowserToolbar() {
912933
ImageView btnSearch = findViewById(R.id.fileBrowser_activity_main_btnSearch);
913934
SearchView searchView = findViewById(R.id.fileBrowser_activity_main_searchView);
935+
914936
btnSearch.setOnClickListener(v -> {
915937
searchView.show();
916938
});
917939
searchView.setOnQueryChangeListener(new SearchView.OnQueryChangeListener() {
918940
@Override
919941
public void onQueryChanged(String query) {
920-
if (isShowingFileBrowser()) {
942+
if (isShowingFileBrowser() && !shouldShowSystemFileBrowser()) {
921943
searchFile(query);
922944
}
923945
}
@@ -928,6 +950,7 @@ public void onQueryChanged(String query) {
928950
}
929951
searchView.setOnVisibilityChangeListener(mOnVisibilityChangeListener);
930952

953+
931954
}
932955

933956
private void showGalleryToolbar() {
@@ -944,7 +967,7 @@ private void showGalleryToolbar() {
944967
private void initGalleryToolbarViews() {
945968
AppCompatTextView spnSelectAlbum = findViewById(R.id.fileBrowser_activity_main_spnSelectAlbum);
946969
ImageButton btnVerticalDotsMore = findViewById(R.id.fileBrowser_activity_main_btnGalleryMenu);
947-
if (!mShowPickFromSystemGalleryMenuButton){
970+
if (!mShowPickFromSystemGalleryMenuButton) {
948971
btnVerticalDotsMore.setVisibility(View.GONE);
949972
}
950973
spnSelectAlbum.setOnClickListener(v -> {
@@ -1221,6 +1244,9 @@ private void showGallery(boolean animate) {
12211244
mGalleryViewModel
12221245
.getAllGalleryModels(mShowCamera, mShowVideosInGallery);
12231246
}
1247+
// if (mSystemBrowserButtonView != null) {
1248+
// mSystemBrowserButtonView.setVisibility(View.GONE);
1249+
// }
12241250
}
12251251

12261252

@@ -1247,7 +1273,7 @@ public void scrollFileBrowserToFirstPos() {
12471273

12481274
//<editor-fold desc="FileBrowser codes">
12491275
public boolean isFileBrowserInSubDirectory() {
1250-
return mFileBrowserAdapter.isInSubDirectory();
1276+
return mFileBrowserAdapter != null && mFileBrowserAdapter.isInSubDirectory();
12511277
}
12521278

12531279
public void goBackToFileBrowserParentDirectory() {
@@ -1273,24 +1299,75 @@ public void changePages(FileBrowserMainActivity.PageType pageType) {
12731299
}
12741300

12751301
private void getFirstPageList() {
1276-
1302+
String[] mimeTypes;
12771303
switch (mPageType) {
12781304
case TYPE_FILE_BROWSER:
1279-
mFilesViewModel.getFirstPageFilesLiveData(mFileFilter);
1305+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1306+
mimeTypes = new String[]{"*/*"};
1307+
showSystemFileBrowserPage(mimeTypes, R.string.sfb_files, R.string.openSystemFileBrowser_file);
1308+
} else {
1309+
mFilesViewModel.getFirstPageFilesLiveData(mFileFilter);
1310+
}
12801311
break;
12811312
case TYPE_VIDEO:
12821313
mFilesViewModel.getFirstPageVideosLiveData(mFileFilter);
12831314
break;
12841315
case TYPE_PDF:
1285-
mFilesViewModel.getFirstPagePdfLiveData(mFileFilter);
1316+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1317+
mimeTypes = new String[]{"application/pdf"};
1318+
showSystemFileBrowserPage(mimeTypes, R.string.sfb_pdfs, R.string.openSystemFileBrowser_pdfs);
1319+
} else {
1320+
mFilesViewModel.getFirstPagePdfLiveData(mFileFilter);
1321+
}
12861322
break;
12871323
case TYPE_AUDIO:
1324+
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1325+
// mimeTypes = new String[]{"application/pdf"};
1326+
// showSystemFileBrowserPage(mimeTypes, R.string.sfb_audios, R.string.openSystemFileBrowser_audios);
1327+
// } else {
12881328
mFilesViewModel.getFirstPageAudiosLiveData(mFileFilter);
1329+
hideSystemFileBrowserPage();
1330+
// }
12891331
break;
12901332
}
12911333

12921334
}
12931335

1336+
private void hideSystemFileBrowserPage() {
1337+
if (mSystemBrowserButtonView != null) {
1338+
1339+
mSystemBrowserButtonView.setVisibility(View.GONE);
1340+
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
1341+
}
1342+
1343+
}
1344+
1345+
private void showSystemFileBrowserPage(String[] mimeTypes, int typeTextRes, int buttonTextRes) {
1346+
if (mSystemBrowserButtonView == null) {
1347+
ViewStub viewStub = findViewById(R.id.fileBrowser_activity_main_openSystemFileBrowserViewStub);
1348+
mSystemBrowserButtonView = viewStub.inflate();
1349+
}
1350+
mSystemBrowserButtonView.setVisibility(View.VISIBLE);
1351+
mFileBrowserRecyclerView.setVisibility(View.GONE);
1352+
mBottomSheetBehavior.setState(MyBehavior.STATE_EXPANDED);
1353+
TextView txtMessage = mSystemBrowserButtonView.findViewById(R.id.sfb_system_file_browser_txtMessage);
1354+
Button btnShowSystemFileBrowser = mSystemBrowserButtonView.findViewById(R.id.sfb_system_file_browser_btnOpenSystemFileBrowser);
1355+
btnShowSystemFileBrowser.setOnClickListener(v -> {
1356+
openSystemFileBrowser(mimeTypes);
1357+
});
1358+
btnShowSystemFileBrowser.setText(buttonTextRes);
1359+
txtMessage.setText(getString(R.string.sfb_android11_storage_restrict_message, getString(typeTextRes)));
1360+
}
1361+
1362+
private void openSystemFileBrowser(String[] mimeTypes) {
1363+
Intent systemFileBrowserIntent = new Intent(Intent.ACTION_GET_CONTENT);
1364+
systemFileBrowserIntent.setType("*/*");
1365+
systemFileBrowserIntent.addCategory(Intent.CATEGORY_OPENABLE);
1366+
systemFileBrowserIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
1367+
systemFileBrowserIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
1368+
startActivityForResult(systemFileBrowserIntent, REQ_CODE_SYSTEM_FILE_BROWSER);
1369+
}
1370+
12941371
public void removeAllFileBrowserSelection() {
12951372
mFileBrowserAdapter.removeAllSelection();
12961373
}
@@ -1370,7 +1447,7 @@ public int getGalleryItemSelectionCount() {
13701447
public void imageUpdated(String newFilePath, int editedImagePosition) {
13711448
if (mGalleryAdapter != null) {
13721449
mGalleryAdapter.getItem(editedImagePosition).setPath(newFilePath);
1373-
if (Build.VERSION.SDK_INT <21){
1450+
if (Build.VERSION.SDK_INT < 21) {
13741451
mGalleryAdapter.notifyItemChanged(editedImagePosition);
13751452
}
13761453
}
@@ -1398,7 +1475,7 @@ public void onBackPressed() {
13981475
searchView.close(true);
13991476
return;
14001477
}
1401-
if (isShowingFileBrowser()) {
1478+
if (isShowingFileBrowser() && !shouldShowSystemFileBrowser()) {
14021479
if (isFileBrowserInSubDirectory()) {
14031480
goBackToFileBrowserParentDirectory();
14041481
return;
@@ -1460,6 +1537,7 @@ public PageType getPageType() {
14601537
public OnItemSelectListener<FileModel> getOnFileItemSelectListener() {
14611538
return mOnFileItemSelectListener;
14621539
}
1540+
14631541
public OnItemClickListener<GalleryModel> getOnGalleryItemClickListener() {
14641542
return mOnGalleryItemClickListener;
14651543
}
@@ -1508,6 +1586,36 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
15081586
setResult(RESULT_OK, resultIntent);
15091587
finish();
15101588
}
1589+
}else if (requestCode == REQ_CODE_SYSTEM_FILE_BROWSER){
1590+
if (resultCode == RESULT_OK && data !=null){
1591+
ClipData clipData= data.getClipData();
1592+
List<Uri> uris=new ArrayList<>();
1593+
List<File> selectedFiles= mSelectionFileViewModel.getSelectedFiles();
1594+
if (selectedFiles!=null){
1595+
for (File file:selectedFiles){
1596+
uris.add(FileProvider.getUriForFile(getApplicationContext(),
1597+
getPackageName()+".sfb_provider",file));
1598+
}
1599+
}
1600+
if (clipData!=null){
1601+
int count=clipData.getItemCount();
1602+
for (int i=0;i<count;i++){
1603+
uris.add(clipData.getItemAt(i).getUri());
1604+
}
1605+
}else {
1606+
Uri uri=data.getData();
1607+
if (uri!=null){
1608+
uris.add(uri);
1609+
}
1610+
}
1611+
Bundle bundle = new Bundle();
1612+
bundle.putParcelableArray(EXTRA_RESULT_URIS, uris.toArray(new Uri[]{}));
1613+
Intent resultIntent = new Intent();
1614+
resultIntent.putExtras(bundle);
1615+
setResult(RESULT_OK, resultIntent);
1616+
finish();
1617+
1618+
}
15111619
}
15121620
}
15131621
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:color="?attr/colorControlHighlight"
5+
tools:ignore="NewApi">
6+
<item>
7+
<shape>
8+
<solid android:color="@color/sfb_colorBlue"/>
9+
<corners android:radius="50dp"/>
10+
</shape>
11+
</item>
12+
</ripple>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M18,2h-8L4.02,8 4,20c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,4c0,-1.1 -0.9,-2 -2,-2zM12,8h-2L10,4h2v4zM15,8h-2L13,4h2v4zM18,8h-2L16,4h2v4z"/>
10+
</vector>

SmartFileBrowser/src/main/res/layout/activity_file_browser_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
/>
6161

62+
6263
</FrameLayout>
6364

6465
</ir.smartdevelopers.smartfilebrowser.customClasses.RoundViewGroup>

0 commit comments

Comments
 (0)