-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# DATA BINDING + ROOM | ||
|
||
### DATA BINDING: | ||
Whenever the developer wants to interact with the UI element, it can be achieved by infalating the Activity or Fragment layout, bind the UI element through findViewById or using ButterKnife binding technique and finally allocate the data value to element. | ||
|
||
At Google I/O 2015, the new binding technology introduced called "DATA BINDING", which helps the developer to remove all boilerplate binding calls as well as having to manually update those views in the code. | ||
|
||
##### Environment Setting: | ||
|
||
- Add dataBinding element to your build.gradle file in the app module, which will enable data binding in your project. | ||
|
||
```sh | ||
android { | ||
... | ||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
``` | ||
|
||
- Add <layout> root tag in your activity xml. | ||
|
||
```sh | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:context="com.example.ali.roomapplication.ui.MainActivity"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="20dp"> | ||
|
||
<android.support.design.widget.TextInputLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
<EditText | ||
android:id="@+id/txt_name" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="Name" | ||
android:text='@{data.name}' /> | ||
</android.support.design.widget.TextInputLayout> | ||
|
||
</LinearLayout> | ||
</layout> | ||
``` | ||
|
||
For more info regarding data binding visit: | ||
* [Data Binding](https://developer.android.com/topic/libraries/data-binding/index.html) - Data Binding Official documentation | ||
* [Android Pub](https://android.jlelse.eu/android-data-binding-8d0eb34b9bad) - Descriptive intro of data binding | ||
|
||
### ROOM (New approach to store data): | ||
|
||
While building any data storage application that can store data in db by using some medium i.e abstraction layer. This layer can be the SQLiteOpenHelper class or ContentProvider class. | ||
At Google I/0 2017 Room persistance library introduced, the new technique that can help to save data in SQLite database. Room provides enhanced security, easy access, easy to setup and quick to get started with new database. | ||
|
||
Three major components of Room: | ||
- Database | ||
- Entity | ||
- DAO (Data Access Object) | ||
|
||
If we talk about DML (Data Manipulation Language), all of the commands annotated like: | ||
- @Insert | ||
- @Update | ||
- @Delete | ||
- @Query (for select command) | ||
|
||
##### Environment Setting: | ||
|
||
- Add dependencies in your build.gradle file in the app module. | ||
|
||
```sh | ||
compile "android.arch.persistence.room:runtime:1.0.0" | ||
annotationProcessor "android.arch.persistence.room:compiler:1.0.0" | ||
``` | ||
|
||
- Add maven url in your build.gradle file in the project module. | ||
|
||
```sh | ||
allprojects { | ||
repositories { | ||
google() | ||
jcenter() | ||
maven { url 'https://maven.google.com' } | ||
} | ||
} | ||
``` | ||
For more info regarding Room visit: | ||
* [Room](https://developer.android.com/training/data-storage/room/index.html) - Room Official documentation | ||
* [Android Pub](https://android.jlelse.eu/room-store-your-data-c6d49b4d53a3) - Descriptive intro of room | ||
### Working | ||
It's a simple CRUD operation implement with Data Binding and Room. When inserting data it'll show in the list. If you want to update or delete any data, simply click on record that's populated in list, it'll fill the fields then you can perform update and delete operation. | ||
<img src="ScreenShots/1.png" alt="Insert Data" width="50%" height="50%"> | ||
<img src="ScreenShots/2.png" alt="Show data in list" width="50%" height="50%"> | ||
<img src="ScreenShots/3.png" alt="Tap on list item" width="50%" height="50%"> | ||
### Contributors | ||
Contributor: Ali Azaz Alam [email protected] | ||
License | ||
---- | ||
The MIT License (MIT) | ||
Copyright (c) 2017 Ali Azaz Alam. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
defaultConfig { | ||
applicationId "com.example.ali.roomapplication" | ||
minSdkVersion 16 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
dataBinding { | ||
enabled = true | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:27.1.1' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.0' | ||
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' | ||
|
||
implementation 'com.android.support:design:27.1.1' | ||
implementation "android.arch.persistence.room:runtime:1.0.0" | ||
annotationProcessor "android.arch.persistence.room:compiler:1.0.0" | ||
|
||
// RecyclerView | ||
implementation 'com.android.support:recyclerview-v7:27.1.1' | ||
implementation 'com.android.support:cardview-v7:27.1.1' | ||
|
||
implementation 'com.squareup.retrofit2:retrofit:2.3.0' | ||
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.0' | ||
implementation group: 'javax.xml.stream', name: 'stax-api', version: '1.0-2' | ||
|
||
} |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.ali.roomapplication; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.example.ali.roomapplication", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.ali.roomapplication"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".activity.ListActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity android:name=".activity.FeedActivity"/> | ||
</application> | ||
|
||
</manifest> |