Skip to content

Commit ccda2ab

Browse files
committed
增加下载的视频分组名
Signed-off-by: JeffMony <jeffmony@163.com>
1 parent 93c1200 commit ccda2ab

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

app/src/main/java/com/jeffmony/videodemo/download/VideoDownloadListActivity.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4242
}
4343

4444
private void initDatas() {
45-
VideoTaskItem item1 = new VideoTaskItem("https://v3.dious.cc/20201224/v04Vp1ES/index.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test1");
46-
VideoTaskItem item2 = new VideoTaskItem("https://v3.dious.cc/20201224/6Q1yAHRu/index.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test2");
47-
VideoTaskItem item3 = new VideoTaskItem("https://v3.dious.cc/20201224/aQKzuq6G/index.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test3");
48-
VideoTaskItem item4 = new VideoTaskItem("https://v3.dious.cc/20201224/WWTyUxS6/index.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test3");
49-
VideoTaskItem item5 = new VideoTaskItem("http://videoconverter.vivo.com.cn/201706/655_1498479540118.mp4.main.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test4");
50-
VideoTaskItem item6 = new VideoTaskItem("https://europe.olemovienews.com/hlstimeofffmp4/20210226/fICqcpqr/mp4/fICqcpqr.mp4/master.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test5");
51-
VideoTaskItem item7 = new VideoTaskItem("https://rrsp-1252816746.cos.ap-shanghai.myqcloud.com/0c1f023caa3bbefbe16a5ce564142bbe.mp4", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test6");
45+
VideoTaskItem item1 = new VideoTaskItem("https://v3.dious.cc/20201224/v04Vp1ES/index.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test1", "group-1");
46+
VideoTaskItem item2 = new VideoTaskItem("https://v3.dious.cc/20201224/6Q1yAHRu/index.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test2", "group-1");
47+
VideoTaskItem item3 = new VideoTaskItem("https://v3.dious.cc/20201224/aQKzuq6G/index.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test3", "group-1");
48+
VideoTaskItem item4 = new VideoTaskItem("https://v3.dious.cc/20201224/WWTyUxS6/index.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test3", "group-1");
49+
VideoTaskItem item5 = new VideoTaskItem("http://videoconverter.vivo.com.cn/201706/655_1498479540118.mp4.main.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test4", "group-2");
50+
VideoTaskItem item6 = new VideoTaskItem("https://europe.olemovienews.com/hlstimeofffmp4/20210226/fICqcpqr/mp4/fICqcpqr.mp4/master.m3u8", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test5", "group-2");
51+
VideoTaskItem item7 = new VideoTaskItem("https://rrsp-1252816746.cos.ap-shanghai.myqcloud.com/0c1f023caa3bbefbe16a5ce564142bbe.mp4", "https://i.loli.net/2021/04/18/WuAUZc85meB6D2Q.jpg", "test6", "group-2");
5252

5353
items[0] = item1;
5454
items[1] = item2;

downloader/src/main/java/com/jeffmony/downloader/database/VideoDownloadDatabaseHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public void updateDownloadProgressInfo(SQLiteDatabase db, VideoTaskItem item) {
9494
values.put(VideoDownloadSQLiteHelper.Columns.COVER_URL, item.getCoverUrl());
9595
values.put(VideoDownloadSQLiteHelper.Columns.COVER_PATH, item.getCoverPath());
9696
values.put(VideoDownloadSQLiteHelper.Columns.VIDEO_TITLE, item.getTitle());
97+
values.put(VideoDownloadSQLiteHelper.Columns.GROUP_NAME, item.getGroupName());
9798
String whereClause = VideoDownloadSQLiteHelper.Columns.VIDEO_URL + " = ?";
9899
String[] whereArgs = {item.getUrl()};
99100
db.update(VideoDownloadSQLiteHelper.TABLE_VIDEO_DOWNLOAD_INFO, values, whereClause, whereArgs);
@@ -126,6 +127,7 @@ private void insertVideoDownloadInfo(SQLiteDatabase db, VideoTaskItem item) {
126127
values.put(VideoDownloadSQLiteHelper.Columns.COVER_URL, item.getCoverUrl());
127128
values.put(VideoDownloadSQLiteHelper.Columns.COVER_PATH, item.getCoverPath());
128129
values.put(VideoDownloadSQLiteHelper.Columns.VIDEO_TITLE, item.getTitle());
130+
values.put(VideoDownloadSQLiteHelper.Columns.GROUP_NAME, item.getGroupName());
129131
db.insert(VideoDownloadSQLiteHelper.TABLE_VIDEO_DOWNLOAD_INFO, null, values);
130132
db.setTransactionSuccessful();
131133
} catch (Exception e) {
@@ -190,6 +192,7 @@ public List<VideoTaskItem> getDownloadInfos() {
190192
item.setCoverUrl(cursor.getString(cursor.getColumnIndex(VideoDownloadSQLiteHelper.Columns.COVER_URL)));
191193
item.setCoverPath(cursor.getString(cursor.getColumnIndex(VideoDownloadSQLiteHelper.Columns.COVER_PATH)));
192194
item.setTitle(cursor.getString(cursor.getColumnIndex(VideoDownloadSQLiteHelper.Columns.VIDEO_TITLE)));
195+
item.setGroupName(cursor.getString(cursor.getColumnIndex(VideoDownloadSQLiteHelper.Columns.GROUP_NAME)));
193196
if (item.isRunningTask() && Math.abs(item.getSpeed()) < 0.0001f) {
194197
item.setTaskState(VideoTaskState.PAUSE);
195198
}

downloader/src/main/java/com/jeffmony/downloader/database/VideoDownloadSQLiteHelper.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class VideoDownloadSQLiteHelper extends SQLiteOpenHelper {
88

99
private static final String DATABASE_NAME = "video_download_info.db";
10-
private static final int DATABASE_VERSION = 3;
10+
private static final int DATABASE_VERSION = 4;
1111

1212
public static final String TABLE_VIDEO_DOWNLOAD_INFO = "video_download_info";
1313

@@ -29,6 +29,7 @@ public static class Columns {
2929
public static final String COVER_URL = "cover_url";
3030
public static final String COVER_PATH = "cover_path";
3131
public static final String VIDEO_TITLE = "video_title";
32+
public static final String GROUP_NAME = "group_name";
3233
}
3334

3435
public VideoDownloadSQLiteHelper(Context context) {
@@ -48,6 +49,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
4849
if (oldVersion == 2) {
4950
upgradeDatabaseToVersion3(db);
5051
}
52+
if (oldVersion == 3) {
53+
upgradeDatabaseToVersion4(db);
54+
}
5155
}
5256

5357
@Override
@@ -73,7 +77,8 @@ private void createVideoDownloadInfoTable(SQLiteDatabase db) {
7377
+ Columns.FILE_PATH + " TEXT, "
7478
+ Columns.COVER_URL + " TEXT, "
7579
+ Columns.COVER_PATH + " TEXT,"
76-
+ Columns.VIDEO_TITLE +" TEXT);");
80+
+ Columns.VIDEO_TITLE + " TEXT,"
81+
+ Columns.GROUP_NAME + " TEXT);");
7782
}
7883

7984
private void upgradeDatabaseToVersion2(SQLiteDatabase db) {
@@ -84,4 +89,8 @@ private void upgradeDatabaseToVersion2(SQLiteDatabase db) {
8489
private void upgradeDatabaseToVersion3(SQLiteDatabase db) {
8590
db.execSQL("ALTER TABLE " + TABLE_VIDEO_DOWNLOAD_INFO + " ADD COLUMN " + Columns.VIDEO_TITLE + " TEXT");
8691
}
92+
93+
private void upgradeDatabaseToVersion4(SQLiteDatabase db) {
94+
db.execSQL("ALTER TABLE " + TABLE_VIDEO_DOWNLOAD_INFO + " ADD COLUMN " + Columns.GROUP_NAME + " TEXT");
95+
}
8796
}

downloader/src/main/java/com/jeffmony/downloader/model/VideoTaskItem.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class VideoTaskItem implements Cloneable {
1010
private String mCoverUrl; //封面图的url
1111
private String mCoverPath; //封面图存储的位置
1212
private String mTitle; //视频的标题
13+
private String mGroupName; //下载分组的名称
1314
private long mDownloadCreateTime; //下载创建的时间
1415
private int mTaskState; //当前任务的状态
1516
private String mMimeType; // 视频url的mime type
@@ -33,13 +34,14 @@ public class VideoTaskItem implements Cloneable {
3334
private boolean mPaused;
3435

3536
public VideoTaskItem(String url) {
36-
this(url, "", "");
37+
this(url, "", "", "");
3738
}
3839

39-
public VideoTaskItem(String url, String coverUrl, String title) {
40+
public VideoTaskItem(String url, String coverUrl, String title, String groupName) {
4041
mUrl = url;
4142
mCoverUrl = coverUrl;
4243
mTitle = title;
44+
mGroupName = groupName;
4345
}
4446

4547
public String getUrl() {
@@ -58,6 +60,10 @@ public String getUrl() {
5860

5961
public String getTitle() { return mTitle; }
6062

63+
public void setGroupName(String groupName) { mGroupName = groupName; }
64+
65+
public String getGroupName() { return mGroupName; }
66+
6167
public void setDownloadCreateTime(long time) {
6268
mDownloadCreateTime = time;
6369
}
@@ -283,6 +289,7 @@ public void reset() {
283289
mCoverUrl = "";
284290
mCoverPath = "";
285291
mTitle = "";
292+
mGroupName = "";
286293
}
287294

288295
@Override
@@ -303,6 +310,7 @@ public Object clone() {
303310
taskItem.setCoverUrl(mCoverUrl);
304311
taskItem.setCoverPath(mCoverPath);
305312
taskItem.setTitle(mTitle);
313+
taskItem.setGroupName(mGroupName);
306314
return taskItem;
307315
}
308316

0 commit comments

Comments
 (0)