This repository has been archived by the owner on Aug 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#14 , create user repository , closed #13 , create verification code viewmodel , clsoed #11 , create verification code view , closed #10
- Loading branch information
1 parent
9bc6909
commit 8d284c5
Showing
23 changed files
with
346 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.netalic | ||
|
||
import android.app.Application | ||
import de.netalic.peacock.di.apiModule | ||
import de.netalic.peacock.di.repositoryModule | ||
import de.netalic.peacock.di.viewModelModule | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.android.ext.koin.androidLogger | ||
import org.koin.core.context.startKoin | ||
|
||
class MyApp : Application() { | ||
|
||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
instance = this | ||
|
||
startKoin { | ||
|
||
androidLogger() | ||
androidContext(this@MyApp) | ||
|
||
modules( | ||
listOf( | ||
repositoryModule, | ||
apiModule, | ||
viewModelModule | ||
) | ||
) | ||
} | ||
} | ||
|
||
companion object { | ||
|
||
lateinit var instance: Application | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package de.netalic.peacock | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import de.netalic.peacock.ui.registeration.codeverification.CodeVerificationFragment | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.fragment_codeverification) | ||
setContentView(R.layout.activity_main) | ||
|
||
supportFragmentManager.beginTransaction().add(R.id.frameLayout_mainActivity_fragmentContainer, CodeVerificationFragment()).commit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ data class MyResponse<T>( | |
} | ||
|
||
enum class Status { | ||
|
||
LOADING, | ||
SUCCESS, | ||
FAILED | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 73 additions & 8 deletions
81
app/src/main/java/de/netalic/peacock/data/webservice/ApiClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,87 @@ | ||
package de.netalic.peacock.data.webservice | ||
|
||
|
||
import com.franmontiel.persistentcookiejar.PersistentCookieJar | ||
import com.franmontiel.persistentcookiejar.cache.SetCookieCache | ||
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor | ||
import de.netalic.MyApp | ||
import nuesoft.helpdroid.network.SharedPreferencesJwtPersistor | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Response | ||
import okhttp3.ResponseBody | ||
import retrofit2.Retrofit | ||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.io.IOException | ||
|
||
class ApiClient { | ||
|
||
companion object{ | ||
|
||
fun getClient():InterfaceApi{ | ||
companion object { | ||
private var sRetrofit: Retrofit? = null | ||
private var sApi: InterfaceApi? = null | ||
|
||
|
||
private fun getClient(): Retrofit { | ||
|
||
if (sRetrofit == null) { | ||
|
||
val okHttpClient = OkHttpClient().newBuilder() | ||
val cookieJar = PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(MyApp.instance)) | ||
okHttpClient.cookieJar(cookieJar).addInterceptor(AuthorizationInterceptor()) | ||
|
||
val retrofit=Retrofit.Builder() | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.baseUrl("https://nightly-alpha.carrene.com/apiv1/") | ||
.build() | ||
return retrofit.create(InterfaceApi::class.java) | ||
sRetrofit = Retrofit.Builder().baseUrl("https://nightly-alpha.carrene.com/apiv1/") | ||
.client(okHttpClient.build()) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.build() | ||
} | ||
return sRetrofit!! | ||
} | ||
|
||
|
||
fun getService(): InterfaceApi? { | ||
|
||
if (sApi == null) { | ||
sApi = getClient().create(InterfaceApi::class.java) | ||
} | ||
return sApi | ||
} | ||
} | ||
|
||
private class AuthorizationInterceptor : Interceptor { | ||
|
||
internal var sharedPreferencesJwtPersistor = SharedPreferencesJwtPersistor(MyApp.instance) | ||
|
||
@Throws(IOException::class) | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
|
||
val token = sharedPreferencesJwtPersistor.get() | ||
var request = chain.request() | ||
|
||
if (token != null) { | ||
request = request.newBuilder().addHeader("Authorization", "Bearer $token").build() | ||
} | ||
|
||
var response = chain.proceed(request) | ||
|
||
if (response.request().method() == "BIND" && response.code() == 200) { | ||
|
||
val responseBodyString = response.body()!!.string() | ||
val contentType = response.body()!!.contentType() | ||
val body = ResponseBody.create(contentType, responseBodyString) | ||
response = response.newBuilder().body(body).build() | ||
} | ||
|
||
val newJwtToken = response.header("X-New-JWT-Token") | ||
|
||
if (newJwtToken != null) { | ||
sharedPreferencesJwtPersistor.save(newJwtToken) | ||
} | ||
|
||
return response | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.netalic.peacock.di | ||
|
||
import de.netalic.peacock.data.repository.UserRepository | ||
import de.netalic.peacock.data.webservice.ApiClient | ||
import de.netalic.peacock.ui.registeration.codeverification.CodeVerificationViewModel | ||
import org.koin.android.viewmodel.dsl.viewModel | ||
import org.koin.dsl.module | ||
|
||
val repositoryModule = module { | ||
|
||
single { | ||
|
||
UserRepository(get()) | ||
} | ||
} | ||
val viewModelModule = module { | ||
|
||
viewModel { | ||
|
||
CodeVerificationViewModel(get()) | ||
} | ||
} | ||
|
||
val apiModule= module { | ||
|
||
single { | ||
|
||
ApiClient.getService() | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.