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

ユーザ名、メールアドレスを更新できるようにする #284

Open
wants to merge 7 commits into
base: development
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
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<activity
android:name=".view.activity.ContactActivity"
android:screenOrientation="portrait" />
<activity
android:name=".view.activity.SettingActivity"
android:screenOrientation="portrait" />

</application>

Expand Down
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 @@ -22,5 +22,6 @@ interface ActivityComponent {
fun inject(activity: SearchVideoActivity)
fun inject(activity: UserReportActivity)
fun inject(activity: ContactActivity)
fun inject(activity: SettingActivity)
fun plus(module: FragmentModule): FragmentComponent
}
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
@@ -0,0 +1,42 @@
package com.cyder.android.syncpod.view.activity

import android.content.Context
import android.content.Intent
import android.databinding.DataBindingUtil
import android.os.Bundle
import com.cyder.android.syncpod.R
import com.cyder.android.syncpod.databinding.ActivitySettingBinding
import com.cyder.android.syncpod.view.helper.setUpSnackbar
import com.cyder.android.syncpod.viewmodel.SettingActivityViewModel
import javax.inject.Inject

/**
* Created by shikibu on 2018/05/21.
*/

class SettingActivity: BaseActivity() {
@Inject
lateinit var viewModel: SettingActivityViewModel
private lateinit var binding: ActivitySettingBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
getComponent().inject(this)
bindViewModel(viewModel)

binding = DataBindingUtil.setContentView(this, R.layout.activity_setting)
binding.viewModel = viewModel

viewModel.callback = setUpSnackbar()
}

override fun onDestroy() {
viewModel.callback = null
super.onDestroy()
}


companion object {
fun createIntent(context: Context): Intent = Intent(context, SettingActivity::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ class Navigator @Inject constructor(
fun navigateToSearchVideoActivity() = activity.startActivity(SearchVideoActivity.createIntent(activity))
fun navigateToUserReportActivity(roomKey: String) = activity.startActivity(UserReportActivity.createIntent(activity, roomKey))
fun navigateToContactActivity() = activity.startActivity(ContactActivity.createIntent(activity))
fun navigateToSettingActivity() = activity.startActivity(SettingActivity.createIntent(activity))
fun closeActivity() = activity.finish()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.cyder.android.syncpod.viewmodel

import android.databinding.ObservableField
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

/**
* Created by shikibu on 2018/05/21.
*/

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

override fun onStart() {

}

override fun onResume() {

}

override fun onPause() {

}

override fun onStop() {

}

override fun onDestroy() {
}

fun onBackButtonClicked() = navigator.closeActivity()

fun onSubmit() {
repository.editUser(
mailAddress.get() ?: "",
name.get() ?: ""
).subscribe({
navigator.navigateToTopActivity()
}, {
callback?.onFailed(R.string.sign_up_used_email)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class TopActivityViewModel @Inject constructor(

fun onContactUs() = navigator.navigateToContactActivity()

fun onSetting() = navigator.navigateToSettingActivity()

fun onRefresh() {
isLoading.set(true)
getRooms()
Expand Down
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.
78 changes: 78 additions & 0 deletions app/src/main/res/layout/activity_setting.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="viewModel"
type="com.cyder.android.syncpod.viewmodel.SettingActivityViewModel" />
</data>

<LinearLayout
android:id="@+id/setting_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/setting_tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:navigationIcon="@drawable/ic_arrow_back_black_24dp"
app:navigationOnClick="@{(v) -> viewModel.onBackButtonClicked()}"
app:title="@string/setting_title" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">

<EditText
android:id="@+id/setting_name_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:ems="10"
android:gravity="top"
android:hint="@string/setting_name_description"
android:inputType="textPersonName"
android:text="@={viewModel.message}" />

<EditText
android:id="@+id/setting_email_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:ems="10"
android:gravity="top"
android:hint="@string/setting_email_description"
android:inputType="textEmailAddress"
android:text="@={viewModel.message}" />

<Button
android:id="@+id/setting_submit"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="@color/appBlue"
android:onClick="@{(v) -> viewModel.onSubmit()}"
android:text="@string/update_button"
android:textColor="@color/appWhite"
android:textSize="18sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</layout>
13 changes: 12 additions & 1 deletion app/src/main/res/layout/activity_top.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:logo="@drawable/toolbar_logo" />
app:logo="@drawable/toolbar_logo" >

<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="@drawable/ic_setting_black_32dp" />
</android.support.v7.widget.Toolbar>

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_joined_rooms"
Expand Down
6 changes: 5 additions & 1 deletion 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 Expand Up @@ -88,4 +89,7 @@
<string name="contact_us">ご意見・お問い合わせ</string>
<string name="contact_description">ご意見・お問い合わせ内容を記述して下さい。</string>
<string name="publishing_setting">公開設定</string>
</resources>
<string name="setting_title">設定</string>
<string name="setting_name_description">ユーザ名</string>
<string name="setting_email_description">メールアドレス</string>
</resources>