Skip to content

Commit 33f36c7

Browse files
author
Josh
committed
0.6.0
Add DialogFragmentBase/VM Update Badge android Arsenal
1 parent 9310af5 commit 33f36c7

File tree

21 files changed

+261
-63
lines changed

21 files changed

+261
-63
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
2+
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-easydatabinding-green.svg?style=true)](https://android-arsenal.com/details/1/4106)
3+
14
# easydatabinding
25
This project goal is to create activity fragment and views, with less code to be more efficient on the view models
36

47

5-
# Version : 0.4.5
8+
# Version : 0.6.0
69
# Goal
710

811
I used DataBinding for a few weeks since Google allows us to use it.

annotation/annotation.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":annotation" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.joxad.easydatabinding" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":annotation" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="easydatabinding" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -27,6 +27,6 @@
2727
</content>
2828
<orderEntry type="inheritedJdk" />
2929
<orderEntry type="sourceFolder" forTests="false" />
30-
<orderEntry type="library" exported="" name="annotation.annotation-1.0-SNAPSHOT" level="project" />
30+
<orderEntry type="library" exported="" name="annotation.annotation" level="project" />
3131
</component>
3232
</module>

compiler/compiler.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
<orderEntry type="library" exported="" name="javapoet-1.0.0" level="project" />
3333
<orderEntry type="library" exported="" name="auto-common-0.3" level="project" />
3434
<orderEntry type="library" exported="" name="guava-18.0" level="project" />
35+
<orderEntry type="library" exported="" name="compiler.compiler" level="project" />
3536
</component>
3637
</module>

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# Default value: -Xmx10248m -XX:MaxPermSize=256m
1313
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
1414

15-
# When configured, Gradle will run in incubating parallel mode.
15+
# When configured, Gradle will run incubating parallel mode.
1616
# This option should only be used with decoupled projects. More details, visit
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919

20-
VERSION_NAME=0.4.5
20+
VERSION_NAME=0.6.0
2121

2222
POM_GROUP=com.joxad.easydatabinding
2323
POM_NAME=easydatabinding

lib/lib.iml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":lib" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.joxad.easydatabinding" external.system.module.version="0.4.5" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":lib" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.joxad.easydatabinding" external.system.module.version="0.5.1" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -64,14 +64,6 @@
6464
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
6565
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
67-
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
68-
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
69-
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
70-
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
71-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
72-
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
73-
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
74-
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
7567
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
7668
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
7769
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@@ -80,6 +72,14 @@
8072
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
8173
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
8274
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
79+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
80+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
81+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
82+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
8383
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
8484
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
8585
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
@@ -103,19 +103,33 @@
103103
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
104104
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
105105
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
106+
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
106107
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
108+
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
107109
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
108110
</content>
109111
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
110112
<orderEntry type="sourceFolder" forTests="false" />
111-
<orderEntry type="library" exported="" name="adapters-1.1" level="project" />
112-
<orderEntry type="library" exported="" name="baseLibrary-2.1.0" level="project" />
113+
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
113114
<orderEntry type="library" exported="" name="juniversalchardet-1.0.3" level="project" />
115+
<orderEntry type="library" exported="" name="compiler-2.1.2" level="project" />
116+
<orderEntry type="library" exported="" name="antlr4-4.5" level="project" />
117+
<orderEntry type="library" exported="" name="guava-17.0" level="project" />
118+
<orderEntry type="library" exported="" name="kotlin-stdlib-1.0.0" level="project" />
119+
<orderEntry type="library" exported="" name="baseLibrary-2.1.2" level="project" />
120+
<orderEntry type="library" exported="" name="adapters-1.1" level="project" />
121+
<orderEntry type="library" exported="" name="antlr4-annotations-4.5" level="project" />
122+
<orderEntry type="library" exported="" name="antlr4-runtime-4.5" level="project" />
123+
<orderEntry type="library" exported="" name="antlr-runtime-3.5.2" level="project" />
114124
<orderEntry type="library" exported="" name="library-1.1" level="project" />
115125
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
126+
<orderEntry type="library" exported="" name="org.abego.treelayout.core-1.0.1" level="project" />
127+
<orderEntry type="library" exported="" name="ST4-4.0.8" level="project" />
128+
<orderEntry type="library" exported="" name="compilerCommon-2.1.2" level="project" />
116129
<orderEntry type="library" exported="" name="support-v4-23.3.0" level="project" />
130+
<orderEntry type="library" exported="" name="commons-codec-1.10" level="project" />
117131
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
118-
<orderEntry type="library" exported="" name="compiler-2.1.0" level="project" />
132+
<orderEntry type="library" exported="" name="kotlin-runtime-1.0.0" level="project" />
119133
<orderEntry type="library" exported="" name="support-annotations-23.3.0" level="project" />
120134
<orderEntry type="library" exported="" name="support-vector-drawable-23.3.0" level="project" />
121135
<orderEntry type="library" exported="" name="animated-vector-drawable-23.3.0" level="project" />

lib/src/main/java/com/joxad/easydatabinding/activity/ActivityBase.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.support.annotation.NonNull;
99
import android.support.annotation.Nullable;
1010
import android.support.v7.app.AppCompatActivity;
11+
import android.view.MenuItem;
1112

1213
/**
1314
* {@link ActivityBase} will allow you to generate a basic activity that put your view model {@link B} and its {@link VM}
@@ -33,6 +34,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3334
binding.setVariable(data(), vm);
3435
}
3536

37+
3638
@Override
3739
public void onBackPressed() {
3840
if (vm.onBackPressed() ) super.onBackPressed();
@@ -51,6 +53,20 @@ protected void onPause() {
5153
vm.onPause();
5254
}
5355

56+
@Override
57+
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
58+
super.onPostCreate(savedInstanceState);
59+
vm.onPostCreate(savedInstanceState);
60+
}
61+
62+
@Override
63+
public boolean onOptionsItemSelected(MenuItem item) {
64+
if (vm.onOptionsItemSelected(item)) {
65+
return true;
66+
}
67+
return super.onOptionsItemSelected(item);
68+
}
69+
5470
/**
5571
* The int value found in the {@link com.joxad.easydatabinding.BR} class generated by DataBinding
5672
*

lib/src/main/java/com/joxad/easydatabinding/activity/ActivityBaseVM.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import android.databinding.BaseObservable;
55
import android.databinding.ViewDataBinding;
6+
import android.os.Bundle;
7+
import android.view.MenuItem;
68

79
import com.joxad.easydatabinding.base.IVM;
810

@@ -52,4 +54,22 @@ protected void onPause() {
5254
protected boolean onBackPressed() {
5355
return true;
5456
}
57+
58+
/**
59+
* PostCreate
60+
*
61+
* @param savedInstanceState
62+
*/
63+
public void onPostCreate(Bundle savedInstanceState) {
64+
}
65+
66+
/**
67+
* Manage item
68+
*
69+
* @param item
70+
* @return
71+
*/
72+
public boolean onOptionsItemSelected(MenuItem item) {
73+
return false;
74+
}
5575
}

lib/src/main/java/com/joxad/easydatabinding/activity/INewIntent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import android.content.Intent;
44

55
/**
6-
* Created by josh on 13/04/16.
6+
* {@link INewIntent} is used for the activity VM that needs to handle newIntent from the activity
77
*/
88
public interface INewIntent {
99
/**

lib/src/main/java/com/joxad/easydatabinding/activity/IPermission.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import android.support.annotation.NonNull;
44

55
/**
6-
* Created by josh on 13/04/16.
6+
* {@link IPermission} will handle the permission result from the activity
77
*/
88
public interface IPermission {
99
/***

lib/src/main/java/com/joxad/easydatabinding/activity/IResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import android.content.Intent;
44

55
/**
6-
*
6+
* {@link IResult} will handle the onActivityResult from the activity
77
*/
88
public interface IResult {
99

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
package com.joxad.easydatabinding.fragment;
3+
4+
import android.content.Intent;
5+
import android.databinding.DataBindingUtil;
6+
import android.databinding.ViewDataBinding;
7+
import android.os.Bundle;
8+
import android.support.annotation.LayoutRes;
9+
import android.support.annotation.NonNull;
10+
import android.support.annotation.Nullable;
11+
import android.support.v4.app.DialogFragment;
12+
import android.view.LayoutInflater;
13+
import android.view.View;
14+
import android.view.ViewGroup;
15+
16+
import com.joxad.easydatabinding.activity.IPermission;
17+
import com.joxad.easydatabinding.activity.IResult;
18+
19+
/**
20+
* Created by josh on 13/04/16.
21+
*/
22+
public abstract class DialogFragmentBase<B extends ViewDataBinding, VM extends DialogFragmentBaseVM> extends DialogFragment {
23+
24+
/***
25+
* FragmentBinding used in this view
26+
*/
27+
28+
protected B binding;
29+
/***
30+
* The view model that will be used to handle this fragment
31+
*/
32+
33+
protected VM vm;
34+
35+
@Nullable
36+
@Override
37+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
38+
binding = DataBindingUtil.inflate(inflater, layoutResources(), container, false);
39+
vm = baseFragmentVM(binding);
40+
binding.setVariable(data(), vm);
41+
return binding.getRoot();
42+
}
43+
44+
45+
@Override
46+
public void onResume() {
47+
super.onResume();
48+
vm.onResume();
49+
}
50+
51+
@Override
52+
public void onPause() {
53+
super.onPause();
54+
vm.onPause();
55+
}
56+
57+
58+
/***
59+
* Handle the permission and give it to the activity
60+
*
61+
* @param requestCode
62+
* @param permissions
63+
* @param grantResults
64+
*/
65+
@Override
66+
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
67+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
68+
if (vm instanceof IPermission)
69+
((IPermission) vm).onRequestPermissionsResult(requestCode, permissions, grantResults);
70+
}
71+
72+
/***
73+
* Handle the activity result if you need to use it inside the vm of the fragment
74+
*
75+
* @param requestCode
76+
* @param resultCode
77+
* @param data
78+
*/
79+
@Override
80+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
81+
super.onActivityResult(requestCode, resultCode, data);
82+
if (vm instanceof IResult)
83+
((IResult) vm).onActivityResult(requestCode, resultCode, data);
84+
}
85+
86+
/**
87+
* The int value found in the {@link com.joxad.easydatabinding.BR} class generated by DataBinding
88+
*
89+
* @return
90+
*/
91+
public abstract int data();
92+
93+
/***
94+
* @return your layout resources
95+
*/
96+
@LayoutRes
97+
public abstract int layoutResources();
98+
99+
/***
100+
* @param binding
101+
* @return the {@link VM} you want to use in this activity
102+
*/
103+
public abstract VM baseFragmentVM(B binding);
104+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.joxad.easydatabinding.fragment;
2+
3+
import android.databinding.BaseObservable;
4+
import android.databinding.ViewDataBinding;
5+
6+
import com.joxad.easydatabinding.base.IVM;
7+
8+
9+
/**
10+
* Created by josh on 13/04/16.
11+
*/
12+
public abstract class DialogFragmentBaseVM<F extends DialogFragmentBase, B extends ViewDataBinding> extends BaseObservable implements IVM {
13+
14+
/***
15+
* {@link F} is the fragment that use the current VM
16+
*/
17+
protected F fragment;
18+
/**
19+
* {@link B} will be used to find the views inside the fragment
20+
*/
21+
protected B binding;
22+
23+
/***
24+
* @param
25+
* @param binding
26+
*/
27+
public DialogFragmentBaseVM(F fragment, B binding) {
28+
this.fragment = fragment;
29+
this.binding = binding;
30+
init();
31+
}
32+
33+
/***
34+
* LifeCycle of the Fragment
35+
*/
36+
protected void onResume() {
37+
38+
}
39+
40+
/***
41+
* LifeCycle of the fragment
42+
*/
43+
protected void onPause() {
44+
45+
}
46+
47+
public abstract void init();
48+
}

lib/src/main/res/values/colors.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="colorPrimary">#3F51B5</color>
4-
<color name="colorPrimaryDark">#303F9F</color>
5-
<color name="colorAccent">#FF4081</color>
3+
<color name="easyColorPrimary">#3F51B5</color>
4+
<color name="easyColorPrimaryDark">#303F9F</color>
5+
<color name="easyColorAccent">#FF4081</color>
66
</resources>

lib/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<resources>
2-
<string name="app_name">Easydatabinding</string>
2+
<string name="easy_data_name">Easydatabinding</string>
33
</resources>

0 commit comments

Comments
 (0)