Search in sources :

Example 1 with DBAccessHelper

use of com.jams.music.player.DBHelpers.DBAccessHelper in project JamsMusicPlayer by psaravan.

the class AsyncRemovePinnedSongsTask method doInBackground.

@Override
protected Boolean doInBackground(String... params) {
    //Delete the specified local copies of the song(s) and remove the local copy reference from the DB.
    Cursor cursor = null;
    DBAccessHelper dbHelper = new DBAccessHelper(mContext);
    if (mSmartPlaylistCursor == null) {
        mSelection += " AND " + DBAccessHelper.SONG_SOURCE + "=" + "'GOOGLE_PLAY_MUSIC'";
        cursor = dbHelper.getAllSongsSearchable(mSelection);
    } else {
        cursor = mSmartPlaylistCursor;
    }
    if (cursor != null) {
        for (int i = 0; i < cursor.getCount(); i++) {
            try {
                cursor.moveToPosition(i);
                String localCopyPath = cursor.getString(cursor.getColumnIndex(DBAccessHelper.LOCAL_COPY_PATH));
                String songID = cursor.getString(cursor.getColumnIndex(DBAccessHelper.SONG_ID));
                File file = new File(localCopyPath);
                if (file != null && file.exists()) {
                    file.delete();
                }
                String selection = DBAccessHelper.SONG_ID + "=" + "'" + songID + "'";
                ContentValues values = new ContentValues();
                values.put(DBAccessHelper.LOCAL_COPY_PATH, "");
                dbHelper.getWritableDatabase().update(DBAccessHelper.MUSIC_LIBRARY_TABLE, values, selection, null);
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
        }
    }
    if (dbHelper != null) {
        dbHelper.close();
        dbHelper = null;
    }
    return true;
}
Also used : ContentValues(android.content.ContentValues) DBAccessHelper(com.jams.music.player.DBHelpers.DBAccessHelper) Cursor(android.database.Cursor) File(java.io.File)

Example 2 with DBAccessHelper

use of com.jams.music.player.DBHelpers.DBAccessHelper in project JamsMusicPlayer by psaravan.

the class ID3sArtistEditorDialog method getAllSongsByArtist.

public static ArrayList<String> getAllSongsByArtist(String artistName) {
    ArrayList<String> songURIsList = new ArrayList<String>();
    DBAccessHelper dbHelper = new DBAccessHelper(parentActivity);
    //Escape any rogue apostrophes.
    if (artistName.contains("'")) {
        artistName = artistName.replace("'", "''");
    }
    String selection = DBAccessHelper.SONG_ARTIST + "=" + "'" + artistName + "'" + " AND " + DBAccessHelper.SONG_SOURCE + "<>" + "'GOOGLE_PLAY_MUSIC'";
    String[] projection = { DBAccessHelper._ID, DBAccessHelper.SONG_FILE_PATH };
    Cursor cursor = dbHelper.getWritableDatabase().query(DBAccessHelper.MUSIC_LIBRARY_TABLE, projection, selection, null, null, null, null);
    cursor.moveToFirst();
    if (cursor.getCount() != 0) {
        songURIsList.add(cursor.getString(1));
        while (cursor.moveToNext()) {
            songURIsList.add(cursor.getString(1));
        }
    }
    cursor.close();
    return songURIsList;
}
Also used : DBAccessHelper(com.jams.music.player.DBHelpers.DBAccessHelper) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 3 with DBAccessHelper

use of com.jams.music.player.DBHelpers.DBAccessHelper in project JamsMusicPlayer by psaravan.

the class ID3sSongEditorDialog method saveSongTags.

//This method is called if the user touches the 'OK' button when they're editing an individual song's tags.
public boolean saveSongTags(String uri) {
    File file = new File(uri);
    AudioFile audioFile = null;
    //Update the DB entries.
    DBAccessHelper dbHelper = new DBAccessHelper(mContext.getApplicationContext());
    //Escape any rogue apostrophes.
    if (SONG_URI.contains("'")) {
        SONG_URI = SONG_URI.replace("'", "''");
    }
    String whereClause = DBAccessHelper.SONG_FILE_PATH + "=" + "'" + SONG_URI + "'";
    ContentValues values = new ContentValues();
    try {
        audioFile = AudioFileIO.read(file);
    } catch (CannotReadException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TagException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ReadOnlyFileException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidAudioFrameException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Tag tag = audioFile.getTag();
    if (tag != null) {
        if (titleEdited == false) {
        //Don't do anything here. The user didn't change the title.
        } else {
            try {
                tag.setField(FieldKey.TITLE, titleEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String title = titleEditText.getText().toString();
            if (title.contains("'")) {
                title = title.replace("'", "''");
            }
            values.put(DBAccessHelper.SONG_TITLE, title);
        }
        if (albumEdited == false) {
        //Don't do anything here. The user didn't change the album.
        } else {
            try {
                tag.setField(FieldKey.ALBUM, albumEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String album = albumEditText.getText().toString();
            if (album.contains("'")) {
                album = album.replace("'", "''");
            }
            values.put(DBAccessHelper.SONG_ALBUM, album);
        }
        if (artistEdited == false) {
        //Don't do anything here. The user didn't change the artist.
        } else {
            try {
                tag.setField(FieldKey.ARTIST, artistEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String artist = artistEditText.getText().toString();
            if (artist.contains("'")) {
                artist = artist.replace("'", "''");
            }
            values.put(DBAccessHelper.SONG_ARTIST, artist);
        }
        if (albumArtistEdited == false) {
        //Don't do anything here. The user didn't change the album artist.
        } else {
            try {
                tag.setField(FieldKey.ALBUM_ARTIST, albumArtistEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String albumArtist = albumArtistEditText.getText().toString();
            if (albumArtist.contains("'")) {
                albumArtist = albumArtist.replace("'", "''");
            }
            values.put(DBAccessHelper.SONG_ALBUM_ARTIST, albumArtist);
        }
        if (genreEdited == false) {
        //Don't do anything here. The user didn't change the genre.
        } else {
            try {
                tag.setField(FieldKey.GENRE, genreEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        if (producerEdited == false) {
        //Don't do anything here. The user didn't change the producer.
        } else {
            try {
                tag.setField(FieldKey.PRODUCER, producerEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        if (yearEdited == false) {
        //Don't do anything here. The user didn't change the year.
        } else {
            try {
                tag.setField(FieldKey.YEAR, yearEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String year = yearEditText.getText().toString();
            if (year.contains("'")) {
                year = year.replace("'", "''");
            }
            values.put(DBAccessHelper.SONG_YEAR, year);
        }
        if (trackEdited == false) {
        //Don't do anything here. The user didn't change the track number.
        } else {
            try {
                tag.setField(FieldKey.TRACK, trackEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NumberFormatException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String track = trackEditText.getText().toString();
            if (track.contains("'")) {
                track = track.replace("'", "''");
            }
            values.put(DBAccessHelper.SONG_TRACK_NUMBER, track);
        }
        try {
            tag.setField(FieldKey.TRACK_TOTAL, trackTotalEditText.getText().toString());
        } catch (KeyNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FieldDataInvalidException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchElementException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NumberFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (commentEdited == false) {
        //Don't do anything here. The user didn't change the comments.
        } else {
            try {
                tag.setField(FieldKey.COMMENT, commentsEditText.getText().toString());
            } catch (KeyNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (FieldDataInvalidException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NoSuchElementException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        try {
            audioFile.commit();
        } catch (CannotWriteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //Write the values to the DB.
        if (values.size() != 0) {
            //Write the values to the DB.
            try {
                dbHelper.getWritableDatabase().update(DBAccessHelper.MUSIC_LIBRARY_TABLE, values, whereClause, null);
                dbHelper.close();
                dbHelper = null;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        Toast.makeText(mContext, R.string.unable_to_edit_song_tags, Toast.LENGTH_SHORT).show();
    }
    return true;
}
Also used : ContentValues(android.content.ContentValues) CannotWriteException(org.jaudiotagger.audio.exceptions.CannotWriteException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) DBAccessHelper(com.jams.music.player.DBHelpers.DBAccessHelper) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) IOException(java.io.IOException) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) FieldDataInvalidException(org.jaudiotagger.tag.FieldDataInvalidException) NoSuchElementException(java.util.NoSuchElementException) CannotWriteException(org.jaudiotagger.audio.exceptions.CannotWriteException) KeyNotFoundException(org.jaudiotagger.tag.KeyNotFoundException) IOException(java.io.IOException) TagException(org.jaudiotagger.tag.TagException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) AudioFile(org.jaudiotagger.audio.AudioFile) TagException(org.jaudiotagger.tag.TagException) FieldDataInvalidException(org.jaudiotagger.tag.FieldDataInvalidException) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) Tag(org.jaudiotagger.tag.Tag) AudioFile(org.jaudiotagger.audio.AudioFile) File(java.io.File) KeyNotFoundException(org.jaudiotagger.tag.KeyNotFoundException) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with DBAccessHelper

use of com.jams.music.player.DBHelpers.DBAccessHelper in project JamsMusicPlayer by psaravan.

the class MusicLibraryEditorActivity method onCreate.

@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
    //Initialize Context and SharedPreferences.
    mContext = this;
    mApp = (Common) mContext.getApplicationContext();
    //Retrieve the name/icon of the library from the arguments.
    libraryName = getIntent().getExtras().getString("LIBRARY_NAME");
    libraryIconName = getIntent().getExtras().getString("LIBRARY_ICON");
    if (getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET") != null) {
        songDBIdsList = (HashSet<String>) getIntent().getExtras().getSerializable("SONG_IDS_HASH_SET");
    }
    //Set the UI theme.
    if (mApp.getCurrentTheme() == Common.DARK_THEME) {
        setTheme(R.style.AppTheme);
    } else {
        setTheme(R.style.AppThemeLight);
    }
    super.onCreate(savedInstanceState);
    //Initialize the database helper.
    dbHelper = new DBAccessHelper(mContext.getApplicationContext());
    //Create a set of options to optimize the bitmap memory usage.
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;
    //Display Image Options.
    int defaultArt = UIElementsHelper.getIcon(mContext, "default_album_art_padded");
    displayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.default_album_art).showImageOnFail(R.drawable.default_album_art).showStubImage(R.drawable.transparent_drawable).cacheInMemory(false).cacheOnDisc(true).decodingOptions(options).imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(400)).delayBeforeLoading(100).build();
    //Attach tabs to the ActionBar.
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //Add the artists tab.
    String artistsLabel = getResources().getString(R.string.artists);
    Tab tab = actionBar.newTab();
    tab.setText(artistsLabel);
    TabListener<ArtistsPickerFragment> artistsTabListener = new TabListener<ArtistsPickerFragment>(this, artistsLabel, ArtistsPickerFragment.class);
    tab.setTabListener(artistsTabListener);
    actionBar.addTab(tab);
    //Add the albums tab.
    String albumsLabel = getResources().getString(R.string.albums);
    tab = actionBar.newTab();
    tab.setText(albumsLabel);
    TabListener<AlbumsPickerFragment> albumsTabListener = new TabListener<AlbumsPickerFragment>(this, albumsLabel, AlbumsPickerFragment.class);
    tab.setTabListener(albumsTabListener);
    actionBar.addTab(tab);
    //Add the songs tab.
    String songsLabel = getResources().getString(R.string.songs);
    tab = actionBar.newTab();
    tab.setText(songsLabel);
    TabListener<SongsPickerFragment> songsTabListener = new TabListener<SongsPickerFragment>(this, songsLabel, SongsPickerFragment.class);
    tab.setTabListener(songsTabListener);
    actionBar.addTab(tab);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
        int topPadding = Common.getStatusBarHeight(mContext);
        View activityView = (View) findViewById(android.R.id.content);
        //Calculate ActionBar height
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        }
        if (activityView != null) {
            activityView.setPadding(0, topPadding + actionBarHeight, 0, 0);
        }
    }
}
Also used : DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions) DBAccessHelper(com.jams.music.player.DBHelpers.DBAccessHelper) SpannableString(android.text.SpannableString) View(android.view.View) Tab(android.app.ActionBar.Tab) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) BitmapFactory(android.graphics.BitmapFactory) ActionBar(android.app.ActionBar) TypedValue(android.util.TypedValue)

Example 5 with DBAccessHelper

use of com.jams.music.player.DBHelpers.DBAccessHelper in project JamsMusicPlayer by psaravan.

the class ID3sArtistEditorDialog method getAllSongsInAlbum.

public static ArrayList<String> getAllSongsInAlbum(String albumName, String artistName) {
    ArrayList<String> songURIsList = new ArrayList<String>();
    DBAccessHelper dbHelper = new DBAccessHelper(parentActivity);
    //Escape any rogue apostrophes.
    if (albumName.contains("'")) {
        albumName = albumName.replace("'", "''");
    }
    if (artistName.contains("'")) {
        artistName = artistName.replace("'", "''");
    }
    String selection = DBAccessHelper.SONG_ALBUM + "=" + "'" + albumName + "'" + " AND " + DBAccessHelper.SONG_ARTIST + "=" + "'" + artistName + "'" + " AND " + DBAccessHelper.SONG_SOURCE + "<>" + "'GOOGLE_PLAY_MUSIC'";
    String[] projection = { DBAccessHelper._ID, DBAccessHelper.SONG_FILE_PATH };
    Cursor cursor = dbHelper.getWritableDatabase().query(DBAccessHelper.MUSIC_LIBRARY_TABLE, projection, selection, null, null, null, null);
    cursor.moveToFirst();
    if (cursor.getCount() != 0) {
        songURIsList.add(cursor.getString(1));
        while (cursor.moveToNext()) {
            songURIsList.add(cursor.getString(1));
        }
    }
    cursor.close();
    return songURIsList;
}
Also used : DBAccessHelper(com.jams.music.player.DBHelpers.DBAccessHelper) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

DBAccessHelper (com.jams.music.player.DBHelpers.DBAccessHelper)8 Cursor (android.database.Cursor)4 File (java.io.File)3 ContentValues (android.content.ContentValues)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AudioFile (org.jaudiotagger.audio.AudioFile)2 CannotReadException (org.jaudiotagger.audio.exceptions.CannotReadException)2 CannotWriteException (org.jaudiotagger.audio.exceptions.CannotWriteException)2 InvalidAudioFrameException (org.jaudiotagger.audio.exceptions.InvalidAudioFrameException)2 ReadOnlyFileException (org.jaudiotagger.audio.exceptions.ReadOnlyFileException)2 Tag (org.jaudiotagger.tag.Tag)2 TagException (org.jaudiotagger.tag.TagException)2 ActionBar (android.app.ActionBar)1 Tab (android.app.ActionBar.Tab)1 BitmapFactory (android.graphics.BitmapFactory)1 SpannableString (android.text.SpannableString)1 TypedValue (android.util.TypedValue)1 View (android.view.View)1 WebView (android.webkit.WebView)1