// Path: app/src/main/java/com/zsorg/neteasecloudmusic/models/beans/MusicBean.java
// public class MusicBean implements Parcelable{
//     private final String mSinger;
//     private final String mAlbum;
//     private String mPath;
//     private String mName;
//     private long mDuration;
// 
//     protected MusicBean(Parcel in) {
//         mSinger = in.readString();
//         mAlbum = in.readString();
//         mPath = in.readString();
//         mName = in.readString();
//         mDuration = in.readLong();
//     }
// 
//     public static final Creator<MusicBean> CREATOR = new Creator<MusicBean>() {
//         @Override
//         public MusicBean createFromParcel(Parcel in) {
//             return new MusicBean(in);
//         }
// 
//         @Override
//         public MusicBean[] newArray(int size) {
//             return new MusicBean[size];
//         }
//     };
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel parcel, int i) {
// 
//         parcel.writeString(mSinger);
//         parcel.writeString(mAlbum);
//         parcel.writeString(mPath);
//         parcel.writeString(mName);
//         parcel.writeLong(mDuration);
//     }
// 
//     @Override
//     public int hashCode() {
//         return mPath==null?0:mPath.hashCode();
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         return obj instanceof MusicBean && (((MusicBean) obj).hashCode()==hashCode());
//     }
// 
//     public MusicBean(String name, String singer, String album, long duration, String path) {
//         mPath = path;
//         mName = name;
//         mSinger = singer;
//         mAlbum = album;
//         mDuration = duration;
//     }
// 
//     public String getSinger() {
//         return mSinger;
//     }
// 
//     public String getAlbum() {
//         return mAlbum;
//     }
// 
//     public String getPath() {
//         return mPath;
//     }
// 
//     public void setPath(String mPath) {
//         this.mPath = mPath;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// 
//     public void setName(String mName) {
//         this.mName = mName;
//     }
// 
//     public long getDuration() {
//         return mDuration;
//     }
// 
//     public void setDuration(long mDuration) {
//         this.mDuration = mDuration;
//     }
// }
// 
// Path: app/src/main/java/com/zsorg/neteasecloudmusic/utils/MusicUtil.java
// public class MusicUtil {
// 
//     public static boolean isMusic(File file) {
//         return null!=file && file.getName().toLowerCase().endsWith(".mp3");
//     }
// 
//     public static String getAlbumArt(Context mContext, String album_id) {
//         String[] projection = new String[]{MediaStore.Audio.Albums.ALBUM_ART};
//         Cursor cur = mContext.getContentResolver().query(
//                 MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
//                 projection, MediaStore.Audio.Albums._ID + "=?", new String[]{album_id}, null);
//         String album_art = null;
//         if (null!=cur && cur.moveToNext()) {
//             album_art = cur.getString(0);
//             cur.close();
//         }
// 
//         return album_art;
//     }
// 
//     public static String[] getParentAndFileName(String path) {
//         if (null!=path) {
//             int lastIndex = path.lastIndexOf(File.separatorChar);
//             if (lastIndex == path.length() - 1 && lastIndex > 0) {
//                 String tmp = path.substring(0, lastIndex);
//                 lastIndex = tmp.lastIndexOf(File.separatorChar);
//             }
//             String parent = path.substring(0, lastIndex+1);
//             String name = path.substring(lastIndex+1, path.length());
//             return new String[]{parent,name};
//         }
//         return new String[]{path,path};
//     }
// }


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import com.zsorg.neteasecloudmusic.models.beans.MusicBean;
import com.zsorg.neteasecloudmusic.utils.MusicUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
        mDBHelper.getWritableDatabase().execSQL("delete from diskMusic where album"+(null==album?" is null":"==\""+album.replace("\"", "\\\"")+"\";"));
    }

    public void deleteSingerMusicList(String singer) {
        mDBHelper.getWritableDatabase().execSQL("delete from diskMusic where singer"+(null==singer?" is null":"==\""+singer.replace("\"", "\\\"")+"\";"));
    }

    public List<MusicBean> queryAlbumList() {
        Cursor cursor = mDBHelper.getReadableDatabase().rawQuery("select singer,album,path,count(path) from diskMusic group by album order by album desc;", null);
        List<MusicBean> list = new ArrayList<>();
        while (null != cursor && cursor.moveToNext()) {
            String singer = cursor.getString(0);
            String album = cursor.getString(1);
            String path = cursor.getString(2);
            int count = cursor.getInt(3);
            list.add(new MusicBean( null, singer, album,count, path));
        }
        if (cursor != null) {
            cursor.close();
        }
        return list;
    }

    public List<MusicBean> queryPathList() {
        Cursor cursor = mDBHelper.getReadableDatabase().rawQuery("select parent,path,count(parent) from diskMusic group by parent order by parent desc;", null);
        List<MusicBean> list = new ArrayList<>();
        while (null != cursor && cursor.moveToNext()) {
            String parent = cursor.getString(0);
            String path = cursor.getString(1);
            int count = cursor.getInt(2);
// Path: app/src/main/java/com/zsorg/neteasecloudmusic/models/beans/MusicBean.java
// public class MusicBean implements Parcelable{
//     private final String mSinger;
//     private final String mAlbum;
//     private String mPath;
//     private String mName;
//     private long mDuration;
// 
//     protected MusicBean(Parcel in) {
//         mSinger = in.readString();
//         mAlbum = in.readString();
//         mPath = in.readString();
//         mName = in.readString();
//         mDuration = in.readLong();
//     }
// 
//     public static final Creator<MusicBean> CREATOR = new Creator<MusicBean>() {
//         @Override
//         public MusicBean createFromParcel(Parcel in) {
//             return new MusicBean(in);
//         }
// 
//         @Override
//         public MusicBean[] newArray(int size) {
//             return new MusicBean[size];
//         }
//     };
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel parcel, int i) {
// 
//         parcel.writeString(mSinger);
//         parcel.writeString(mAlbum);
//         parcel.writeString(mPath);
//         parcel.writeString(mName);
//         parcel.writeLong(mDuration);
//     }
// 
//     @Override
//     public int hashCode() {
//         return mPath==null?0:mPath.hashCode();
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         return obj instanceof MusicBean && (((MusicBean) obj).hashCode()==hashCode());
//     }
// 
//     public MusicBean(String name, String singer, String album, long duration, String path) {
//         mPath = path;
//         mName = name;
//         mSinger = singer;
//         mAlbum = album;
//         mDuration = duration;
//     }
// 
//     public String getSinger() {
//         return mSinger;
//     }
// 
//     public String getAlbum() {
//         return mAlbum;
//     }
// 
//     public String getPath() {
//         return mPath;
//     }
// 
//     public void setPath(String mPath) {
//         this.mPath = mPath;
//     }
// 
//     public String getName() {
//         return mName;
//     }
// 
//     public void setName(String mName) {
//         this.mName = mName;
//     }
// 
//     public long getDuration() {
//         return mDuration;
//     }
// 
//     public void setDuration(long mDuration) {
//         this.mDuration = mDuration;
//     }
// }
// 
// Path: app/src/main/java/com/zsorg/neteasecloudmusic/utils/MusicUtil.java
// public class MusicUtil {
// 
//     public static boolean isMusic(File file) {
//         return null!=file && file.getName().toLowerCase().endsWith(".mp3");
//     }
// 
//     public static String getAlbumArt(Context mContext, String album_id) {
//         String[] projection = new String[]{MediaStore.Audio.Albums.ALBUM_ART};
//         Cursor cur = mContext.getContentResolver().query(
//                 MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
//                 projection, MediaStore.Audio.Albums._ID + "=?", new String[]{album_id}, null);
//         String album_art = null;
//         if (null!=cur && cur.moveToNext()) {
//             album_art = cur.getString(0);
//             cur.close();
//         }
// 
//         return album_art;
//     }
// 
//     public static String[] getParentAndFileName(String path) {
//         if (null!=path) {
//             int lastIndex = path.lastIndexOf(File.separatorChar);
//             if (lastIndex == path.length() - 1 && lastIndex > 0) {
//                 String tmp = path.substring(0, lastIndex);
//                 lastIndex = tmp.lastIndexOf(File.separatorChar);
//             }
//             String parent = path.substring(0, lastIndex+1);
//             String name = path.substring(lastIndex+1, path.length());
//             return new String[]{parent,name};
//         }
//         return new String[]{path,path};
//     }
// }


// Path: app/src/main/java/com/zsorg/neteasecloudmusic/models/db/DiskMusicDao.java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import com.zsorg.neteasecloudmusic.models.beans.MusicBean;
import com.zsorg.neteasecloudmusic.utils.MusicUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

        mDBHelper.getWritableDatabase().execSQL("delete from diskMusic where album"+(null==album?" is null":"==\""+album.replace("\"", "\\\"")+"\";"));
    }

    public void deleteSingerMusicList(String singer) {
        mDBHelper.getWritableDatabase().execSQL("delete from diskMusic where singer"+(null==singer?" is null":"==\""+singer.replace("\"", "\\\"")+"\";"));
    }

    public List<MusicBean> queryAlbumList() {
        Cursor cursor = mDBHelper.getReadableDatabase().rawQuery("select singer,album,path,count(path) from diskMusic group by album order by album desc;", null);
        List<MusicBean> list = new ArrayList<>();
        while (null != cursor && cursor.moveToNext()) {
            String singer = cursor.getString(0);
            String album = cursor.getString(1);
            String path = cursor.getString(2);
            int count = cursor.getInt(3);
            list.add(new MusicBean( null, singer, album,count, path));
        }
        if (cursor != null) {
            cursor.close();
        }
        return list;
    }

    public List<MusicBean> queryPathList() {
        Cursor cursor = mDBHelper.getReadableDatabase().rawQuery("select parent,path,count(parent) from diskMusic group by parent order by parent desc;", null);
        List<MusicBean> list = new ArrayList<>();
        while (null != cursor && cursor.moveToNext()) {
            String parent = cursor.getString(0);
            String path = cursor.getString(1);
            int count = cursor.getInt(2);
            String[] parentAndFileName = MusicUtil.getParentAndFileName(parent);