Option to exclude albums in Phimpme Android Application
In the Phimpme Android Application, users can perform various operations on the albums available such as move, creating a .zip file of the album, rename an album, delete the album and much more. However one another important functionality that has been implemented in the application is the option to exclude album/albums. In this post we will be discussing how we achieved the functionality to exclude albums in Phimpme Android Application.
Step 1
First we need to keep track of the albums selected by the user to exclude. This can be done by storing the selected albums in an Arraylist<Album> which can be referred later when required for the process of exclusion. The storing of the albums can be done with the help of following lines of code.
private int toggleSelectAlbum(int index) { if (dispAlbums.get(index) != null) { dispAlbums.get(index).setSelected(!dispAlbums.get(index).isSelected()); if (dispAlbums.get(index).isSelected()) selectedAlbums.add(dispAlbums.get(index)); else selectedAlbums.remove(dispAlbums.get(index)); } return index; } |
Step 2
After the selected albums are stored in an Arraylist<Album>, a function call of excludeSelectedAlbums() of HandlingAlbums class is done passing in Context as the parameter. In the method excludeSelectedAlbums() the selected albums are retrieved from the Arraylist one by one and another method excludeAlbum() is called with the album, context being passed as the parameters. The code snippet performing the above operation is provided below.
public void excludeSelectedAlbums(Context context) { for (Album selectedAlbum : selectedAlbums) excludeAlbum(context, selectedAlbum); clearSelectedAlbums(); } |
Step 3
Thereafter an instance of class CustomsAlbumHelper is created and excludeAlbum() method is called with path of the album passed as parameter, and the selected album is removed from the list containing the currently displayed albums. Code snippets for the above operations are provided below.
private void excludeAlbum(Context context, Album a) { CustomAlbumsHelper h = CustomAlbumsHelper.getInstance(context); h.excludeAlbum(a.getPath()); dispAlbums.remove(a); } |
Step 4
Now in the excludeAlbum() method of CustomsAlbumHelper class a writable instance of albums_settings sqlite database is obtained. A check is performed if the current album is present in the albums table or not, if not then a row representing the current album is created. Thereafter the excluded value for the current album in the table is updated to integer 1 denoting that the album is excluded. The code snippet required for the above mentioned operations are provided below.
public void excludeAlbum(String path) { SQLiteDatabase db = this.getWritableDatabase(); checkAndCreateAlbum(db, path); ContentValues values = new ContentValues(); values.put(ALBUM_EXCLUDED, 1); db.update(TABLE_ALBUMS, values, ALBUM_PATH+“=?”, new String[]{ path}); db.close(); } |
This is how we have achieved the functionality of excluding albums in the Phimpme Android application. To get the full source code, please refer to the Phimpme Android GitHub repository listed in the resources section below.
The screenshot for the display of the excluded albums is provided below.
Resources
- Android Developer Guide –https://developer.android.com/training/data-storage/sqlite.html
- Github-Phimpme Android Repository –https://github.com/fossasia/phimpme-android/
- Sqlite Operations Tutorial – https://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
You must be logged in to post a comment.