Skip to content

Commit

Permalink
[fix] 효송 그룹 서버 연결 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
hyooosong committed Jan 15, 2021
1 parent a087da4 commit d2b11aa
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 35 deletions.
24 changes: 6 additions & 18 deletions app/src/main/java/meaning/morning/MeaningStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,20 @@ class MeaningStorage(context: Context) {
val nickName: String?
get() = meaningSharedPref.getString(NICK_NAME, null)


fun getGroupName(): String? {
return meaningSharedPref.getString("groupName", "")
return meaningSharedPref.getString(GROUP_NAME, "")
}
fun saveGroupName(groupName: String) {
meaningEdit.putString("groupName", groupName)
meaningEdit.putString(GROUP_NAME, groupName)
meaningEdit.apply()
}

fun saveGroupId(groupId: Int){
meaningEdit.putInt("groupId", groupId)
meaningEdit.putInt(GROUP_ID, groupId).apply()
}

fun getGroupId(): Int{
return meaningSharedPref.getInt("groupId", 0)
}

fun saveGroupNumber(groupNumber : Int){
meaningEdit.putInt("groupNumber",groupNumber)
}

fun getGroupNumber() : Int{
return meaningSharedPref.getInt("groupNumber",0)
}

fun saveUserToken(token: String) {
meaningEdit.putString("userToken", token)
meaningEdit.apply()
return meaningSharedPref.getInt(GROUP_ID, 0)
}

fun saveMission1(successMission1: Int) {
Expand Down Expand Up @@ -95,5 +81,7 @@ class MeaningStorage(context: Context) {
private const val REFRESH_TOKEN = "refreshToken"
private const val NICK_NAME = "nickName"
private const val TIME = "wakeUpTime"
private const val GROUP_ID = "groupId"
private const val GROUP_NAME = "groupName"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interface MeaningService {
fun addGroup(
@Header("token") token: String?,
@Body body: GroupAddRequest
): Call<GroupAddResponse>
): Call<BaseResponse<GroupAddResponse>>

// 미션 2. 오늘 하루 다짐
@GET("/user/daypromise")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ class AddGroupActivity : AppCompatActivity() {
}

private fun remoteAddGroup(){
val call: Call <GroupAddResponse> =
val call: Call <BaseResponse<GroupAddResponse>> =
MeaningService.getInstance().addGroup(
MeaningStorage.getInstance(this).accessToken,
GroupAddRequest(groupName.get().toString(), groupMemberNum.get()!!.toInt(), groupContent.get().toString())
)
call.enqueueListener(
onSuccess = {
MeaningStorage.getInstance(this).saveGroupId(it.body()!!.groupId)
MeaningStorage.getInstance(this).saveGroupId(it.body()!!.data!!.groupId)
val intent = Intent(this, CompleteGroupActivity::class.java)
startActivity(intent)
finish()
},
onError = {
failAddGroup(it)
failAddGroup(it.data?: return@enqueueListener)
}
)
}
Expand Down Expand Up @@ -97,7 +98,6 @@ class AddGroupActivity : AppCompatActivity() {
if (checkEditTextBlank() && validNum()) {
remoteAddGroup()
saveAddGroupData(groupName.get().toString())
finish()
return
}
if (checkEditTextBlank() && !validNum()) {
Expand All @@ -111,11 +111,6 @@ class AddGroupActivity : AppCompatActivity() {
finish()
}

fun sendGroupId() : Int{
val groupId = MeaningStorage.getInstance(this).getGroupId()
return groupId
}

private fun saveAddGroupData(addName: String) {
MeaningStorage.getInstance(applicationContext)
.saveGroupName(addName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import meaning.morning.presentation.adapter.group.RecommendGroupAdapter
import meaning.morning.presentation.group.feed.GroupFeedActivity
import meaning.morning.utils.enqueueListener
import retrofit2.Call
import kotlin.properties.Delegates


class GroupFragment : Fragment() {
private lateinit var groupAdapter: GroupAdapter
private lateinit var recommendAdapter: RecommendGroupAdapter
private lateinit var binding: FragmentGroupBinding
var myGroupId by Delegates.notNull<Int>()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand Down Expand Up @@ -61,7 +63,6 @@ class GroupFragment : Fragment() {
startActivity(intent)
}
}

private fun hasMyGroup() {
val call: Call<BaseResponse<MyGroupResponse>> =
MeaningService.getInstance().getMyGroup(MeaningStorage.getInstance(requireContext()).accessToken)
Expand All @@ -71,6 +72,8 @@ class GroupFragment : Fragment() {
binding.layoutMyGroupNull.visibility = View.VISIBLE
return@enqueueListener
}
myGroupId = it.body()?.data!!.groupId
saveMyGroupId()
binding.textviewGroupName.text = it.body()?.data!!.groupName
binding.textviewNumber.text = it.body()?.data!!.countMember.toString() + "/" + it.body()?.data!!.maximumMemberNumber.toString()
binding.layoutMyGroupNull.visibility = View.INVISIBLE
Expand All @@ -81,6 +84,10 @@ class GroupFragment : Fragment() {
)
}

private fun saveMyGroupId() {
MeaningStorage.getInstance(requireContext()).saveGroupId(myGroupId)
}

private fun loadNoImageGroup() {
val call: Call<BaseResponse<GroupListResponse>> =
MeaningService.getInstance().getGroupList(MeaningStorage.getInstance(requireContext()).accessToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import meaning.morning.network.response.GroupSettingResponse
import meaning.morning.presentation.adapter.group.GroupSettingAdapter
import meaning.morning.utils.enqueueListener
import retrofit2.Call
import kotlin.properties.Delegates

class GroupSettingActivity : AppCompatActivity() {
private lateinit var binding: ActivityGroupSettingBinding
private lateinit var groupSettingAdapter: GroupSettingAdapter
var groupIdx by Delegates.notNull<Int>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -50,21 +52,21 @@ class GroupSettingActivity : AppCompatActivity() {
val settingUserList = it.body()!!.data!!.users
val settingUserData = mutableListOf<GroupMemberData>()

groupIdx = settingGroupList.groupId.toInt()
binding.textviewGroupName.text = settingGroupList.groupName
binding.textviewCreateDate.text =
"${settingGroupList.createdAt.slice(IntRange(0, 3))}" +
"${settingGroupList.createdAt.slice(IntRange(5, 6))}" +
"${settingGroupList.createdAt.slice(IntRange(8, 9))}"
binding.textviewMemberNum.text = "${settingGroupList.currentMemberNumber}"
MeaningStorage.getInstance(this).saveGroupNumber(settingGroupList.currentMemberNumber)

for (i in settingUserList.indices) {
settingUserData.apply {
if (settingUserList[i].wakeUpTime.slice(IntRange(3, 4)) != "00") {
add(
GroupMemberData(
settingUserList[i].userName.slice(IntRange(0, 0)),
settingUserList[i].userName,
settingUserList[i].nickName.slice(IntRange(0, 0)),
settingUserList[i].nickName,
"매일 ${settingUserList[i].wakeUpTime.slice(IntRange(1, 1))}" +
" ${settingUserList[i].wakeUpTime.slice(IntRange(3, 4))}분 기상",
"${settingUserList[i].dayPassed}일째 진행 중"
Expand All @@ -89,6 +91,7 @@ class GroupSettingActivity : AppCompatActivity() {
)
}


fun back() {
finish()
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/meaning/morning/utils/meaningEnqueue.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package meaning.morning.utils

import android.text.TextUtils
import android.util.Log
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import meaning.morning.network.response.BaseResponse
Expand All @@ -15,6 +17,9 @@ fun <ResponseType> Call<ResponseType>.enqueueListener(
) {
this.enqueue(object : Callback<ResponseType> {
override fun onFailure(call: Call<ResponseType>, t: Throwable) {
Log.d("jinsu4755", "${t.message} \n")
Log.d("jinsu4755", "${t.localizedMessage} \n")
Log.d("jinsu4755", TextUtils.join("\n", t.stackTrace))
onFail()
}

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/dialog_group_recycler.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?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">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

Expand Down Expand Up @@ -30,7 +31,7 @@
android:layout_marginTop="92dp"
android:fontFamily="@font/spoqahansansneo_medium"
android:lines="1"
android:text="default"
tools:text="default"
android:textAlignment="center"
android:textColor="@color/grey2_4F"
android:textSize="17dp" />
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# baseUrl
MeaningServiceBaseURL="http://13.124.61.0:3001"
MeaningServiceBaseURL="http://13.124.61.0:3000"

0 comments on commit d2b11aa

Please sign in to comment.