Skip to content

Commit

Permalink
Save question UI
Browse files Browse the repository at this point in the history
  • Loading branch information
kichan05 committed Feb 15, 2022
1 parent d66f0d2 commit 7e0f92a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .idea/misc.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
@@ -0,0 +1,16 @@
package com.edcan.howtosunrin.ui.all.recyclerDeco

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

class VerticalSpaceItemDecoration(private val spaceSize : Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
outRect.bottom = spaceSize
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package com.edcan.howtosunrin.ui.savequestion
import android.content.Intent
import android.os.Bundle
import androidx.activity.viewModels
import androidx.databinding.ObservableArrayList
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.edcan.howtosunrin.R
import com.edcan.howtosunrin.base.BaseActivity
import com.edcan.howtosunrin.databinding.ActivitySaveQuestionBinding
import com.edcan.howtosunrin.ui.qna.QnAActivity
import com.edcan.howtosunrin.ui.all.recyclerDeco.VerticalSpaceItemDecoration
import com.edcan.howtosunrin.ui.qnaSlider.QnASliderActivity

class SaveQuestionActivity : BaseActivity<ActivitySaveQuestionBinding>(R.layout.activity_save_question) {
Expand All @@ -30,5 +31,7 @@ class SaveQuestionActivity : BaseActivity<ActivitySaveQuestionBinding>(R.layout.

val saveQnaListAdapter = SaveQnARecyclerAdapter()
binding.recyclerSaveQnA.adapter = saveQnaListAdapter
// binding.recyclerSaveQnA.addItemDecoration(VerticalSpaceItemDecoration(20))
binding.recyclerSaveQnA.addItemDecoration(DividerItemDecoration(this, LinearLayoutManager(this).orientation))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ import kotlinx.coroutines.withContext
class UserDataActivity : BaseActivity<ActivityUserDataBinding>(R.layout.activity_user_data) {
lateinit var viewModel: UserDataViewModel

val majorArray = arrayOf("학과를 선택해주세요.", "정보보호과", "소프트웨어과", "IT경영과", "콘텐츠 디자인과")

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(UserDataViewModel::class.java)
binding.viewModel = viewModel

with(binding){
btnUserDataInputEnd.setOnClickListener(createUserData)

spinnerUserDataChoiceMajor.adapter = ArrayAdapter(this@UserDataActivity, android.R.layout.simple_spinner_dropdown_item, majorArray)
spinnerUserDataChoiceMajor.onItemSelectedListener = viewModel!!.choiceMajorCallBack
}
}

Expand All @@ -42,17 +37,11 @@ class UserDataActivity : BaseActivity<ActivityUserDataBinding>(R.layout.activity
binding.edtUserDataInputName.error = "이름을 입력해주세요."
return@createUserData
}
else if (viewModel.major.value!! == 0){
//todo
Toast.makeText(this, "학과를 선택해주세요.", Toast.LENGTH_LONG).show()
return@createUserData
}

CoroutineScope(Dispatchers.IO).launch {
val result = viewModel.saveUserData()

withContext(Dispatchers.Main){
//todo
if(result != UserUtil.ResultSuccess){
Toast.makeText(this@UserDataActivity, "유저 등록에 실패했습니다.", Toast.LENGTH_LONG).show()
return@withContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,9 @@ import java.util.*

class UserDataViewModel : ViewModel() {
val name = MutableLiveData("")
val major = MutableLiveData(0)
val newbie = MutableLiveData(false)

lateinit var userData : User

val choiceMajorCallBack = object : AdapterView.OnItemSelectedListener{
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
major.value = position
}

override fun onNothingSelected(parent: AdapterView<*>?) {

}
}

suspend fun saveUserData() : Int{

val userId = getRandomUserId()
Expand All @@ -40,9 +23,7 @@ class UserDataViewModel : ViewModel() {

userData = User(
name = name.value!!,
major = major.value!!,
userID = userId,
newbie = newbie.value!!
)

return userDB.saveUserData(userData)
Expand Down
53 changes: 3 additions & 50 deletions app/src/main/res/layout/activity_user_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
android:layout_height="wrap_content"

android:text="환영합니다!\n로그인을 해주세요"
android:textColor="@color/black"
android:textSize="32sp"
android:textFontWeight="700"

Expand Down Expand Up @@ -65,57 +64,13 @@

android:text="@={viewModel.name}"

app:layout_constraintTop_toBottomOf="@+id/img_userData_illust"
app:layout_constraintBottom_toTopOf="@+id/spinner_userData_choiceMajor"
app:layout_constraintStart_toStartOf="@+id/guide_userData_line1"
app:layout_constraintEnd_toEndOf="@+id/guide_userData_line2"
/>


<Spinner
android:id="@+id/spinner_userData_choiceMajor"
android:layout_width="0dp"
android:layout_height="wrap_content"

style="@style/customEditTextStyle"

android:gravity="center"
android:shadowColor="@color/gray1"

android:layout_marginVertical="8dp"

app:layout_constraintTop_toBottomOf="@+id/edt_userData_inputName"
app:layout_constraintBottom_toTopOf="@+id/checkBoc_userData_choiceNewbi"
app:layout_constraintTop_toBottomOf="@+id/img_userData_illust"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/guide_userData_line1"
app:layout_constraintEnd_toEndOf="@+id/guide_userData_line2"
/>

<CheckBox
android:id="@+id/checkBoc_userData_choiceNewbi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:checked="@={viewModel.newbie}"

app:layout_constraintBottom_toTopOf="@id/btn_userData_inputEnd"
app:layout_constraintEnd_toStartOf="@id/txt_userData_newBi"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="@id/guide_userData_line1"
app:layout_constraintTop_toBottomOf="@id/spinner_userData_choiceMajor"
/>

<TextView
android:id="@+id/txt_userData_newBi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="신입생입니다."

app:layout_constraintBottom_toBottomOf="@id/checkBoc_userData_choiceNewbi"
app:layout_constraintEnd_toStartOf="@+id/guide_userData_line2"
app:layout_constraintStart_toEndOf="@+id/checkBoc_userData_choiceNewbi"
app:layout_constraintTop_toTopOf="@id/checkBoc_userData_choiceNewbi" />


<Button
android:id="@+id/btn_userData_inputEnd"
Expand All @@ -125,7 +80,7 @@
android:text="입력 완료"
android:textSize="20sp"

app:layout_constraintTop_toBottomOf="@id/checkBoc_userData_choiceNewbi"
app:layout_constraintTop_toBottomOf="@id/edt_userData_inputName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/guide_userData_line1"
app:layout_constraintEnd_toEndOf="@+id/guide_userData_line2"
Expand All @@ -147,7 +102,5 @@

android:orientation="vertical"
app:layout_constraintGuide_end="40dp" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/dialog_save_question.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

style="@style/reversedButtonStyle"

android:text="저장 삭제하기"
android:text="삭제하기"

android:layout_marginVertical="8dp"
/>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/layout_question.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
android:layout_height="wrap_content"
android:paddingHorizontal="12dp"
android:paddingVertical="16dp"

android:clickable="true"
android:focusable="true"

android:background="?android:attr/selectableItemBackground"
>

<TextView
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

<item name="editTextBackground">@color/gray1</item>
<item name="editTextTextColor">@color/black</item>
<item name="editTextHintColor">@color/gray6</item>

<item name="toolBarBackGroundColor">@color/black</item>
<item name="toolBarBackGroundColor">@color/gray8</item>

<!-- Secondary brand color. -->
<item name="colorSecondary">@color/EDCAN</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<attr name="editTextBackGroundColor" type="color"/>
<attr name="editTextTextColor" type="color"/>
<attr name="editTextHintColor" type="color"/>

<attr name="toolBarBackGroundColor" format="color"/>
</resources>
14 changes: 11 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>

<color name="gray1">#E9E9E9</color>
<color name="gray2">#D3D6DB</color>
<color name="gray3">#C4C4C4</color>

<color name="gray0">#E9E9E9</color>
<color name="gray1">#D3D6DB</color>
<color name="gray2">#C4C4C4</color>
<color name="gray3">#dee2e6</color>
<color name="gray4">#ced4da</color>
<color name="gray5">#adb5bd</color>
<color name="gray6">#868e96</color>
<color name="gray7">#495057</color>
<color name="gray8">#343a40</color>
<color name="gray9">#212529</color>

<color name="EDCAN">#00B8D4</color>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<item name="editTextBackground">@color/gray1</item>
<item name="editTextTextColor">@color/black</item>
<item name="editTextHintColor">@color/gray6</item>

<item name="toolBarBackGroundColor">@color/white</item>

Expand Down Expand Up @@ -60,6 +61,7 @@

<style name="customEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:textColor">?attr/editTextTextColor</item>
<item name="android:textColorHint">?attr/editTextHintColor</item>
<item name="android:background">@drawable/default_rect_round</item>
<item name="backgroundTint">?attr/editTextBackground</item>
</style>
Expand Down

0 comments on commit 7e0f92a

Please sign in to comment.