Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SmartFileBrowser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
}
}
group = 'ir.smartdevelopers'
version = '2.0.7'
version = '2.0.9'

dependencies {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -48,35 +46,30 @@
import android.widget.Toast;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.constraintlayout.widget.Group;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.app.SharedElementCallback;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.ColorUtils;
import androidx.core.graphics.Insets;
import androidx.core.graphics.drawable.DrawableKt;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.exifinterface.media.ExifInterface;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;

import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
Expand All @@ -87,6 +80,7 @@
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -174,14 +168,13 @@ public class FileBrowserMainActivity extends AppCompatActivity {
private ResultListener mResultListener;
private OnItemSelectListener<FileModel> mOnFileItemSelectListener;
//<editor-fold desc="FileBrowser parameters">
private View mFileBrowserContainer;
private RecyclerView mFileBrowserRecyclerView;
private LinearLayoutManager mFileBrowserLayoutManager;
private FileBrowserAdapter mFileBrowserAdapter;
private FilesViewModel mFilesViewModel;
private OnItemClickListener<FileBrowserModel> mOnFileBrowserItemClickListener;
private OnSearchListener mOnFileSearchListener;
private Group mFileBrowserNoItemGroup;
private View mNoItemContainer;
private TextView txtFileBrowserNotFoundSubTitle;
private String mFileBrowserSearchPendingQuery = "";
private View mPermissionMessageContainer;
Expand Down Expand Up @@ -398,7 +391,13 @@ public void onChanged(List<GalleryModel> galleryModels) {
galleryModels.remove(position);
}
}
mGalleryAdapter.setList(galleryModels);
if (galleryModels.isEmpty()){
showNoGalleryItem();
}else{
mGalleryAdapter.setList(galleryModels);
}
}else{
showNoGalleryItem();
}
}
});
Expand Down Expand Up @@ -439,6 +438,8 @@ public void onResultSet(String path) {
handleBackPress();
}



private void handleBackPress() {
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
Expand Down Expand Up @@ -576,10 +577,9 @@ private void findViews() {
btnBack = findViewById(R.id.fileBrowser_activity_main_btnBack);
mMainRootView = findViewById(R.id.fileBrowser_activity_main_windowRoot);
mFileBrowserRecyclerView = findViewById(R.id.fragment_file_browser_recyclerView);
mFileBrowserContainer = findViewById(R.id.fileBrowser_activity_main_fileBrowserContainer);
// mGalleryContainer=findViewById(R.id.fileBrowser_activity_main_galleryContainer);
mGalleryRecyclerView = findViewById(R.id.sfb_fragment_gallery_recyclerView);
mFileBrowserNoItemGroup = findViewById(R.id.fragment_file_browser_noItemGroup);
mNoItemContainer = findViewById(R.id.sfb_noItemContainer);
txtFileBrowserNotFoundSubTitle = findViewById(R.id.fragment_file_browser_txtNoItemFoundSubTitle);
mPermissionMessageContainer = findViewById(R.id.sfb_partialSelectionContainer);
}
Expand Down Expand Up @@ -733,9 +733,9 @@ public void onItemClicked(FileBrowserModel model, View view, int position) {
@Override
public void onSearch(int count, String searchedText) {
if (count == 0) {
showNoItem(searchedText);
showFilesBrowserNoItem(searchedText);
} else {
hideNoItem();
hideFileBrowserNoItem();
}
}
};
Expand Down Expand Up @@ -903,6 +903,7 @@ public void onStateChanged(@NonNull View bottomSheet, int newState) {

finish();
}
calculateNoItemLocation();
}

@Override
Expand Down Expand Up @@ -948,6 +949,7 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
if (slideOffset > h) {
showSuitableToolbar(mPageType);
}
calculateNoItemLocation();
}
});

Expand Down Expand Up @@ -987,13 +989,14 @@ public void onGlobalLayout() {
});
}
if (isShowingGallery()) {
mFileBrowserContainer.setVisibility(View.INVISIBLE);
mFileBrowserRecyclerView.setVisibility(View.INVISIBLE);
mGalleryRecyclerView.setVisibility(View.VISIBLE);

} else {
mGalleryRecyclerView.setVisibility(View.INVISIBLE);
mFileBrowserContainer.setVisibility(View.VISIBLE);
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
}
checkGalleryNoItem();

mFileBrowserRecyclerView.setItemAnimator(null);

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

}

private void calculateNoItemLocation(){
if (mNoItemContainer.getVisibility() != View.VISIBLE){
return;
}
View topView = (View) mGalleryRecyclerView.getParent();
int[] topViewLoc = new int[2];
int[] bottomViewLoc = new int[2];
int[] noItemLoc = new int[2];
topView.getLocationInWindow(topViewLoc);
mBottomNavigationView.getLocationInWindow(bottomViewLoc);
mNoItemContainer.getLocationInWindow(noItemLoc);
float diff = ((Math.abs((topViewLoc[1] - bottomViewLoc[1])) / 2f) + topViewLoc[1]) -
(noItemLoc[1] + (mNoItemContainer.getHeight()/2f));
if ((diff + noItemLoc[1]) < topViewLoc[1]){
diff = topViewLoc[1] - noItemLoc[1];
}
float translation = mNoItemContainer.getTranslationY() + diff;
mNoItemContainer.setTranslationY(translation);

}
private void sendBackResult(FileModel model) {
Intent result = new Intent();
File[] resultFiles;
Expand Down Expand Up @@ -1088,7 +1111,7 @@ private boolean isAndroid30AndAbove() {
}

private boolean isShowingFileBrowser() {
return mFileBrowserContainer.getVisibility() == View.VISIBLE;
return mGalleryRecyclerView.getVisibility() != View.VISIBLE;
}

private boolean isShowingGallery() {
Expand Down Expand Up @@ -1390,11 +1413,12 @@ private void showPDFPage(boolean animate) {
if (animate) {
animateBottomSheet();
if (isShowingGallery()) {
swapContainers(mGalleryRecyclerView, mFileBrowserContainer);
swapContainers(mGalleryRecyclerView, mFileBrowserRecyclerView);
}
} else {
mGalleryRecyclerView.setVisibility(View.INVISIBLE);
mFileBrowserContainer.setVisibility(View.VISIBLE);
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
checkGalleryNoItem();
}
mFileFilter = new FileFilter() {
@Override
Expand All @@ -1414,11 +1438,12 @@ private void showAudioPage(boolean animate) {
if (animate) {
animateBottomSheet();
if (isShowingGallery()) {
swapContainers(mGalleryRecyclerView, mFileBrowserContainer);
swapContainers(mGalleryRecyclerView, mFileBrowserRecyclerView);
}
} else {
mGalleryRecyclerView.setVisibility(View.INVISIBLE);
mFileBrowserContainer.setVisibility(View.VISIBLE);
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
checkGalleryNoItem();
}
mFileFilter = new FileFilter() {
@Override
Expand All @@ -1437,11 +1462,12 @@ private void showFilesPage(boolean animate) {
if (animate) {
animateBottomSheet();
if (isShowingGallery()) {
swapContainers(mGalleryRecyclerView, mFileBrowserContainer);
swapContainers(mGalleryRecyclerView, mFileBrowserRecyclerView);
}
} else {
mGalleryRecyclerView.setVisibility(View.INVISIBLE);
mFileBrowserContainer.setVisibility(View.VISIBLE);
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
checkGalleryNoItem();
}
if (mFileTabFileFilter != null) {
mFileFilter = mFileTabFileFilter;
Expand Down Expand Up @@ -1479,8 +1505,10 @@ private void swapContainers(View visibleContainer, View hiddenContainer) {
public void onAnimationEnd(Animator animation) {
try {
if (hiddenContainer == mGalleryRecyclerView) {
checkGalleryNoItem();
MyBehavior.from(mBottomSheetRoot).setScrollingView(mGalleryRecyclerView);
} else {
hideNoGalleryItem();
MyBehavior.from(mBottomSheetRoot).setScrollingView(mFileBrowserRecyclerView);
}
} catch (Exception ignore) {
Expand All @@ -1495,12 +1523,13 @@ public void onAnimationEnd(Animator animation) {
private void showGallery(boolean animate) {
if (animate) {
animateBottomSheet();
if (mFileBrowserContainer.getVisibility() == View.VISIBLE) {
swapContainers(mFileBrowserContainer, mGalleryRecyclerView);
if (mFileBrowserRecyclerView.getVisibility() == View.VISIBLE) {
swapContainers(mFileBrowserRecyclerView, mGalleryRecyclerView);
}
} else {
mGalleryRecyclerView.setVisibility(View.VISIBLE);
mFileBrowserContainer.setVisibility(View.INVISIBLE);
mFileBrowserRecyclerView.setVisibility(View.INVISIBLE);
checkGalleryNoItem();
}
checkPermission(mPageType,animate);
if (mGalleryAdapter.getItemCount() == 0) {
Expand All @@ -1509,6 +1538,17 @@ private void showGallery(boolean animate) {
}

}
private void checkGalleryNoItem(){
if (mGalleryAdapter == null){
return;
}
List<GalleryModel> models = mGalleryAdapter.getGalleryModels();
if (models == null || models.isEmpty()){
showNoGalleryItem();
}else{
hideNoGalleryItem();
}
}


private void checkPermission(PageType pageType,boolean animate) {
Expand Down Expand Up @@ -1722,18 +1762,45 @@ public void goBackToFileBrowserParentDirectory() {
mFileBrowserAdapter.goBackToParentDirectory();
}

private void hideNoItem() {
mFileBrowserNoItemGroup.setVisibility(View.GONE);
private void hideFileBrowserNoItem() {
changeNoItemVisibility(false,null,null,0);
mFileBrowserRecyclerView.setVisibility(View.VISIBLE);
}

private void showNoItem(String searchedText) {
mFileBrowserRecyclerView.setVisibility(View.GONE);
mFileBrowserNoItemGroup.setVisibility(View.VISIBLE);
private void showFilesBrowserNoItem(String searchedText) {
mFileBrowserRecyclerView.setVisibility(View.INVISIBLE);
CharSequence text = Html.fromHtml(getString(R.string.sfb_no_results_found_sub_title, searchedText));
txtFileBrowserNotFoundSubTitle.setText(text);
changeNoItemVisibility(true,getString(R.string.sfb_no_result_found),
text.toString(), R.drawable.sfb_ic_file_not_found);
}
private void showNoGalleryItem() {
changeNoItemVisibility(true,getString(R.string.sfb_no_media),
"",R.drawable.sfb_ic_gallery);
}
private void hideNoGalleryItem() {
changeNoItemVisibility(false,null,
"",0);
}
private void changeNoItemVisibility(boolean visible, String noItemTitle, String noItemSubTitle, @DrawableRes int iconRes){
if (visible){
mNoItemContainer.setVisibility(View.VISIBLE);
mNoItemContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
mNoItemContainer.getViewTreeObserver().removeOnPreDrawListener(this);
calculateNoItemLocation();
return true;
}
});
ImageView imgNoItem = mBottomSheetRoot.findViewById(R.id.fragment_file_browser_imgNoItem);
TextView txtNoItemTitle = mBottomSheetRoot.findViewById(R.id.fragment_file_browser_txtNoItemFoundTitle);
imgNoItem.setImageResource(iconRes);
txtFileBrowserNotFoundSubTitle.setText(noItemSubTitle);
txtNoItemTitle.setText(noItemTitle);
}else{
mNoItemContainer.setVisibility(View.GONE);
}
}


public void changePages(FileBrowserMainActivity.PageType pageType) {
mPageType = pageType;
Expand Down
Loading