Skip to content

Commit

Permalink
Fixed deprecated classes for workmanager.
Browse files Browse the repository at this point in the history
  • Loading branch information
rumaan committed Sep 27, 2018
1 parent 3796798 commit e59dd87
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 259 deletions.
14 changes: 2 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

def supportLibVersion = '27.1.1'
def work_version = "1.0.0-alpha08"
def work_version = "1.0.0-alpha09"

android {

/* Disable multi apk for dev builds */
if (project.hasProperty('devBuild')) {
splits.abi.enable = false
splits.density.enable = false
aaptOptions.cruncherEnabled = false
}

compileSdkVersion 27
defaultConfig {
applicationId "com.thecoolguy.rumaan.fileio"
Expand Down Expand Up @@ -64,9 +57,7 @@ dependencies {
}
annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:3.2.0"
// Firebase Crashlytics
implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
transitive = true
}
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation 'com.google.firebase:firebase-core:16.0.3'
/* Room */
implementation 'android.arch.persistence.room:rxjava2:1.1.1'
Expand All @@ -84,7 +75,6 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.2'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

implementation 'androidx.core:core-ktx:0.3'
implementation "android.arch.work:work-runtime-ktx:$work_version"
androidTestImplementation "android.arch.work:work-testing:$work_version"

Expand Down
Binary file modified app/build/outputs/apk/debug/app-debug.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ const val ID = "id"

class ClearHistoryWorker : Worker() {

override fun doWork(): WorkerResult {
UploadHistoryRoomDatabase.getInstance(applicationContext)
.uploadItemDao()
.clearAll()
override fun doWork(): Result {
UploadHistoryRoomDatabase.getInstance(applicationContext)
.uploadItemDao()
.clearAll()

return WorkerResult.SUCCESS
}

return Result.SUCCESS
}
}

class DeleteSingleItemWorker : Worker() {
override fun doWork(): WorkerResult {
val id = inputData.getLong(ID, -1)
if (id == -1L) return WorkerResult.FAILURE

UploadHistoryRoomDatabase.getInstance(applicationContext)
.uploadItemDao()
.deleteItemWithId(id)
return WorkerResult.SUCCESS
}
override fun doWork(): Result {
val id = inputData.getLong(ID, -1)
if (id == -1L) return Result.FAILURE

UploadHistoryRoomDatabase.getInstance(applicationContext)
.uploadItemDao()
.deleteItemWithId(id)
return Result.FAILURE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.Log
import androidx.work.Data
import androidx.work.Worker
import androidx.work.toWorkData
import androidx.work.workDataOf
import com.thecoolguy.rumaan.fileio.data.db.DatabaseHelper
import com.thecoolguy.rumaan.fileio.data.db.UploadHistoryRoomDatabase
import com.thecoolguy.rumaan.fileio.data.models.FileEntity
Expand All @@ -16,45 +17,44 @@ import com.thecoolguy.rumaan.fileio.utils.Utils

class UploadWorker : Worker() {

companion object {
const val KEY_URI = "file_uri"
const val KEY_RESULT = "file_url"
private val TAG = UploadWorker::class.simpleName
companion object {
const val KEY_URI = "file_uri"
const val KEY_RESULT = "file_url"
private val TAG = UploadWorker::class.simpleName

}

private fun save(fileEntity: FileEntity) {
val id = DatabaseHelper.saveToDatabase(
fileEntity, UploadHistoryRoomDatabase.getInstance(applicationContext).uploadItemDao()
)
Log.d(TAG, "Insert Id: $id")
}

override fun doWork(): WorkerResult {
val fileUri = inputData.getString(KEY_URI, null)
fileUri?.let { uri ->
// get the local file object from the backing storage
Utils.getLocalFile(applicationContext, Uri.parse(uri))
?.let { localFile ->
// Upload the file
val (_, response, _) = Uploader.upload(localFile)

val fileEntity =
composeIntoFileEntity(Response.Deserializer().deserialize(response), localFile)

/* Save the uploaded file details into the LocalDb */
save(fileEntity)

// post a notification
NotificationHelper().create(applicationContext, fileEntity)
}

val output: Data = mapOf(KEY_RESULT to fileEntity.url).toWorkData()
outputData = output
private fun save(fileEntity: FileEntity) {
val id = DatabaseHelper.saveToDatabase(
fileEntity, UploadHistoryRoomDatabase.getInstance(applicationContext).uploadItemDao()
)
Log.d(TAG, "Insert Id: $id")
}

return WorkerResult.SUCCESS
}
override fun doWork(): Result {
val fileUri = inputData.getString(KEY_URI)
fileUri?.let { uri ->
// get the local file object from the backing storage
Utils.getLocalFile(applicationContext, Uri.parse(uri))
?.let { localFile ->
// Upload the file
val (_, response, _) = Uploader.upload(localFile)

val fileEntity =
composeIntoFileEntity(Response.Deserializer().deserialize(response), localFile)

/* Save the uploaded file details into the LocalDb */
save(fileEntity)

// post a notification
NotificationHelper().create(applicationContext, fileEntity)
val output: Data = workDataOf(KEY_RESULT to fileEntity.url)
outputData = output

return Result.SUCCESS
}
}
return Result.FAILURE
}
return WorkerResult.FAILURE
}

}
Loading

0 comments on commit e59dd87

Please sign in to comment.