17 |
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/phunware/example/mvvmrecyclerviewblog/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.phunware.example.mvvmrecyclerviewblog;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.phunware.example.mvvmrecyclerviewblog", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/LICENSE.md/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2018 Phunware Inc.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 | MVVMRecyclerViewBlog
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
23 |
24 | 200dp
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
23 |
24 | @android:color/darker_gray
25 | @android:color/black
26 | #303F9F
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/phunware/example/mvvmrecyclerviewblog/databinding/AppDataBindingComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | package com.phunware.example.mvvmrecyclerviewblog.databinding;
23 |
24 | /**
25 | * Created by Gregory Rasmussen on 7/26/17.
26 | */
27 | public class AppDataBindingComponent implements android.databinding.DataBindingComponent {
28 | @Override
29 | public RecyclerViewDataBinding getRecyclerViewDataBinding() {
30 | return new RecyclerViewDataBinding();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/phunware/example/mvvmrecyclerviewblog/model/DataModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | package com.phunware.example.mvvmrecyclerviewblog.model;
23 |
24 | import android.support.annotation.Nullable;
25 |
26 | /**
27 | * Created by Gregory Rasmussen on 7/26/17.
28 | */
29 | public class DataModel {
30 | private String title;
31 |
32 | public DataModel() {
33 | }
34 |
35 | @Nullable
36 | public String getTitle() {
37 | return title;
38 | }
39 |
40 | public void setTitle(@Nullable String title) {
41 | this.title = title;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/phunware/example/mvvmrecyclerviewblog/App.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | package com.phunware.example.mvvmrecyclerviewblog;
23 |
24 | import android.app.Application;
25 | import android.databinding.DataBindingUtil;
26 |
27 | import com.phunware.example.mvvmrecyclerviewblog.databinding.AppDataBindingComponent;
28 |
29 | /**
30 | * Created by Gregory Rasmussen on 7/26/17.
31 | */
32 | public class App extends Application {
33 | @Override
34 | public void onCreate() {
35 | super.onCreate();
36 | DataBindingUtil.setDefaultComponent(new AppDataBindingComponent());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
41 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
23 |
25 |
26 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_data.xml:
--------------------------------------------------------------------------------
1 |
2 |
23 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
45 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # ================================================================================
2 | #
3 | # Copyright (c) 2018 Phunware Inc.
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 |
12 | # The above copyright notice and this permission notice shall be included in all
13 | # copies or substantial portions of the Software.
14 |
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | # SOFTWARE.
22 | #
23 | # ================================================================================
24 | #
25 | # Project-wide Gradle settings.
26 |
27 | # IDE (e.g. Android Studio) users:
28 | # Gradle settings configured through the IDE *will override*
29 | # any settings specified in this file.
30 |
31 | # For more details on how to configure your build environment visit
32 | # http://www.gradle.org/docs/current/userguide/build_environment.html
33 |
34 | # Specifies the JVM arguments used for the daemon process.
35 | # The setting is particularly useful for tweaking memory settings.
36 | org.gradle.jvmargs=-Xmx1536m
37 |
38 | # When configured, Gradle will run in incubating parallel mode.
39 | # This option should only be used with decoupled projects. More details, visit
40 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
41 | # org.gradle.parallel=true
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/phunware/example/mvvmrecyclerviewblog/viewmodel/DataItemViewModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | package com.phunware.example.mvvmrecyclerviewblog.viewmodel;
23 |
24 | import android.databinding.BaseObservable;
25 | import android.databinding.Bindable;
26 | import android.text.TextUtils;
27 |
28 | import com.phunware.example.mvvmrecyclerviewblog.model.DataModel;
29 |
30 | /**
31 | * Created by Gregory Rasmussen on 7/26/17.
32 | */
33 | public class DataItemViewModel extends BaseObservable {
34 | private DataModel dataModel;
35 |
36 | public DataItemViewModel(DataModel dataModel) {
37 | this.dataModel = dataModel;
38 | }
39 |
40 | public void setUp() {
41 | // perform set up tasks, such as adding listeners
42 | }
43 |
44 | public void tearDown() {
45 | // perform tear down tasks, such as removing listeners
46 | }
47 |
48 | @Bindable
49 | public String getTitle() {
50 | return !TextUtils.isEmpty(dataModel.getTitle()) ? dataModel.getTitle() : "";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # ================================================================================
2 | #
3 | # Copyright (c) 2018 Phunware Inc.
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 |
12 | # The above copyright notice and this permission notice shall be included in all
13 | # copies or substantial portions of the Software.
14 |
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | # SOFTWARE.
22 | #
23 | # ================================================================================
24 | #
25 | # Add project specific ProGuard rules here.
26 | # By default, the flags in this file are appended to flags specified
27 | # in /Users/gregoryrasmussen/Library/Android/sdk/tools/proguard/proguard-android.txt
28 | # You can edit the include path and order by changing the proguardFiles
29 | # directive in build.gradle.
30 | #
31 | # For more details, see
32 | # http://developer.android.com/guide/developing/tools/proguard.html
33 |
34 | # Add any project specific keep options here:
35 |
36 | # If your project uses WebView with JS, uncomment the following
37 | # and specify the fully qualified class name to the JavaScript interface
38 | # class:
39 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
40 | # public *;
41 | #}
42 |
43 | # Uncomment this to preserve the line number information for
44 | # debugging stack traces.
45 | #-keepattributes SourceFile,LineNumberTable
46 |
47 | # If you keep the line number information, uncomment this to
48 | # hide the original source file name.
49 | #-renamesourcefileattribute SourceFile
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/phunware/example/mvvmrecyclerviewblog/databinding/RecyclerViewDataBinding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | package com.phunware.example.mvvmrecyclerviewblog.databinding;
23 |
24 | import android.databinding.BindingAdapter;
25 | import android.support.v7.widget.RecyclerView;
26 |
27 | import com.phunware.example.mvvmrecyclerviewblog.adapter.DataAdapter;
28 | import com.phunware.example.mvvmrecyclerviewblog.model.DataModel;
29 |
30 | import java.util.List;
31 |
32 | /**
33 | * Created by Gregory Rasmussen on 7/26/17.
34 | */
35 | public class RecyclerViewDataBinding {
36 | /**
37 | * Binds the data to the {@link android.support.v7.widget.RecyclerView.Adapter}, sets the
38 | * recycler view on the adapter, and performs some other recycler view initialization.
39 | *
40 | * @param recyclerView passed in automatically with the data binding
41 | * @param adapter must be explicitly passed in
42 | * @param data must be explicitly passed in
43 | */
44 | @BindingAdapter({"app:adapter", "app:data"})
45 | public void bind(RecyclerView recyclerView, DataAdapter adapter, List data) {
46 | recyclerView.setAdapter(adapter);
47 | adapter.updateData(data);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | apply plugin: 'com.android.application'
23 |
24 | android {
25 | compileSdkVersion 27
26 | buildToolsVersion '27.0.3'
27 | defaultConfig {
28 | applicationId "com.phunware.example.mvvmrecyclerviewblog"
29 | minSdkVersion 16
30 | targetSdkVersion 27
31 | versionCode 1
32 | versionName "1.0"
33 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
34 | }
35 | buildTypes {
36 | release {
37 | minifyEnabled false
38 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
39 | }
40 | }
41 |
42 | dataBinding {
43 | enabled = true
44 | }
45 | }
46 |
47 | dependencies {
48 | implementation fileTree(include: ['*.jar'], dir: 'libs')
49 | implementation 'com.android.support:recyclerview-v7:27.1.1'
50 | implementation 'com.android.support:appcompat-v7:27.1.1'
51 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
52 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
53 | exclude group: 'com.android.support', module: 'support-annotations'
54 | })
55 | testImplementation 'junit:junit:4.12'
56 | }
57 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/phunware/example/mvvmrecyclerviewblog/viewmodel/DataViewModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | package com.phunware.example.mvvmrecyclerviewblog.viewmodel;
23 |
24 | import android.databinding.BaseObservable;
25 | import android.databinding.Bindable;
26 |
27 | import com.phunware.example.mvvmrecyclerviewblog.BR;
28 | import com.phunware.example.mvvmrecyclerviewblog.adapter.DataAdapter;
29 | import com.phunware.example.mvvmrecyclerviewblog.model.DataModel;
30 |
31 | import java.util.ArrayList;
32 | import java.util.List;
33 |
34 | /**
35 | * Created by Gregory Rasmussen on 7/26/17.
36 | */
37 | public class DataViewModel extends BaseObservable {
38 | private static final String TAG = "DataViewModel";
39 | private DataAdapter adapter;
40 | private List data;
41 |
42 | public DataViewModel() {
43 | data = new ArrayList<>();
44 | adapter = new DataAdapter();
45 | }
46 |
47 | public void setUp() {
48 | // perform set up tasks, such as adding listeners, data population, etc.
49 | populateData();
50 | }
51 |
52 | public void tearDown() {
53 | // perform tear down tasks, such as removing listeners
54 | }
55 |
56 | @Bindable
57 | public List getData() {
58 | return this.data;
59 | }
60 |
61 | @Bindable
62 | public DataAdapter getAdapter() {
63 | return this.adapter;
64 | }
65 |
66 | private void populateData() {
67 | // populate the data from the source, such as the database.
68 | for (int i = 0; i < 50; i++) {
69 | DataModel dataModel = new DataModel();
70 | dataModel.setTitle(String.valueOf(i));
71 | data.add(dataModel);
72 | }
73 | notifyPropertyChanged(BR.data);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/phunware/example/mvvmrecyclerviewblog/view/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | package com.phunware.example.mvvmrecyclerviewblog.view;
23 |
24 | import android.databinding.DataBindingUtil;
25 | import android.os.Bundle;
26 | import android.support.v7.app.AppCompatActivity;
27 | import android.support.v7.widget.DividerItemDecoration;
28 | import android.support.v7.widget.LinearLayoutManager;
29 | import android.support.v7.widget.RecyclerView;
30 | import android.view.View;
31 |
32 | import com.phunware.example.mvvmrecyclerviewblog.R;
33 | import com.phunware.example.mvvmrecyclerviewblog.databinding.ActivityMainBinding;
34 | import com.phunware.example.mvvmrecyclerviewblog.viewmodel.DataViewModel;
35 |
36 | import static android.support.v7.widget.LinearLayoutManager.VERTICAL;
37 |
38 | /**
39 | * Created by Gregory Rasmussen on 7/26/17.
40 | */
41 | public class MainActivity extends AppCompatActivity {
42 | private DataViewModel dataViewModel;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | View view = bind();
48 | initRecyclerView(view);
49 | }
50 |
51 | @Override
52 | protected void onResume() {
53 | super.onResume();
54 | dataViewModel.setUp();
55 | }
56 |
57 | @Override
58 | protected void onPause() {
59 | super.onPause();
60 | dataViewModel.tearDown();
61 | }
62 |
63 | private View bind() {
64 | ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
65 | dataViewModel = new DataViewModel();
66 | binding.setViewModel(dataViewModel);
67 | return binding.getRoot();
68 | }
69 |
70 | private void initRecyclerView(View view) {
71 | RecyclerView recyclerView = view.findViewById(R.id.data_recycler_view);
72 | recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
73 | recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), VERTICAL));
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/phunware/example/mvvmrecyclerviewblog/adapter/DataAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018 Phunware Inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy
5 | * of this software and associated documentation files (the "Software"), to deal
6 | * in the Software without restriction, including without limitation the rights
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | * copies of the Software, and to permit persons to whom the Software is
9 | * furnished to do so, subject to the following conditions:
10 |
11 | * The above copyright notice and this permission notice shall be included in all
12 | * copies or substantial portions of the Software.
13 |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | * SOFTWARE.
21 | */
22 | package com.phunware.example.mvvmrecyclerviewblog.adapter;
23 |
24 | import android.databinding.DataBindingUtil;
25 | import android.support.annotation.Nullable;
26 | import android.support.v7.widget.RecyclerView;
27 | import android.view.LayoutInflater;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.widget.FrameLayout;
31 |
32 | import com.phunware.example.mvvmrecyclerviewblog.R;
33 | import com.phunware.example.mvvmrecyclerviewblog.databinding.ItemDataBinding;
34 | import com.phunware.example.mvvmrecyclerviewblog.model.DataModel;
35 | import com.phunware.example.mvvmrecyclerviewblog.viewmodel.DataItemViewModel;
36 |
37 | import java.util.ArrayList;
38 | import java.util.List;
39 |
40 | /**
41 | * Created by Gregory Rasmussen on 7/26/17.
42 | */
43 | public class DataAdapter extends RecyclerView.Adapter {
44 | private static final String TAG = "DataAdapter";
45 | private List data;
46 |
47 | public DataAdapter() {
48 | this.data = new ArrayList<>();
49 | }
50 |
51 | @Override
52 | public DataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
53 | View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_data,
54 | new FrameLayout(parent.getContext()), false);
55 | return new DataViewHolder(itemView);
56 | }
57 |
58 | @Override
59 | public void onBindViewHolder(DataViewHolder holder, int position) {
60 | DataModel dataModel = data.get(position);
61 | holder.setViewModel(new DataItemViewModel(dataModel));
62 | }
63 |
64 | @Override
65 | public int getItemCount() {
66 | return this.data.size();
67 | }
68 |
69 | @Override
70 | public void onViewAttachedToWindow(DataViewHolder holder) {
71 | super.onViewAttachedToWindow(holder);
72 | holder.bind();
73 | }
74 |
75 | @Override
76 | public void onViewDetachedFromWindow(DataViewHolder holder) {
77 | super.onViewDetachedFromWindow(holder);
78 | holder.unbind();
79 | }
80 |
81 | public void updateData(@Nullable List data) {
82 | if (data == null || data.isEmpty()) {
83 | this.data.clear();
84 | } else {
85 | this.data.addAll(data);
86 | }
87 | notifyDataSetChanged();
88 | }
89 |
90 | /* package */ static class DataViewHolder extends RecyclerView.ViewHolder {
91 | /* package */ ItemDataBinding binding;
92 |
93 | /* package */ DataViewHolder(View itemView) {
94 | super(itemView);
95 | bind();
96 | }
97 |
98 | /* package */ void bind() {
99 | if (binding == null) {
100 | binding = DataBindingUtil.bind(itemView);
101 | }
102 | }
103 |
104 | /* package */ void unbind() {
105 | if (binding != null) {
106 | binding.unbind(); // Don't forget to unbind
107 | }
108 | }
109 |
110 | /* package */ void setViewModel(DataItemViewModel viewModel) {
111 | if (binding != null) {
112 | binding.setViewModel(viewModel);
113 | }
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------