package io.hefuyi.listener.provider; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; /** * Created by hefuyi on 2016/11/5. */ public class MusicDB extends SQLiteOpenHelper{ private static final String DATABASENAME = "musicdb.db"; private static final int VERSION = 1; private static volatile MusicDB sInstance = null; private final Context mContext; private MusicDB(final Context context) { super(context, DATABASENAME, null, VERSION); mContext = context; } public static MusicDB getInstance(final Context context) { if (sInstance == null) { synchronized (MusicDB.class) { if (sInstance == null) { sInstance = new MusicDB(context.getApplicationContext()); } } } return sInstance; } @Override public void onCreate(SQLiteDatabase db) { MusicPlaybackState.getInstance(mContext).onCreate(db); RecentStore.getInstance(mContext).onCreate(db); SongPlayCount.getInstance(mContext).onCreate(db); SearchHistory.getInstance(mContext).onCreate(db); FavoriteSong.getInstance(mContext).onCreate(db); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { MusicPlaybackState.getInstance(mContext).onUpgrade(db, oldVersion, newVersion); RecentStore.getInstance(mContext).onUpgrade(db, oldVersion, newVersion); SongPlayCount.getInstance(mContext).onUpgrade(db, oldVersion, newVersion); SearchHistory.getInstance(mContext).onUpgrade(db, oldVersion, newVersion); FavoriteSong.getInstance(mContext).onUpgrade(db, oldVersion, newVersion); } @Override public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { MusicPlaybackState.getInstance(mContext).onDowngrade(db, oldVersion, newVersion); RecentStore.getInstance(mContext).onDowngrade(db, oldVersion, newVersion); SongPlayCount.getInstance(mContext).onDowngrade(db, oldVersion, newVersion); SearchHistory.getInstance(mContext).onDowngrade(db, oldVersion, newVersion); FavoriteSong.getInstance((mContext)).onDowngrade(db, oldVersion, newVersion); } }