Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .idea/caches/build_file_checksums.ser
Binary file not shown.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

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

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

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

40 changes: 40 additions & 0 deletions .idea/jarRepositories.xml

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

25 changes: 22 additions & 3 deletions .idea/misc.xml

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

4 changes: 2 additions & 2 deletions .idea/modules.xml

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

Empty file.
32 changes: 30 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,42 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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 "androidx.appcompat:appcompat:$rootProject.appCompatVersion"

// Room components
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
annotationProcessor "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

// Lifecycle components
implementation "androidx.lifecycle:lifecycle-viewmodel:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-livedata:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$rootProject.lifecycleVersion"


compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12' //or v. 1.16.2 in your case.

// Testing
testImplementation "junit:junit:$rootProject.junitVersion"
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
androidTestImplementation ("androidx.test.espresso:espresso-core:$rootProject.espressoVersion", {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation "androidx.test.ext:junit:$rootProject.androidxJunitVersion"
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/ng/riby/androidtest/MainActivity.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ng.riby.androidtest.database.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import java.util.List;

import ng.riby.androidtest.database.entities.Location;

public interface LocationDao {

@Insert(onConflict = OnConflictStrategy.IGNORE)
void insert(Location location);

@Query("SELECT * FROM location_table ORDER BY latitude ASC")
LiveData<List<Location>> getLocations();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ng.riby.androidtest.database.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import ng.riby.androidtest.database.dao.LocationDao;
import ng.riby.androidtest.database.entities.Location;

@Database(entities = {Location.class}, version = 1, exportSchema = false)
public abstract class LocationDataBase extends RoomDatabase {
public abstract LocationDao locationDao();

private static volatile LocationDataBase INSTANCE;
private static final int NUMBER_OF_THREADS = 4;
public static final ExecutorService databaseWriteExecutor =
Executors.newFixedThreadPool(NUMBER_OF_THREADS);

public static LocationDataBase getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (LocationDataBase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
LocationDataBase.class, "word_database")
.build();
}
}
}
return INSTANCE;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package ng.riby.androidtest.database.entities;

import androidx.annotation.NonNull;

import androidx.room.Entity;
import androidx.room.PrimaryKey;

@Entity(tableName = "location_table")

public class Location {

@PrimaryKey(autoGenerate = true)
@NonNull
private int id;
@NonNull
private Double latitude;
@NonNull
private Double longitude;

public Location(int id, @NonNull Double latitude, @NonNull Double longitude) {
this.id = id;
this.latitude = latitude;
this.longitude = longitude;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@NonNull
public Double getLatitude() {
return latitude;
}

public void setLatitude(@NonNull Double latitude) {
this.latitude = latitude;
}

@NonNull
public Double getLongitude() {
return longitude;
}

public void setLongitude(@NonNull Double longitude) {
this.longitude = longitude;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ng.riby.androidtest.repository;

import android.app.Application;

import androidx.lifecycle.LiveData;
import java.util.List;

import ng.riby.androidtest.database.database.LocationDataBase;
import ng.riby.androidtest.database.dao.LocationDao;
import ng.riby.androidtest.database.entities.Location;

public class LocationRepository {

private LocationDao locationDao;
private LiveData<List<Location>> getLocations;

public LocationRepository(Application application) {
LocationDataBase db = LocationDataBase.getDatabase(application);
locationDao = db.locationDao();
getLocations = locationDao.getLocations();
}

// Room executes all queries on a separate thread.
// Observed LiveData will notify the observer when the data has changed.
public LiveData<List<Location>> getLocation() {
return getLocations;
}

// You must call this on a non-UI thread or your app will throw an exception. Room ensures
// that you're not doing any long running operations on the main thread, blocking the UI.
public void insert(Location location) {
LocationDataBase.databaseWriteExecutor.execute(() -> {
locationDao.insert(location);
});
}
}
Loading