Commit 7b515a36 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Fix bug which caused progress bar to run forever

parent d987d20f
......@@ -25,27 +25,29 @@ class OutdatedApplicationsFileReader(private val applicationManager: Application
totalLines++
}
}
context[0].openFileInput(Constants.OUTDATED_APPLICATIONS_FILENAME).use {
BufferedReader(InputStreamReader(it)).forEachLine { packageName ->
Execute({
val application = applicationManager.findOrCreateApp(packageName)
val error = application.assertBasicData(context[0])
if (error == null) {
if (application.state == State.NOT_UPDATED) {
applications.add(application)
if (totalLines > 0) {
context[0].openFileInput(Constants.OUTDATED_APPLICATIONS_FILENAME).use {
BufferedReader(InputStreamReader(it)).forEachLine { packageName ->
Execute({
val application = applicationManager.findOrCreateApp(packageName)
val error = application.assertBasicData(context[0])
if (error == null) {
if (application.state == State.NOT_UPDATED) {
applications.add(application)
}
}
}
}, {
requestsComplete++
if (requestsComplete == totalLines) {
synchronized(blocker) {
blocker.notify()
}, {
requestsComplete++
if (requestsComplete == totalLines) {
synchronized(blocker) {
blocker.notify()
}
}
}
})
}
synchronized(blocker) {
blocker.wait()
})
}
synchronized(blocker) {
blocker.wait()
}
}
}
} catch (exception: Exception) {
......
......@@ -29,12 +29,14 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
}
override fun onApplicationsFound(applications: ArrayList<Application>) {
applicationContext.openFileOutput(Constants.OUTDATED_APPLICATIONS_FILENAME,
Context.MODE_PRIVATE).use {
applications.forEach { application ->
it.write((application.basicData!!.packageName + "\n").toByteArray())
if (applications.size > 0) {
applicationContext.openFileOutput(Constants.OUTDATED_APPLICATIONS_FILENAME,
Context.MODE_PRIVATE).use {
applications.forEach { application ->
it.write((application.basicData!!.packageName + "\n").toByteArray())
}
it.close()
}
it.close()
}
synchronized(blocker) {
blocker.notify()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment