Skip to content

Commit

Permalink
testshit
Browse files Browse the repository at this point in the history
  • Loading branch information
LagradOst committed Oct 29, 2022
1 parent f1cbfd4 commit 799480e
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
-->
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.lagradost.fetchbutton.example

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.MenuItem
import android.view.View
Expand Down Expand Up @@ -42,6 +45,24 @@ fun View.popupMenuNoIcons(
}

class MainActivity : AppCompatActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK) {
val uri = data?.data
if (uri != null) {
Log.d("TAG", "onActivityResult: " + uri.path);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
contentResolver.takePersistableUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
}

}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -65,7 +86,10 @@ class MainActivity : AppCompatActivity() {
//val image = BitmapFactory.decodeResource(resources, R.drawable.example_poster)

val uriReq = newUriRequest(
pId, "https://speed.hetzner.de/100MB.bin", "Hello World",
pId,
"https://speed.hetzner.de/100MB.bin",
"Hello World",
"/storage/emulated/0/Download",
notificationMetaData = NotificationMetaData(
pId.toInt(),
0xFF0000,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<item name="aria2c_icon_scale">1.0</item>

<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor" >?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ abstract class AbstractClient(
sessionGidToId[json.gid]?.let { id ->
sessionIdToLastRequest[id]?.let { lastRequest ->
val ginfo = getInfo(json.gid)
DownloadListener.mainListener?.invoke(ginfo)
lastRequest.notificationMetaData?.let { notificationMetaData ->
DefaultNotificationBuilder.createNotification(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,63 @@ object Aria2Starter {

// this is used to store keys
var saveActivity: WeakReference<Activity> = WeakReference(null)
//TODO https://developer.android.com/training/data-storage/shared/documents-files
/*fun checkPermission(request: UriRequest): Boolean {
request.directory?.let { dir ->
if (!File(dir).canWrite()) {
println("CANT WRITE TO $dir")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
saveActivity.get()?.let { act ->
act.contentResolver
val sm: StorageManager =
act.getSystemService(Context.STORAGE_SERVICE) as StorageManager
val intent = sm.primaryStorageVolume.createOpenDocumentTreeIntent()
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION and Intent.FLAG_GRANT_WRITE_URI_PERMISSION and Intent.FLAG_GRANT_READ_URI_PERMISSION)
val uri: Uri =
intent.getParcelableExtra("android.provider.extra.INITIAL_URI") ?: return false
var scheme = uri.toString()
Log.d("TAG", "INITIAL_URI scheme: $scheme")
scheme = scheme.replace("/root/", "/document/")
val finalDirPath = "$scheme%3A$dir"
val furi = Uri.parse(finalDirPath)
intent.putExtra("android.provider.extra.INITIAL_URI", furi)
intent.putExtra("android.content.extra.SHOW_ADVANCED", true)
Log.d("TAG", "uri: $furi")
act.startActivityForResult(intent, 6);
}
}
return false
}
}
return true
}*/

fun download(request: UriRequest) {
// if (!checkPermission(request)) return

//
//
//
//
//
//
//
//
//
//
//
//
client?.download(request) {}
}

fun download(request: List<UriRequest>) {
//if (request.any { !checkPermission(it) }) return

client?.downloadFailQueue(request) { _, _ -> }
}

fun download(vararg requests: UriRequest) {
// if (requests.any { !checkPermission(it) }) return
client?.downloadFailQueue(requests.toList()) { _, _ -> }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ object DownloadListener {

val currentDownloadStatus: HashMap<String, AbstractClient.JsonTell> = hashMapOf()

var mainListener : ((Metadata) -> Unit)? = null

// this points to the parent gid
//val follow: HashMap<String, String> = hashMapOf()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
private var iconPaused: Int = 0
private var hideWhenIcon: Boolean = true

protected var overrideLayout: Int? = null
var overrideLayout: Int? = null

companion object {
val fillArray = arrayOf(
Expand Down

0 comments on commit 799480e

Please sign in to comment.