Skip to content

Commit

Permalink
#19 유저가 업적을 딜성했을 때 업적에 반영하기: companion object에 함수가 적용되지 않는 오류
Browse files Browse the repository at this point in the history
  • Loading branch information
otcroz committed Sep 14, 2022
1 parent 282dee5 commit 4414aba
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import com.example.shape_up_2022.common.MyPageActivity
import com.example.shape_up_2022.common.SaveSharedPreference
import com.example.shape_up_2022.databinding.ActivityAchieveBinding
import com.example.shape_up_2022.common.SimulationActivity
import com.example.shape_up_2022.retrofit.CompleteAchieveRes
import com.example.shape_up_2022.retrofit.GetPetInfoRes
import com.example.shape_up_2022.retrofit.MyApplication
import com.example.shape_up_2022.simulation.TestActivity
import com.example.shape_up_2022.todo.TodoActivity
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
Expand All @@ -33,17 +33,7 @@ class AchieveActivity : AppCompatActivity() {
setContentView(binding.root)

/* 준비도: progressBar */
var clearCount = 0
val checkedArray = SaveSharedPreference.getAchieve(this)!!
for(i in 0 until checkedArray.size){
if(checkedArray[i]) clearCount++
if(i == checkedArray.size - 1){ // 마지막 인덱스일 때
// 준비도 반영하기
val ratio = (clearCount.toFloat() / 14)
Log.d("mobileApp", "$ratio")
binding.pbAchieveTodo.progress = (ratio * 100).toInt()
}
}
DisplayProgress()

/*
binding.btn.setOnClickListener { view ->
Expand Down Expand Up @@ -172,4 +162,53 @@ class AchieveActivity : AppCompatActivity() {
}
})
}

/* 업적을 달성했을 때 */
/* 준비도: progressBar */
private fun DisplayProgress(){
var clearCount = 0
val checkedArray = SaveSharedPreference.getAchieve(this)!!
for(i in 0 until checkedArray.size){
if(checkedArray[i]) clearCount++
if(i == checkedArray.size - 1){ // 마지막 인덱스일 때
// 준비도 반영하기
val ratio = (clearCount.toFloat() / 14)
Log.d("mobileApp", "$ratio")
binding.pbAchieveTodo.progress = (ratio * 100).toInt()
}
}
}

fun clearAchieve(position: Int){
// 프리퍼런스 값 바꾸기
val temp = SaveSharedPreference.getAchieve(this)!!
temp[position] = true
SaveSharedPreference.setAchieve(this, temp)

// 라우터 연결, 업데이트
val call: Call<CompleteAchieveRes> = MyApplication.networkServiceUsers.setCheckedTrue(
userID = SaveSharedPreference.getUserID(this)!!, position = position
)

call?.enqueue(object : Callback<CompleteAchieveRes> {
override fun onResponse(call: Call<CompleteAchieveRes>, response: Response<CompleteAchieveRes>) {
if(response.isSuccessful){
Log.d("mobileApp", "$response ${response.body()}")
if(response.body()!!.success){
Log.d("mobileApp", "업데이트 완료!")

}
}
}

override fun onFailure(call: Call<CompleteAchieveRes>, t: Throwable) {
Log.d("mobileApp", "onFailure $t")
//Toast.makeText(baseContext, "네트워크 오류 발생", Toast.LENGTH_SHORT).show()
}
})

// 진행도 업데이트
DisplayProgress()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.shape_up_2022.R
import com.example.shape_up_2022.adapter.AchieveProgressAdapter
import com.example.shape_up_2022.common.SaveSharedPreference
import com.example.shape_up_2022.databinding.AchieveFragment1Binding
import com.example.shape_up_2022.simulation.SimWalkSearchAdapter

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.shape_up_2022.R
import com.example.shape_up_2022.common.MainActivity
import com.example.shape_up_2022.retrofit.LoginReq
import com.example.shape_up_2022.retrofit.LoginRes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.example.shape_up_2022.databinding.ActivityMyPageBinding
import com.example.shape_up_2022.databinding.MypageDialogJoinFamilyBinding
import com.example.shape_up_2022.retrofit.*
import com.example.shape_up_2022.todo.TodoActivity
import com.google.android.material.datepicker.MaterialDatePicker.Builder.datePicker
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ interface NetworkServiceUsers {
@Body body: CompleteTestReq,
): Call<CompleteTestRes>

@GET("achieveCheck/{userID}/{position}")
fun setCheckedTrue(
@Path("userID") userID: String,
@Path("position") position: Int
): Call<CompleteAchieveRes>
}

// req, res
Expand All @@ -47,5 +52,8 @@ data class JoinFamilyRes(val success: String, val message: String, val familyID:
data class CompleteTestReq(val userID: String)
data class CompleteTestRes(val success: String, val message: String)

data class CompleteAchieveRes(val success: Boolean, val message: String)


// data class
data class UserInfo(val _id: String, val name: String, val email: String, val tested: Boolean, val familyID: String?, val achieve: ArrayList<Boolean>)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.example.shape_up_2022.achieve.AchieveActivity.Companion.clearAchieve
import com.example.shape_up_2022.common.MainActivity
import com.example.shape_up_2022.common.SaveSharedPreference
import com.example.shape_up_2022.databinding.ActivitySimStartNamingBinding
Expand Down Expand Up @@ -89,6 +90,13 @@ class SimStartNamingActivity : AppCompatActivity() {
.setCancelable(false)

builder.show()

// 강아지 업적 달성 position: 0
val check = SaveSharedPreference.getAchieve(this)!![0] // 업적 달성 여부 확인
if(!check){ // 업적을 1번도 달성하지 않았었다면
clearAchieve(0) // 업적 달성 업데이트 실행
}

}
}

Expand Down

0 comments on commit 4414aba

Please sign in to comment.