Slake07 / MyGallery

Custom gallery view with multiple selection
1 stars 0 forks source link

on Done button click i want updated no of images of all albums ? #2

Open engr-erum opened 9 years ago

engr-erum commented 9 years ago

i have open album and then i see all images inside album i select two images and then i have button for delete images from the gallery no i finish activity and i return back to the same activity that contains list of albums and their total no of images .....images are deleted from gallery but my activity is not showing updated no of immags in albums i m calling code for setAlbum in onResume but that is showing me same no of images

Slake07 commented 9 years ago

have you update your listview onresume of your activity.?

engr-erum commented 9 years ago

i have called these two methods in onResume : initImageLoader(); setAlbum(); and they are already present inside java file : GalleryActivity.java and they are updating gridview and getting current data as well but still no luck right now some times its getting data like total images are : 15 i removed 3 then its showing me 14 instead of 12

Slake07 commented 9 years ago

what is the code of setAlbum method?

engr-erum commented 9 years ago

public static void setAlbum(){ Log.d(TAG,"setAlbum called"); ArrayList mAlbumsList = new ArrayList();

     Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID,MediaStore.Images.Thumbnails._ID,
                MediaStore.Images.Media.BUCKET_DISPLAY_NAME };

        Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
        ArrayList<String> ids = new ArrayList<String>();
        mAlbumsList.clear();
        if (cursor != null) {
            while (cursor.moveToNext()) {
                Album album = new Album();

                int columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);
                album.id = cursor.getString(columnIndex);

                if (!ids.contains(album.id)) {
                    columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
                    album.name = cursor.getString(columnIndex);

                    columnIndex = cursor.getColumnIndex(MediaStore.Images.Media._ID);
                    album.coverID = cursor.getLong(columnIndex);

                    mAlbumsList.add(album);
                    Log.d(TAG,"album.id:"+album.id);
                    Log.d(TAG,"album.name:"+album.name);
                    Log.d(TAG,"album.coverID:"+album.coverID);
                    ids.add(album.id);
                } else {
                    mAlbumsList.get(ids.indexOf(album.id)).count++;
                }
            }
            cursor.close();

        }

        AlbumAdapter adapter = new AlbumAdapter(context, mAlbumsList, imageLoader);
        // gridView = (ListView) context.findViewById(R.id.gridView);
        gridView.setAdapter(adapter);
        Collections.sort(mAlbumsList, myComparator);

        gridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // TODO Auto-generated method stub

                String bid = view.getTag().toString();
                System.out.println("Bucket id = " + bid);
                Intent i = new Intent(context, GridViewActivity.class);
                i.putExtra("bid", bid);

                context.startActivity(i);
                ((Activity)context).finish();

            }
        });
}

static Comparator<Album> myComparator = new Comparator<Album>() {
    public int compare(Album obj1,Album obj2) {
        return obj1.getName().toLowerCase().compareTo(obj2.getName().toLowerCase());
    }
 };
Slake07 commented 9 years ago

i think problem is in your count of album..or you have to refresh gallery for that.

engr-erum commented 9 years ago

my gallery is refreshing fine but issue is in count of individual album can u pls tell me how can i resolve this ??? @Override public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.album_row, null);
    }

    TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
    tvName.setText(items.get(position).getName());

    TextView tvCount = (TextView) convertView.findViewById(R.id.tvTotal);
    tvCount.setText(items.get(position).getCount()+"");
    System.out.println(items.get(position).getName()+": "+items.get(position).getCount());

the issue is in this line items.get(position).getCount() where u r setting in this library ???/

engr-erum commented 9 years ago

i m using this library now my solution stuck just because of this issue

engr-erum commented 9 years ago

i have detect that the error is because of this : before deleting image this cursor is running till 7 times because total number of images are 7 while after deleting image total no of image inside gallery is fine but this loop of cursor is still running till 7 times ......
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_ID,MediaStore.Images.Thumbnails._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME }; Log.d(TAG,"MediaStore.Images.Thumbnails._ID:"+MediaStore.Images.Thumbnails._ID); Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); mAlbumsList.clear(); if (cursor != null) { while (cursor.moveToNext()) {

engr-erum commented 9 years ago

@Slake07 can u pls respond me ?

Slake07 commented 9 years ago

if its still running 7 times that means image not delete or gallery not refreshed. i didnt implement delete on gallery before.. you have to try or else send me your code, i will look into it whenever i will be free.

engr-erum commented 9 years ago

@Slake07 i have uploaded code on dropbox can u pls check this ..... i stuck at this stage i ahve deleted functionality in file "GridViewActivity.java" pls check this https://www.dropbox.com/s/et9vfe4308sgh2x/AlbumCode.rar?dl=0