-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9969360
commit 5a4c662
Showing
148 changed files
with
4,894 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
defaultConfig { | ||
applicationId "com.commonsware.todo" | ||
minSdkVersion 21 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
testApplicationId "com.commonsware.todo.test" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
dataBinding { | ||
enabled=true | ||
} | ||
} | ||
|
||
def supportVer="27.1.1" | ||
def autoValueVer="1.5.1" | ||
def archVer="1.1.1" | ||
def roomVer="1.1.0" | ||
|
||
dependencies { | ||
implementation "com.android.support:recyclerview-v7:$supportVer" | ||
implementation "com.android.support:support-fragment:$supportVer" | ||
implementation "android.arch.lifecycle:extensions:$archVer" | ||
implementation "android.arch.lifecycle:reactivestreams:$archVer" | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.0' | ||
implementation "io.reactivex.rxjava2:rxjava:2.1.7" | ||
implementation "android.arch.persistence.room:runtime:$roomVer" | ||
implementation "android.arch.persistence.room:rxjava2:$roomVer" | ||
annotationProcessor "android.arch.persistence.room:compiler:$roomVer" | ||
compileOnly "com.google.auto.value:auto-value:$autoValueVer" | ||
annotationProcessor "com.google.auto.value:auto-value:$autoValueVer" | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
102 changes: 102 additions & 0 deletions
102
T31-Load/ToDo/app/src/androidTest/java/com/commonsware/todo/ControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.commonsware.todo; | ||
|
||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.TimeUnit; | ||
import io.reactivex.subjects.PublishSubject; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ControllerTest { | ||
@Before | ||
public void setUp() { | ||
ToDoDatabase db=ToDoDatabase.get(InstrumentationRegistry.getTargetContext()); | ||
|
||
db.todoStore().deleteAll(); | ||
} | ||
|
||
@Test | ||
public void controller() throws InterruptedException { | ||
final Controller controller=new Controller(InstrumentationRegistry.getTargetContext()); | ||
final PublishSubject<Action> actionSubject=PublishSubject.create(); | ||
final LinkedBlockingQueue<Result> receivedResults=new LinkedBlockingQueue<>(); | ||
|
||
controller.subscribeToActions(actionSubject); | ||
controller.resultStream().subscribe(receivedResults::offer); | ||
|
||
actionSubject.onNext(Action.load()); | ||
|
||
Result.Loaded resultLoaded= | ||
(Result.Loaded)receivedResults.poll(1, TimeUnit.SECONDS); | ||
|
||
assertEquals(0, resultLoaded.models().size()); | ||
|
||
final ToDoModel fooModel=ToDoModel.creator().description("foo").notes("hello, world!").build(); | ||
|
||
actionSubject.onNext(Action.add(fooModel)); | ||
|
||
Result.Added resultAdded= | ||
(Result.Added)receivedResults.poll(1, TimeUnit.SECONDS); | ||
|
||
assertEquals(fooModel, resultAdded.model()); | ||
|
||
final ToDoModel barModel=ToDoModel.creator().description("bar").build(); | ||
actionSubject.onNext(Action.add(barModel)); | ||
resultAdded= | ||
(Result.Added)receivedResults.poll(1, TimeUnit.SECONDS); | ||
assertEquals(barModel, resultAdded.model()); | ||
|
||
final ToDoModel gooModel=ToDoModel.creator() | ||
.description("goo") | ||
.isCompleted(true) | ||
.build(); | ||
actionSubject.onNext(Action.add(gooModel)); | ||
resultAdded= | ||
(Result.Added)receivedResults.poll(1, TimeUnit.SECONDS); | ||
assertEquals(gooModel, resultAdded.model()); | ||
|
||
final ToDoModel mutatedFoo=fooModel.toBuilder().isCompleted(true).build(); | ||
actionSubject.onNext(Action.edit(mutatedFoo)); | ||
|
||
Result.Modified resultModified= | ||
(Result.Modified)receivedResults.poll(1, TimeUnit.SECONDS); | ||
|
||
assertEquals(mutatedFoo, resultModified.model()); | ||
|
||
final ToDoModel mutatedBar=barModel.toBuilder().description("bar!").notes("hi!").build(); | ||
actionSubject.onNext(Action.edit(mutatedBar)); | ||
resultModified= | ||
(Result.Modified)receivedResults.poll(1, TimeUnit.SECONDS); | ||
assertEquals(mutatedBar, resultModified.model()); | ||
|
||
final ToDoModel mutatedGoo=gooModel.toBuilder() | ||
.description("goo!") | ||
.isCompleted(false) | ||
.build(); | ||
actionSubject.onNext(Action.edit(mutatedGoo)); | ||
resultModified= | ||
(Result.Modified)receivedResults.poll(1, TimeUnit.SECONDS); | ||
assertEquals(mutatedGoo, resultModified.model()); | ||
|
||
actionSubject.onNext(Action.delete(barModel)); | ||
|
||
Result.Deleted resultDeleted= | ||
(Result.Deleted)receivedResults.poll(1, TimeUnit.SECONDS); | ||
|
||
assertEquals(barModel, resultDeleted.model()); | ||
|
||
actionSubject.onNext(Action.delete(fooModel)); | ||
resultDeleted= | ||
(Result.Deleted)receivedResults.poll(1, TimeUnit.SECONDS); | ||
assertEquals(fooModel, resultDeleted.model()); | ||
|
||
actionSubject.onNext(Action.delete(gooModel)); | ||
resultDeleted= | ||
(Result.Deleted)receivedResults.poll(1, TimeUnit.SECONDS); | ||
assertEquals(gooModel, resultDeleted.model()); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
T31-Load/ToDo/app/src/androidTest/java/com/commonsware/todo/RepoTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.commonsware.todo; | ||
|
||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import java.util.List; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertSame; | ||
import static org.junit.Assert.assertThat; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class RepoTests { | ||
private ToDoRepository repo; | ||
|
||
@Before | ||
public void setUp() { | ||
ToDoDatabase db=ToDoDatabase.get(InstrumentationRegistry.getTargetContext()); | ||
|
||
db.todoStore().deleteAll(); | ||
repo=ToDoRepository.get(InstrumentationRegistry.getTargetContext()); | ||
repo.add(ToDoModel.creator() | ||
.description("Buy a copy of _Exploring Android_") | ||
.notes("See https://wares.commonsware.com") | ||
.isCompleted(true) | ||
.build()); | ||
repo.add(ToDoModel.creator() | ||
.description("Complete all of the tutorials") | ||
.build()); | ||
repo.add(ToDoModel.creator() | ||
.description("Write an app for somebody in my community") | ||
.notes("Talk to some people at non-profit organizations to see what they need!") | ||
.build()); | ||
} | ||
|
||
@Test | ||
public void getAll() { | ||
assertEquals(3, repo.all().size()); | ||
} | ||
|
||
@Test | ||
public void add() { | ||
ToDoModel model=ToDoModel.creator() | ||
.isCompleted(true) | ||
.description("foo") | ||
.build(); | ||
|
||
repo.add(model); | ||
|
||
List<ToDoModel> models=repo.all(); | ||
|
||
assertEquals(4, models.size()); | ||
assertThat(models, hasItem(model)); | ||
} | ||
|
||
@Test | ||
public void replace() { | ||
ToDoModel original=repo.all().get(1); | ||
ToDoModel edited=original.toBuilder() | ||
.isCompleted(true) | ||
.description("Currently on Tutorial #30") | ||
.build(); | ||
|
||
repo.replace(edited); | ||
assertEquals(3, repo.all().size()); | ||
assertEquals(edited, repo.all().get(1)); | ||
} | ||
|
||
@Test | ||
public void delete() { | ||
assertEquals(3, repo.all().size()); | ||
repo.delete(repo.all().get(0)); | ||
assertEquals(2, repo.all().size()); | ||
repo.delete(repo.all().get(0).toBuilder().build()); | ||
assertEquals(1, repo.all().size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.commonsware.todo" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<supports-screens | ||
android:largeScreens="true" | ||
android:normalScreens="true" | ||
android:smallScreens="true" | ||
android:xlargeScreens="true" /> | ||
|
||
<application | ||
android:name=".ToDoApp" | ||
android:allowBackup="false" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
tools:ignore="GoogleAppIndexingWarning"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".AboutActivity"></activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h1>About This App</h1> | ||
|
||
<p>This app is cool!</p> | ||
|
||
<p>No, really — this app is awesome!</p> | ||
|
||
<div> | ||
. | ||
<br/> | ||
. | ||
<br/> | ||
. | ||
<br/> | ||
. | ||
</div> | ||
|
||
<p>OK, this app isn't all that much. But, hey, it's mine!</p> |
18 changes: 18 additions & 0 deletions
18
T31-Load/ToDo/app/src/main/java/com/commonsware/todo/AboutActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.commonsware.todo; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.FragmentActivity; | ||
import android.webkit.WebView; | ||
|
||
public class AboutActivity extends FragmentActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_about); | ||
|
||
WebView wv=findViewById(R.id.about); | ||
|
||
wv.loadUrl("file:///android_asset/about.html"); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
T31-Load/ToDo/app/src/main/java/com/commonsware/todo/Action.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.commonsware.todo; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
public abstract class Action { | ||
public static Action add(ToDoModel model) { | ||
return new AutoValue_Action_Add(model); | ||
} | ||
|
||
public static Action edit(ToDoModel model) { | ||
return new AutoValue_Action_Edit(model); | ||
} | ||
|
||
public static Action delete(ToDoModel model) { | ||
return new AutoValue_Action_Delete(model); | ||
} | ||
|
||
public static Action show(ToDoModel model) { | ||
return new AutoValue_Action_Show(model); | ||
} | ||
|
||
public static Action load() { | ||
return new Action.Load(); | ||
} | ||
|
||
@AutoValue | ||
public static abstract class Add extends Action { | ||
public abstract ToDoModel model(); | ||
} | ||
|
||
@AutoValue | ||
public static abstract class Edit extends Action { | ||
public abstract ToDoModel model(); | ||
} | ||
|
||
@AutoValue | ||
public static abstract class Delete extends Action { | ||
public abstract ToDoModel model(); | ||
} | ||
|
||
@AutoValue | ||
static abstract class Show extends Action { | ||
public abstract ToDoModel current(); | ||
} | ||
|
||
public static class Load extends Action { | ||
|
||
} | ||
} |
Oops, something went wrong.