Skip to content

Commit 7480d02

Browse files
Merge pull request #10 from smartdevelopers-ir/changes_for_android_11
2022/04/04
2 parents 9c23c6a + 5f57d07 commit 7480d02

File tree

9 files changed

+130
-19
lines changed

9 files changed

+130
-19
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.8'
34+
version = '1.4.9'
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ public void onChanged(List<FileBrowserModel> fileBrowserModels) {
317317
int imageHeight = (getResources().getDisplayMetrics().widthPixels / spanCount) - (gapSpace * 2);
318318
mGalleryRecyclerView.setItemViewCacheSize(20);
319319
mGalleryRecyclerView.setHasFixedSize(true);
320-
mGalleryLayoutManager.setItemPrefetchEnabled(true);
321-
mGalleryLayoutManager.setInitialPrefetchItemCount(15);
320+
// mGalleryLayoutManager.setItemPrefetchEnabled(true);
321+
// mGalleryLayoutManager.setInitialPrefetchItemCount(15);
322322
mGalleryRecyclerView.setLayoutManager(mGalleryLayoutManager);
323323
mGalleryRecyclerView.addItemDecoration(new GalleyItemDecoration(spanCount, gapSpace, true));
324324
mGalleryRecyclerView.setAdapter(mGalleryAdapter);

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import androidx.appcompat.widget.AppCompatImageView;
1414
import androidx.appcompat.widget.AppCompatTextView;
1515
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
16+
import androidx.recyclerview.widget.DiffUtil;
1617
import androidx.recyclerview.widget.RecyclerView;
1718

1819
import com.bumptech.glide.Glide;
@@ -24,6 +25,7 @@
2425
import java.io.File;
2526
import java.util.ArrayList;
2627
import java.util.List;
28+
import java.util.Objects;
2729

2830
import ir.smartdevelopers.smartfilebrowser.R;
2931
import ir.smartdevelopers.smartfilebrowser.customClasses.FileUtil;
@@ -33,6 +35,7 @@
3335
import ir.smartdevelopers.smartfilebrowser.customClasses.OnItemSelectListener;
3436
import ir.smartdevelopers.smartfilebrowser.customClasses.SFBCheckboxWithNumber;
3537
import ir.smartdevelopers.smartfilebrowser.customClasses.SFBCountingCheckBox;
38+
import ir.smartdevelopers.smartfilebrowser.models.FileBrowserModel;
3639
import ir.smartdevelopers.smartfilebrowser.models.FileModel;
3740
import ir.smartdevelopers.smartfilebrowser.models.GalleryModel;
3841

@@ -50,7 +53,8 @@ public class GalleryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
5053
private OnItemLongClickListener<GalleryModel> mOnItemLongClickListener;
5154
/**If can not select multiple image when clicking on image it choose as only image this listener send result back*/
5255
private OnItemChooseListener mOnItemChooseListener;
53-
56+
/**For preventing multiple btnZoom click*/
57+
private boolean mZoomButtonClicked=false;
5458

5559
public GalleryAdapter(List<File> selectedFiles) {
5660
mGalleryModels=new ArrayList<>();
@@ -116,7 +120,36 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
116120
public int getItemCount() {
117121
return mGalleryModels.size();
118122
}
123+
class DiffCallback extends DiffUtil.Callback{
124+
List<GalleryModel> oldList;
125+
List<GalleryModel> newList;
126+
127+
public DiffCallback(List<GalleryModel> oldList, List<GalleryModel> newList) {
128+
this.oldList = oldList;
129+
this.newList = newList;
130+
}
131+
132+
@Override
133+
public int getOldListSize() {
134+
return oldList.size();
135+
}
136+
137+
@Override
138+
public int getNewListSize() {
139+
return newList.size();
140+
}
119141

142+
@Override
143+
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
144+
145+
return Objects.equals(oldList.get(oldItemPosition),newList.get(newItemPosition));
146+
}
147+
148+
@Override
149+
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
150+
return Objects.equals(oldList.get(oldItemPosition),newList.get(newItemPosition));
151+
}
152+
}
120153
public void setList(List<GalleryModel> galleryModels) {
121154

122155

@@ -128,6 +161,9 @@ public void setList(List<GalleryModel> galleryModels) {
128161
model.setSelected(true);
129162
}
130163
}
164+
// DiffUtil.DiffResult result=DiffUtil.calculateDiff(new DiffCallback(mGalleryModels,galleryModels),true);
165+
// mGalleryModels = galleryModels;
166+
// result.dispatchUpdatesTo(this);
131167
/*if there is just camera item in it*/
132168
boolean firstItemIsCamera=false;
133169
if (mGalleryModels.size()>0 && mGalleryModels.get(0).getId()==0){
@@ -290,6 +326,13 @@ public boolean onLongClick(View v) {
290326
}
291327
});
292328
btnZoomOut.setOnClickListener(v->{
329+
if (mZoomButtonClicked){
330+
return;
331+
}
332+
mZoomButtonClicked=true;
333+
btnZoomOut.postDelayed(()->{
334+
mZoomButtonClicked=false;
335+
},300);
293336
if (mOnZoomOutClickListener != null) {
294337
mOnZoomOutClickListener.onItemClicked(mGalleryModels.get(getAdapterPosition()),mImageView,getAdapterPosition());
295338
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import android.content.Context;
44
import android.util.AttributeSet;
5+
import android.util.DisplayMetrics;
56

67
import androidx.recyclerview.widget.GridLayoutManager;
8+
import androidx.recyclerview.widget.LinearSmoothScroller;
9+
import androidx.recyclerview.widget.RecyclerView;
710

811
public class GalleryLayoutManager extends GridLayoutManager {
912
public GalleryLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@@ -22,4 +25,34 @@ public GalleryLayoutManager(Context context, int spanCount, int orientation, boo
2225
public boolean supportsPredictiveItemAnimations() {
2326
return false;
2427
}
28+
29+
@Override
30+
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
31+
32+
startSmoothScroll(new Scroller(recyclerView.getContext(),position));
33+
}
34+
35+
public static class Scroller extends LinearSmoothScroller {
36+
37+
public Scroller(Context context,int targetPosition) {
38+
super(context);
39+
setTargetPosition(targetPosition);
40+
41+
}
42+
43+
44+
45+
@Override
46+
protected int calculateTimeForScrolling(int dx) {
47+
return 800;
48+
}
49+
50+
@Override
51+
protected int calculateTimeForDeceleration(int dx) {
52+
return 200;
53+
}
54+
55+
56+
57+
}
2558
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,39 @@
22

33
import android.content.Context;
44
import android.util.AttributeSet;
5+
import android.util.DisplayMetrics;
56

67
import androidx.annotation.NonNull;
78
import androidx.annotation.Nullable;
89
import androidx.appcompat.widget.AppCompatImageView;
910

11+
import ir.smartdevelopers.smartfilebrowser.R;
12+
1013
public class SquareImageView extends AppCompatImageView {
14+
private int size=0;
1115
public SquareImageView(@NonNull Context context) {
12-
super(context);
16+
this(context,null);
1317
}
1418

1519
public SquareImageView(@NonNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs) {
16-
super(context, attrs);
20+
this(context, attrs,0);
1721
}
1822

1923
public SquareImageView(@NonNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs, int defStyleAttr) {
2024
super(context, attrs, defStyleAttr);
25+
DisplayMetrics metrics=getResources().getDisplayMetrics();
26+
int deviceWidth=metrics.widthPixels;
27+
int gapSize=getResources().getDimensionPixelSize(R.dimen.sfb_gallery_gap_size);
28+
int imageCount=getResources().getInteger(R.integer.sfb_gallery_grid);
29+
int gapCount=imageCount+1;
30+
size=(deviceWidth-(gapSize*gapCount))/imageCount;
31+
2132
}
2233

2334
@Override
2435
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
25-
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
36+
super.onMeasure(MeasureSpec.makeMeasureSpec(size,MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(size,MeasureSpec.EXACTLY));
2637
}
38+
39+
2740
}

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,40 @@
33
import android.content.Context;
44
import android.os.Build;
55
import android.util.AttributeSet;
6+
import android.util.DisplayMetrics;
67
import android.widget.FrameLayout;
78

89
import androidx.annotation.NonNull;
910
import androidx.annotation.Nullable;
1011
import androidx.annotation.RequiresApi;
1112

13+
import ir.smartdevelopers.smartfilebrowser.R;
14+
1215
public class SquareLayout extends FrameLayout {
16+
private int size=0;
17+
1318
public SquareLayout(@NonNull Context context) {
14-
super(context);
19+
this(context,null);
1520
}
1621

17-
public SquareLayout(@NonNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs) {
18-
super(context, attrs);
22+
public SquareLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
23+
this(context, attrs,0);
1924
}
2025

2126
public SquareLayout(@NonNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs, int defStyleAttr) {
2227
super(context, attrs, defStyleAttr);
28+
DisplayMetrics metrics=getResources().getDisplayMetrics();
29+
int deviceWidth=metrics.widthPixels;
30+
int gapSize=getResources().getDimensionPixelSize(R.dimen.sfb_gallery_gap_size);
31+
int imageCount=getResources().getInteger(R.integer.sfb_gallery_grid);
32+
int gapCount=imageCount+1;
33+
size=(deviceWidth-(gapSize*gapCount))/imageCount;
2334
}
2435

25-
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
26-
public SquareLayout(@NonNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
27-
super(context, attrs, defStyleAttr, defStyleRes);
28-
}
36+
2937

3038
@Override
3139
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
32-
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
40+
super.onMeasure(MeasureSpec.makeMeasureSpec(size,MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(size,MeasureSpec.EXACTLY));
3341
}
3442
}

SmartFileBrowser/src/main/java/ir/smartdevelopers/smartfilebrowser/models/GalleryModel.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.net.Uri;
44

55
import java.io.File;
6+
import java.util.Objects;
67

78
import ir.smartdevelopers.smartfilebrowser.customClasses.FileUtil;
89
import ir.smartdevelopers.smartfilebrowser.customClasses.Utils;
@@ -129,4 +130,17 @@ public void setDuration(long duration) {
129130
public String getDurationTime(){
130131
return Utils.formatTime(duration);
131132
}
133+
134+
@Override
135+
public boolean equals(Object o) {
136+
if (this == o) return true;
137+
if (o == null || getClass() != o.getClass()) return false;
138+
GalleryModel that = (GalleryModel) o;
139+
return id == that.id;
140+
}
141+
142+
@Override
143+
public int hashCode() {
144+
return Objects.hash(id);
145+
}
132146
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<ir.smartdevelopers.smartfilebrowser.customClasses.SquareLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4-
android:layout_width="match_parent"
4+
android:layout_width="wrap_content"
55
android:layout_height="wrap_content"
66

77
xmlns:app="http://schemas.android.com/apk/res-auto">
88
<ir.smartdevelopers.smartfilebrowser.customClasses.SquareImageView
99
android:id="@+id/item_gallery_image"
10-
android:layout_width="match_parent"
11-
android:layout_height="match_parent"
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
1212
android:scaleType="centerCrop"
1313
android:background="#9C9C9C"
1414
tools:ignore="ContentDescription" />

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
jcenter()
1010
}
1111
dependencies {
12-
classpath "com.android.tools.build:gradle:7.0.3"
12+
classpath "com.android.tools.build:gradle:7.0.4"
1313

1414
// NOTE: Do not place your application dependencies here; they belong
1515
// in the individual module build.gradle files

0 commit comments

Comments
 (0)