Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Andy B-S
Companion App Android
Commits
c0bf33b8
Commit
c0bf33b8
authored
Aug 21, 2019
by
Anon
Browse files
AppDetailFragment: Launch batch transfer after download.
parent
44b89b41
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/de/ccc/events/badge/card10/hatchery/AppDetailFragment.kt
View file @
c0bf33b8
...
...
@@ -22,6 +22,7 @@
package
de.ccc.events.badge.card10.hatchery
import
android.net.Uri
import
android.os.AsyncTask
import
android.os.Bundle
import
android.util.Log
...
...
@@ -29,9 +30,13 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.appcompat.app.AlertDialog
import
androidx.core.net.toUri
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.FragmentManager
import
de.ccc.events.badge.card10.R
import
de.ccc.events.badge.card10.common.LoadingDialog
import
de.ccc.events.badge.card10.filetransfer.BatchTransferFragment
import
de.ccc.events.badge.card10.filetransfer.TransferJob
import
kotlinx.android.synthetic.main.app_detail_fragment.*
import
org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import
org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
...
...
@@ -73,7 +78,8 @@ class AppDetailFragment : Fragment() {
)
{
dialog
,
_
->
dialog
.
dismiss
()
}
.
create
()
ReleaseDownload
(
app
,
ctx
.
cacheDir
,
loadingDialog
,
errorDialog
).
execute
()
val
fm
=
fragmentManager
?:
throw
java
.
lang
.
IllegalStateException
()
ReleaseDownload
(
app
,
ctx
.
cacheDir
,
loadingDialog
,
errorDialog
,
fm
).
execute
()
}
}
...
...
@@ -81,10 +87,11 @@ class AppDetailFragment : Fragment() {
private
val
app
:
App
,
private
val
cacheDir
:
File
,
private
val
loadingDialog
:
LoadingDialog
,
private
val
errorDialog
:
AlertDialog
)
:
AsyncTask
<
Void
,
Void
,
List
<
String
>?>()
{
private
val
errorDialog
:
AlertDialog
,
private
val
fragmentManager
:
FragmentManager
)
:
AsyncTask
<
Void
,
Void
,
List
<
TransferJob
>?>()
{
override
fun
doInBackground
(
vararg
p0
:
Void
?):
List
<
String
>?
{
override
fun
doInBackground
(
vararg
p0
:
Void
?):
List
<
TransferJob
>?
{
return
try
{
cacheDir
.
deleteRecursively
()
cacheDir
.
mkdir
()
...
...
@@ -96,7 +103,7 @@ class AppDetailFragment : Fragment() {
inputStream
.
copyTo
(
outputStream
)
val
appFiles
=
mutableListOf
<
String
>()
val
appFiles
=
mutableListOf
<
TransferJob
>()
val
tarStream
=
TarArchiveInputStream
(
GzipCompressorInputStream
(
file
.
inputStream
()))
while
(
true
)
{
val
entry
=
tarStream
.
nextTarEntry
?:
break
...
...
@@ -110,7 +117,7 @@ class AppDetailFragment : Fragment() {
targetFile
.
createNewFile
()
Log
.
d
(
TAG
,
"Extracting ${entry.name} to ${targetFile.absolutePath}"
)
tarStream
.
copyTo
(
targetFile
.
outputStream
())
appFiles
.
add
(
"apps/${entry.name}"
)
appFiles
.
add
(
TransferJob
(
targetFile
.
toUri
(),
"apps/${entry.name}"
)
)
}
val
launcher
=
createLauncher
(
app
.
slug
,
cacheDir
)
...
...
@@ -122,17 +129,27 @@ class AppDetailFragment : Fragment() {
}
}
override
fun
onPostExecute
(
result
:
List
<
String
>?)
{
if
(
result
==
null
)
{
override
fun
onPostExecute
(
jobs
:
List
<
TransferJob
>?)
{
if
(
jobs
==
null
)
{
loadingDialog
.
dismiss
()
errorDialog
.
show
()
return
}
loadingDialog
.
dismiss
()
val
bundle
=
Bundle
()
bundle
.
putParcelableArray
(
"jobs"
,
jobs
.
toTypedArray
())
val
fragment
=
BatchTransferFragment
()
fragment
.
arguments
=
bundle
fragmentManager
.
beginTransaction
()
.
replace
(
R
.
id
.
fragment_container
,
fragment
)
.
addToBackStack
(
null
)
.
commit
()
}
fun
createLauncher
(
slug
:
String
,
cacheDir
:
File
):
String
{
fun
createLauncher
(
slug
:
String
,
cacheDir
:
File
):
TransferJob
{
val
fileName
=
"$slug.py"
val
file
=
File
(
cacheDir
,
fileName
)
file
.
createNewFile
()
...
...
@@ -145,7 +162,7 @@ class AppDetailFragment : Fragment() {
file
.
writeText
(
src
)
return
fileName
return
TransferJob
(
file
.
toUri
(),
fileName
)
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment