Skip to content

Commit b44eb8c

Browse files
Merge pull request #8 from smartdevelopers-ir/changes_for_android_11
2022/02/26
2 parents 9967705 + 5d59da9 commit b44eb8c

File tree

9 files changed

+116
-31
lines changed

9 files changed

+116
-31
lines changed

SmartFileBrowser/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ android {
3131
}
3232
}
3333
group = 'ir.smartdevelopers'
34-
version = '1.4.6'
34+
version = '1.4.7'
3535
task sourcesJar(type: Jar) {
3636
archiveClassifier.set("sources")
3737
from android.sourceSets.main.java.srcDirs

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import ir.smartdevelopers.smartfilebrowser.adapters.AlbumAdapter;
7373
import ir.smartdevelopers.smartfilebrowser.adapters.FileBrowserAdapter;
7474
import ir.smartdevelopers.smartfilebrowser.adapters.GalleryAdapter;
75+
import ir.smartdevelopers.smartfilebrowser.customClasses.GalleryLayoutManager;
7576
import ir.smartdevelopers.smartfilebrowser.customClasses.GalleyItemDecoration;
7677
import ir.smartdevelopers.smartfilebrowser.customClasses.MyBehavior;
7778
import ir.smartdevelopers.smartfilebrowser.customClasses.OnItemLongClickListener;
@@ -157,7 +158,7 @@ public class FileBrowserMainActivity extends AppCompatActivity {
157158
//<editor-fold desc="Gallery parameters">
158159
private RecyclerView mGalleryRecyclerView;
159160
private GalleryAdapter mGalleryAdapter;
160-
private GridLayoutManager mGalleryLayoutManager;
161+
private GalleryLayoutManager mGalleryLayoutManager;
161162
/**
162163
* this listener is user listener
163164
*/
@@ -304,7 +305,7 @@ public void onChanged(List<FileBrowserModel> fileBrowserModels) {
304305
int spanCount = getResources().getInteger(R.integer.sfb_gallery_grid);
305306
int gapSpace = getResources().getDimensionPixelSize(R.dimen.sfb_gallery_gap_size);
306307

307-
mGalleryLayoutManager = new GridLayoutManager(this, spanCount);
308+
mGalleryLayoutManager = new GalleryLayoutManager(this, spanCount);
308309
mGalleryAdapter = new GalleryAdapter(mSelectionFileViewModel.getSelectedFiles());
309310
mGalleryAdapter.setCanSelectMultiple(mCanSelectMultipleInGallery);
310311
mGalleryAdapter.setOnItemClickListener(mGalleryModelItemClickListener);
@@ -1262,7 +1263,7 @@ private void showGallery(boolean animate) {
12621263
}
12631264
if (mGalleryAdapter.getItemCount() == 0) {
12641265
mGalleryViewModel
1265-
.getAllGalleryModels(mShowCamera, mShowVideosInGallery);
1266+
.getAllGalleryModels(mShowCamera, mShowVideosInGallery,false);
12661267
}
12671268

12681269
}
@@ -1416,12 +1417,17 @@ private void openCamera() {
14161417
}
14171418
}
14181419

1420+
private long lastAlbumId=-1;
14191421
public void updateGallery(AlbumModel albumModel) {
1422+
if (albumModel.getId()==lastAlbumId){
1423+
return;
1424+
}
14201425
if (albumModel.getId() == -1) {
1421-
mGalleryViewModel.getAllGalleryModels(mShowCamera, mShowVideosInGallery);
1426+
mGalleryViewModel.getAllGalleryModels(mShowCamera, mShowVideosInGallery,true);
14221427
} else {
14231428
mGalleryViewModel.getGalleryModelsByAlbumName(albumModel.getName(), mShowVideosInGallery);
14241429
}
1430+
lastAlbumId=albumModel.getId();
14251431
}
14261432

14271433
public List<File> getSelectedGalleryFiles() {

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141
import com.google.android.material.slider.Slider;
4242
import java.util.Locale;
4343
import ir.smartdevelopers.smartfilebrowser.R;
44+
import ir.smartdevelopers.smartfilebrowser.customClasses.MyVideoView;
4445

4546
public class VideoViewActivity extends AppCompatActivity {
4647

4748
public static final String KEY_TRANSITION_NAME="transition_name";
4849
private Uri mVideoUri;
4950
private ImageView imgThumbnailHolder;
5051

51-
private VideoView mVideoView;
52+
private MyVideoView mVideoView;
5253
private boolean isExiting=false;
5354
private AppCompatImageView btnPlay;
5455
private AppCompatTextView txtVideoLength,txtCurrentTime;
@@ -186,11 +187,19 @@ public String getFormattedValue(float value) {
186187
}
187188
};
188189
mSlider.setLabelFormatter(labelFormatter);
190+
mSlider.addOnChangeListener(new Slider.OnChangeListener() {
191+
@Override
192+
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
193+
if (fromUser){
194+
mVideoView.seekTo((int) slider.getValue());
195+
}
196+
}
197+
});
189198
mSlider.addOnSliderTouchListener(new Slider.OnSliderTouchListener() {
190199
boolean lastPlayingStateIsPlaying=false;
191200
@Override
192201
public void onStartTrackingTouch(@NonNull Slider slider) {
193-
lastPlayingStateIsPlaying=isPlaying;
202+
lastPlayingStateIsPlaying=isPlaying || btnPlay.getVisibility()!=View.VISIBLE;
194203
mVideoView.pause();
195204
isPlaying=false;
196205
mTimerHandler.removeCallbacks(mTimerRunnable);
@@ -204,6 +213,7 @@ public void onStopTrackingTouch(@NonNull Slider slider) {
204213
playVideo();
205214
}
206215
}
216+
207217
});
208218

209219
}
@@ -213,6 +223,7 @@ private void loadVideoThumbnail() {
213223
retriever.setDataSource(this,mVideoUri);
214224
Bitmap bitmap=retriever.getFrameAtTime();
215225
imgThumbnailHolder.setImageBitmap(bitmap);
226+
216227
String durationSt=retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
217228
if (durationSt!=null){
218229
long duration=Long.parseLong(durationSt);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import androidx.recyclerview.widget.RecyclerView;
1717

1818
import com.bumptech.glide.Glide;
19+
import com.bumptech.glide.GlideBuilder;
20+
import com.bumptech.glide.Priority;
21+
import com.bumptech.glide.load.engine.executor.GlideExecutor;
1922

2023
import java.io.File;
2124
import java.util.ArrayList;
@@ -295,13 +298,13 @@ public boolean onLongClick(View v) {
295298
}
296299
void bindView(GalleryModel model){
297300

298-
301+
299302
Glide.with(mImageView.getContext().getApplicationContext()).load(model.getUri())
300303
.override(THUMBNAIL_SIZE,THUMBNAIL_SIZE)
301304
//.dontAnimate()
302305
//.thumbnail(0.2f)
303306
.encodeQuality(30)
304-
307+
.priority(Priority.LOW)
305308
.into(mImageView);
306309

307310

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ir.smartdevelopers.smartfilebrowser.customClasses;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
6+
import androidx.recyclerview.widget.GridLayoutManager;
7+
8+
public class GalleryLayoutManager extends GridLayoutManager {
9+
public GalleryLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
10+
super(context, attrs, defStyleAttr, defStyleRes);
11+
}
12+
13+
public GalleryLayoutManager(Context context, int spanCount) {
14+
super(context, spanCount);
15+
}
16+
17+
public GalleryLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
18+
super(context, spanCount, orientation, reverseLayout);
19+
}
20+
21+
@Override
22+
public boolean supportsPredictiveItemAnimations() {
23+
return false;
24+
}
25+
}

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

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class MyVideoView extends VideoView {
1212
private int mVideoWidth;
1313
private int mVideoHeight;
14-
14+
private int mVideoRotation;
1515
public MyVideoView(Context context, AttributeSet attrs) {
1616
super(context, attrs);
1717
}
@@ -31,38 +31,67 @@ public void setVideoURI(Uri uri) {
3131
retriever.setDataSource(this.getContext(), uri);
3232
String width=retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
3333
String height=retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
34-
if (!TextUtils.isEmpty(width) && !TextUtils.isEmpty(height)){
34+
String rotation=retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
35+
if (!TextUtils.isEmpty(width) && !TextUtils.isEmpty(height) && !TextUtils.isEmpty(rotation)){
3536
assert width != null;
3637
mVideoWidth = Integer.parseInt(width);
3738
assert height != null;
3839
mVideoHeight = Integer.parseInt(height);
40+
mVideoRotation=Integer.parseInt(rotation);
3941
}else {
4042
DisplayMetrics metrics=getContext().getResources().getDisplayMetrics();
4143
mVideoWidth=metrics.widthPixels;
4244
mVideoHeight=metrics.heightPixels;
45+
mVideoRotation=0;
4346
}
4447
super.setVideoURI(uri);
4548
}
4649

4750
@Override
4851
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
4952
// Log.i("@@@", "onMeasure");
50-
int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
51-
int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
53+
double deviceWidth = getDefaultSize(mVideoWidth, widthMeasureSpec);
54+
double deviceHeight = getDefaultSize(mVideoHeight, heightMeasureSpec);
55+
double scaleFactor=1;
56+
double finalWidth;
57+
double finalHeight;
58+
59+
if ((Math.abs(mVideoRotation)==90 || Math.abs(mVideoRotation)==270) ){
60+
finalWidth=mVideoHeight;
61+
finalHeight=mVideoWidth;
62+
}else {
63+
finalHeight=mVideoHeight;
64+
finalWidth=mVideoWidth;
65+
}
5266
if (mVideoWidth > 0 && mVideoHeight > 0) {
53-
if (mVideoWidth * height > width * mVideoHeight) {
54-
// Log.i("@@@", "image too tall, correcting");
55-
height = width * mVideoHeight / mVideoWidth;
56-
} else if (mVideoWidth * height < width * mVideoHeight) {
57-
// Log.i("@@@", "image too wide, correcting");
58-
width = height * mVideoWidth / mVideoHeight;
59-
} else {
60-
// Log.i("@@@", "aspect ratio is correct: " +
61-
// width+"/"+height+"="+
62-
// mVideoWidth+"/"+mVideoHeight);
67+
if (mVideoWidth >= mVideoHeight){
68+
scaleFactor=deviceWidth/finalWidth;
69+
}else {
70+
scaleFactor=deviceHeight/finalHeight;
6371
}
6472
}
73+
finalWidth=finalWidth*scaleFactor;
74+
finalHeight=finalHeight*scaleFactor;
75+
76+
// if (mVideoWidth > 0 && mVideoHeight > 0) {
77+
// if (mVideoWidth * deviceHeight > deviceWidth * mVideoHeight) {
78+
// // Log.i("@@@", "image too tall, correcting");
79+
// deviceHeight = deviceWidth * mVideoHeight / mVideoWidth;
80+
// } else if (mVideoWidth * deviceHeight < deviceWidth * mVideoHeight) {
81+
// // Log.i("@@@", "image too wide, correcting");
82+
// deviceWidth = deviceHeight * mVideoWidth / mVideoHeight;
83+
// } else {
84+
// // Log.i("@@@", "aspect ratio is correct: " +
85+
// // width+"/"+height+"="+
86+
// // mVideoWidth+"/"+mVideoHeight);
87+
// }
88+
// }
89+
// if ((Math.abs(mVideoRotation)==90 || Math.abs(mVideoRotation)==270) ){
90+
// int tempWidth=deviceWidth;
91+
// deviceWidth=deviceHeight;
92+
// deviceHeight=tempWidth;
93+
// }
6594
// Log.i("@@@", "setting size: " + width + 'x' + height);
66-
setMeasuredDimension(width, height);
95+
setMeasuredDimension((int)finalWidth, (int)finalHeight);
6796
}
6897
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ private boolean mustFetchNewData(){
3434
}
3535
return mGalleryModelsLiveData.getValue().size() == 0;
3636
}
37-
public void getAllGalleryModels(boolean addCamera, boolean showVideosInGallery){
37+
public void getAllGalleryModels(boolean addCamera, boolean showVideosInGallery,boolean forceFetchNewData){
3838

39-
if (mustFetchNewData()) {
39+
if (mustFetchNewData() || forceFetchNewData) {
4040
mRepository.getGalleryMediaList(null,null,addCamera,showVideosInGallery);
4141
}else {
4242
mGalleryModelsLiveData.setValue(mRepository.getGalleryListLiveData().getValue());

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,21 +169,26 @@
169169
android:layout_width="match_parent"
170170
android:layout_height="match_parent"
171171
android:visibility="gone"
172+
tools:visibility="visible"
172173
android:translationZ="16dp"
173174

174175
>
175176
<FrameLayout
176177
android:id="@+id/fileBrowser_activity_main_albumPlaceHolder"
177178
android:layout_width="180dp"
178179
android:layout_height="wrap_content"
179-
android:maxHeight="300dp"
180+
tools:layout_height="300dp"
181+
android:maxHeight="500dp"
180182
android:background="@color/white"
181183

182184
android:transformPivotX="0dp"
183185
android:transformPivotY="0dp"
184186
android:scaleX="0"
185187
android:scaleY="0"
188+
tools:scaleX="1"
189+
tools:scaleY="1"
186190
android:visibility="invisible"
191+
tools:visibility="visible"
187192
android:focusable="true"
188193
android:translationZ="16dp"
189194
/>
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="180dp"
44
android:layout_height="wrap_content"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
56
android:background="@color/white"
67
android:maxWidth="180dp"
7-
android:maxHeight="200dp">
8+
android:maxHeight="500dp">
89

910
<androidx.recyclerview.widget.RecyclerView
1011
android:id="@+id/fileBrowser_activity_main_albumRecyclerView"
1112
android:layout_width="match_parent"
12-
android:layout_height="wrap_content" />
13-
</FrameLayout>
13+
android:layout_height="wrap_content"
14+
app:layout_constraintTop_toTopOf="parent"
15+
app:layout_constraintBottom_toBottomOf="parent"
16+
app:layout_constraintHeight_max="500dp"
17+
app:layout_constrainedHeight="true"
18+
/>
19+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)