-
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,11 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches/build_file_checksums.ser | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.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.
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 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "org.deguet.roomdemo" | ||
minSdkVersion 16 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
def room_version = "2.1.0-alpha03" | ||
|
||
implementation "androidx.room:room-runtime:$room_version" | ||
annotationProcessor "androidx.room:room-compiler:$room_version" // use kapt for Kotlin | ||
|
||
// optional - RxJava support for Room | ||
implementation "androidx.room:room-rxjava2:$room_version" | ||
|
||
// optional - Guava support for Room, including Optional and ListenableFuture | ||
implementation "androidx.room:room-guava:$room_version" | ||
|
||
// optional - Coroutines support for Room | ||
implementation "androidx.room:room-coroutines:$room_version" | ||
|
||
// Test helpers | ||
testImplementation "androidx.room:room-testing:$room_version" | ||
|
||
implementation 'androidx.appcompat:appcompat:1.0.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.2' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test:runner:1.1.0' | ||
//androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.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 org.deguet.roomdemo; | ||
|
||
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() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("org.deguet.roomdemo", appContext.getPackageName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.deguet.roomdemo"> | ||
|
||
<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=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.deguet.roomdemo; | ||
|
||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import org.deguet.roomdemo.dao.MaBD; | ||
import org.deguet.roomdemo.modele.DemoAlbum; | ||
|
||
import java.util.Date; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.room.Room; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
MaBD bd = Room.databaseBuilder(getApplicationContext(), MaBD.class, "pipo") | ||
.allowMainThreadQueries() | ||
.build(); | ||
|
||
DemoAlbum album = new DemoAlbum(); | ||
album.artiste = "U2"; | ||
album.dateDeSortie = new Date(); | ||
album.nom = "TestDemo"; | ||
bd.dao().creerAlbum(album); | ||
|
||
for(DemoAlbum a : bd.dao().tousLesAlbums()) { | ||
Log.i("ALBUM", ">> "+ a.nom + " " + a.dateDeSortie); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.deguet.roomdemo.dao; | ||
|
||
import java.util.Date; | ||
|
||
import androidx.room.TypeConverter; | ||
|
||
public class Converters { | ||
|
||
@TypeConverter | ||
public Date fromTimestamp(Long value) { | ||
return value == null ? null : new Date(value); | ||
} | ||
|
||
@TypeConverter | ||
public Long dateToTimestamp(Date date) { | ||
if (date == null) { | ||
return null; | ||
} else { | ||
return date.getTime(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.deguet.roomdemo.dao; | ||
|
||
import org.deguet.roomdemo.modele.DemoAlbum; | ||
|
||
import java.util.List; | ||
|
||
import androidx.room.Dao; | ||
import androidx.room.Insert; | ||
import androidx.room.Query; | ||
|
||
@Dao | ||
public interface DemoDAO { | ||
|
||
@Insert | ||
Long creerAlbum(DemoAlbum album); | ||
|
||
@Query("SELECT * FROM DemoAlbum") | ||
List<DemoAlbum> tousLesAlbums(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.deguet.roomdemo.dao; | ||
|
||
import org.deguet.roomdemo.modele.DemoAlbum; | ||
|
||
import androidx.room.Database; | ||
import androidx.room.RoomDatabase; | ||
import androidx.room.TypeConverters; | ||
|
||
|
||
@Database(entities = {DemoAlbum.class}, | ||
version = 1) | ||
@TypeConverters({Converters.class}) | ||
public abstract class MaBD extends RoomDatabase{ | ||
public abstract DemoDAO dao(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.deguet.roomdemo.modele; | ||
|
||
import java.util.Date; | ||
|
||
import androidx.room.ColumnInfo; | ||
import androidx.room.Entity; | ||
import androidx.room.PrimaryKey; | ||
|
||
@Entity | ||
public class DemoAlbum { | ||
|
||
@PrimaryKey(autoGenerate = true) | ||
public Long id; | ||
|
||
@ColumnInfo | ||
public String nom; | ||
|
||
@ColumnInfo | ||
public String artiste; | ||
|
||
@ColumnInfo | ||
public Date dateDeSortie; | ||
|
||
} |