-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add folder selector; use folder to download and move finally to the c…
…orrect place; fix back on bottomSheet
- Loading branch information
1 parent
bcb1a1e
commit 74513d1
Showing
13 changed files
with
402 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
auto.sync=false | ||
build.scans.enabled=false | ||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) | ||
connection.project.dir= | ||
eclipse.preferences.version=1 | ||
gradle.user.home= | ||
offline.mode=false | ||
override.workspace.settings=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/me/harshithgoka/youtubedl/Utils/DownloadReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package me.harshithgoka.youtubedl.Utils; | ||
|
||
import android.app.DownloadManager; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.database.Cursor; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class DownloadReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
long receivedID = intent.getLongExtra( | ||
DownloadManager.EXTRA_DOWNLOAD_ID, -1L); | ||
DownloadManager mgr = (DownloadManager) | ||
context.getSystemService(Context.DOWNLOAD_SERVICE); | ||
|
||
DownloadManager.Query query = new DownloadManager.Query(); | ||
query.setFilterById(receivedID); | ||
Cursor cur = mgr.query(query); | ||
int status_index = cur.getColumnIndex(DownloadManager.COLUMN_STATUS); | ||
int id_index = cur.getColumnIndex(DownloadManager.COLUMN_ID); | ||
int uri_index = cur.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI); | ||
int dest_index = cur.getColumnIndex(DownloadManager.COLUMN_DESCRIPTION); | ||
|
||
SharedPreferences sharedPreferences = context.getSharedPreferences("download_history", Context.MODE_PRIVATE); | ||
Set<String> inProgressDownloads = sharedPreferences.getStringSet("in_progress", new HashSet<String>()); | ||
|
||
|
||
|
||
if(cur.moveToFirst()) { | ||
if(cur.getInt(status_index) == DownloadManager.STATUS_SUCCESSFUL){ | ||
long id = cur.getLong(id_index); | ||
if(inProgressDownloads.remove("" + id)) { | ||
URI uri = URI.create(cur.getString(uri_index)); | ||
File file = new File(uri); | ||
Log.d("DownloadReceiver", file.getAbsolutePath()); | ||
File destFile = new File(cur.getString(dest_index)); | ||
if(file.renameTo(destFile)){ | ||
Log.d("DownloadReceiver", "Move to final dest successful"); | ||
Toast.makeText(context, String.format("YoutubeDL download complete to folder \"%s\"", destFile.getParentFile().getAbsolutePath()), Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
} | ||
} | ||
cur.close(); | ||
|
||
SharedPreferences.Editor editor = sharedPreferences.edit(); | ||
editor.putStringSet("in_progress", inProgressDownloads); | ||
editor.apply(); | ||
} | ||
} | ||
|
Oops, something went wrong.