Skip to content

Commit

Permalink
Merge pull request #46 from levibostian/fix-0.2.0
Browse files Browse the repository at this point in the history
Fix RuntimeException while deleting SQLite database.
  • Loading branch information
levibostian authored Jun 11, 2018
2 parents f9c40d4 + 5593c4a commit b93f22b
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 35 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### [0.2.1-alpha] 2018-06-11

### Fixed
- Fix RuntimeException while deleting SQLite database.

### Added
- Wendy `.clear()` has an async and sync version.
- **Breaking Change** `Wendy.clear()` has been renamed to `Wendy.clearAsync()`. `Wendy.clear()` is the synchronous version now.

### [0.2.0-alpha] 2018-06-11

### Added
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ fun createNewGroceryStoreItem(itemName: String) {

Done! Wendy takes care of all the rest. Wendy will try to run your task right away but if you're offline or in a spotty Internet connection, Wendy will wait and try again later.

Oh, and lastly. If your user decides to logout of your app and you want to delete all of Wendy's data, you can do so via `Wendy.shared.clear()` or `Wendy.shared.clearAsync()`.

There is a document on [best practices when using Wendy](BEST_PRACTICES.md). Check that out to answer your questions you have about why Wendy works the way that it does.

## Example app
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/levibostian/wendyexample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.levibostian.wendy.service.Wendy
import com.levibostian.wendy.types.ReasonPendingTaskSkipped
import com.levibostian.wendyexample.extension.closeKeyboard
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*

class MainActivity : AppCompatActivity(), TaskRunnerListener {

Expand Down Expand Up @@ -48,9 +49,17 @@ class MainActivity : AppCompatActivity(), TaskRunnerListener {
}
activity_main_clear_all_data_button.setOnClickListener {
Toast.makeText(this, "Clearing data...", Toast.LENGTH_SHORT).show()
Wendy.shared.clear {

// This way we can test both the async and sync version.
if (Random().nextFloat() >= 0.5f) {
Wendy.shared.clear()
refreshListOfTasks()
Toast.makeText(this, "Data cleared!", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Data cleared (sync)!", Toast.LENGTH_SHORT).show()
} else {
Wendy.shared.clearAsync {
refreshListOfTasks()
Toast.makeText(this, "Data cleared (async)!", Toast.LENGTH_SHORT).show()
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions docs/wendy/com.levibostian.wendy.service/-wendy/clear-async.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<HTML>
<HEAD>
<meta charset="UTF-8">
<title>Wendy.clearAsync - wendy</title>
<link rel="stylesheet" href="../../../style.css">
</HEAD>
<BODY>
<a href="../../index.html">wendy</a>&nbsp;/&nbsp;<a href="../index.html">com.levibostian.wendy.service</a>&nbsp;/&nbsp;<a href="index.html">Wendy</a>&nbsp;/&nbsp;<a href="./clear-async.html">clearAsync</a><br/>
<br/>
<h1>clearAsync</h1>
<a name="com.levibostian.wendy.service.Wendy$clearAsync(kotlin.Function0((kotlin.Unit)))"></a>
<code><span class="keyword">fun </span><span class="identifier">clearAsync</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$clearAsync(kotlin.Function0((kotlin.Unit)))/complete">complete</span><span class="symbol">:</span>&nbsp;<span class="symbol">(</span><span class="symbol">)</span>&nbsp;<span class="symbol">-&gt;</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></code>
<p>Async version of <a href="clear.html">clear</a>.</p>
<p><strong>See Also</strong><br/>
<p><a href="clear.html">clear</a></p>
</p>
</BODY>
</HTML>
9 changes: 6 additions & 3 deletions docs/wendy/com.levibostian.wendy.service/-wendy/clear.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
<a href="../../index.html">wendy</a>&nbsp;/&nbsp;<a href="../index.html">com.levibostian.wendy.service</a>&nbsp;/&nbsp;<a href="index.html">Wendy</a>&nbsp;/&nbsp;<a href="./clear.html">clear</a><br/>
<br/>
<h1>clear</h1>
<a name="com.levibostian.wendy.service.Wendy$clear(kotlin.Function0((kotlin.Unit)))"></a>
<code><span class="keyword">fun </span><span class="identifier">clear</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$clear(kotlin.Function0((kotlin.Unit)))/complete">complete</span><span class="symbol">:</span>&nbsp;<span class="symbol">(</span><span class="symbol">)</span>&nbsp;<span class="symbol">-&gt;</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></code>
<a name="com.levibostian.wendy.service.Wendy$clear()"></a>
<code><span class="keyword">fun </span><span class="identifier">clear</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></code>
<p>Stop the task runner and clear all of the <a href="../-pending-task/index.html">PendingTask</a>s added to Wendy.</p>
<p>This function was written with the intention of using when a user of your app is logged out and you want to clear all of the data associated with that user.</p>
<p>This function will stop the task runner any tasks, deletes all of the data from the task database, and deletes all the data stored in</p>
<p>This function will stop the task runner any tasks, deletes all of the data from the task database, and deletes all the data stored in SharedPreferences.</p>
<p><strong>See Also</strong><br/>
<p><a href="clear-async.html">clearAsync</a></p>
</p>
</BODY>
</HTML>
11 changes: 10 additions & 1 deletion docs/wendy/com.levibostian.wendy.service/-wendy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ <h3>Functions</h3>
<p><a href="clear.html">clear</a></p>
</td>
<td>
<code><span class="keyword">fun </span><span class="identifier">clear</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$clear(kotlin.Function0((kotlin.Unit)))/complete">complete</span><span class="symbol">:</span>&nbsp;<span class="symbol">(</span><span class="symbol">)</span>&nbsp;<span class="symbol">-&gt;</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></code>
<code><span class="keyword">fun </span><span class="identifier">clear</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></code>
<p>Stop the task runner and clear all of the <a href="../-pending-task/index.html">PendingTask</a>s added to Wendy.</p>
</td>
</tr>
<tr>
<td>
<p><a href="clear-async.html">clearAsync</a></p>
</td>
<td>
<code><span class="keyword">fun </span><span class="identifier">clearAsync</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$clearAsync(kotlin.Function0((kotlin.Unit)))/complete">complete</span><span class="symbol">:</span>&nbsp;<span class="symbol">(</span><span class="symbol">)</span>&nbsp;<span class="symbol">-&gt;</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></code>
<p>Async version of <a href="clear.html">clear</a>.</p>
</td>
</tr>
<tr>
<td>
<p><a href="debug.html">debug</a></p>
</td>
<td>
Expand Down
6 changes: 4 additions & 2 deletions docs/wendy/index-outline.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@
</HEAD>
<BODY>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/add-task.html"><span class="keyword">fun </span><span class="identifier">addTask</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$addTask(com.levibostian.wendy.service.PendingTask, kotlin.Boolean)/pendingTask">pendingTask</span><span class="symbol">:</span>&nbsp;<a href="com.levibostian.wendy.service/-pending-task/index.html"><span class="identifier">PendingTask</span></a><span class="symbol">, </span><span class="identifier" id="com.levibostian.wendy.service.Wendy$addTask(com.levibostian.wendy.service.PendingTask, kotlin.Boolean)/resolveErrorIfTaskExists">resolveErrorIfTaskExists</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a>&nbsp;<span class="symbol">=</span>&nbsp;true<span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html"><span class="identifier">Long</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/clear.html"><span class="keyword">fun </span><span class="identifier">clear</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$clear(kotlin.Function0((kotlin.Unit)))/complete">complete</span><span class="symbol">:</span>&nbsp;<span class="symbol">(</span><span class="symbol">)</span>&nbsp;<span class="symbol">-&gt;</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/clear.html"><span class="keyword">fun </span><span class="identifier">clear</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/clear-async.html"><span class="keyword">fun </span><span class="identifier">clearAsync</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$clearAsync(kotlin.Function0((kotlin.Unit)))/complete">complete</span><span class="symbol">:</span>&nbsp;<span class="symbol">(</span><span class="symbol">)</span>&nbsp;<span class="symbol">-&gt;</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/debug.html"><span class="keyword">fun </span><span class="identifier">debug</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$debug(kotlin.Boolean)/enableDebug">enableDebug</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a>&nbsp;<span class="symbol">=</span>&nbsp;false<span class="symbol">)</span><span class="symbol">: </span><a href="com.levibostian.wendy.service/-wendy/index.html"><span class="identifier">Wendy</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/does-error-exist.html"><span class="keyword">fun </span><span class="identifier">doesErrorExist</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$doesErrorExist(kotlin.Long)/taskId">taskId</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html"><span class="identifier">Long</span></a><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/get-all-errors.html"><span class="keyword">fun </span><span class="identifier">getAllErrors</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html"><span class="identifier">List</span></a><span class="symbol">&lt;</span><a href="com.levibostian.wendy.db/-pending-task-error/index.html"><span class="identifier">PendingTaskError</span></a><span class="symbol">&gt;</span></a></a><br/>
Expand Down Expand Up @@ -445,7 +446,8 @@
</HEAD>
<BODY>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/add-task.html"><span class="keyword">fun </span><span class="identifier">addTask</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$addTask(com.levibostian.wendy.service.PendingTask, kotlin.Boolean)/pendingTask">pendingTask</span><span class="symbol">:</span>&nbsp;<a href="com.levibostian.wendy.service/-pending-task/index.html"><span class="identifier">PendingTask</span></a><span class="symbol">, </span><span class="identifier" id="com.levibostian.wendy.service.Wendy$addTask(com.levibostian.wendy.service.PendingTask, kotlin.Boolean)/resolveErrorIfTaskExists">resolveErrorIfTaskExists</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a>&nbsp;<span class="symbol">=</span>&nbsp;true<span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html"><span class="identifier">Long</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/clear.html"><span class="keyword">fun </span><span class="identifier">clear</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$clear(kotlin.Function0((kotlin.Unit)))/complete">complete</span><span class="symbol">:</span>&nbsp;<span class="symbol">(</span><span class="symbol">)</span>&nbsp;<span class="symbol">-&gt;</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/clear.html"><span class="keyword">fun </span><span class="identifier">clear</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/clear-async.html"><span class="keyword">fun </span><span class="identifier">clearAsync</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$clearAsync(kotlin.Function0((kotlin.Unit)))/complete">complete</span><span class="symbol">:</span>&nbsp;<span class="symbol">(</span><span class="symbol">)</span>&nbsp;<span class="symbol">-&gt;</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a><span class="symbol">?</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html"><span class="identifier">Unit</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/debug.html"><span class="keyword">fun </span><span class="identifier">debug</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$debug(kotlin.Boolean)/enableDebug">enableDebug</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a>&nbsp;<span class="symbol">=</span>&nbsp;false<span class="symbol">)</span><span class="symbol">: </span><a href="com.levibostian.wendy.service/-wendy/index.html"><span class="identifier">Wendy</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/does-error-exist.html"><span class="keyword">fun </span><span class="identifier">doesErrorExist</span><span class="symbol">(</span><span class="identifier" id="com.levibostian.wendy.service.Wendy$doesErrorExist(kotlin.Long)/taskId">taskId</span><span class="symbol">:</span>&nbsp;<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html"><span class="identifier">Long</span></a><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html"><span class="identifier">Boolean</span></a></a></a><br/>
<a href="docs/wendy/index"><a href="com.levibostian.wendy.service/-wendy/get-all-errors.html"><span class="keyword">fun </span><span class="identifier">getAllErrors</span><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">: </span><a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html"><span class="identifier">List</span></a><span class="symbol">&lt;</span><a href="com.levibostian.wendy.db/-pending-task-error/index.html"><span class="identifier">PendingTaskError</span></a><span class="symbol">&gt;</span></a></a><br/>
Expand Down
2 changes: 1 addition & 1 deletion wendy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "0.2.0-alpha"
versionName "0.2.1-alpha"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ internal class PendingTasksManager(private val context: Context) {

@Synchronized
internal fun clear() {
if (!context.deleteDatabase(PendingTasksDatabaseHelper.DATABASE_NAME)) throw RuntimeException("Wendy database did not delete successfully.")
context.deleteDatabase(PendingTasksDatabaseHelper.DATABASE_NAME)
}

}
Loading

0 comments on commit b93f22b

Please sign in to comment.