Skip to content

Commit

Permalink
修复图片过多导致异常崩溃问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay committed Mar 27, 2018
1 parent 49e1af6 commit 802d4ce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 45 deletions.
4 changes: 2 additions & 2 deletions daguerre/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
versionCode 7
versionName "1.0.7"
versionCode 8
versionName "1.0.8"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class DaguerreActivity extends AppCompatActivity
MIME_TYPE, BUCKET_DISPLAY_NAME
};

private ArrayList<Media.Resource> mResources = new ArrayList<>();
private ArrayList<Media.Resource> mResources = Media.getResourceStoreInstance().getResources();
private ArrayList<Media.Album> mAlbums = new ArrayList<>();
private RecyclerView mRecyclerView;
private ResourceItemAdapter mAdapter;
Expand Down Expand Up @@ -297,7 +297,6 @@ public void onListItemClick(View itemView) {
int adapterPosition = mRecyclerView.getChildViewHolder(itemView).getAdapterPosition();
Intent intent = new Intent(this, PreviewResourceActivity.class);
intent.putExtra("position", adapterPosition);
intent.putExtra("images", mResources);

ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation(this, itemView.findViewById(R.id.image), "element");
Expand Down
59 changes: 19 additions & 40 deletions daguerre/src/main/java/com/jay/daguerre/internal/Media.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.jay.daguerre.internal;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.jay.daguerre.MimeType;

import java.util.ArrayList;
Expand All @@ -12,7 +8,7 @@
* Created by jay on 2017/11/23 下午3:29
*/
final class Media {
static class Resource implements Parcelable {
static class Resource{
String id;
String data = ""; //file path
// long size;
Expand Down Expand Up @@ -51,41 +47,6 @@ public boolean isGif() {
return mineType != null && mineType.equals(MimeType.GIF);
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
dest.writeString(this.data);
dest.writeString(this.displayName);
dest.writeString(this.mineType);
dest.writeString(this.bucketDisplayName);
dest.writeByte(this.isChecked ? (byte) 1 : (byte) 0);
}

protected Resource(Parcel in) {
this.id = in.readString();
this.data = in.readString();
this.displayName = in.readString();
this.mineType = in.readString();
this.bucketDisplayName = in.readString();
this.isChecked = in.readByte() != 0;
}

public static final Creator<Resource> CREATOR = new Creator<Resource>() {
@Override
public Resource createFromParcel(Parcel source) {
return new Resource(source);
}

@Override
public Resource[] newArray(int size) {
return new Resource[size];
}
};
}

static class Album {
Expand All @@ -94,4 +55,22 @@ static class Album {
ArrayList<Resource> resources = new ArrayList<>();
int resourceCount;
}

static ResourceStore getResourceStoreInstance() {
return ResourceStore.instance;
}

static class ResourceStore{

private ArrayList<Media.Resource> mResources = new ArrayList<>();
static ResourceStore instance = new ResourceStore();

private ResourceStore() {

}

ArrayList<Resource> getResources() {
return mResources;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
int position = intent.getIntExtra("position", 0);
ArrayList<Media.Resource> images = getIntent().getParcelableArrayListExtra("images");
ArrayList<Media.Resource> images = Media.getResourceStoreInstance().getResources();

setContentView(R.layout.daguerre_activity_preview_resource);
Toolbar toolbar = findViewById(R.id.toolbar);
Expand Down

0 comments on commit 802d4ce

Please sign in to comment.