Skip to content

Commit 44fad36

Browse files
Merge pull request #22 from smartdevelopers-ir/v2.0.8
bug fixed
2 parents f84e316 + 3dd4bd8 commit 44fad36

File tree

5 files changed

+161
-109
lines changed

5 files changed

+161
-109
lines changed

SmartFileBrowser/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ android {
3434
}
3535
}
3636
group = 'ir.smartdevelopers'
37-
version = '2.0.7'
37+
version = '2.0.9'
3838

3939
dependencies {
4040

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

Lines changed: 101 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
import android.content.Intent;
1212
import android.content.pm.PackageManager;
1313
import android.content.pm.ResolveInfo;
14-
import android.content.res.Resources;
1514
import android.content.res.TypedArray;
1615
import android.graphics.Bitmap;
1716
import android.graphics.Color;
1817
import android.graphics.Rect;
1918
import android.graphics.drawable.ColorDrawable;
2019
import android.graphics.drawable.Drawable;
21-
import android.graphics.drawable.VectorDrawable;
2220
import android.net.Uri;
2321
import android.os.Build;
2422
import android.os.Bundle;
@@ -48,35 +46,30 @@
4846
import android.widget.Toast;
4947

5048
import androidx.activity.OnBackPressedCallback;
49+
import androidx.annotation.DrawableRes;
5150
import androidx.annotation.NonNull;
5251
import androidx.annotation.Nullable;
5352
import androidx.appcompat.app.AppCompatActivity;
54-
import androidx.appcompat.app.AppCompatDelegate;
5553
import androidx.appcompat.content.res.AppCompatResources;
56-
import androidx.appcompat.view.ContextThemeWrapper;
5754
import androidx.appcompat.widget.AppCompatTextView;
58-
import androidx.constraintlayout.widget.Group;
5955
import androidx.core.app.ActivityCompat;
6056
import androidx.core.app.ActivityOptionsCompat;
6157
import androidx.core.app.SharedElementCallback;
6258
import androidx.core.content.ContextCompat;
6359
import androidx.core.content.FileProvider;
64-
import androidx.core.content.res.ResourcesCompat;
6560
import androidx.core.graphics.ColorUtils;
6661
import androidx.core.graphics.Insets;
6762
import androidx.core.graphics.drawable.DrawableKt;
6863
import androidx.core.view.ViewCompat;
6964
import androidx.core.view.WindowCompat;
7065
import androidx.core.view.WindowInsetsCompat;
71-
import androidx.core.view.WindowInsetsControllerCompat;
7266
import androidx.exifinterface.media.ExifInterface;
7367
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
7468
import androidx.lifecycle.LiveData;
7569
import androidx.lifecycle.Observer;
7670
import androidx.lifecycle.ViewModelProvider;
7771
import androidx.recyclerview.widget.LinearLayoutManager;
7872
import androidx.recyclerview.widget.RecyclerView;
79-
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
8073

8174
import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
8275
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
@@ -87,6 +80,7 @@
8780
import java.io.FileFilter;
8881
import java.io.IOException;
8982
import java.util.ArrayList;
83+
import java.util.Arrays;
9084
import java.util.Collections;
9185
import java.util.List;
9286
import java.util.Map;
@@ -174,14 +168,13 @@ public class FileBrowserMainActivity extends AppCompatActivity {
174168
private ResultListener mResultListener;
175169
private OnItemSelectListener<FileModel> mOnFileItemSelectListener;
176170
//<editor-fold desc="FileBrowser parameters">
177-
private View mFileBrowserContainer;
178171
private RecyclerView mFileBrowserRecyclerView;
179172
private LinearLayoutManager mFileBrowserLayoutManager;
180173
private FileBrowserAdapter mFileBrowserAdapter;
181174
private FilesViewModel mFilesViewModel;
182175
private OnItemClickListener<FileBrowserModel> mOnFileBrowserItemClickListener;
183176
private OnSearchListener mOnFileSearchListener;
184-
private Group mFileBrowserNoItemGroup;
177+
private View mNoItemContainer;
185178
private TextView txtFileBrowserNotFoundSubTitle;
186179
private String mFileBrowserSearchPendingQuery = "";
187180
private View mPermissionMessageContainer;
@@ -398,7 +391,13 @@ public void onChanged(List<GalleryModel> galleryModels) {
398391
galleryModels.remove(position);
399392
}
400393
}
401-
mGalleryAdapter.setList(galleryModels);
394+
if (galleryModels.isEmpty()){
395+
showNoGalleryItem();
396+
}else{
397+
mGalleryAdapter.setList(galleryModels);
398+
}
399+
}else{
400+
showNoGalleryItem();
402401
}
403402
}
404403
});
@@ -439,6 +438,8 @@ public void onResultSet(String path) {
439438
handleBackPress();
440439
}
441440

441+
442+
442443
private void handleBackPress() {
443444
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
444445
@Override
@@ -576,10 +577,9 @@ private void findViews() {
576577
btnBack = findViewById(R.id.fileBrowser_activity_main_btnBack);
577578
mMainRootView = findViewById(R.id.fileBrowser_activity_main_windowRoot);
578579
mFileBrowserRecyclerView = findViewById(R.id.fragment_file_browser_recyclerView);
579-
mFileBrowserContainer = findViewById(R.id.fileBrowser_activity_main_fileBrowserContainer);
580580
// mGalleryContainer=findViewById(R.id.fileBrowser_activity_main_galleryContainer);
581581
mGalleryRecyclerView = findViewById(R.id.sfb_fragment_gallery_recyclerView);
582-
mFileBrowserNoItemGroup = findViewById(R.id.fragment_file_browser_noItemGroup);
582+
mNoItemContainer = findViewById(R.id.sfb_noItemContainer);
583583
txtFileBrowserNotFoundSubTitle = findViewById(R.id.fragment_file_browser_txtNoItemFoundSubTitle);
584584
mPermissionMessageContainer = findViewById(R.id.sfb_partialSelectionContainer);
585585
}
@@ -733,9 +733,9 @@ public void onItemClicked(FileBrowserModel model, View view, int position) {
733733
@Override
734734
public void onSearch(int count, String searchedText) {
735735
if (count == 0) {
736-
showNoItem(searchedText);
736+
showFilesBrowserNoItem(searchedText);
737737
} else {
738-
hideNoItem();
738+
hideFileBrowserNoItem();
739739
}
740740
}
741741
};
@@ -903,6 +903,7 @@ public void onStateChanged(@NonNull View bottomSheet, int newState) {
903903

904904
finish();
905905
}
906+
calculateNoItemLocation();
906907
}
907908

908909
@Override
@@ -948,6 +949,7 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
948949
if (slideOffset > h) {
949950
showSuitableToolbar(mPageType);
950951
}
952+
calculateNoItemLocation();
951953
}
952954
});
953955

@@ -987,13 +989,14 @@ public void onGlobalLayout() {
987989
});
988990
}
989991
if (isShowingGallery()) {
990-
mFileBrowserContainer.setVisibility(View.INVISIBLE);
992+
mFileBrowserRecyclerView.setVisibility(View.INVISIBLE);
991993
mGalleryRecyclerView.setVisibility(View.VISIBLE);
992994

993995
} else {
994996
mGalleryRecyclerView.setVisibility(View.INVISIBLE);
995-
mFileBrowserContainer.setVisibility(View.VISIBLE);
997+
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
996998
}
999+
checkGalleryNoItem();
9971000

9981001
mFileBrowserRecyclerView.setItemAnimator(null);
9991002

@@ -1008,6 +1011,26 @@ public void onGlobalLayout() {
10081011

10091012
}
10101013

1014+
private void calculateNoItemLocation(){
1015+
if (mNoItemContainer.getVisibility() != View.VISIBLE){
1016+
return;
1017+
}
1018+
View topView = (View) mGalleryRecyclerView.getParent();
1019+
int[] topViewLoc = new int[2];
1020+
int[] bottomViewLoc = new int[2];
1021+
int[] noItemLoc = new int[2];
1022+
topView.getLocationInWindow(topViewLoc);
1023+
mBottomNavigationView.getLocationInWindow(bottomViewLoc);
1024+
mNoItemContainer.getLocationInWindow(noItemLoc);
1025+
float diff = ((Math.abs((topViewLoc[1] - bottomViewLoc[1])) / 2f) + topViewLoc[1]) -
1026+
(noItemLoc[1] + (mNoItemContainer.getHeight()/2f));
1027+
if ((diff + noItemLoc[1]) < topViewLoc[1]){
1028+
diff = topViewLoc[1] - noItemLoc[1];
1029+
}
1030+
float translation = mNoItemContainer.getTranslationY() + diff;
1031+
mNoItemContainer.setTranslationY(translation);
1032+
1033+
}
10111034
private void sendBackResult(FileModel model) {
10121035
Intent result = new Intent();
10131036
File[] resultFiles;
@@ -1088,7 +1111,7 @@ private boolean isAndroid30AndAbove() {
10881111
}
10891112

10901113
private boolean isShowingFileBrowser() {
1091-
return mFileBrowserContainer.getVisibility() == View.VISIBLE;
1114+
return mGalleryRecyclerView.getVisibility() != View.VISIBLE;
10921115
}
10931116

10941117
private boolean isShowingGallery() {
@@ -1390,11 +1413,12 @@ private void showPDFPage(boolean animate) {
13901413
if (animate) {
13911414
animateBottomSheet();
13921415
if (isShowingGallery()) {
1393-
swapContainers(mGalleryRecyclerView, mFileBrowserContainer);
1416+
swapContainers(mGalleryRecyclerView, mFileBrowserRecyclerView);
13941417
}
13951418
} else {
13961419
mGalleryRecyclerView.setVisibility(View.INVISIBLE);
1397-
mFileBrowserContainer.setVisibility(View.VISIBLE);
1420+
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
1421+
checkGalleryNoItem();
13981422
}
13991423
mFileFilter = new FileFilter() {
14001424
@Override
@@ -1414,11 +1438,12 @@ private void showAudioPage(boolean animate) {
14141438
if (animate) {
14151439
animateBottomSheet();
14161440
if (isShowingGallery()) {
1417-
swapContainers(mGalleryRecyclerView, mFileBrowserContainer);
1441+
swapContainers(mGalleryRecyclerView, mFileBrowserRecyclerView);
14181442
}
14191443
} else {
14201444
mGalleryRecyclerView.setVisibility(View.INVISIBLE);
1421-
mFileBrowserContainer.setVisibility(View.VISIBLE);
1445+
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
1446+
checkGalleryNoItem();
14221447
}
14231448
mFileFilter = new FileFilter() {
14241449
@Override
@@ -1437,11 +1462,12 @@ private void showFilesPage(boolean animate) {
14371462
if (animate) {
14381463
animateBottomSheet();
14391464
if (isShowingGallery()) {
1440-
swapContainers(mGalleryRecyclerView, mFileBrowserContainer);
1465+
swapContainers(mGalleryRecyclerView, mFileBrowserRecyclerView);
14411466
}
14421467
} else {
14431468
mGalleryRecyclerView.setVisibility(View.INVISIBLE);
1444-
mFileBrowserContainer.setVisibility(View.VISIBLE);
1469+
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
1470+
checkGalleryNoItem();
14451471
}
14461472
if (mFileTabFileFilter != null) {
14471473
mFileFilter = mFileTabFileFilter;
@@ -1479,8 +1505,10 @@ private void swapContainers(View visibleContainer, View hiddenContainer) {
14791505
public void onAnimationEnd(Animator animation) {
14801506
try {
14811507
if (hiddenContainer == mGalleryRecyclerView) {
1508+
checkGalleryNoItem();
14821509
MyBehavior.from(mBottomSheetRoot).setScrollingView(mGalleryRecyclerView);
14831510
} else {
1511+
hideNoGalleryItem();
14841512
MyBehavior.from(mBottomSheetRoot).setScrollingView(mFileBrowserRecyclerView);
14851513
}
14861514
} catch (Exception ignore) {
@@ -1495,12 +1523,13 @@ public void onAnimationEnd(Animator animation) {
14951523
private void showGallery(boolean animate) {
14961524
if (animate) {
14971525
animateBottomSheet();
1498-
if (mFileBrowserContainer.getVisibility() == View.VISIBLE) {
1499-
swapContainers(mFileBrowserContainer, mGalleryRecyclerView);
1526+
if (mFileBrowserRecyclerView.getVisibility() == View.VISIBLE) {
1527+
swapContainers(mFileBrowserRecyclerView, mGalleryRecyclerView);
15001528
}
15011529
} else {
15021530
mGalleryRecyclerView.setVisibility(View.VISIBLE);
1503-
mFileBrowserContainer.setVisibility(View.INVISIBLE);
1531+
mFileBrowserRecyclerView.setVisibility(View.INVISIBLE);
1532+
checkGalleryNoItem();
15041533
}
15051534
checkPermission(mPageType,animate);
15061535
if (mGalleryAdapter.getItemCount() == 0) {
@@ -1509,6 +1538,17 @@ private void showGallery(boolean animate) {
15091538
}
15101539

15111540
}
1541+
private void checkGalleryNoItem(){
1542+
if (mGalleryAdapter == null){
1543+
return;
1544+
}
1545+
List<GalleryModel> models = mGalleryAdapter.getGalleryModels();
1546+
if (models == null || models.isEmpty()){
1547+
showNoGalleryItem();
1548+
}else{
1549+
hideNoGalleryItem();
1550+
}
1551+
}
15121552

15131553

15141554
private void checkPermission(PageType pageType,boolean animate) {
@@ -1722,18 +1762,45 @@ public void goBackToFileBrowserParentDirectory() {
17221762
mFileBrowserAdapter.goBackToParentDirectory();
17231763
}
17241764

1725-
private void hideNoItem() {
1726-
mFileBrowserNoItemGroup.setVisibility(View.GONE);
1765+
private void hideFileBrowserNoItem() {
1766+
changeNoItemVisibility(false,null,null,0);
17271767
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
17281768
}
17291769

1730-
private void showNoItem(String searchedText) {
1731-
mFileBrowserRecyclerView.setVisibility(View.GONE);
1732-
mFileBrowserNoItemGroup.setVisibility(View.VISIBLE);
1770+
private void showFilesBrowserNoItem(String searchedText) {
1771+
mFileBrowserRecyclerView.setVisibility(View.INVISIBLE);
17331772
CharSequence text = Html.fromHtml(getString(R.string.sfb_no_results_found_sub_title, searchedText));
1734-
txtFileBrowserNotFoundSubTitle.setText(text);
1773+
changeNoItemVisibility(true,getString(R.string.sfb_no_result_found),
1774+
text.toString(), R.drawable.sfb_ic_file_not_found);
1775+
}
1776+
private void showNoGalleryItem() {
1777+
changeNoItemVisibility(true,getString(R.string.sfb_no_media),
1778+
"",R.drawable.sfb_ic_gallery);
1779+
}
1780+
private void hideNoGalleryItem() {
1781+
changeNoItemVisibility(false,null,
1782+
"",0);
1783+
}
1784+
private void changeNoItemVisibility(boolean visible, String noItemTitle, String noItemSubTitle, @DrawableRes int iconRes){
1785+
if (visible){
1786+
mNoItemContainer.setVisibility(View.VISIBLE);
1787+
mNoItemContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
1788+
@Override
1789+
public boolean onPreDraw() {
1790+
mNoItemContainer.getViewTreeObserver().removeOnPreDrawListener(this);
1791+
calculateNoItemLocation();
1792+
return true;
1793+
}
1794+
});
1795+
ImageView imgNoItem = mBottomSheetRoot.findViewById(R.id.fragment_file_browser_imgNoItem);
1796+
TextView txtNoItemTitle = mBottomSheetRoot.findViewById(R.id.fragment_file_browser_txtNoItemFoundTitle);
1797+
imgNoItem.setImageResource(iconRes);
1798+
txtFileBrowserNotFoundSubTitle.setText(noItemSubTitle);
1799+
txtNoItemTitle.setText(noItemTitle);
1800+
}else{
1801+
mNoItemContainer.setVisibility(View.GONE);
1802+
}
17351803
}
1736-
17371804

17381805
public void changePages(FileBrowserMainActivity.PageType pageType) {
17391806
mPageType = pageType;

0 commit comments

Comments
 (0)