Skip to content

Commit d8be54b

Browse files
committed
before changing bottom navigation view
1 parent f5690c1 commit d8be54b

File tree

8 files changed

+187
-40
lines changed

8 files changed

+187
-40
lines changed

SmartFileBrowser/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies {
4141
implementation 'com.github.bumptech.glide:glide:4.11.0'
4242
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
4343
implementation 'it.sephiroth.android.library.bottomnavigation:bottom-navigation:3.0.0'
44+
implementation 'com.aurelhubert:ahbottomnavigation:2.3.4'
4445
// implementation 'com.ashokvarma.android:bottom-navigation-bar:2.2.0'
4546
def lifecycle_version = "2.2.0"
4647
// ViewModel

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

Lines changed: 134 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import androidx.recyclerview.widget.RecyclerView;
1111

1212
import android.annotation.SuppressLint;
13+
import android.content.Context;
14+
import android.content.Intent;
1315
import android.content.res.TypedArray;
1416
import android.os.Bundle;
1517
import android.util.Log;
@@ -19,6 +21,8 @@
1921
import android.view.View;
2022
import android.view.ViewGroup;
2123
import android.view.ViewPropertyAnimator;
24+
import android.view.ViewTreeObserver;
25+
import android.view.WindowManager;
2226
import android.view.animation.AccelerateDecelerateInterpolator;
2327
import android.view.animation.AccelerateInterpolator;
2428
import android.view.animation.OvershootInterpolator;
@@ -41,6 +45,7 @@
4145
import ir.smartdevelopers.smartfilebrowser.customClasses.OnItemClickListener;
4246
import ir.smartdevelopers.smartfilebrowser.customClasses.OnItemSelectListener;
4347
import ir.smartdevelopers.smartfilebrowser.customClasses.RoundLinearLayout;
48+
import ir.smartdevelopers.smartfilebrowser.customClasses.SFBFileFilter;
4449
import ir.smartdevelopers.smartfilebrowser.customClasses.SearchView;
4550
import ir.smartdevelopers.smartfilebrowser.fragments.FileBrowserFragment;
4651
import ir.smartdevelopers.smartfilebrowser.fragments.GalleryFragment;
@@ -62,6 +67,7 @@ public class FileBrowserMainActivity extends AppCompatActivity {
6267
private BottomNavigation mBottomNavigationView;
6368
// private BottomNavigationBar mBottomNavigationView;
6469
// private BottomNavigationView mBottomNavigationView;
70+
private View mMainRootView;
6571
private int mActionBarSize;
6672
private float mRadius;
6773
private View mDraggingLineView;
@@ -89,6 +95,106 @@ public class FileBrowserMainActivity extends AppCompatActivity {
8995
private boolean mAlbumListIsShowing=false;
9096
private ImageButton btnBack;
9197

98+
/*Builder parameters*/
99+
private FileFilter mFileTabFileFilter;
100+
private boolean mShowVideosInGallery=true;
101+
private boolean mShowCamera=true;
102+
private boolean mCanSelectMultipleInGallery=true;
103+
private boolean mCanSelectMultipleInFiles=true;
104+
private boolean mShowPDFTab=true;
105+
private boolean mShowFilesTab=true;
106+
private boolean mShowAudioTab=true;
107+
private boolean mShowGalleryTab=true;
108+
109+
110+
public static class Builder{
111+
private SFBFileFilter fileTabFileFilter;
112+
private boolean showVideosInGallery=true;
113+
private boolean showCamera=true;
114+
private boolean canSelectMultipleInGallery=true;
115+
private boolean canSelectMultipleInFiles=true;
116+
private boolean showPDFTab=true;
117+
private boolean showFilesTab=true;
118+
private boolean showAudioTab=true;
119+
private boolean showGalleryTab=true;
120+
121+
public Builder setFileTabFileFilter(@NonNull FileFilter fileTabFileFilter) {
122+
this.fileTabFileFilter = new SFBFileFilter(){
123+
@Override
124+
public boolean accept(File pathname) {
125+
return fileTabFileFilter.accept(pathname);
126+
}
127+
};
128+
return this;
129+
}
130+
131+
public Builder setShowVideosInGallery(boolean showVideosInGallery) {
132+
this.showVideosInGallery = showVideosInGallery;
133+
return this;
134+
}
135+
136+
public Builder setShowCamera(boolean showCamera) {
137+
this.showCamera = showCamera;
138+
return this;
139+
}
140+
141+
public Builder setCanSelectMultipleInGallery(boolean canSelectMultipleInGallery) {
142+
this.canSelectMultipleInGallery = canSelectMultipleInGallery;
143+
return this;
144+
}
145+
146+
public Builder setCanSelectMultipleInFiles(boolean canSelectMultipleInFiles) {
147+
this.canSelectMultipleInFiles = canSelectMultipleInFiles;
148+
return this;
149+
}
150+
151+
public Builder setShowPDFTab(boolean showPDFTab) {
152+
this.showPDFTab = showPDFTab;
153+
return this;
154+
}
155+
156+
public Builder setShowFilesTab(boolean showFilesTab) {
157+
this.showFilesTab = showFilesTab;
158+
return this;
159+
}
160+
161+
public Builder setShowAudioTab(boolean showAudioTab) {
162+
this.showAudioTab = showAudioTab;
163+
return this;
164+
}
165+
166+
public Builder setShowGalleryTab(boolean showGalleryTab) {
167+
this.showGalleryTab = showGalleryTab;
168+
return this;
169+
}
170+
public void show(Context context){
171+
172+
Intent filePickerIntent=new Intent(context,FileBrowserMainActivity.class);
173+
filePickerIntent.putExtra("mFileTabFileFilter",fileTabFileFilter);
174+
filePickerIntent.putExtra("mShowVideosInGallery",showVideosInGallery);
175+
filePickerIntent.putExtra("mShowCamera",showCamera);
176+
filePickerIntent.putExtra("mCanSelectMultipleInGallery",canSelectMultipleInGallery);
177+
filePickerIntent.putExtra("mCanSelectMultipleInFiles",canSelectMultipleInFiles);
178+
filePickerIntent.putExtra("mShowPDFTab",showPDFTab);
179+
filePickerIntent.putExtra("mShowFilesTab",showFilesTab);
180+
filePickerIntent.putExtra("mShowAudioTab",showAudioTab);
181+
filePickerIntent.putExtra("mShowGalleryTab",showGalleryTab);
182+
context.startActivity(filePickerIntent);
183+
184+
}
185+
}
186+
187+
private void getDataFromIntent(){
188+
mFileTabFileFilter= (FileFilter) getIntent().getSerializableExtra("mFileTabFileFilter");
189+
mShowVideosInGallery=getIntent().getBooleanExtra("mShowVideosInGallery",true);
190+
mShowCamera=getIntent().getBooleanExtra("mShowCamera",true);
191+
mCanSelectMultipleInGallery=getIntent().getBooleanExtra("mCanSelectMultipleInGallery",true);
192+
mCanSelectMultipleInFiles=getIntent().getBooleanExtra("mCanSelectMultipleInFiles",true);
193+
mShowPDFTab=getIntent().getBooleanExtra("mShowPDFTab",true);
194+
mShowFilesTab=getIntent().getBooleanExtra("mShowFilesTab",true);
195+
mShowAudioTab=getIntent().getBooleanExtra("mShowAudioTab",true);
196+
mShowGalleryTab=getIntent().getBooleanExtra("mShowGalleryTab",true);
197+
}
92198
// private BottomNavigationBar.OnTabSelectedListener mOnTabSelectedListener;
93199
@Override
94200
protected void onCreate(Bundle savedInstanceState) {
@@ -98,6 +204,7 @@ protected void onCreate(Bundle savedInstanceState) {
98204
mGalleryViewModel=new ViewModelProvider(this,new ViewModelProvider.AndroidViewModelFactory(getApplication()))
99205
.get(GalleryViewModel.class);
100206
findViews();
207+
getDataFromIntent();
101208
initListeners();
102209
initViews(savedInstanceState);
103210
if (savedInstanceState==null) {
@@ -149,6 +256,7 @@ private void findViews() {
149256
mToolbarPlaceHolder = findViewById(R.id.fileBrowser_activity_main_toolbarPlaceHolder);
150257
mAlbumPlaceHolder = findViewById(R.id.fileBrowser_activity_main_albumPlaceHolder);
151258
btnBack = findViewById(R.id.fileBrowser_activity_main_btnBack);
259+
mMainRootView = findViewById(R.id.fileBrowser_activity_main_windowRoot);
152260

153261
}
154262
private void initListeners() {
@@ -255,11 +363,14 @@ private void initViews(Bundle savedInstanceState) {
255363
ViewGroup.LayoutParams appBarParams = mAppBarLayout.getLayoutParams();
256364
appBarParams.height = mActionBarSize;
257365
mAppBarLayout.setLayoutParams(appBarParams);
258-
366+
int screenHeight=getResources().getDisplayMetrics().heightPixels;
259367
mRadius = getResources().getDimension(R.dimen.bottom_sheet_top_radius);
260368
mAppBarLayout.setTranslationY(-mActionBarSize);
261369
mBottomSheetBehavior = BottomSheetBehavior.from(mBottomSheetRoot);
262370
mBottomSheetBehavior.setHideable(true);
371+
// mBottomSheetBehavior.setFitToContents(false);
372+
// mBottomSheetBehavior.setHalfExpandedRatio(0.5f);
373+
mBottomSheetBehavior.setPeekHeight(screenHeight/2,true);
263374
mBottomSheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
264375
@Override
265376
public void onStateChanged(@NonNull View bottomSheet, int newState) {
@@ -300,6 +411,14 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
300411
}
301412
}
302413
});
414+
mMainRootView.setOnTouchListener(new View.OnTouchListener() {
415+
@SuppressLint("ClickableViewAccessibility")
416+
@Override
417+
public boolean onTouch(View v, MotionEvent event) {
418+
finish();
419+
return true;
420+
}
421+
});
303422

304423
// if (savedInstanceState==null){
305424
// mBottomSheetRoot.post(()->{
@@ -309,15 +428,23 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
309428
btnBack.setOnClickListener(v->{
310429
onBackPressed();
311430
});
312-
mBottomSheetRoot.setTranslationY(1000);
313-
mBottomNavigationView.setTranslationY(200);
314-
431+
if (savedInstanceState==null){
432+
mBottomSheetRoot.setTranslationY(screenHeight*0.6f);
433+
mBottomNavigationView.setTranslationY(200);
434+
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
435+
@Override
436+
public void onGlobalLayout() {
437+
startFirstAnimation();
438+
getWindow().getDecorView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
439+
}
440+
});
441+
}
315442
}
316443

317444
private void startFirstAnimation() {
318-
long duration=800;
445+
long duration=300;
319446
mBottomSheetRoot.animate().setDuration(duration).translationY(0)
320-
.setInterpolator(new FastOutSlowInInterpolator()).start();
447+
.setInterpolator(new OvershootInterpolator()).start();
321448
mBottomNavigationView.animate().setDuration(duration).translationY(0)
322449
.setInterpolator(new FastOutSlowInInterpolator()).start();
323450
}
@@ -326,7 +453,7 @@ private void startFirstAnimation() {
326453
protected void onStart() {
327454
super.onStart();
328455

329-
startFirstAnimation();
456+
330457

331458
}
332459

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static boolean isDirectory(File file){
103103
public static File getImageFile(Context context) throws IOException {
104104
File folder= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
105105
DateFormat dateFormat=new SimpleDateFormat("yyyyMMdd-HHmmss",new Locale("en"));
106-
String name="JPEG_"+dateFormat.format(new Date())+"_";
106+
String name="JPEG_"+dateFormat.format(new Date());
107107
// return File.createTempFile(name,".jpg",folder);
108108
return new File(folder,name+".jpg");
109109
}

SmartFileBrowser/src/main/java/ir/smartdevelopers/smartfilebrowser/viewModel/Repository.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public LiveData<List<AlbumModel>> getAlbums(){
8080
String[] projection= {MediaStore.Files.FileColumns.BUCKET_ID,
8181
MediaStore.Files.FileColumns.BUCKET_DISPLAY_NAME,
8282
MediaStore.Files.FileColumns.DATE_ADDED,
83-
MediaStore.Files.FileColumns.DATA,
84-
"MAX("+ MediaStore.Images.Media.DATE_ADDED+") as max"};
85-
String selection="1) GROUP BY ("+ MediaStore.Images.Media.BUCKET_DISPLAY_NAME;
86-
// String[] selectionArgs={Utils.join(new String[]{String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
87-
// String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO)},",")};
88-
String orderBy="max DESC";
83+
MediaStore.Files.FileColumns.DATA};
84+
String selection=MediaStore.Files.FileColumns.MIME_TYPE+" NOT NULL ";
85+
String[] mediaTypes={String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
86+
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO)};
87+
// String[] selectionArgs={Utils.join(mediaTypes,",")};
88+
String orderBy=MediaStore.Files.FileColumns.DATE_ADDED+" DESC";
8989
Cursor imageCursor= mContentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
9090
projection,selection,null,orderBy);
9191
Cursor videoCursor= mContentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
@@ -113,6 +113,9 @@ public int compare(AlbumModel o1, AlbumModel o2) {
113113
}
114114
private Set<AlbumModel> getAlbumModels(Cursor cursor,String[] projection){
115115
Set<AlbumModel> albumModels=new HashSet<>();
116+
if (cursor==null){
117+
return albumModels;
118+
}
116119
int bucketIdIndex=cursor.getColumnIndex(projection[0]);
117120
int bucketNameIndex=cursor.getColumnIndex(projection[1]);
118121
int dateTakenIndex=cursor.getColumnIndex(projection[2]);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:id="@+id/fileBrowser_activity_main_windowRoot"
78
tools:context=".acitivties.FileBrowserMainActivity">
89

910

@@ -16,20 +17,20 @@
1617
app:layout_constraintEnd_toEndOf="parent"
1718
app:layout_constraintBottom_toBottomOf="parent"
1819
android:fillViewport="true"
19-
android:layout_marginTop="?actionBarSize"
20+
21+
android:layout_marginTop="@dimen/sfb_expanded_margin_top"
2022
>
2123

2224
<ir.smartdevelopers.smartfilebrowser.customClasses.RoundLinearLayout
2325
android:id="@+id/fileBrowser_activity_main_contentRootLayout"
2426
android:layout_width="match_parent"
2527
android:layout_height="match_parent"
26-
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
2728
android:orientation="vertical"
2829
android:topRightRadius="20dp"
2930
android:topLeftRadius="20dp"
3031
android:bottomRightRadius="0dp"
3132
android:bottomLeftRadius="0dp"
32-
33+
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
3334
>
3435
<View
3536
android:id="@+id/fileBrowser_activity_main_draggingLineView"
@@ -44,6 +45,7 @@
4445
android:layout_width="match_parent"
4546
android:layout_height="match_parent"
4647
android:layout_marginTop="16dp"
48+
4749
/>
4850
</ir.smartdevelopers.smartfilebrowser.customClasses.RoundLinearLayout>
4951

@@ -61,9 +63,10 @@
6163
>
6264
<LinearLayout
6365
android:layout_width="match_parent"
64-
android:layout_height="?actionBarSize"
66+
android:layout_height="@dimen/appbarSize"
6567
android:orientation="horizontal"
6668
android:layout_gravity="bottom"
69+
6770
>
6871
<ImageButton
6972
android:id="@+id/fileBrowser_activity_main_btnBack"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<dimen name="appbarSize">64dp</dimen>
4+
<dimen name="sfb_expanded_margin_top">52dp</dimen>
5+
</resources>

SmartFileBrowser/src/main/res/values/dimens.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
<dimen name="colorFileBrowserItemTitleSize">18sp</dimen>
66
<dimen name="colorFileBrowserItemSubTitleSize">12sp</dimen>
77
<dimen name="fileBrowserListSpliterSize">16dp</dimen>
8+
<dimen name="appbarSize">56dp</dimen>
9+
<dimen name="sfb_expanded_margin_top">44dp</dimen>
810
</resources>

0 commit comments

Comments
 (0)