Defaulting to bidiriectional bindings
Credit to afergan@ for this more elegant approach!
Change-Id: I69b27a434a9cb7c32b8ba4a3a340e3ff4b9ebff5
diff --git a/examples/hellobaku/android/app/build.gradle b/examples/hellobaku/android/app/build.gradle
index fbd75ee..c356459 100644
--- a/examples/hellobaku/android/app/build.gradle
+++ b/examples/hellobaku/android/app/build.gradle
@@ -33,7 +33,7 @@
}
dependencies {
- compile 'io.v:baku-toolkit:0.7.0'
+ compile 'io.v:baku-toolkit:0.8.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
apk ('org.slf4j:slf4j-android:1.7.12')
}
diff --git a/examples/hellobaku/android/app/src/main/AndroidManifest.xml b/examples/hellobaku/android/app/src/main/AndroidManifest.xml
index f3d2c93..ad765e3 100644
--- a/examples/hellobaku/android/app/src/main/AndroidManifest.xml
+++ b/examples/hellobaku/android/app/src/main/AndroidManifest.xml
@@ -17,6 +17,15 @@
</intent-filter>
</activity>
<activity
+ android:name=".HelloActivityOneWay"
+ android:label="@string/oneway_label" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity
android:name=".HelloActivityComposition"
android:label="@string/comp_label" >
<intent-filter>
diff --git a/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivity.java b/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivity.java
index 84026f7..a87c670 100644
--- a/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivity.java
+++ b/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivity.java
@@ -6,6 +6,7 @@
import android.os.Bundle;
import android.widget.EditText;
+import android.widget.TextView;
import io.v.baku.toolkit.BakuActivity;
@@ -15,15 +16,16 @@
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello);
- // Binds the Syncbase row named "message" to displayTextView
+ final TextView txtOutput = (TextView) findViewById(R.id.displayTextView);
+ // Binds the Syncbase row named "message" to displayTextView, a.k.a. txtOutput.
binder().key("message")
- .bindTo(R.id.displayTextView);
+ .bindTo(txtOutput);
final EditText txtInput = (EditText) findViewById(R.id.inputEditText);
findViewById(R.id.actionButton).setOnClickListener(bn -> {
- // Writes the text of inputEditText to the Syncbase row named "message"
- getSyncbaseTable().put("message", txtInput.getText().toString());
-
+ // Setting the text on txtOutput will update the "message" Syncbase row via the data
+ // binding we established above.
+ txtOutput.setText(txtInput.getText());
txtInput.setText("");
});
}
diff --git a/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityALaCarte.java b/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityALaCarte.java
index 28085d5..5326e7c 100644
--- a/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityALaCarte.java
+++ b/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityALaCarte.java
@@ -7,8 +7,8 @@
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
+import android.widget.TextView;
-import io.v.baku.toolkit.ErrorReporters;
import io.v.baku.toolkit.VAndroidContextMixin;
import io.v.baku.toolkit.VAndroidContextTrait;
import io.v.baku.toolkit.bind.SyncbaseBinding;
@@ -35,25 +35,25 @@
final RxDb db = mSb.rxApp(getPackageName()).rxDb("db");
final RxTable t = db.rxTable("t");
+ final TextView txtOutput = (TextView) findViewById(R.id.displayTextView);
+
// We want this data binding to share the lifecycle of the Activity from onCreate to
// onDestroy, so keep track of its Subscription and unsubscribe in onDestroy.
mActivityDataBindings = SyncbaseBinding.builder()
.activity(vActivity)
.rxTable(db.rxTable("t"))
- // Binds the Syncbase row named "message" to displayTextView
+ // Binds the Syncbase row named "message" to displayTextView, a.k.a. txtOutput.
.key("message")
- .bindTo(R.id.displayTextView)
+ .bindTo(txtOutput)
.getAllBindings();
final EditText txtInput = (EditText) findViewById(R.id.inputEditText);
findViewById(R.id.actionButton).setOnClickListener(bn -> {
- // Writes the text of inputEditText to the Syncbase row named "message"
- t.put("message", txtInput.getText().toString())
- // Report any error. Normally BakuActivityMixin does this for you.
- .subscribe(x -> {}, ErrorReporters.getDefaultSyncErrorReporter(vActivity));
-
+ // Setting the text on txtOutput will update the "message" Syncbase row via the data
+ // binding we established above.
+ txtOutput.setText(txtInput.getText());
txtInput.setText("");
});
diff --git a/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityComposition.java b/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityComposition.java
index 93612eb..8c9a084 100644
--- a/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityComposition.java
+++ b/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityComposition.java
@@ -7,6 +7,7 @@
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
+import android.widget.TextView;
import io.v.baku.toolkit.BakuActivityMixin;
import io.v.baku.toolkit.BakuActivityTrait;
@@ -21,15 +22,16 @@
mBaku = new BakuActivityMixin<>(this, savedInstanceState);
- // Binds the Syncbase row named "message" to displayTextView
+ final TextView txtOutput = (TextView) findViewById(R.id.displayTextView);
+ // Binds the Syncbase row named "message" to displayTextView, a.k.a. txtOutput.
mBaku.binder().key("message")
- .bindTo(R.id.displayTextView);
+ .bindTo(txtOutput);
final EditText txtInput = (EditText) findViewById(R.id.inputEditText);
findViewById(R.id.actionButton).setOnClickListener(bn -> {
- // Writes the text of inputEditText to the Syncbase row named "message"
- mBaku.getSyncbaseTable().put("message", txtInput.getText().toString());
-
+ // Setting the text on txtOutput will update the "message" Syncbase row via the data
+ // binding we established above.
+ txtOutput.setText(txtInput.getText());
txtInput.setText("");
});
}
diff --git a/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityOneWay.java b/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityOneWay.java
new file mode 100644
index 0000000..6b8147b
--- /dev/null
+++ b/examples/hellobaku/android/app/src/main/java/io/v/baku/hellobaku/HelloActivityOneWay.java
@@ -0,0 +1,34 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package io.v.baku.hellobaku;
+
+import android.os.Bundle;
+import android.widget.EditText;
+
+import io.v.baku.toolkit.BakuActivity;
+
+/**
+ * This example is similar to {@link HelloActivity} but uses a unidirectional rather than
+ * bidirectional data binding to {@code displayTextView}, instead writing to Syncbase directly.
+ */
+public class HelloActivityOneWay extends BakuActivity {
+ @Override
+ protected void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_hello);
+
+ // Binds the Syncbase row named "message" to displayTextView, read-only
+ binder().key("message")
+ .bindReadOnly(R.id.displayTextView);
+
+ final EditText txtInput = (EditText) findViewById(R.id.inputEditText);
+ findViewById(R.id.actionButton).setOnClickListener(bn -> {
+ // Writes the text of inputEditText to the Syncbase row named "message"
+ getSyncbaseTable().put("message", txtInput.getText().toString());
+
+ txtInput.setText("");
+ });
+ }
+}
diff --git a/examples/hellobaku/android/app/src/main/res/values/strings.xml b/examples/hellobaku/android/app/src/main/res/values/strings.xml
index ca2df86..744d9f3 100644
--- a/examples/hellobaku/android/app/src/main/res/values/strings.xml
+++ b/examples/hellobaku/android/app/src/main/res/values/strings.xml
@@ -1,5 +1,6 @@
<resources>
<string name="app_name">Hello Baku</string>
+ <string name="oneway_label">Hello Baku - One-Way</string>
<string name="comp_label">Hello Baku - Composition</string>
<string name="alacarte_label">Hello Baku - À la Carte</string>
<string name="bn_text">Write</string>