Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use LinkedHashSet instead of Set to keep image selection order #74

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import android.widget.ImageView;

import java.io.File;
import java.util.HashSet;
import java.util.Iterator;

import nl.changer.polypicker.Config;
import nl.changer.polypicker.ImagePickerActivity;
Expand All @@ -33,7 +31,7 @@ public class MainActivity extends AppCompatActivity {
private Context mContext;

private ViewGroup mSelectedImagesContainer;
HashSet<Uri> mMedia = new HashSet<Uri>();
private Uri[] uris;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -93,15 +91,10 @@ protected void onActivityResult(int requestCode, int resuleCode, Intent intent)
}

// Java doesn't allow array casting, this is a little hack
Uri[] uris = new Uri[parcelableUris.length];
uris = new Uri[parcelableUris.length];
System.arraycopy(parcelableUris, 0, uris, 0, parcelableUris.length);

if (uris != null) {
for (Uri uri : uris) {
Log.i(TAG, " uri: " + uri);
mMedia.add(uri);
}

showMedia();
}
}
Expand All @@ -113,14 +106,12 @@ private void showMedia() {
// adding the new ones.
mSelectedImagesContainer.removeAllViews();

Iterator<Uri> iterator = mMedia.iterator();
ImageInternalFetcher imageFetcher = new ImageInternalFetcher(this, 500);
while (iterator.hasNext()) {
Uri uri = iterator.next();
for (Uri uri : uris) {

// showImage(uri);
Log.i(TAG, " uri: " + uri);
if (mMedia.size() >= 1) {
if (uris.length >= 1) {
mSelectedImagesContainer.setVisibility(View.VISIBLE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.LinkedHashSet;

import nl.changer.polypicker.model.Image;
import nl.changer.polypicker.utils.ImageInternalFetcher;
Expand All @@ -35,7 +34,7 @@ public class ImagePickerActivity extends AppCompatActivity {
*/
public static final String EXTRA_IMAGE_URIS = "nl.changer.changer.nl.polypicker.extra.selected_image_uris";

private Set<Image> mSelectedImages;
private LinkedHashSet<Image> mSelectedImages;
private LinearLayout mSelectedImagesContainer;
protected TextView mSelectedImageEmptyMessage;

Expand Down Expand Up @@ -81,7 +80,7 @@ protected void onCreate(Bundle savedInstanceState) {
mCancelButtonView = (Button) findViewById(R.id.pp__btn_cancel);
mDoneButtonView = (Button) findViewById(R.id.pp__btn_done);

mSelectedImages = new HashSet<Image>();
mSelectedImages = new LinkedHashSet<Image>();
mImageFetcher = new ImageInternalFetcher(this, 500);

mCancelButtonView.setOnClickListener(mOnFinishGettingImages);
Expand Down Expand Up @@ -122,7 +121,7 @@ public boolean addImage(Image image) {
// this condition may arise when the activity is being
// restored when sufficient memory is available. onRestoreState()
// will be called.
mSelectedImages = new HashSet<Image>();
mSelectedImages = new LinkedHashSet<Image>();
}

if (mSelectedImages.size() == mConfig.getSelectionLimit()) {
Expand Down