-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
signup screen with avatar image uploading
- Loading branch information
Ruslan Faizullin
committed
Apr 2, 2021
1 parent
43a49c3
commit 85c7625
Showing
45 changed files
with
873 additions
and
24 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
1 change: 1 addition & 0 deletions
1
app/src/main/graphql/com/flatstack/android/graphql/fragment/User.graphql
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,4 +1,5 @@ | ||
fragment UserGqlFragment on User { | ||
firstName | ||
lastName | ||
avatarUrl | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/graphql/com/flatstack/android/graphql/mutation/PresignAvatar.graphql
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,11 @@ | ||
mutation PresignAvatar( | ||
$input: PresignDataInput! | ||
) { | ||
presignData(input: $input) { | ||
fields { | ||
key | ||
value | ||
} | ||
url | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
app/src/main/graphql/com/flatstack/android/graphql/mutation/Signin.graphql
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,5 +1,5 @@ | ||
mutation Login($email: String!, $password: String!) { | ||
signin(email: $email, password: $password) { | ||
mutation Login($input: SignInInput!) { | ||
signin(input: $input) { | ||
accessToken | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/graphql/com/flatstack/android/graphql/mutation/Signup.graphql
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,5 @@ | ||
mutation Register($input: SignUpInput!) { | ||
signup(input: $input) { | ||
accessToken | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/flatstack/android/di/modules/mapperModule.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.flatstack.android.di.modules | ||
|
||
import com.flatstack.android.registration.SessionFromRegistrationMapper | ||
import com.flatstack.android.registration.mapper.PresignDataFromNetworkMapper | ||
import com.flatstack.android.registration.mapper.PresignDataToNetworkMapper | ||
import com.flatstack.android.registration.mapper.RegisterRequestToNetworkMapper | ||
import org.kodein.di.Kodein | ||
import org.kodein.di.generic.bind | ||
import org.kodein.di.generic.provider | ||
|
||
val mapperModule = Kodein.Module(name = "mapperModule") { | ||
bind<SessionFromRegistrationMapper>() with provider { SessionFromRegistrationMapper() } | ||
bind<RegisterRequestToNetworkMapper>() with provider { RegisterRequestToNetworkMapper() } | ||
bind<PresignDataToNetworkMapper>() with provider { PresignDataToNetworkMapper() } | ||
bind<PresignDataFromNetworkMapper>() with provider { PresignDataFromNetworkMapper() } | ||
} |
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
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
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/flatstack/android/model/network/NetworkManager.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.flatstack.android.model.network | ||
|
||
import okhttp3.* | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.RequestBody.Companion.asRequestBody | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
class NetworkManager(private val okHttpClient: OkHttpClient) { | ||
|
||
fun uploadImageToAws(url: String, fields: Map<String, String>, file: File) : Boolean { | ||
val requestBody = MultipartBody.Builder().setType(MultipartBody.FORM) | ||
fields.forEach { | ||
requestBody.addFormDataPart(it.key, it.value) | ||
} | ||
requestBody.addFormDataPart( | ||
FORM_DATA_KEY, | ||
file.name, | ||
file.asRequestBody(contentType = REQUEST_BODY_CONTENT_TYPE.toMediaTypeOrNull()) | ||
) | ||
val request = Request.Builder() | ||
.url(url) | ||
.method(REQUEST_METHOD, requestBody.build()) | ||
.build() | ||
var isSuccessful = false | ||
okHttpClient | ||
.newCall(request) | ||
.enqueue(object : Callback { | ||
override fun onFailure(call: Call, e: IOException) { | ||
isSuccessful = false | ||
} | ||
|
||
override fun onResponse(call: Call, response: Response) { | ||
isSuccessful = true | ||
} | ||
|
||
}) | ||
return isSuccessful | ||
} | ||
|
||
companion object { | ||
const val FORM_DATA_KEY = "file" | ||
const val REQUEST_BODY_CONTENT_TYPE = "application/octet-stream" | ||
const val REQUEST_METHOD = "POST" | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/flatstack/android/registration/PresignDataRepository.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.flatstack.android.registration | ||
|
||
import com.apollographql.apollo.ApolloClient | ||
import com.apollographql.apollo.coroutines.toDeferred | ||
import com.flatstack.android.graphql.mutation.PresignAvatarMutation | ||
import com.flatstack.android.model.network.NetworkManager | ||
import com.flatstack.android.registration.entities.request.PresignDataRequest | ||
import com.flatstack.android.registration.mapper.PresignDataFromNetworkMapper | ||
import com.flatstack.android.registration.mapper.PresignDataToNetworkMapper | ||
import java.io.File | ||
|
||
|
||
class PresignDataRepository( | ||
private val apolloClient: ApolloClient, | ||
private val networkManager: NetworkManager, | ||
private val mapPresignDataToNetwork: PresignDataToNetworkMapper, | ||
private val mapPresignDataFromNetwork: PresignDataFromNetworkMapper | ||
) { | ||
suspend fun presignData(fileName: String, type: String) = | ||
apolloClient.mutate( | ||
PresignAvatarMutation( | ||
PresignDataRequest(fileName, type).run(mapPresignDataToNetwork) | ||
) | ||
) | ||
.toDeferred() | ||
.await() | ||
.data?.presignData | ||
?.run(mapPresignDataFromNetwork) | ||
|
||
fun uploadImageToAws(url: String, fields: Map<String, String>, file: File) : Boolean = | ||
networkManager.uploadImageToAws(url, fields, file) | ||
} |
Oops, something went wrong.