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

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

Open
engr-erum opened this issue Dec 27, 2014 · 11 comments
Open

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

engr-erum opened this issue Dec 27, 2014 · 11 comments

Comments

@engr-erum
Copy link

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
Copy link
Owner

Slake07 commented Dec 27, 2014

have you update your listview onresume of your activity.?

@engr-erum
Copy link
Author

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
Copy link
Owner

Slake07 commented Dec 27, 2014

what is the code of setAlbum method?

@engr-erum
Copy link
Author

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
Copy link
Owner

Slake07 commented Dec 29, 2014

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

@engr-erum
Copy link
Author

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
Copy link
Author

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

@engr-erum
Copy link
Author

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
Copy link
Author

@Slake07 can u pls respond me ?

@Slake07
Copy link
Owner

Slake07 commented Dec 30, 2014

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
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants