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

Whole project is alive and working. #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
72 changes: 72 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.ievazygaite.androidparty"
minSdkVersion 21
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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
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'

//MVP
kapt "com.arello-mobile:moxy-compiler:$moxyVersion"
implementation "com.arello-mobile:moxy-app-compat:$moxyVersion"

//retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

//RxJava
implementation "io.reactivex.rxjava2:rxandroid:2.1.0"
implementation "io.reactivex.rxjava2:rxjava:2.2.0"


//Gson
implementation "com.google.code.gson:gson:2.8.4"

//Dagger
implementation "com.google.dagger:dagger:$dagger2_version"
implementation "com.google.dagger:dagger-android:$dagger2_version"
implementation "com.google.dagger:dagger-android-support:$dagger2_version"
kapt "com.google.dagger:dagger-compiler:$dagger2_version"
kapt "com.google.dagger:dagger-android-processor:$dagger2_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger2_version"
compileOnly 'javax.annotation:jsr250-api:1.0'
implementation 'javax.inject:javax.inject:1'

//Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
//Room database
implementation "android.arch.persistence.room:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
//UI
// //noinspection GradleCompatible
implementation "com.android.support:design:28.0.0"

}
22 changes: 22 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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

28 changes: 28 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="com.example.ievazygaite.androidparty">
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".BaseApplication"
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" tools:ignore="GoogleAppIndexingWarning"
android:usesCleartextTraffic="true"
tools:targetApi="m">

<activity android:name=".ui.main.MainActivity"
android:windowSoftInputMode="adjustResize|stateHidden">
<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,27 @@
package com.example.ievazygaite.androidparty

import android.app.Application
import com.example.ievazygaite.androidparty.data.DataManager
import com.example.ievazygaite.androidparty.di.component.ApplicationComponent
import com.example.ievazygaite.androidparty.di.component.DaggerApplicationComponent

class BaseApplication : Application() {

lateinit var component: ApplicationComponent

override fun onCreate() {
super.onCreate()
instance = this
DataManager.initManager(this)
setup()
}

private fun setup() {
component = DaggerApplicationComponent.builder().build()
component.inject(this)
}

companion object {
lateinit var instance: BaseApplication private set
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.ievazygaite.androidparty.api

import com.example.ievazygaite.androidparty.data.login.LoginBody
import com.example.ievazygaite.androidparty.data.login.LoginResponse
import com.example.ievazygaite.androidparty.data.server.Server
import com.example.ievazygaite.androidparty.utils.BASE_URL
import io.reactivex.Observable
import io.reactivex.Single
import okhttp3.OkHttpClient
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST

interface TesoApi {

companion object Factory {

fun create(): TesoApi {
val retrofit = retrofit2.Retrofit.Builder()
.client(OkHttpClient.Builder().addInterceptor { chain ->
chain.proceed(
chain.request().newBuilder()
.addHeader("Accept", "application/json")
.addHeader("Accept-Language", "en")
.addHeader("Content-Type", "application/json")
.build()
)
}
.build())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build()

return retrofit.create(TesoApi::class.java)
}
}

@POST("tokens")
fun authUser(@Body userBody: LoginBody): Single<LoginResponse>


@GET("servers")
fun getServers(@Header("Authorization") bearerToken: String): Single<List<Server>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.ievazygaite.androidparty.data

import android.content.Context
import com.example.ievazygaite.androidparty.R.string.password
import com.example.ievazygaite.androidparty.api.TesoApi
import com.example.ievazygaite.androidparty.data.login.LoginBody
import com.example.ievazygaite.androidparty.data.login.LoginResponse
import com.example.ievazygaite.androidparty.data.server.Server
import io.reactivex.Observable
import io.reactivex.Single

interface DataManager {
companion object {
lateinit var prefs: SharedPrefsStorage
lateinit var api: TesoApi

@Synchronized
fun initManager(context: Context) {
prefs = SharedPrefsStorage(context)
api = TesoApi.create()
}

fun auth(email: String, password: String): Single<LoginResponse> {
return api.authUser(LoginBody(email, password))
}

fun getServers(bearerToken: String): Single<List<Server>> {
return api.getServers(bearerToken)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.ievazygaite.androidparty.data

import android.content.Context
import android.content.SharedPreferences
import com.example.ievazygaite.androidparty.utils.DEF_TOKEN
import com.example.ievazygaite.androidparty.utils.KEY_TOKEN
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SharedPrefsStorage @Inject constructor(context: Context) {
private var mPref: SharedPreferences = context.getSharedPreferences(KEY_TOKEN, Context.MODE_PRIVATE)

fun clear() {
mPref.edit().clear().apply()
}

fun addToken(searchKey: String) {
mPref.edit().putString(KEY_TOKEN, searchKey).apply()
}

fun getToken(): String {
return mPref.getString(KEY_TOKEN, DEF_TOKEN)!!
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.example.ievazygaite.androidparty.data.login

data class LoginBody(val username:String, val password:String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.example.ievazygaite.androidparty.data.login

data class LoginResponse(var token: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.ievazygaite.androidparty.data.server

import android.os.Parcel
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
data class Server(@SerializedName("name") val serverName: String, val distance: String):Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readString()!!
) {
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(serverName)
parcel.writeString(distance)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<Server> {
override fun createFromParcel(parcel: Parcel): Server {
return Server(parcel)
}

override fun newArray(size: Int): Array<Server?> {
return arrayOfNulls(size)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.ievazygaite.androidparty.di.component

import com.example.ievazygaite.androidparty.di.module.ActivityModule
import com.example.ievazygaite.androidparty.ui.main.MainActivity
import dagger.Component

@Component(modules = [ActivityModule::class])
interface ActivityComponent {
fun inject(mainActivity: MainActivity)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.ievazygaite.androidparty.di.component

import com.example.ievazygaite.androidparty.BaseApplication
import com.example.ievazygaite.androidparty.di.module.ApplicationModule
import dagger.Component

@Component(modules = [ApplicationModule::class])
interface ApplicationComponent {
fun inject(application: BaseApplication)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.ievazygaite.androidparty.di.component

import com.example.ievazygaite.androidparty.di.module.FragmentModule
import com.example.ievazygaite.androidparty.ui.list.ServerListFragment
import com.example.ievazygaite.androidparty.ui.login.LoginFragment
import dagger.Component


@Component(modules = [FragmentModule::class])
interface FragmentComponent {
fun inject(serverListFragment: ServerListFragment)
fun inject(loginFragment: LoginFragment)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.ievazygaite.androidparty.di.module

import android.app.Activity
import com.example.ievazygaite.androidparty.ui.main.MainContract
import com.example.ievazygaite.androidparty.ui.main.MainPresenter
import dagger.Module
import dagger.Provides

@Module
class ActivityModule(private var activity: Activity) {

@Provides
fun provideActivity(): Activity {
return activity
}

@Provides
fun providePresenter(): MainContract.Presenter {
return MainPresenter()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.ievazygaite.androidparty.di.module

import android.app.Application
import android.content.Context
import com.example.ievazygaite.androidparty.BaseApplication
import com.example.ievazygaite.androidparty.di.scope.PerApplication
import dagger.Module
import dagger.Provides
import javax.inject.Singleton

@Module
class ApplicationModule(private val baseApp: BaseApplication) {
@Provides
@Singleton
@PerApplication
fun provideApplication(): Application {
return baseApp
}

@Provides
@Singleton
@PerApplication
fun provideApplicationContext(): Context {
return this.baseApp
}

}
Loading