Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ДЗ-6: Clean Architecture #10

Open
wants to merge 11 commits into
base: dagger2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/captures
.externalNativeBuild
.idea/
**/*/res/values/secrets.xml
14 changes: 13 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ android {
}

dependencies {

// Support libs
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'

// Moxy mvp
implementation 'com.arello-mobile:moxy:1.5.5'
Expand All @@ -47,6 +48,9 @@ dependencies {
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'

// Google maps util
implementation 'com.google.maps.android:android-maps-utils:0.5'

// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
Expand All @@ -61,6 +65,14 @@ dependencies {
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
implementation "android.arch.persistence.room:rxjava2:$room_version"

// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

// Logger HTTP
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'

// Test
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:name=".app.AppDelegate"
android:name=".presentation.app.AppDelegate"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.kkaysheva.ituniver.database;
package com.kkaysheva.ituniver.data.database;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.RoomDatabase;

import com.kkaysheva.ituniver.model.ContactInfo;
import com.kkaysheva.ituniver.domain.model.ContactInfo;

/**
* AppDatabase
Expand All @@ -13,5 +13,5 @@
*/
@Database(entities = {ContactInfo.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
public abstract ContactDao getContactDaO();
public abstract ContactDao getContactDao();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.kkaysheva.ituniver.database;
package com.kkaysheva.ituniver.data.database;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.List;

import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Single;

/**
Expand All @@ -19,17 +19,16 @@ public interface BaseRepository<Entity, Id> {
@NonNull
Single<List<Entity>> getAll();

@Nullable
Single<Entity> getById(@NonNull Id id);
@NonNull
Maybe<Entity> getById(@NonNull Id id);

@NonNull
Completable update(@NonNull Entity entity);

@NonNull
Completable insert(@NonNull Entity entity);

@NonNull
Completable delete(@NonNull Entity entity);
void delete(@NonNull Entity entity);

@NonNull
Completable deleteAll();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kkaysheva.ituniver.database;
package com.kkaysheva.ituniver.data.database;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
Expand All @@ -7,12 +7,12 @@
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.kkaysheva.ituniver.model.ContactInfo;
import com.kkaysheva.ituniver.domain.model.ContactInfo;

import java.util.List;

import io.reactivex.Maybe;
import io.reactivex.Single;

/**
Expand All @@ -28,9 +28,9 @@ public interface ContactDao {
@Query("SELECT * FROM contacts")
Single<List<ContactInfo>> getAll();

@Nullable
@NonNull
@Query("SELECT * FROM contacts WHERE id = :id")
Single<ContactInfo> getContactInfoById(Long id);
Maybe<ContactInfo> getContactInfoById(Long id);

@Update
void updateContactInfo(ContactInfo contactInfo);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.kkaysheva.ituniver.data.database;
RomanPozdeev marked this conversation as resolved.
Show resolved Hide resolved

import android.support.annotation.NonNull;

import com.kkaysheva.ituniver.domain.model.ContactInfo;

import java.util.List;

import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Single;

/**
* ContactInfoRepository
*
* @author Ksenya Kaysheva (murrcha@me.com)
* @since 01.2019
*/
public interface ContactInfoRepository {

@NonNull
Single<List<ContactInfo>> getAll();

@NonNull
Maybe<ContactInfo> getById(@NonNull Long id);

@NonNull
Completable insert(@NonNull ContactInfo contactInfo);

@NonNull
Completable update(@NonNull ContactInfo contactInfo);

void delete(@NonNull ContactInfo contactInfo);

@NonNull
Completable deleteAll();
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,65 @@
package com.kkaysheva.ituniver.database;
package com.kkaysheva.ituniver.data.database;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.kkaysheva.ituniver.model.ContactInfo;
import com.kkaysheva.ituniver.domain.model.ContactInfo;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Single;

/**
* ContactRepository
* ContactInfoRepositoryRoom
*
* @author Ksenya Kaysheva (murrcha@me.com)
* @since 12.2018
*/
public final class ContactRepository implements BaseRepository<ContactInfo, Long> {
public final class ContactInfoRepositoryRoom implements ContactInfoRepository {

@NonNull
private AppDatabase appDatabase;
private final AppDatabase appDatabase;
RomanPozdeev marked this conversation as resolved.
Show resolved Hide resolved

@Inject
public ContactRepository(@NonNull AppDatabase appDatabase) {
public ContactInfoRepositoryRoom(@NonNull AppDatabase appDatabase) {
this.appDatabase = appDatabase;
}

@NonNull
@Override
public Single<List<ContactInfo>> getAll() {
return appDatabase.getContactDaO().getAll();
return appDatabase.getContactDao().getAll();
}

@Nullable
@NonNull
@Override
public Single<ContactInfo> getById(@NonNull Long id) {
return appDatabase.getContactDaO().getContactInfoById(id);
public Maybe<ContactInfo> getById(@NonNull Long id) {
return appDatabase.getContactDao().getContactInfoById(id);
}

@NonNull
@Override
public Completable update(@NonNull ContactInfo contactInfo) {
return Completable.fromAction(() -> appDatabase.getContactDaO().updateContactInfo(contactInfo));
return Completable.fromAction(() -> appDatabase.getContactDao().updateContactInfo(contactInfo));
}

@NonNull
@Override
public Completable insert(@NonNull ContactInfo contactInfo) {
return Completable.fromAction(() -> appDatabase.getContactDaO().insertContactInfo(contactInfo));
return Completable.fromAction(() -> appDatabase.getContactDao().insertContactInfo(contactInfo));
RomanPozdeev marked this conversation as resolved.
Show resolved Hide resolved
}

@NonNull
@Override
public Completable delete(@NonNull ContactInfo contactInfo) {
return Completable.fromAction(() -> appDatabase.getContactDaO().deleteContactInfo(contactInfo));
public void delete(@NonNull ContactInfo contactInfo) {
appDatabase.getContactDao().deleteContactInfo(contactInfo);
}

@NonNull
@Override
public Completable deleteAll() {
return Completable.fromAction(() -> appDatabase.getContactDaO().deleteAll());
return Completable.fromAction(() -> appDatabase.getContactDao().deleteAll());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.kkaysheva.ituniver.data.network.directions;

import com.google.gson.annotations.SerializedName;

import java.util.List;

/**
* DirectionsResponse
*
* @author Ksenya Kaysheva (murrcha@me.com)
* @since 01.2019
*/
public final class DirectionsResponse {

@SerializedName("status")
private String status;

@SerializedName("routes")
private List<Route> routes;

public String getStatus() {
return status;
}

public List<Route> getRoutes() {
return routes;
}

public static class Route {

@SerializedName("overview_polyline")
private OverviewPolyLine overviewPolyLine;

@SerializedName("legs")
private List<Legs> legs;

public OverviewPolyLine getOverviewPolyLine() {
return overviewPolyLine;
}

public List<Legs> getLegs() {
return legs;
}

public static class OverviewPolyLine {

@SerializedName("points")
private String points;

public String getPoints() {
return points;
}
}

public static class Legs {

@SerializedName("steps")
private List<Steps> steps;

public List<Steps> getSteps() {
return steps;
}

public static class Steps {

@SerializedName("start_location")
private Location startLocation;

@SerializedName("end_location")
private Location endLocation;

@SerializedName("polyline")
private OverviewPolyLine polyline;

public Location getStartLocation() {
return startLocation;
}

public Location getEndLocation() {
return endLocation;
}

public OverviewPolyLine getPolyline() {
return polyline;
}

public static class Location {

@SerializedName("lat")
private double lat;

@SerializedName("lng")
private double lng;

public double getLat() {
return lat;
}

public double getLng() {
return lng;
}
}
}
}
}
}

RomanPozdeev marked this conversation as resolved.
Show resolved Hide resolved







Loading