Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Zabka
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 @@
...
@@ -22,6 +22,7 @@
package
de.ccc.events.badge.card10.hatchery
package
de.ccc.events.badge.card10.hatchery
import
android.net.Uri
import
android.os.AsyncTask
import
android.os.AsyncTask
import
android.os.Bundle
import
android.os.Bundle
import
android.util.Log
import
android.util.Log
...
@@ -29,9 +30,13 @@ import android.view.LayoutInflater
...
@@ -29,9 +30,13 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
androidx.appcompat.app.AlertDialog
import
androidx.appcompat.app.AlertDialog
import
androidx.core.net.toUri
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.FragmentManager
import
de.ccc.events.badge.card10.R
import
de.ccc.events.badge.card10.R
import
de.ccc.events.badge.card10.common.LoadingDialog
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
kotlinx.android.synthetic.main.app_detail_fragment.*
import
org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import
org.apache.commons.compress.archivers.tar.TarArchiveInputStream
import
org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
import
org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
...
@@ -73,7 +78,8 @@ class AppDetailFragment : Fragment() {
...
@@ -73,7 +78,8 @@ class AppDetailFragment : Fragment() {
)
{
dialog
,
_
->
dialog
.
dismiss
()
}
)
{
dialog
,
_
->
dialog
.
dismiss
()
}
.
create
()
.
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() {
...
@@ -81,10 +87,11 @@ class AppDetailFragment : Fragment() {
private
val
app
:
App
,
private
val
app
:
App
,
private
val
cacheDir
:
File
,
private
val
cacheDir
:
File
,
private
val
loadingDialog
:
LoadingDialog
,
private
val
loadingDialog
:
LoadingDialog
,
private
val
errorDialog
:
AlertDialog
private
val
errorDialog
:
AlertDialog
,
)
:
AsyncTask
<
Void
,
Void
,
List
<
String
>
?
>()
{
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
{
return
try
{
cacheDir
.
deleteRecursively
()
cacheDir
.
deleteRecursively
()
cacheDir
.
mkdir
()
cacheDir
.
mkdir
()
...
@@ -96,7 +103,7 @@ class AppDetailFragment : Fragment() {
...
@@ -96,7 +103,7 @@ class AppDetailFragment : Fragment() {
inputStream
.
copyTo
(
outputStream
)
inputStream
.
copyTo
(
outputStream
)
val
appFiles
=
mutableListOf
<
String
>()
val
appFiles
=
mutableListOf
<
TransferJob
>()
val
tarStream
=
TarArchiveInputStream
(
GzipCompressorInputStream
(
file
.
inputStream
()))
val
tarStream
=
TarArchiveInputStream
(
GzipCompressorInputStream
(
file
.
inputStream
()))
while
(
true
)
{
while
(
true
)
{
val
entry
=
tarStream
.
nextTarEntry
?:
break
val
entry
=
tarStream
.
nextTarEntry
?:
break
...
@@ -110,7 +117,7 @@ class AppDetailFragment : Fragment() {
...
@@ -110,7 +117,7 @@ class AppDetailFragment : Fragment() {
targetFile
.
createNewFile
()
targetFile
.
createNewFile
()
Log
.
d
(
TAG
,
"Extracting ${entry.name} to ${targetFile.absolutePath}"
)
Log
.
d
(
TAG
,
"Extracting ${entry.name} to ${targetFile.absolutePath}"
)
tarStream
.
copyTo
(
targetFile
.
outputStream
())
tarStream
.
copyTo
(
targetFile
.
outputStream
())
appFiles
.
add
(
"apps/${entry.name}"
)
appFiles
.
add
(
TransferJob
(
targetFile
.
toUri
(),
"apps/${entry.name}"
)
)
}
}
val
launcher
=
createLauncher
(
app
.
slug
,
cacheDir
)
val
launcher
=
createLauncher
(
app
.
slug
,
cacheDir
)
...
@@ -122,17 +129,27 @@ class AppDetailFragment : Fragment() {
...
@@ -122,17 +129,27 @@ class AppDetailFragment : Fragment() {
}
}
}
}
override
fun
onPostExecute
(
result
:
List
<
String
>?)
{
override
fun
onPostExecute
(
jobs
:
List
<
TransferJob
>?)
{
if
(
result
==
null
)
{
if
(
jobs
==
null
)
{
loadingDialog
.
dismiss
()
loadingDialog
.
dismiss
()
errorDialog
.
show
()
errorDialog
.
show
()
return
return
}
}
loadingDialog
.
dismiss
()
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
fileName
=
"$slug.py"
val
file
=
File
(
cacheDir
,
fileName
)
val
file
=
File
(
cacheDir
,
fileName
)
file
.
createNewFile
()
file
.
createNewFile
()
...
@@ -145,7 +162,7 @@ class AppDetailFragment : Fragment() {
...
@@ -145,7 +162,7 @@ class AppDetailFragment : Fragment() {
file
.
writeText
(
src
)
file
.
writeText
(
src
)
return
fileName
return
TransferJob
(
file
.
toUri
(),
fileName
)
}
}
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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