Skip to content

Commit

Permalink
Merge pull request #67 from maximzhemerenko/develop
Browse files Browse the repository at this point in the history
merge develop to master
  • Loading branch information
Maxim Zhemerenko authored May 29, 2018
2 parents 34028f5 + 36baafe commit 0b99eb7
Show file tree
Hide file tree
Showing 154 changed files with 8,854 additions and 264 deletions.
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: android
android:
components:
- build-tools-27.0.3
- tools
- platform-tools
- android-27
licenses:
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'
- 'google-gdk-license-.+'

before_install:
- cd Android
- chmod +x gradlew

script:
- ./gradlew assemble
14 changes: 14 additions & 0 deletions Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 27

defaultConfig {
applicationId "com.khsm.app"
minSdkVersion project.minSdkVersion
targetSdkVersion project.targetSdkVersion
versionCode project.versionCode
versionName project.versionName

vectorDrawables.useSupportLibrary = true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
Expand All @@ -26,6 +31,8 @@ dependencies {
implementation "com.android.support:appcompat-v7:$project.ANDROID_SUPPORT_VERSION"
implementation "com.android.support.constraint:constraint-layout:$project.CONSTRAINT_LAYOUT_VERSION"
implementation "com.android.support:recyclerview-v7:$project.ANDROID_SUPPORT_VERSION"
implementation "com.android.support:design:$project.ANDROID_SUPPORT_VERSION"
implementation "com.android.support:cardview-v7:$project.ANDROID_SUPPORT_VERSION"

// io.reactivex.rxjava2
implementation "io.reactivex.rxjava2:rxandroid:$project.RX_ANDROID_VERSION"
Expand All @@ -39,4 +46,11 @@ dependencies {
// com.squareup.okhttp3
implementation "com.squareup.okhttp3:okhttp:$project.OKHTTP3_VERSION"
implementation "com.squareup.okhttp3:logging-interceptor:$project.OKHTTP3_VERSION"

// glide
implementation "com.github.bumptech.glide:glide:$project.GLIDE_VERSION"
annotationProcessor "com.github.bumptech.glide:compiler:$project.GLIDE_VERSION"

// com.f2prateek.rx.preferences2
implementation "com.f2prateek.rx.preferences2:rx-preferences:$project.RX_PREFERENCES_VERSION"
}
8 changes: 8 additions & 0 deletions Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".presentation.ui.screens.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".presentation.ui.screens.auth.RegisterActivity"
android:windowSoftInputMode="adjustPan" />

<activity android:name=".presentation.ui.screens.auth.LoginActivity"
android:windowSoftInputMode="adjustPan"/>

</application>

</manifest>
98 changes: 96 additions & 2 deletions Android/app/src/main/java/com/khsm/app/data/api/Api.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package com.khsm.app.data.api;

import android.support.annotation.NonNull;

import com.khsm.app.data.api.base.ApiBase;
import com.khsm.app.data.api.entities.User;
import com.khsm.app.data.api.entities.RankingsFilterInfo;
import com.khsm.app.data.entities.CreateSessionRequest;
import com.khsm.app.data.entities.CreateUserRequest;
import com.khsm.app.data.entities.Discipline;
import com.khsm.app.data.entities.DisciplineRecord;
import com.khsm.app.data.entities.DisciplineResults;
import com.khsm.app.data.entities.Meeting;
import com.khsm.app.data.entities.News;
import com.khsm.app.data.entities.Result;
import com.khsm.app.data.entities.Session;
import com.khsm.app.data.entities.User;

import java.util.List;

Expand All @@ -10,12 +22,94 @@
public class Api extends ApiBase {
private final RestApi restApi;

Api(RestApi restApi) {
Api(RestApi restApi, AuthInterceptor authInterceptor) {
super(authInterceptor);
this.restApi = restApi;
}

public Single<List<Meeting>> getMeetings() {
return restApi.getMeetings()
.compose(this::processResponse);
}

public Single<List<Discipline>> getDisciplines() {
return restApi.getDisciplines()
.compose(this::processResponse);
}

public Single<List<User>> getUsers() {
return restApi.getUsers()
.compose(this::processResponse);
}

public Single<List<DisciplineResults>> getMeetingResults(int id) {
return restApi.getMeetingResults(id)
.compose(this::processResponse);
}

public Single<Meeting> getLastMeeting() {
return restApi.getLastMeeting()
.compose(this::processResponse);
}

public Single<Session> login(CreateSessionRequest createSessionRequest) {
return restApi.login(createSessionRequest)
.compose(this::processResponse);
}

public Single<Session> register(CreateUserRequest createUserRequest) {
return restApi.register(createUserRequest)
.compose(this::processResponse);
}

public Single<Meeting> createMeeting(Meeting meeting){
return restApi.createMeeting(meeting)
.compose(this::processResponse);
}

public Single<Result> createResult(Result result){
return restApi.createResult(result)
.compose(this::processResponse);
}

public Single<User> updateUser(User user){
return restApi.updateUser(user)
.compose(this::processResponse);
}

public Single<List<DisciplineResults>> getMyResults() {
return restApi.getMyResults()
.compose(this::processResponse);
}

public Single<List<DisciplineRecord>> getMyRecords() {
return restApi.getMyRecords()
.compose(this::processResponse);
}

public Single<List<DisciplineResults>> getRankings(@NonNull RankingsFilterInfo rankingsFilterInfo) {
return restApi.getRankings(rankingsFilterInfo.filterType, rankingsFilterInfo.sortType, rankingsFilterInfo.gender)
.compose(this::processResponse);
}

public Single<List<News>> getNews() {
return restApi.getNews()
.compose(this::processResponse);
}

public Single<News> addNews(News news){
return restApi.addNews(news)
.compose(this::processResponse);
}

public Single<List<DisciplineResults>> getNewsResults(int id) {
return restApi.getNewsResults(id)
.compose(this::processResponse);
}

public Single<News> getLastNews() {
return restApi.getLastNews()
.compose(this::processResponse);
}

}
25 changes: 22 additions & 3 deletions Android/app/src/main/java/com/khsm/app/data/api/ApiFactory.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
package com.khsm.app.data.api;

import android.content.Context;
import android.support.annotation.NonNull;

import com.khsm.app.BuildConfig;
import com.khsm.app.data.api.base.ApiBase;
import com.khsm.app.data.api.core.ApiBuilderHelper;
import com.khsm.app.data.entities.Session;
import com.khsm.app.data.preferences.SessionStore;

import okhttp3.logging.HttpLoggingInterceptor;

public abstract class ApiFactory {
public static Api createApi() {
public static Api createApi(@NonNull Context context) {
ApiBuilderHelper apiBuilderHelper = new ApiBuilderHelper();

ApiBase.AuthInterceptor authInterceptor = new ApiBase.AuthInterceptor();

apiBuilderHelper.addInterceptor(authInterceptor);

if (BuildConfig.DEBUG) {
apiBuilderHelper.addLoggingInterceptor(HttpLoggingInterceptor.Level.BODY);
}

String serviceUrl = "http://10.0.2.2:5000/";
String serviceUrl = "http://10.0.2.2:5000/api/";

RestApi restApi = apiBuilderHelper.createRetrofitApi(serviceUrl, RestApi.class);

return new Api(restApi);
Api api = new Api(restApi, authInterceptor);

SessionStore sessionStore = new SessionStore(context);

Session session = sessionStore.getSession();
if (session != null) {
api.setSessionToken(session.token);
}

return api;
}
}
68 changes: 66 additions & 2 deletions Android/app/src/main/java/com/khsm/app/data/api/RestApi.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,77 @@
package com.khsm.app.data.api;

import com.khsm.app.data.api.entities.User;
import com.khsm.app.data.api.entities.RankingsFilterInfo;
import com.khsm.app.data.entities.CreateSessionRequest;
import com.khsm.app.data.entities.CreateUserRequest;
import com.khsm.app.data.entities.Discipline;
import com.khsm.app.data.entities.DisciplineRecord;
import com.khsm.app.data.entities.DisciplineResults;
import com.khsm.app.data.entities.Gender;
import com.khsm.app.data.entities.Meeting;
import com.khsm.app.data.entities.News;
import com.khsm.app.data.entities.Result;
import com.khsm.app.data.entities.Session;
import com.khsm.app.data.entities.User;

import java.util.List;

import io.reactivex.Single;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;

interface RestApi {
@GET("api/users")
@GET("meetings")
Single<List<Meeting>> getMeetings();

@GET("meetings/last")
Single<Meeting> getLastMeeting();

@GET("disciplines")
Single<List<Discipline>> getDisciplines();

@GET("meetings/{id}/results")
Single<List<DisciplineResults>> getMeetingResults(@Path("id") int id);

@POST("sessions")
Single<Session> login(@Body CreateSessionRequest createSessionRequest);

@POST("users")
Single<Session> register(@Body CreateUserRequest createUserRequest);

@POST("meetings")
Single<Meeting> createMeeting(@Body Meeting meeting);

@POST("meetings/results")
Single<Result> createResult(@Body Result result);

@PUT("users/me")
Single<User> updateUser(@Body User user);

@GET("users/me/results")
Single<List<DisciplineResults>> getMyResults();

@GET("users/me/records")
Single<List<DisciplineRecord>> getMyRecords();

@GET("rankings")
Single<List<DisciplineResults>> getRankings(@Query("type") RankingsFilterInfo.FilterType type, @Query("sort") RankingsFilterInfo.SortType sort, @Query("gender") Gender gender);

@GET("news")
Single<List<News>> getNews();

@GET("news/last")
Single<News> getLastNews();

@GET("news/{id}/results")
Single<List<DisciplineResults>> getNewsResults(@Path("id") int id);

@POST("news")
Single<News> addNews(@Body News news);

@GET("users")
Single<List<User>> getUsers();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
package com.khsm.app.data.api.base;

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

import java.io.IOException;

import io.reactivex.Completable;
import io.reactivex.Single;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class ApiBase {
protected ApiBase() {
private final AuthInterceptor authInterceptor;

protected ApiBase(AuthInterceptor authInterceptor) {
this.authInterceptor = authInterceptor;
}

public void setSessionToken(@Nullable String sessionToken) {
authInterceptor.sessionToken = sessionToken;
}

protected Completable processResponse(Completable upstream) {
Expand All @@ -14,4 +29,29 @@ protected Completable processResponse(Completable upstream) {
protected <TResponse> Single<TResponse> processResponse(Single<TResponse> upstream) {
return upstream; // TODO: 14.02.2018 add generic error handling
}

//region Interceptor
public static class AuthInterceptor implements Interceptor {
@Nullable
private String sessionToken;

private static final String HEADER_AUTHORIZATION = "Authorization";

@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();

addHeaders(builder);

return chain.proceed(builder.build());
}

private void addHeaders(@NonNull Request.Builder builder) {
String authentication = sessionToken;
if (authentication != null) {
builder.addHeader(HEADER_AUTHORIZATION, authentication);
}
}
}
//endregion
}
Loading

0 comments on commit 0b99eb7

Please sign in to comment.