From b998e264da143f610b01f1c64a1ef2928202d59d Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Thu, 1 Mar 2018 14:14:01 -0600 Subject: [PATCH] Create Kotlin extensions to work with PendingTask and PendingTaskErrors more easily. --- .travis.yml | 2 +- Dangerfile | 4 ++ app/build.gradle | 5 ++- .../wendyexample/FooPendingTask.kt | 11 ++++- .../levibostian/wendyexample/MainActivity.kt | 18 ++++++++ .../wendyexample/MainApplication.kt | 20 +++++++++ .../wendyexample/NotificationChannelUtil.kt | 9 ++++ .../wendyexample/PendingStatusTextView.kt | 13 ++++++ .../PendingTasksRecyclerViewAdapter.kt | 8 ++-- bin/install_android_sdk.sh | 2 +- docs/wendy/alltypes/index.html | 6 --- .../-pending-task-error/index.html | 18 +++++++- .../-pending-task-error/pending_task.html | 4 ++ .../add-task-status-listener-for-task.html | 15 +++++++ .../get-latest-error.html | 15 +++++++ .../index.html | 37 +++++++++++++++-- .../record-error.html | 15 +++++++ .../resolve-error.html | 18 ++++++++ .../error-recorded.html | 1 + .../-pending-task/index.html | 35 ++++++++++++++-- .../-pending-tasks/get-all-errors.html | 15 +++++++ .../-pending-tasks/index.html | 25 ++++++++++- .../-pending-tasks/resolve-error.html | 4 +- .../-pending-tasks/shared.html | 18 ++++++++ docs/wendy/index-outline.html | 41 +++++-------------- wendy/build.gradle | 2 +- .../extension/PendingTaskErrorExtensions.kt | 9 ++++ .../wendy/extension/PendingTaskExtensions.kt | 27 ++++++++++++ .../listeners/PendingTaskStatusListener.kt | 2 + .../levibostian/wendy/service/PendingTasks.kt | 13 +++++- 30 files changed, 355 insertions(+), 57 deletions(-) create mode 100644 app/src/main/java/com/levibostian/wendyexample/NotificationChannelUtil.kt create mode 100644 docs/wendy/com.levibostian.wendy.extension/add-task-status-listener-for-task.html create mode 100644 docs/wendy/com.levibostian.wendy.extension/get-latest-error.html create mode 100644 docs/wendy/com.levibostian.wendy.extension/record-error.html create mode 100644 docs/wendy/com.levibostian.wendy.extension/resolve-error.html create mode 100644 docs/wendy/com.levibostian.wendy.service/-pending-tasks/get-all-errors.html create mode 100644 docs/wendy/com.levibostian.wendy.service/-pending-tasks/shared.html create mode 100644 wendy/src/main/java/com/levibostian/wendy/extension/PendingTaskErrorExtensions.kt create mode 100644 wendy/src/main/java/com/levibostian/wendy/extension/PendingTaskExtensions.kt diff --git a/.travis.yml b/.travis.yml index 7f27d17..96e7291 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ env: jobs: include: - stage: danger - script: bundle exec danger --fail-on-errors=true + script: bundle exec danger - stage: pr script: ./bin/install_android_sdk.sh && ./gradlew androidDependencies && ./bin/pr-tasks.sh diff --git a/Dangerfile b/Dangerfile index 208b0d4..4a70d56 100644 --- a/Dangerfile +++ b/Dangerfile @@ -3,3 +3,7 @@ if github.branch_for_base == "master" warn 'Did you remember to generate documentation via dokku? (Hint: `./gradlew dokka`)' end end + +if git.modified_files.include? "build.gradle" or git.modified_files.include? "wendy/build.gradle" + warn "I see you edited a `build.gradle` file. Keep in mind that unless you are simply upgrading version numbers of libraries, that is ok. If you are adding dependencies, you may get your PR denied to keep the library slim." +end \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index df15272..4a1bf2d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,8 +29,9 @@ dependencies { androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - implementation 'com.android.support:appcompat-v7:27.0.2' - implementation 'com.android.support:recyclerview-v7:27.0.2' + implementation "com.android.support:support-compat:27.1.0" + implementation 'com.android.support:appcompat-v7:27.1.0' + implementation 'com.android.support:recyclerview-v7:27.1.0' testImplementation 'junit:junit:4.12' implementation project(':wendy') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" diff --git a/app/src/main/java/com/levibostian/wendyexample/FooPendingTask.kt b/app/src/main/java/com/levibostian/wendyexample/FooPendingTask.kt index fa7fee2..ab75b81 100644 --- a/app/src/main/java/com/levibostian/wendyexample/FooPendingTask.kt +++ b/app/src/main/java/com/levibostian/wendyexample/FooPendingTask.kt @@ -2,6 +2,7 @@ package com.levibostian.wendyexample import android.os.Handler import android.os.Looper +import com.levibostian.wendy.extension.recordError import com.levibostian.wendy.service.PendingTask import com.levibostian.wendy.types.PendingTaskResult import java.util.* @@ -12,6 +13,8 @@ class FooPendingTask(manuallyRun: Boolean, companion object { fun blank(): FooPendingTask { return FooPendingTask(false, null, "") } + + const val RANDOMLY_GENERATED_ERROR_ERROR_ID = "randomlyGeneratedErrorErrorId" } override fun runTask(): PendingTaskResult { @@ -21,7 +24,13 @@ class FooPendingTask(manuallyRun: Boolean, val rand = Random() val n = rand.nextInt(100) + 1 // random number between 1 and 100 - val successful: Boolean = n <= 25 // fail 25% of the time. + val successful: Boolean = n <= 50 // fail 50% of the time. + if (!successful) { + if (rand.nextInt(100) <= 50) { + this.recordError("Random error....", RANDOMLY_GENERATED_ERROR_ERROR_ID) + return PendingTaskResult.FAILED_DO_NOT_RESCHEDULE + } + } return if (successful) PendingTaskResult.SUCCESSFUL else PendingTaskResult.FAILED_RESCHEDULE } diff --git a/app/src/main/java/com/levibostian/wendyexample/MainActivity.kt b/app/src/main/java/com/levibostian/wendyexample/MainActivity.kt index 064449b..14adc8e 100644 --- a/app/src/main/java/com/levibostian/wendyexample/MainActivity.kt +++ b/app/src/main/java/com/levibostian/wendyexample/MainActivity.kt @@ -3,6 +3,8 @@ package com.levibostian.wendyexample import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.os.Handler +import android.support.v4.app.NotificationCompat +import android.support.v4.app.NotificationManagerCompat import android.support.v7.widget.LinearLayoutManager import android.view.View import android.widget.CompoundButton @@ -76,5 +78,21 @@ class MainActivity : AppCompatActivity(), TaskRunnerListener { } override fun allTasksComplete() { } + override fun errorRecorded(task: PendingTask, errorMessage: String?, errorId: String?) { + Handler().postDelayed({ + refreshListOfTasks() + }, 1000) + + val notificationManager = NotificationManagerCompat.from(this) + val notification = NotificationCompat.Builder(this, NotificationChannelUtil.ERROR_OCCURRED_CHANNEL_ID) + .setSmallIcon(android.R.drawable.ic_notification_clear_all) + .setContentTitle("Error occurred!") + .setContentText(errorMessage) + .setPriority(NotificationCompat.PRIORITY_DEFAULT) + .build() + notificationManager.notify(0, notification) + } + override fun errorResolved(task: PendingTask) { + } } diff --git a/app/src/main/java/com/levibostian/wendyexample/MainApplication.kt b/app/src/main/java/com/levibostian/wendyexample/MainApplication.kt index 88bfed9..e069145 100644 --- a/app/src/main/java/com/levibostian/wendyexample/MainApplication.kt +++ b/app/src/main/java/com/levibostian/wendyexample/MainApplication.kt @@ -1,16 +1,36 @@ package com.levibostian.wendyexample +import android.annotation.SuppressLint import android.app.Application import com.curiosityio.wendyexample.BuildConfig +import android.app.NotificationChannel +import android.app.NotificationManager +import android.content.Context import com.levibostian.wendy.service.PendingTasks +import android.os.Build +import android.support.v4.app.NotificationCompat +import android.support.v4.app.NotificationManagerCompat +import com.curiosityio.wendyexample.R +import com.levibostian.wendyexample.NotificationChannelUtil.Companion.ERROR_OCCURRED_CHANNEL_DESCRIPTION +import com.levibostian.wendyexample.NotificationChannelUtil.Companion.ERROR_OCCURRED_CHANNEL_ID +import com.levibostian.wendyexample.NotificationChannelUtil.Companion.ERROR_OCCURRED_CHANNEL_NAME class MainApplication : Application() { + @SuppressLint("NewApi") override fun onCreate() { super.onCreate() PendingTasks.init(this, WendyExamplePendingTasksFactory()) .debug(BuildConfig.DEBUG) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val channel = NotificationChannel(ERROR_OCCURRED_CHANNEL_ID, ERROR_OCCURRED_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT) + channel.description = ERROR_OCCURRED_CHANNEL_DESCRIPTION + + val notificationManager = this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + notificationManager.createNotificationChannel(channel) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/levibostian/wendyexample/NotificationChannelUtil.kt b/app/src/main/java/com/levibostian/wendyexample/NotificationChannelUtil.kt new file mode 100644 index 0000000..3953179 --- /dev/null +++ b/app/src/main/java/com/levibostian/wendyexample/NotificationChannelUtil.kt @@ -0,0 +1,9 @@ +package com.levibostian.wendyexample + +class NotificationChannelUtil { + companion object { + const val ERROR_OCCURRED_CHANNEL_ID = "ERROR_OCCURRED_CHANNEL_ID" + const val ERROR_OCCURRED_CHANNEL_NAME = "PendingTask errors" + const val ERROR_OCCURRED_CHANNEL_DESCRIPTION = "Recorded errors for PendingTasks" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/levibostian/wendyexample/PendingStatusTextView.kt b/app/src/main/java/com/levibostian/wendyexample/PendingStatusTextView.kt index d7fa982..930454c 100644 --- a/app/src/main/java/com/levibostian/wendyexample/PendingStatusTextView.kt +++ b/app/src/main/java/com/levibostian/wendyexample/PendingStatusTextView.kt @@ -3,6 +3,7 @@ package com.levibostian.wendyexample import android.annotation.TargetApi import android.content.Context import android.os.Build.VERSION_CODES.LOLLIPOP +import android.support.v4.content.ContextCompat import android.util.AttributeSet import android.widget.TextView import com.levibostian.wendy.listeners.PendingTaskStatusListener @@ -37,10 +38,22 @@ class PendingStatusTextView : TextView, PendingTaskStatusListener { } override fun running(taskId: Long) { text = "Running" + setTextColor(ContextCompat.getColor(mContext, android.R.color.holo_blue_dark)) } override fun complete(taskId: Long, successful: Boolean, rescheduled: Boolean) { text = if (successful) "Success!" else "Failed!" + setTextColor(ContextCompat.getColor(mContext, if (successful) android.R.color.holo_green_dark else android.R.color.holo_orange_dark)) + } + + override fun errorRecorded(taskId: Long, errorMessage: String?, errorId: String?) { + text = errorMessage + setTextColor(ContextCompat.getColor(mContext, android.R.color.holo_red_dark)) + } + + override fun errorResolved(taskId: Long) { + text = "Error gone!" + setTextColor(ContextCompat.getColor(mContext, android.R.color.holo_red_light)) } } \ No newline at end of file diff --git a/app/src/main/java/com/levibostian/wendyexample/PendingTasksRecyclerViewAdapter.kt b/app/src/main/java/com/levibostian/wendyexample/PendingTasksRecyclerViewAdapter.kt index 9405977..0683759 100644 --- a/app/src/main/java/com/levibostian/wendyexample/PendingTasksRecyclerViewAdapter.kt +++ b/app/src/main/java/com/levibostian/wendyexample/PendingTasksRecyclerViewAdapter.kt @@ -37,10 +37,10 @@ class PendingTasksRecyclerViewAdapter(val data: List) : RecyclerVie override fun getItemCount(): Int = data.count() - override fun onBindViewHolder(holder: PendingTasksRecyclerViewAdapter.ViewHolder?, position: Int) { + override fun onBindViewHolder(holder: PendingTasksRecyclerViewAdapter.ViewHolder, position: Int) { val adapterItem: PendingTask = data[position] - holder!!.idTextView.text = String.format("task id: %d", adapterItem.task_id) + holder.idTextView.text = String.format("task id: %d", adapterItem.task_id) holder.dataIdTextView.text = String.format("data id: %s", adapterItem.data_id) holder.groupIdTextView.text = String.format("group id: %s", adapterItem.group_id) holder.manuallyRunTextView.text = String.format("manually run: %s", adapterItem.manually_run.toString()) @@ -55,8 +55,8 @@ class PendingTasksRecyclerViewAdapter(val data: List) : RecyclerVie } } - override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): PendingTasksRecyclerViewAdapter.ViewHolder { - return ViewHolder(LayoutInflater.from(parent!!.context).inflate(R.layout.adapter_pending_task_recyclerview, parent, false)) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PendingTasksRecyclerViewAdapter.ViewHolder { + return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.adapter_pending_task_recyclerview, parent, false)) } } \ No newline at end of file diff --git a/bin/install_android_sdk.sh b/bin/install_android_sdk.sh index d52faab..e8f06f5 100755 --- a/bin/install_android_sdk.sh +++ b/bin/install_android_sdk.sh @@ -7,6 +7,6 @@ unzip -qq -n $HOME/android-sdk-dl/sdk-tools.zip -d $HOME/android-sdk # Install or update Android SDK components (will not do anything if already up to date thanks to the cache mechanism) echo y | $HOME/android-sdk/tools/bin/sdkmanager 'tools' > /dev/null echo y | $HOME/android-sdk/tools/bin/sdkmanager 'platform-tools' > /dev/null -echo y | $HOME/android-sdk/tools/bin/sdkmanager 'build-tools;27.0.3' > /dev/null +echo y | $HOME/android-sdk/tools/bin/sdkmanager 'build-tools;27.1.0' > /dev/null echo y | $HOME/android-sdk/tools/bin/sdkmanager 'platforms;android-27' > /dev/null echo y | $HOME/android-sdk/tools/bin/sdkmanager 'extras;google;m2repository' > /dev/null diff --git a/docs/wendy/alltypes/index.html b/docs/wendy/alltypes/index.html index 9c67101..87d346e 100644 --- a/docs/wendy/alltypes/index.html +++ b/docs/wendy/alltypes/index.html @@ -10,12 +10,6 @@

All Types

-com.levibostian.wendy.extension.CreateGroceryStoreItemPendingTask - - - - - com.levibostian.wendy.service.PendingTask

Represents a single task to perform. Usually used to sync offline data stored on the device with online remote storage.

diff --git a/docs/wendy/com.levibostian.wendy.db/-pending-task-error/index.html b/docs/wendy/com.levibostian.wendy.db/-pending-task-error/index.html index f534ecf..deb18fa 100644 --- a/docs/wendy/com.levibostian.wendy.db/-pending-task-error/index.html +++ b/docs/wendy/com.levibostian.wendy.db/-pending-task-error/index.html @@ -60,7 +60,9 @@

Properties

pending_task

-lateinit var pending_task: PendingTask +lateinit var pending_task: PendingTask +

The PendingTask this error is associated with.

+ @@ -85,5 +87,19 @@

Functions

+

Extension Functions

+ + + + + + + +
+

resolveError

+
+fun PendingTaskError.resolveError(): Boolean +

Extension to PendingTasks.resolveError easily from a PendingTaskError instance.

+
diff --git a/docs/wendy/com.levibostian.wendy.db/-pending-task-error/pending_task.html b/docs/wendy/com.levibostian.wendy.db/-pending-task-error/pending_task.html index 918b048..289f94d 100644 --- a/docs/wendy/com.levibostian.wendy.db/-pending-task-error/pending_task.html +++ b/docs/wendy/com.levibostian.wendy.db/-pending-task-error/pending_task.html @@ -10,5 +10,9 @@

pending_task

lateinit var pending_task: PendingTask +

The PendingTask this error is associated with.

+

Property

+

+pending_task - The PendingTask this error is associated with.

diff --git a/docs/wendy/com.levibostian.wendy.extension/add-task-status-listener-for-task.html b/docs/wendy/com.levibostian.wendy.extension/add-task-status-listener-for-task.html new file mode 100644 index 0000000..92535e7 --- /dev/null +++ b/docs/wendy/com.levibostian.wendy.extension/add-task-status-listener-for-task.html @@ -0,0 +1,15 @@ + + + +addTaskStatusListenerForTask - wendy + + + +wendy / com.levibostian.wendy.extension / addTaskStatusListenerForTask
+
+

addTaskStatusListenerForTask

+ +fun PendingTask.addTaskStatusListenerForTask(listener: PendingTaskStatusListener): Unit +

Extension to WendyConfig.addTaskStatusListenerForTask easily from a PendingTask instance.

+ + diff --git a/docs/wendy/com.levibostian.wendy.extension/get-latest-error.html b/docs/wendy/com.levibostian.wendy.extension/get-latest-error.html new file mode 100644 index 0000000..8b4c3d9 --- /dev/null +++ b/docs/wendy/com.levibostian.wendy.extension/get-latest-error.html @@ -0,0 +1,15 @@ + + + +getLatestError - wendy + + + +wendy / com.levibostian.wendy.extension / getLatestError
+
+

getLatestError

+ +fun PendingTask.getLatestError(): PendingTaskError? +

Extension to PendingTasks.getLatestError easily from a PendingTask instance.

+ + diff --git a/docs/wendy/com.levibostian.wendy.extension/index.html b/docs/wendy/com.levibostian.wendy.extension/index.html index b88f1d1..9c23c76 100644 --- a/docs/wendy/com.levibostian.wendy.extension/index.html +++ b/docs/wendy/com.levibostian.wendy.extension/index.html @@ -8,15 +8,46 @@ wendy / com.levibostian.wendy.extension

Package com.levibostian.wendy.extension

-

Types

+

Functions

+fun PendingTask.addTaskStatusListenerForTask(listener: PendingTaskStatusListener): Unit +

Extension to WendyConfig.addTaskStatusListenerForTask easily from a PendingTask instance.

+ + + + + + + + + + + + +
-

CreateGroceryStoreItemPendingTask

+

addTaskStatusListenerForTask

-class CreateGroceryStoreItemPendingTask : PendingTask
+

getLatestError

+
+fun PendingTask.getLatestError(): PendingTaskError? +

Extension to PendingTasks.getLatestError easily from a PendingTask instance.

+
+

recordError

+
+fun PendingTask.recordError(humanReadableErrorMessage: String?, errorId: String?): Unit +

Extension to PendingTasks.recordError easily from a PendingTask instance.

+
+

resolveError

+
+fun PendingTaskError.resolveError(): Boolean +

Extension to PendingTasks.resolveError easily from a PendingTaskError instance.

+fun PendingTask.resolveError(): Boolean +

Extension to PendingTasks.resolveError easily from a PendingTask instance.

+
diff --git a/docs/wendy/com.levibostian.wendy.extension/record-error.html b/docs/wendy/com.levibostian.wendy.extension/record-error.html new file mode 100644 index 0000000..016bb54 --- /dev/null +++ b/docs/wendy/com.levibostian.wendy.extension/record-error.html @@ -0,0 +1,15 @@ + + + +recordError - wendy + + + +wendy / com.levibostian.wendy.extension / recordError
+
+

recordError

+ +fun PendingTask.recordError(humanReadableErrorMessage: String?, errorId: String?): Unit +

Extension to PendingTasks.recordError easily from a PendingTask instance.

+ + diff --git a/docs/wendy/com.levibostian.wendy.extension/resolve-error.html b/docs/wendy/com.levibostian.wendy.extension/resolve-error.html new file mode 100644 index 0000000..83785d3 --- /dev/null +++ b/docs/wendy/com.levibostian.wendy.extension/resolve-error.html @@ -0,0 +1,18 @@ + + + +resolveError - wendy + + + +wendy / com.levibostian.wendy.extension / resolveError
+
+

resolveError

+ +fun PendingTaskError.resolveError(): Boolean +

Extension to PendingTasks.resolveError easily from a PendingTaskError instance.

+ +fun PendingTask.resolveError(): Boolean +

Extension to PendingTasks.resolveError easily from a PendingTask instance.

+ + diff --git a/docs/wendy/com.levibostian.wendy.listeners/-pending-task-status-listener/error-recorded.html b/docs/wendy/com.levibostian.wendy.listeners/-pending-task-status-listener/error-recorded.html index a394de5..51d978c 100644 --- a/docs/wendy/com.levibostian.wendy.listeners/-pending-task-status-listener/error-recorded.html +++ b/docs/wendy/com.levibostian.wendy.listeners/-pending-task-status-listener/error-recorded.html @@ -11,6 +11,7 @@

errorRecorded

@UiThread abstract fun errorRecorded(taskId: Long, errorMessage: String?, errorId: String?): Unit

There was an error recorded to Wendy for this PendingTask.

+

Tip: It's recommended that when errorRecorded gets called and if you decide to show something in the UI about a PendingTask having an error, keep that UI up until the user dismisses it. They touch it, swipe it, whatever. Why? Because other methods may get called after errorRecorded gets called and errors are a pretty important thing to fix.

Parameters

taskId - the task_id of the PendingTask that an error occurred to.

diff --git a/docs/wendy/com.levibostian.wendy.service/-pending-task/index.html b/docs/wendy/com.levibostian.wendy.service/-pending-task/index.html index 2773161..b59ba9a 100644 --- a/docs/wendy/com.levibostian.wendy.service/-pending-task/index.html +++ b/docs/wendy/com.levibostian.wendy.service/-pending-task/index.html @@ -134,15 +134,44 @@

Functions

-

Inheritors

+

Extension Functions

+fun PendingTask.addTaskStatusListenerForTask(listener: PendingTaskStatusListener): Unit +

Extension to WendyConfig.addTaskStatusListenerForTask easily from a PendingTask instance.

+ + + + + + + + + + + + +
-

CreateGroceryStoreItemPendingTask

+

addTaskStatusListenerForTask

-class CreateGroceryStoreItemPendingTask : PendingTask
+

getLatestError

+
+fun PendingTask.getLatestError(): PendingTaskError? +

Extension to PendingTasks.getLatestError easily from a PendingTask instance.

+
+

recordError

+
+fun PendingTask.recordError(humanReadableErrorMessage: String?, errorId: String?): Unit +

Extension to PendingTasks.recordError easily from a PendingTask instance.

+
+

resolveError

+
+fun PendingTask.resolveError(): Boolean +

Extension to PendingTasks.resolveError easily from a PendingTask instance.

+
diff --git a/docs/wendy/com.levibostian.wendy.service/-pending-tasks/get-all-errors.html b/docs/wendy/com.levibostian.wendy.service/-pending-tasks/get-all-errors.html new file mode 100644 index 0000000..7c19278 --- /dev/null +++ b/docs/wendy/com.levibostian.wendy.service/-pending-tasks/get-all-errors.html @@ -0,0 +1,15 @@ + + + +PendingTasks.getAllErrors - wendy + + + +wendy / com.levibostian.wendy.service / PendingTasks / getAllErrors
+
+

getAllErrors

+ +fun getAllErrors(): List<PendingTaskError> +

Get all errors that currently exist for PendingTasks.

+ + diff --git a/docs/wendy/com.levibostian.wendy.service/-pending-tasks/index.html b/docs/wendy/com.levibostian.wendy.service/-pending-tasks/index.html index 4ef5fca..47e6b7b 100644 --- a/docs/wendy/com.levibostian.wendy.service/-pending-tasks/index.html +++ b/docs/wendy/com.levibostian.wendy.service/-pending-tasks/index.html @@ -45,6 +45,15 @@

Functions

+

getAllErrors

+ + +fun getAllErrors(): List<PendingTaskError> +

Get all errors that currently exist for PendingTasks.

+ + + +

getAllTasks

@@ -75,7 +84,7 @@

Functions

resolveError

-fun resolveError(taskId: Long): Unit +fun resolveError(taskId: Long): Boolean

Mark a previously recorded error for a PendingTask as resolved.

@@ -99,6 +108,20 @@

Functions

+

Companion Object Properties

+ + + + + + + +
+

shared

+
+val shared: PendingTasks +

Short hand version of calling sharedInstance.

+

Companion Object Functions

diff --git a/docs/wendy/com.levibostian.wendy.service/-pending-tasks/resolve-error.html b/docs/wendy/com.levibostian.wendy.service/-pending-tasks/resolve-error.html index aa3d962..320cffa 100644 --- a/docs/wendy/com.levibostian.wendy.service/-pending-tasks/resolve-error.html +++ b/docs/wendy/com.levibostian.wendy.service/-pending-tasks/resolve-error.html @@ -9,13 +9,15 @@

resolveError

-fun resolveError(taskId: Long): Unit +fun resolveError(taskId: Long): Boolean

Mark a previously recorded error for a PendingTask as resolved.

Note: If you attempt to resolve an error using a taskId that does not exist, your request to record an error will be ignored.

Note: If you attempt to resolve an error when an error does not exist in Wendy (because it has already been resolved or was never recorded) then the TaskRunnerListener.errorResolved and PendingTaskStatusListener.errorResolved will not be called.

Parameters

taskId - The task_id of a PendingTask previously recorded an error for.

+

Return
+If PendingTask had a previously recorded error and it has been marked as resolved now.

See Also

recordError

diff --git a/docs/wendy/com.levibostian.wendy.service/-pending-tasks/shared.html b/docs/wendy/com.levibostian.wendy.service/-pending-tasks/shared.html new file mode 100644 index 0000000..8dabb1b --- /dev/null +++ b/docs/wendy/com.levibostian.wendy.service/-pending-tasks/shared.html @@ -0,0 +1,18 @@ + + + +PendingTasks.shared - wendy + + + +wendy / com.levibostian.wendy.service / PendingTasks / shared
+
+

shared

+ +@JvmStatic val shared: PendingTasks +

Short hand version of calling sharedInstance.

+

Getter
+

Short hand version of calling sharedInstance.

+

+ + diff --git a/docs/wendy/index-outline.html b/docs/wendy/index-outline.html index 98917ff..b18b8de 100644 --- a/docs/wendy/index-outline.html +++ b/docs/wendy/index-outline.html @@ -23,20 +23,6 @@ -class CreateGroceryStoreItemPendingTask : PendingTask
-abstract class PendingTask : PendingTaskFields
@@ -420,13 +399,15 @@ fun addTask(pendingTask: PendingTask): Long
fun debug(enableDebug: Boolean = false): PendingTasks
+fun getAllErrors(): List<PendingTaskError>
fun getAllTasks(): List<PendingTask>
fun getLatestError(taskId: Long): PendingTaskError?
@JvmStatic fun init(context: Context, tasksFactory: PendingTasksFactory): PendingTasks
fun recordError(taskId: Long, humanReadableErrorMessage: String?, errorId: String?): Unit
-fun resolveError(taskId: Long): Unit
+fun resolveError(taskId: Long): Boolean
fun runTask(taskId: Long): Unit
fun runTasks(): Unit
+@JvmStatic val shared: PendingTasks
@JvmStatic fun sharedInstance(): PendingTasks
val tasksFactory: PendingTasksFactory
diff --git a/wendy/build.gradle b/wendy/build.gradle index 7dbf36b..340e15b 100644 --- a/wendy/build.gradle +++ b/wendy/build.gradle @@ -36,7 +36,7 @@ dependencies { androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - implementation 'com.android.support:support-annotations:27.0.2' + implementation 'com.android.support:support-annotations:27.1.0' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:2.10.0' diff --git a/wendy/src/main/java/com/levibostian/wendy/extension/PendingTaskErrorExtensions.kt b/wendy/src/main/java/com/levibostian/wendy/extension/PendingTaskErrorExtensions.kt new file mode 100644 index 0000000..b628f10 --- /dev/null +++ b/wendy/src/main/java/com/levibostian/wendy/extension/PendingTaskErrorExtensions.kt @@ -0,0 +1,9 @@ +package com.levibostian.wendy.extension + +import com.levibostian.wendy.db.PendingTaskError +import com.levibostian.wendy.service.PendingTasks + +/** + * Extension to [PendingTasks.resolveError] easily from a [PendingTaskError] instance. + */ +fun PendingTaskError.resolveError() = PendingTasks.shared.resolveError(this.task_id) \ No newline at end of file diff --git a/wendy/src/main/java/com/levibostian/wendy/extension/PendingTaskExtensions.kt b/wendy/src/main/java/com/levibostian/wendy/extension/PendingTaskExtensions.kt new file mode 100644 index 0000000..af7bb32 --- /dev/null +++ b/wendy/src/main/java/com/levibostian/wendy/extension/PendingTaskExtensions.kt @@ -0,0 +1,27 @@ +package com.levibostian.wendy.extension + +import com.levibostian.wendy.WendyConfig +import com.levibostian.wendy.db.PendingTaskError +import com.levibostian.wendy.listeners.PendingTaskStatusListener +import com.levibostian.wendy.service.PendingTask +import com.levibostian.wendy.service.PendingTasks + +/** + * Extension to [PendingTasks.recordError] easily from a [PendingTask] instance. + */ +fun PendingTask.recordError(humanReadableErrorMessage: String?, errorId: String?) = PendingTasks.shared.recordError(this.task_id, humanReadableErrorMessage, errorId) + +/** + * Extension to [PendingTasks.resolveError] easily from a [PendingTask] instance. + */ +fun PendingTask.resolveError() = PendingTasks.shared.resolveError(this.task_id) + +/** + * Extension to [PendingTasks.getLatestError] easily from a [PendingTask] instance. + */ +fun PendingTask.getLatestError(): PendingTaskError? = PendingTasks.shared.getLatestError(this.task_id) + +/** + * Extension to [WendyConfig.addTaskStatusListenerForTask] easily from a [PendingTask] instance. + */ +fun PendingTask.addTaskStatusListenerForTask(listener: PendingTaskStatusListener) = WendyConfig.addTaskStatusListenerForTask(this.task_id, listener) \ No newline at end of file diff --git a/wendy/src/main/java/com/levibostian/wendy/listeners/PendingTaskStatusListener.kt b/wendy/src/main/java/com/levibostian/wendy/listeners/PendingTaskStatusListener.kt index 3ac7e5a..28bc049 100644 --- a/wendy/src/main/java/com/levibostian/wendy/listeners/PendingTaskStatusListener.kt +++ b/wendy/src/main/java/com/levibostian/wendy/listeners/PendingTaskStatusListener.kt @@ -36,6 +36,8 @@ interface PendingTaskStatusListener { /** * There was an error recorded to Wendy for this [PendingTask]. * + * *Tip:* It's recommended that when [errorRecorded] gets called and if you decide to show something in the UI about a [PendingTask] having an error, keep that UI up until the user dismisses it. They touch it, swipe it, whatever. Why? Because other methods may get called after [errorRecorded] gets called and errors are a pretty important thing to fix. + * * @param taskId the task_id of the [PendingTask] that an error occurred to. * @param errorMessage The human readable error message recorded for the error. * @param errorId The error ID recorded to Wendy for the error. diff --git a/wendy/src/main/java/com/levibostian/wendy/service/PendingTasks.kt b/wendy/src/main/java/com/levibostian/wendy/service/PendingTasks.kt index 293292a..e7d2b79 100644 --- a/wendy/src/main/java/com/levibostian/wendy/service/PendingTasks.kt +++ b/wendy/src/main/java/com/levibostian/wendy/service/PendingTasks.kt @@ -46,6 +46,12 @@ open class PendingTasks private constructor(context: Context, val tasksFactory: if (instance == null) throw RuntimeException("Sorry, you must initialize the instance first.") return instance!! } + + /** + * Short hand version of calling [sharedInstance]. + */ + @JvmStatic val shared: PendingTasks by lazy { sharedInstance() } + } /** @@ -161,15 +167,18 @@ open class PendingTasks private constructor(context: Context, val tasksFactory: * *Note:* If you attempt to resolve an error when an error does not exist in Wendy (because it has already been resolved or was never recorded) then the [TaskRunnerListener.errorResolved] and [PendingTaskStatusListener.errorResolved] will not be called. * * @param taskId The task_id of a [PendingTask] previously recorded an error for. + * @return If [PendingTask] had a previously recorded error and it has been marked as resolved now. * * @see recordError This is how to record an error. */ - fun resolveError(taskId: Long) { - val pendingTask = tasksManager.getPendingTaskTaskById(taskId) ?: return + fun resolveError(taskId: Long): Boolean { + val pendingTask = tasksManager.getPendingTaskTaskById(taskId) ?: return false if (tasksManager.deletePendingTaskError(taskId)) { // Only log error as resolved if an error was even recorded in the first place. WendyConfig.logErrorResolved(pendingTask) + return true } + return false } /**