|
@ -9,6 +9,8 @@ import android.view.MenuItem |
|
|
import android.view.View |
|
|
import android.view.View |
|
|
import androidx.appcompat.view.ContextThemeWrapper |
|
|
import androidx.appcompat.view.ContextThemeWrapper |
|
|
import androidx.appcompat.widget.PopupMenu |
|
|
import androidx.appcompat.widget.PopupMenu |
|
|
|
|
|
import androidx.core.app.NotificationCompat |
|
|
|
|
|
import androidx.core.app.NotificationManagerCompat |
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
import androidx.documentfile.provider.DocumentFile |
|
|
import androidx.work.* |
|
|
import androidx.work.* |
|
|
import awais.instagrabber.R |
|
|
import awais.instagrabber.R |
|
@ -16,6 +18,7 @@ import awais.instagrabber.fragments.settings.PreferenceKeys |
|
|
import awais.instagrabber.models.enums.MediaItemType |
|
|
import awais.instagrabber.models.enums.MediaItemType |
|
|
import awais.instagrabber.repositories.responses.Media |
|
|
import awais.instagrabber.repositories.responses.Media |
|
|
import awais.instagrabber.repositories.responses.stories.StoryMedia |
|
|
import awais.instagrabber.repositories.responses.stories.StoryMedia |
|
|
|
|
|
import awais.instagrabber.utils.AppExecutors.tasksThread |
|
|
import awais.instagrabber.utils.TextUtils.isEmpty |
|
|
import awais.instagrabber.utils.TextUtils.isEmpty |
|
|
import awais.instagrabber.workers.DownloadWorker |
|
|
import awais.instagrabber.workers.DownloadWorker |
|
|
import com.google.gson.Gson |
|
|
import com.google.gson.Gson |
|
@ -24,6 +27,7 @@ import java.io.IOException |
|
|
import java.io.OutputStreamWriter |
|
|
import java.io.OutputStreamWriter |
|
|
import java.util.* |
|
|
import java.util.* |
|
|
import java.util.regex.Pattern |
|
|
import java.util.regex.Pattern |
|
|
|
|
|
import kotlin.math.abs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object DownloadUtils { |
|
|
object DownloadUtils { |
|
@ -211,7 +215,6 @@ object DownloadUtils { |
|
|
return Pair(fileName, mimeType!!) |
|
|
return Pair(fileName, mimeType!!) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// can't convert to checkFiles() due to lack of Context |
|
|
|
|
|
fun getTempFile(fileName: String?, extension: String): DocumentFile? { |
|
|
fun getTempFile(fileName: String?, extension: String): DocumentFile? { |
|
|
val dir = tempDir |
|
|
val dir = tempDir |
|
|
var name = fileName |
|
|
var name = fileName |
|
@ -382,12 +385,28 @@ object DownloadUtils { |
|
|
download(context, listOf(feedModel), position) |
|
|
download(context, listOf(feedModel), position) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// this must be used for bulk download, but ONLY bulk download |
|
|
@JvmStatic |
|
|
@JvmStatic |
|
|
fun download( |
|
|
fun download( |
|
|
context: Context, |
|
|
context: Context, |
|
|
feedModels: List<Media> |
|
|
feedModels: List<Media> |
|
|
) { |
|
|
) { |
|
|
download(context, feedModels, -1) |
|
|
|
|
|
|
|
|
val builder = NotificationCompat.Builder(context, Constants.DOWNLOAD_CHANNEL_ID) |
|
|
|
|
|
.setCategory(NotificationCompat.CATEGORY_PROGRESS) |
|
|
|
|
|
.setSmallIcon(R.drawable.ic_download) |
|
|
|
|
|
.setOngoing(true) |
|
|
|
|
|
.setProgress(1, 0, true) |
|
|
|
|
|
.setAutoCancel(false) |
|
|
|
|
|
.setOnlyAlertOnce(true) |
|
|
|
|
|
.setContentTitle(context.getString(R.string.downloader_preparing)) |
|
|
|
|
|
val notification = builder.build() |
|
|
|
|
|
val nid = abs(UUID.randomUUID().hashCode()) |
|
|
|
|
|
val nManager = NotificationManagerCompat.from(context.applicationContext) |
|
|
|
|
|
nManager.notify(nid, notification) |
|
|
|
|
|
tasksThread.execute { |
|
|
|
|
|
download(context, feedModels, -1) |
|
|
|
|
|
nManager.cancel(nid) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private fun download( |
|
|
private fun download( |
|
@ -438,9 +457,7 @@ object DownloadUtils { |
|
|
val url = getUrlOfType(child) |
|
|
val url = getUrlOfType(child) |
|
|
val usernamePrepend = |
|
|
val usernamePrepend = |
|
|
if (Utils.settingsHelper.getBoolean(PreferenceKeys.DOWNLOAD_PREPEND_USER_NAME) && mediaUser != null) mediaUser.username else "" |
|
|
if (Utils.settingsHelper.getBoolean(PreferenceKeys.DOWNLOAD_PREPEND_USER_NAME) && mediaUser != null) mediaUser.username else "" |
|
|
val pair = getDownloadChildSavePaths( |
|
|
|
|
|
media.code, i + 1, url, usernamePrepend |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
val pair = getDownloadChildSavePaths(media.code, i + 1, url, usernamePrepend) |
|
|
map[url!!] = pair |
|
|
map[url!!] = pair |
|
|
i++ |
|
|
i++ |
|
|
} |
|
|
} |
|
|