Skip to content

Commit

Permalink
功能改进与bug修复
Browse files Browse the repository at this point in the history
1、修复获取文件长度时删除任务,文件依然存在的bug
2、精确显示下载进度
3、删除FileProvider相关配置文件
  • Loading branch information
Zehhow committed Feb 27, 2019
1 parent 471147d commit 310d1f5
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 30 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId "com.zehhow.jikevideodownloader"
minSdkVersion 21
targetSdkVersion 28
versionCode 3
versionName "1.1.2"
versionCode 4
versionName "1.2.27"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand All @@ -41,7 +41,7 @@ android {

android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${defaultConfig.applicationId}-${buildType.name}-v${defaultConfig.versionName}-${defaultConfig.versionCode}.apk"
outputFileName = "即刻视频助手_${buildType.name}_v${defaultConfig.versionName}_${defaultConfig.versionCode}.apk"
}
}
}
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@
</intent-filter>
</activity>

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>

<meta-data
android:name="com.google.android.actions"
android:resource="@xml/filepaths" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
public boolean onContextItemSelected(MenuItem item) {
TaskBean task = taskAdapter.getCurrentTask();
switch (item.getItemId()) {
case 0: // 删除
deleteTask(task);
break;
case 1: // 分享
case 0: // 分享
shareVideo(task);
break;
case 1: // 删除
deleteTask(task);
break;
}
return super.onContextItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ void onProgress(int progress) {
task.progress = progress;
if(progressBar != null)
progressBar.setProgress(progress);
if(button != null)
button.setText((progress > 0 ? progress + "%" : "启动中"));
Log.d("JKVD", " Progress " + progress + ": " + task.name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DownloadTask extends AsyncTask<TaskBean, Integer, TaskStatus> {
private DownloadListener listener;
private TaskStatus taskStatus = TaskStatus.DOWNLOADING;
private TaskBean task; // 任务信息
private int lastProgress = 0; // 上一次的下载进度
private int lastProgress = -1; // 上一次的下载进度

public DownloadTask(DownloadListener listener) {
this.listener = listener;
Expand Down Expand Up @@ -62,6 +62,7 @@ protected TaskStatus doInBackground(TaskBean... taskBeans) {
return TaskStatus.SUCCESS;
}

publishProgress(0);
// 获取所有ts分段的下载地址及文件长度大小
Vector<String> tsUrls = DownloadUtil.getAllTsUrls(m3u8);
if(tsUrls == null) return TaskStatus.FAILED;
Expand All @@ -76,7 +77,7 @@ protected TaskStatus doInBackground(TaskBean... taskBeans) {
task.totalLength += l;
}
if(task.totalLength == 0) return TaskStatus.FAILED;
SQLiteHelper.getInstance().updateTotalLength(task.urlHashCode, 0);
SQLiteHelper.getInstance().updateTotalLength(task.urlHashCode, task.totalLength);
SQLiteHelper.getInstance().updateProgress(task.urlHashCode, 0, 0);
}

Expand Down Expand Up @@ -106,6 +107,8 @@ protected TaskStatus doInBackground(TaskBean... taskBeans) {
}

try {
// 如果下载状态不正常则退出下载
if(taskStatus != TaskStatus.DOWNLOADING) return taskStatus;
savedFile = new RandomAccessFile(file, "rw");
savedFile.seek(task.downloadedLength); // 定位文件指针至已下载处

Expand Down Expand Up @@ -158,7 +161,7 @@ private long downloadTs(RandomAccessFile savedFile, String tsUrl, long downloade
if(response == null || response.body() == null) return -1;

is = response.body().byteStream();
int len;
int len, progress;
byte[] b = new byte[1024];
// 读取数据并写入文件
while((len = is.read(b)) != -1) {
Expand All @@ -169,7 +172,7 @@ private long downloadTs(RandomAccessFile savedFile, String tsUrl, long downloade
downloadedLength += len;
task.downloadedLength += len;
// 更新进度信息
int progress = (int)(task.downloadedLength * 100 / task.totalLength);
progress = (int)(task.downloadedLength * 100 / task.totalLength);
publishProgress(progress);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public void onClick(View v) {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
if(getCurrentTask().status == TaskStatus.SUCCESS) // 下载完成才可分享
menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, "分享");
menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, "删除");
menu.add(ContextMenu.NONE, 0, ContextMenu.NONE, "分享");

menu.add(ContextMenu.NONE, 1, ContextMenu.NONE, "删除");
}
}

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/xml/filepaths.xml

This file was deleted.

0 comments on commit 310d1f5

Please sign in to comment.