33
This commit is contained in:
+161
@@ -0,0 +1,161 @@
|
||||
package cn.shangyu.gdxzExpert.polyvplayer.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import cn.shangyu.gdxzExpert.bean.PolyvDownloadInfo;
|
||||
|
||||
|
||||
public class PolyvDownloadSQLiteHelper extends SQLiteOpenHelper {
|
||||
private static PolyvDownloadSQLiteHelper sqLiteHelper;
|
||||
private static final String DATABASENAME = "downloadlist.db";
|
||||
private static final int VERSION = 6;
|
||||
|
||||
public static PolyvDownloadSQLiteHelper getInstance(Context context) {
|
||||
if (sqLiteHelper == null) {
|
||||
synchronized (PolyvDownloadSQLiteHelper.class) {
|
||||
if (sqLiteHelper == null)
|
||||
sqLiteHelper = new PolyvDownloadSQLiteHelper(context.getApplicationContext(), DATABASENAME, null, VERSION);
|
||||
}
|
||||
}
|
||||
return sqLiteHelper;
|
||||
}
|
||||
|
||||
private PolyvDownloadSQLiteHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
|
||||
super(context, name, factory, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(
|
||||
"create table if not exists downloadlist(vid varchar(20),title varchar(100),duration varchar(20),filesize int,bitrate int,percent int default 0,total int default 0,img varchar(100),author varchar(20),uuid varchar(100),primary key (vid, bitrate))");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL("drop table if exists downloadlist");
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加下载信息至数据库
|
||||
* @param info
|
||||
*/
|
||||
public void insert(PolyvDownloadInfo info) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "insert into downloadlist(vid,title,duration,filesize,bitrate,img,author,uuid) values(?,?,?,?,?,?,?,?)";
|
||||
db.execSQL(sql, new Object[]{info.getVid(), info.getTitle(), info.getDuration(),info.getFilesize(), info.getBitrate(),info.getHeadImg(),info.getAuthor(),info.getUuid()});
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除下载信息从数据库中
|
||||
* @param info
|
||||
*/
|
||||
public void delete(PolyvDownloadInfo info) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "delete from downloadlist where vid=? and bitrate=?";
|
||||
db.execSQL(sql, new Object[]{info.getVid(), info.getBitrate()});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新下载的进度至数据库
|
||||
* @param info
|
||||
* @param percent
|
||||
* @param total
|
||||
*/
|
||||
public void update(PolyvDownloadInfo info, long percent, long total) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "update downloadlist set percent=?,total=? where vid=? and bitrate=?";
|
||||
db.execSQL(sql, new Object[]{percent, total, info.getVid(), info.getBitrate()});
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断该下载信息是否已以添加过
|
||||
* @param info
|
||||
* @return
|
||||
*/
|
||||
public boolean isAdd(PolyvDownloadInfo info) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "select vid ,duration,filesize,bitrate from downloadlist where vid=? and bitrate=?";
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.rawQuery(sql, new String[]{info.getVid(), info.getBitrate() + ""});
|
||||
return cursor.getCount() == 1 ? true : false;
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的下载信息对象
|
||||
* @return
|
||||
*/
|
||||
public LinkedList<PolyvDownloadInfo> getAll() {
|
||||
LinkedList<PolyvDownloadInfo> infos = new LinkedList<PolyvDownloadInfo>();
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "select vid,title,duration,filesize,bitrate,percent,total,img,author,uuid from downloadlist";
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.rawQuery(sql, null);
|
||||
while (cursor.moveToNext()) {
|
||||
String vid = cursor.getString(cursor.getColumnIndex("vid"));
|
||||
String title = cursor.getString(cursor.getColumnIndex("title"));
|
||||
String duration = cursor.getString(cursor.getColumnIndex("duration"));
|
||||
long filesize = cursor.getInt(cursor.getColumnIndex("filesize"));
|
||||
int bitrate = cursor.getInt(cursor.getColumnIndex("bitrate"));
|
||||
long percent = cursor.getInt(cursor.getColumnIndex("percent"));
|
||||
long total = cursor.getInt(cursor.getColumnIndex("total"));
|
||||
String img = cursor.getString(cursor.getColumnIndex("img"));
|
||||
String author = cursor.getString(cursor.getColumnIndex("author"));
|
||||
String uuid = cursor.getString(cursor.getColumnIndex("uuid"));
|
||||
PolyvDownloadInfo info = new PolyvDownloadInfo(vid, duration, filesize, bitrate, title,img,author,uuid);
|
||||
info.setPercent(percent);
|
||||
info.setTotal(total);
|
||||
infos.addLast(info);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个的下载信息对象
|
||||
* @return
|
||||
*/
|
||||
public LinkedList<PolyvDownloadInfo> getloadInfo(String vid1) {
|
||||
LinkedList<PolyvDownloadInfo> infos = new LinkedList<PolyvDownloadInfo>();
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "select vid,title,duration,filesize,bitrate,percent,total,img,author,uuid from downloadlist where vid=?";
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.rawQuery(sql, new String[]{vid1});
|
||||
while (cursor.moveToNext()) {
|
||||
String vid = cursor.getString(cursor.getColumnIndex("vid"));
|
||||
String title = cursor.getString(cursor.getColumnIndex("title"));
|
||||
String duration = cursor.getString(cursor.getColumnIndex("duration"));
|
||||
long filesize = cursor.getInt(cursor.getColumnIndex("filesize"));
|
||||
int bitrate = cursor.getInt(cursor.getColumnIndex("bitrate"));
|
||||
long percent = cursor.getInt(cursor.getColumnIndex("percent"));
|
||||
long total = cursor.getInt(cursor.getColumnIndex("total"));
|
||||
String img = cursor.getString(cursor.getColumnIndex("img"));
|
||||
String author = cursor.getString(cursor.getColumnIndex("author"));
|
||||
String uuid = cursor.getString(cursor.getColumnIndex("uuid"));
|
||||
PolyvDownloadInfo info = new PolyvDownloadInfo(vid, duration, filesize, bitrate, title,img,author,uuid);
|
||||
info.setPercent(percent);
|
||||
info.setTotal(total);
|
||||
infos.addLast(info);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package cn.shangyu.gdxzExpert.polyvplayer.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import cn.shangyu.gdxzExpert.bean.PolyvUploadInfo;
|
||||
|
||||
|
||||
public class PolyvUploadSQLiteHelper extends SQLiteOpenHelper{
|
||||
private static PolyvUploadSQLiteHelper sqLiteHelper;
|
||||
private static final String DATABASENAME = "uploadlist.db";
|
||||
private static final int VERSION = 6;
|
||||
|
||||
public static PolyvUploadSQLiteHelper getInstance(Context context) {
|
||||
if (sqLiteHelper == null) {
|
||||
synchronized (PolyvUploadSQLiteHelper.class) {
|
||||
if (sqLiteHelper == null)
|
||||
sqLiteHelper = new PolyvUploadSQLiteHelper(context.getApplicationContext(), DATABASENAME, null, VERSION);
|
||||
}
|
||||
}
|
||||
return sqLiteHelper;
|
||||
}
|
||||
|
||||
private PolyvUploadSQLiteHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
|
||||
super(context, name, factory, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(
|
||||
"create table if not exists uploadlist(title varchar(100),filepath varchar(120),desc varchar(20),filesize int,percent int default 0,total int default 0,cataid varchar(20),primary key (filepath))");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL("drop table if exists uploadlist");
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加上传信息至数据库
|
||||
* @param info
|
||||
*/
|
||||
public void insert(PolyvUploadInfo info) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "insert into uploadlist(title,desc,filesize,filepath,cataid) values(?,?,?,?,?)";
|
||||
db.execSQL(sql, new Object[] {info.getTitle(), info.getDesc(), info.getFilesize(),
|
||||
info.getFilepath(),info.getCataid() });
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除上传信息从数据库中
|
||||
* @param info
|
||||
*/
|
||||
public void delete(PolyvUploadInfo info) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "delete from uploadlist where filepath=?";
|
||||
db.execSQL(sql, new Object[] { info.getFilepath() });
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新上传的分类id至数据库
|
||||
* @param info
|
||||
*/
|
||||
public void updateCataid(PolyvUploadInfo info) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "update uploadlist set cataid=? where filepath=?";
|
||||
db.execSQL(sql, new Object[]{ info.getCataid(), info.getFilepath() });
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新上传的进度至数据库
|
||||
* @param info
|
||||
* @param percent
|
||||
* @param total
|
||||
*/
|
||||
public void update(PolyvUploadInfo info, long percent, long total) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "update uploadlist set percent=?,total=? where filepath=?";
|
||||
db.execSQL(sql, new Object[] { percent, total, info.getFilepath() });
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断该上传信息是否已以添加过
|
||||
* @param info
|
||||
* @return
|
||||
*/
|
||||
public boolean isAdd(PolyvUploadInfo info) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "select filepath ,title,desc from uploadlist where filepath=?";
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.rawQuery(sql, new String[] { info.getFilepath() });
|
||||
return cursor.getCount() == 1 ? true : false;
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的上传信息对象
|
||||
* @return
|
||||
*/
|
||||
public LinkedList<PolyvUploadInfo> getAll() {
|
||||
LinkedList<PolyvUploadInfo> infos = new LinkedList<PolyvUploadInfo>();
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String sql = "select title,filepath,desc,filesize,percent,total,cataid from uploadlist";
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.rawQuery(sql, null);
|
||||
while (cursor.moveToNext()) {
|
||||
String title = cursor.getString(cursor.getColumnIndex("title"));
|
||||
String filepath = cursor.getString(cursor.getColumnIndex("filepath"));
|
||||
String desc = cursor.getString(cursor.getColumnIndex("desc"));
|
||||
long filesize = cursor.getLong(cursor.getColumnIndex("filesize"));
|
||||
long percent = cursor.getInt(cursor.getColumnIndex("percent"));
|
||||
long total = cursor.getInt(cursor.getColumnIndex("total"));
|
||||
String cataid = cursor.getString(cursor.getColumnIndex("cataid"));
|
||||
PolyvUploadInfo info = new PolyvUploadInfo(title, desc, filesize, filepath, cataid);
|
||||
info.setPercent(percent);
|
||||
info.setTotal(total);
|
||||
infos.addLast(info);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user