From 7f1c31d80fb02420be5f74279bb16c2b075820c7 Mon Sep 17 00:00:00 2001 From: myung jun Hyun Date: Wed, 27 Nov 2019 11:19:29 +0900 Subject: [PATCH] (#2) fix login ui --- app/src/main/AndroidManifest.xml | 3 +- .../com/mashup/app/login/LoginFragment.kt | 15 +- .../com/mashup/app/login/LoginViewModel.kt | 4 + app/src/main/res/layout/login_fragment.xml | 272 +++++++++--------- app/src/main/res/layout/notice_item.xml | 4 +- app/src/main/res/layout/setting_fragment.xml | 4 +- app/src/main/res/values/dimens.xml | 4 +- 7 files changed, 170 insertions(+), 136 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0507b6b..186b12f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,7 +21,8 @@ - + diff --git a/app/src/main/java/com/mashup/app/login/LoginFragment.kt b/app/src/main/java/com/mashup/app/login/LoginFragment.kt index 5b76693..e769112 100644 --- a/app/src/main/java/com/mashup/app/login/LoginFragment.kt +++ b/app/src/main/java/com/mashup/app/login/LoginFragment.kt @@ -1,10 +1,12 @@ package com.mashup.app.login +import android.content.Context.INPUT_METHOD_SERVICE import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.inputmethod.InputMethodManager import androidx.fragment.app.Fragment import com.google.android.material.snackbar.Snackbar import com.mashup.app.main.MainActivity @@ -45,12 +47,23 @@ class LoginFragment : Fragment() { } private fun setupEventObserver() { - viewModel.isLoginSuccess.observe(this, EventObserver { + viewModel.isLoginSuccess.observe(viewLifecycleOwner, EventObserver { if (it) { activity?.finishAffinity() val intent = Intent(this.context, MainActivity::class.java) startActivity(intent) } }) + + viewModel.hideKeyboard.observe(viewLifecycleOwner, EventObserver { + if (it) { + hideSoftKeyBoard() + } + }) + } + + private fun hideSoftKeyBoard() { + val imm = context?.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager + imm.hideSoftInputFromWindow(viewDataBinding.layoutForm.windowToken, 0) } } diff --git a/app/src/main/java/com/mashup/app/login/LoginViewModel.kt b/app/src/main/java/com/mashup/app/login/LoginViewModel.kt index 74f61ad..a8c50e6 100644 --- a/app/src/main/java/com/mashup/app/login/LoginViewModel.kt +++ b/app/src/main/java/com/mashup/app/login/LoginViewModel.kt @@ -24,6 +24,9 @@ class LoginViewModel( private val _snackbarText = MutableLiveData>() val snackbarText: LiveData> = _snackbarText + private val _hideKeyboard = MutableLiveData>() + val hideKeyboard: LiveData> = _hideKeyboard + val email = MutableLiveData() val password = MutableLiveData() @@ -52,6 +55,7 @@ class LoginViewModel( } fun onClickLoginButton() { + _hideKeyboard.value = Event(true) getAuthToken() } diff --git a/app/src/main/res/layout/login_fragment.xml b/app/src/main/res/layout/login_fragment.xml index 788831c..3d679d0 100644 --- a/app/src/main/res/layout/login_fragment.xml +++ b/app/src/main/res/layout/login_fragment.xml @@ -10,145 +10,159 @@ type="com.mashup.app.login.LoginViewModel" /> - + android:fillViewport="true"> - - - - - - - - - - - - + android:layout_height="wrap_content" + android:background="@color/colorBaseBg" + android:orientation="vertical"> - - - + + + + + + + + + + + + + + + + + + + android:layout_centerVertical="true" + android:layout_marginStart="20dp" + android:layout_marginEnd="20dp" + app:cardCornerRadius="@dimen/card_radius" + app:cardElevation="@dimen/card_elevation"> + + + + + + + + + + + +