From 7f312a8c6bf61996153acec58f57d41c73002f2d Mon Sep 17 00:00:00 2001 From: Shikibu Date: Mon, 21 May 2018 22:38:44 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[add]=20SettingActivity=E3=81=A8=E3=81=9D?= =?UTF-8?q?=E3=81=AE=E5=B0=8E=E7=B7=9A=E3=82=92=E4=BD=9C=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 3 + .../android/syncpod/di/ActivityComponent.kt | 1 + .../syncpod/view/activity/SettingActivity.kt | 42 ++++++++++ .../android/syncpod/view/helper/Navigator.kt | 1 + .../viewmodel/SettingActivityViewModel.kt | 68 ++++++++++++++++ .../syncpod/viewmodel/TopActivityViewModel.kt | 2 + app/src/main/res/layout/activity_setting.xml | 78 +++++++++++++++++++ app/src/main/res/layout/activity_top.xml | 9 ++- app/src/main/res/values/strings.xml | 5 +- 9 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 app/src/main/kotlin/com/cyder/android/syncpod/view/activity/SettingActivity.kt create mode 100644 app/src/main/kotlin/com/cyder/android/syncpod/viewmodel/SettingActivityViewModel.kt create mode 100644 app/src/main/res/layout/activity_setting.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2ec2afb9..198a1e2b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -61,6 +61,9 @@ + diff --git a/app/src/main/kotlin/com/cyder/android/syncpod/di/ActivityComponent.kt b/app/src/main/kotlin/com/cyder/android/syncpod/di/ActivityComponent.kt index 9256776a..854f7b97 100644 --- a/app/src/main/kotlin/com/cyder/android/syncpod/di/ActivityComponent.kt +++ b/app/src/main/kotlin/com/cyder/android/syncpod/di/ActivityComponent.kt @@ -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 } \ No newline at end of file diff --git a/app/src/main/kotlin/com/cyder/android/syncpod/view/activity/SettingActivity.kt b/app/src/main/kotlin/com/cyder/android/syncpod/view/activity/SettingActivity.kt new file mode 100644 index 00000000..de6c75d8 --- /dev/null +++ b/app/src/main/kotlin/com/cyder/android/syncpod/view/activity/SettingActivity.kt @@ -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) + } +} diff --git a/app/src/main/kotlin/com/cyder/android/syncpod/view/helper/Navigator.kt b/app/src/main/kotlin/com/cyder/android/syncpod/view/helper/Navigator.kt index 641fb417..0fae1d29 100644 --- a/app/src/main/kotlin/com/cyder/android/syncpod/view/helper/Navigator.kt +++ b/app/src/main/kotlin/com/cyder/android/syncpod/view/helper/Navigator.kt @@ -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() } diff --git a/app/src/main/kotlin/com/cyder/android/syncpod/viewmodel/SettingActivityViewModel.kt b/app/src/main/kotlin/com/cyder/android/syncpod/viewmodel/SettingActivityViewModel.kt new file mode 100644 index 00000000..53d6172d --- /dev/null +++ b/app/src/main/kotlin/com/cyder/android/syncpod/viewmodel/SettingActivityViewModel.kt @@ -0,0 +1,68 @@ +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.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 userReportRepository: UserReportRepository +) : ActivityViewModel() { + var callback: SnackbarCallback? = null + var message: ObservableField = ObservableField() + + override fun onStart() { + + } + + override fun onResume() { + + } + + override fun onPause() { + + } + + override fun onStop() { + + } + + override fun onDestroy() { + } + + fun onBackButtonClicked() = navigator.closeActivity() + + fun onSubmit() { +// Single.create { 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}""" + } +} diff --git a/app/src/main/kotlin/com/cyder/android/syncpod/viewmodel/TopActivityViewModel.kt b/app/src/main/kotlin/com/cyder/android/syncpod/viewmodel/TopActivityViewModel.kt index d26f2241..feae53af 100644 --- a/app/src/main/kotlin/com/cyder/android/syncpod/viewmodel/TopActivityViewModel.kt +++ b/app/src/main/kotlin/com/cyder/android/syncpod/viewmodel/TopActivityViewModel.kt @@ -59,6 +59,8 @@ class TopActivityViewModel @Inject constructor( fun onContactUs() = navigator.navigateToContactActivity() + fun onSetting() = navigator.navigateToSettingActivity() + fun onRefresh() { isLoading.set(true) getRooms() diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml new file mode 100644 index 00000000..05ac5279 --- /dev/null +++ b/app/src/main/res/layout/activity_setting.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + +