Skip to content

Commit

Permalink
Mise en place de base
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisdeguet committed Jan 10, 2019
0 parents commit 0cc1928
Show file tree
Hide file tree
Showing 44 changed files with 935 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
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
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
45 changes: 45 additions & 0 deletions app/build.gradle
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'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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());
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
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>
35 changes: 35 additions & 0 deletions app/src/main/java/org/deguet/roomdemo/MainActivity.java
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);
}
}
}
22 changes: 22 additions & 0 deletions app/src/main/java/org/deguet/roomdemo/dao/Converters.java
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();
}
}
}
20 changes: 20 additions & 0 deletions app/src/main/java/org/deguet/roomdemo/dao/DemoDAO.java
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();

}
15 changes: 15 additions & 0 deletions app/src/main/java/org/deguet/roomdemo/dao/MaBD.java
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();
}
24 changes: 24 additions & 0 deletions app/src/main/java/org/deguet/roomdemo/modele/DemoAlbum.java
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;

}
Loading

0 comments on commit 0cc1928

Please sign in to comment.