-
Notifications
You must be signed in to change notification settings - Fork 0
Getting started
Dellkan edited this page Feb 17, 2016
·
3 revisions
build.gradle (top-project-level)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta4'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven() { // Robobinding is found here
name 'SonaType snapshot repository'
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
maven { // Robobinding-helpers found here
url "https://dl.bintray.com/dellkan/maven/"
}
mavenCentral()
mavenLocal()
}
}
build.gradle (app/module level)
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
// Robobinding with helpers
compile('org.robobinding:robobinding:0.8.12:with-aop-and-dependencies') {
exclude group: 'com.google.guava', module: 'guava'
}
apt "org.robobinding:codegen:0.8.12"
compile 'com.dellkan:robobinding-helpers-api:0.4.0'
compile 'com.dellkan:robobinding-helpers-common:0.4.0'
apt 'com.dellkan:robobinding-helpers-processor:0.4.0'
}
New to android-apt, and don't understand what it does? Essentially, it allows libraries such as this to have processors that during compile-time look through your code for annotations, and generate new classes and code based on how you are using those annotations.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://robobinding.org/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:id="@+id/error"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/error_network" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/retry"
bind:onClick="retry"
style="@style/button.primary" />
</LinearLayout>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
bind:src="{url}"
bind:errorLayout="@id/error"
bind:onClick="onClick" />
</LinearLayout>
@PresentationModel
public class WebView extends PresentationModelWrapper {
@Get
protected String url;
public WebView(String url) {
this.url = url;
}
public void onClick() {
// Your custom action here
}
public void retry() {
refresh("url");
}
}
public class WebViewFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Bundle args = getArguments();
if (args != null && args.containsKey("item")) {
WebView item = (WebView) args.getSerializable("item");
if (item != null) {
return LayoutBuilder.getViewBinder(inflater.getContext()).inflateAndBindWithoutAttachingToRoot(R.layout.fragment_webview, item.getPresentationModel(), container);
}
}
return null;
}
public static OverlayFragment newInstance(WebView item) {
Fragment fragment = new WebViewFragment();
Bundle args = new Bundle();
args.putSerializable("item", item);
fragment.setArguments(args);
return fragment;
}
}