Skip to content

Commit

Permalink
[add] ユーザ名やメールアドレスを更新できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
shikibu9419 committed May 24, 2018
1 parent 7f312a8 commit f428333
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 31 deletions.
182 changes: 182 additions & 0 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ interface SyncPodApi {
@POST("users")
fun signUp(@Body user: SignUp): Single<Response>

@POST("users")
fun editUser(@Query("email") email: String, @Query("name") name: String): Single<Response>

@GET("joined_rooms")
fun getEnteredRooms(@Header("Authorization") token: String): Single<Response>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class UserDataRepository @Inject constructor(
.toCompletable()
}

override fun editUser(email: String, name: String): Completable {
return editUserValidate(email, name)
.andThen(syncPodApi.editUser(email, name))
.subscribeOn(Schedulers.computation())
.toCompletable()
}

override fun getAccessToken(): Single<String> {
val token = sharedPreferences.getString(STATE_USER_TOKEN, null)
return Single.create { emitter ->
Expand Down Expand Up @@ -97,6 +104,16 @@ class UserDataRepository @Inject constructor(
}
}

private fun editUserValidate(email: String, name: String): Completable {
return Completable.create { emitter ->
if (email.isBlank() || name.isBlank()) {
emitter.onError(NotFilledFormsException())
} else {
emitter.onComplete()
}
}
}

private fun saveSharedPreferences(user: User) {
sharedPreferences.edit {
putString(STATE_USER_TOKEN, user.accessToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface UserRepository {
fun signIn(email: String, password: String, isAgreeTerms: Boolean): Completable
@CheckResult
fun signUp(email: String, name: String, password:String, passwordConfirm: String, isAgreeTerms: Boolean): Completable
@CheckResult
fun editUser(email: String, name: String): Completable
fun getAccessToken(): Single<String>
fun getMyselfId(): Single<Int>
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.cyder.android.syncpod.viewmodel

import android.databinding.ObservableField
import android.os.Build
import com.cyder.android.syncpod.repository.UserReportRepository
import com.cyder.android.syncpod.R
import com.cyder.android.syncpod.repository.UserRepository
import com.cyder.android.syncpod.view.helper.Navigator
import com.cyder.android.syncpod.viewmodel.base.ActivityViewModel
import javax.inject.Inject
Expand All @@ -13,8 +13,10 @@ import javax.inject.Inject

class SettingActivityViewModel @Inject constructor(
private val navigator: Navigator,
private val userReportRepository: UserReportRepository
private val repository: UserRepository
) : ActivityViewModel() {
var mailAddress: ObservableField<String?> = ObservableField()
var name: ObservableField<String?> = ObservableField()
var callback: SnackbarCallback? = null
var message: ObservableField<String> = ObservableField()

Expand All @@ -40,29 +42,13 @@ class SettingActivityViewModel @Inject constructor(
fun onBackButtonClicked() = navigator.closeActivity()

fun onSubmit() {
// Single.create<String> { emitter ->
// if ((message.get() ?: "").isNotBlank()) {
// emitter.onSuccess(message.get())
// } else {
// emitter.onError(NotFilledFormsException())
// }
// }
// .map { createDetailMessage(it) }
// .flatMapCompletable { userReportRepository.sendUserReport(it) }
// .subscribe({
// navigator.closeActivity()
// }, { error ->
// when (error) {
// is NotFilledFormsException -> callback?.onFailed(R.string.form_not_filled)
// else -> callback?.onFailed(R.string.network_error)
// }
// })
}

private fun createDetailMessage(message: String): String {
return """$message
----------------------------------------
端末: Android ${Build.VERSION.RELEASE}"""
repository.editUser(
mailAddress.get() ?: "",
name.get() ?: ""
).subscribe({
navigator.navigateToTopActivity()
}, {
callback?.onFailed(R.string.sign_up_used_email)
})
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
android:layout_height="55dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="@color/appGreen"
android:background="@color/appBlue"
android:onClick="@{(v) -> viewModel.onSubmit()}"
android:text="@string/send_button"
android:text="@string/update_button"
android:textColor="@color/appWhite"
android:textSize="18sp" />
</LinearLayout>
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/layout/activity_top.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:logo="@drawable/toolbar_logo" >

<Button
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:id="@+id/setting_button"
android:background="@null"
android:layout_alignParentEnd="true"
android:onClick="@{(v) -> viewModel.onSetting()}"
android:src="@mipmap/logo"/>
android:src="@drawable/ic_setting_black_32dp" />
</android.support.v7.widget.Toolbar>

<android.support.v4.widget.SwipeRefreshLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<string name="create_room_button">ルーム作成</string>
<string name="send_button">送信</string>
<string name="cancel_button">キャンセル</string>
<string name="update_button">更新</string>
<string name="register_button">登録</string>
<string name="first_start_message">
ようこそ。\n\n
Expand Down

0 comments on commit f428333

Please sign in to comment.