Skip to content

Commit

Permalink
메인페이지, 마이페이지 Retrofit 연결 작업, 프리퍼런스 값에 따른 View Visibility 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
otcroz committed Aug 13, 2022
1 parent 92a3565 commit 217d2e2
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 61 deletions.
3 changes: 3 additions & 0 deletions SHAPEUP2022/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion SHAPEUP2022/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
android:name=".common.YoutubeActivity"
android:exported="false" />
<activity
android:name=".simulation.SimulationActivity"
android:name=".common.SimulationActivity"
android:exported="false" />
<activity
android:name=".common.StartActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package com.example.shape_up_2022.achieve

import android.content.DialogInterface
import android.content.Intent
import com.example.shape_up_2022.adapter.AchieveAdapter
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.example.shape_up_2022.*
import com.example.shape_up_2022.common.MainActivity
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.simulation.SimulationActivity
import com.example.shape_up_2022.common.SimulationActivity
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 Down Expand Up @@ -92,4 +96,29 @@ class AchieveActivity : AppCompatActivity() {
finish()
}
}

override fun onStart() {
super.onStart()


val eventHandler = object : DialogInterface.OnClickListener {
override fun onClick(p0: DialogInterface?, p1: Int) {
if(p1 == DialogInterface.BUTTON_POSITIVE) {
val intent = Intent(this@AchieveActivity, MainActivity::class.java)
startActivity(intent)
finish()
}
}
}
var builder = AlertDialog.Builder(this)
.setTitle("가족 그룹에 가입되어 있지 않은 사용자")
.setIcon(R.drawable.maltese)
.setMessage("가족 그룹에 먼저 가입해주세요.")
.setPositiveButton("확인", eventHandler)
.setCancelable(false)

if(SaveSharedPreference.getFamliyID(this)!! == ""){
builder.show()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.example.shape_up_2022.common

import android.app.AlertDialog
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.AdapterView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.shape_up_2022.R
import com.example.shape_up_2022.adapter.BudgetAdapter
import com.example.shape_up_2022.data.BudgetItem
import com.example.shape_up_2022.databinding.BudgetAddBinding
Expand Down Expand Up @@ -198,5 +200,28 @@ class BudgetActivity : AppCompatActivity() {
builder.show()
Log.d("BudgetActivity", "수정 모달")
}
override fun onStart() {
super.onStart()


val eventHandler = object : DialogInterface.OnClickListener {
override fun onClick(p0: DialogInterface?, p1: Int) {
if(p1 == DialogInterface.BUTTON_POSITIVE) {
val intent = Intent(this@BudgetActivity, MainActivity::class.java)
startActivity(intent)
finish()
}
}
}
var builder = androidx.appcompat.app.AlertDialog.Builder(this)
.setTitle("가족 그룹에 가입되어 있지 않은 사용자")
.setIcon(R.drawable.maltese)
.setMessage("가족 그룹에 먼저 가입해주세요.")
.setPositiveButton("확인", eventHandler)
.setCancelable(false)

if(SaveSharedPreference.getFamliyID(this)!! == ""){
builder.show()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
Expand All @@ -13,7 +14,6 @@ import com.example.shape_up_2022.*
import com.example.shape_up_2022.achieve.AchieveActivity
import com.example.shape_up_2022.databinding.ActivityYoutubeBinding
import com.example.shape_up_2022.databinding.MainPageBinding
import com.example.shape_up_2022.simulation.SimulationActivity
import com.example.shape_up_2022.simulation.TestActivity
import com.example.shape_up_2022.todo.MainCalenderFragment
import com.example.shape_up_2022.todo.TodoActivity
Expand Down Expand Up @@ -84,6 +84,45 @@ class MainActivity : AppCompatActivity() {
}
}

override fun onStart() {
super.onStart()
/* 테스트하지 않은 사용자를 돌려보내는 다이얼로그 */
// 취소(메인으로), 테스트(테스트 시작)
val eventhandler = object : DialogInterface.OnClickListener {
override fun onClick(p0: DialogInterface?, p1: Int) {
if(p1==DialogInterface.BUTTON_POSITIVE) {
val intent = Intent(this@MainActivity, TestActivity::class.java)
startActivity(intent)
finish()
}
// else if (p1==DialogInterface.BUTTON_NEGATIVE) {
// val intent = Intent(this@MainActivity, MainActivity::class.java)
// startActivity(intent)
// finish()
// }
}
}
var builder = AlertDialog.Builder(this)
.setTitle("테스트하지 않은 사용자")
.setMessage("반려견 케어 성향 점검을 먼저 진행하세요.")
.setPositiveButton("테스트", eventhandler)
.setCancelable(false)

if(!SaveSharedPreference.getUserTested(this)!!){ // tested == false
builder.show()

} else{
if(SaveSharedPreference.getFamliyID(this)!! == ""){ // familyID == ""
binding.noFamHomeInfoDog.visibility = View.VISIBLE
binding.homeInfoDog.visibility = View.GONE
} else{
binding.noFamHomeInfoDog.visibility = View.GONE
binding.homeInfoDog.visibility = View.VISIBLE
}

}
}

// 프래그먼트 연결
private fun viewFragment(fragment : Fragment, location:Int){
Log.d("app_test", "viewFragment start")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import com.example.shape_up_2022.achieve.AchieveActivity
import com.example.shape_up_2022.databinding.ActivityMyPageBinding
import com.example.shape_up_2022.retrofit.LogoutRes
import com.example.shape_up_2022.retrofit.MyApplication
import com.example.shape_up_2022.simulation.SimulationActivity
import com.example.shape_up_2022.todo.TodoActivity
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.lang.Exception

class MyPageActivity : AppCompatActivity() {

private lateinit var binding: ActivityMyPageBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val binding = ActivityMyPageBinding.inflate(layoutInflater)
binding = ActivityMyPageBinding.inflate(layoutInflater)
setContentView(binding.root)
Log.d("mobileApp", "${SaveSharedPreference.getUserName(this)}")
binding.mypageUsername.text = SaveSharedPreference.getUserName(this)
Expand Down Expand Up @@ -65,18 +67,23 @@ class MyPageActivity : AppCompatActivity() {
// 로그아웃
val email = SaveSharedPreference.getUserEmail(this)!!.toString()
Log.d("mobileApp", "${email}")
binding.logoutBtn.setOnClickListener {
binding.btnLogout.setOnClickListener {
val call: Call<LogoutRes> = MyApplication.networkServiceAuth.logout(
)

call?.enqueue(object : Callback<LogoutRes> {
override fun onResponse(call: Call<LogoutRes>, response: Response<LogoutRes>) {
if(!response.isSuccessful){
Log.d("mobileApp", "${response}")
}
if(response.isSuccessful){
Log.d("mobileApp", "$response ${response.body()}")

// 저장했던 preference clear
SaveSharedPreference.clearUserEmail(baseContext)
SaveSharedPreference.clearUserName(baseContext)
SaveSharedPreference.clearUserTested(baseContext)
SaveSharedPreference.clearUserID(baseContext)

// StartActivity로 이동
val intent = Intent(baseContext, TempMainActivity::class.java)
Expand All @@ -87,7 +94,7 @@ class MyPageActivity : AppCompatActivity() {

override fun onFailure(call: Call<LogoutRes>, t: Throwable) {
Log.d("mobileApp", "onFailure $t")
Toast.makeText(baseContext, "토스트 메세지 띄우기 입니다.", Toast.LENGTH_SHORT).show()
Toast.makeText(baseContext, "로그아웃에 실패했습니다.", Toast.LENGTH_SHORT).show()
}
})
}
Expand Down Expand Up @@ -155,5 +162,15 @@ class MyPageActivity : AppCompatActivity() {
return inSampleSize
}

override fun onStart() {
super.onStart()

if(SaveSharedPreference.getFamliyID(this)!! == ""){ // familyID == ""
binding.noFamFamilyBtns.visibility = View.VISIBLE
binding.mypageFamilyList.visibility = View.GONE
} else{
binding.noFamFamilyBtns.visibility = View.GONE
binding.mypageFamilyList.visibility = View.VISIBLE
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ public class SaveSharedPreference {
return PreferenceManager.getDefaultSharedPreferences(ctx)
}

// User의 tested
fun setUserTested(ctx: Context, tested: Boolean) {
val editor = getSharedPreferences(ctx)!!.edit()
editor.putBoolean("tested", tested)
editor.commit()
}
fun getUserTested(ctx: Context?): Boolean? { return getSharedPreferences(ctx!!)!!.getBoolean("tested", false) }
fun clearUserTested(ctx: Context?) {
val editor = getSharedPreferences(ctx!!)!!.edit()
editor.clear()
editor.commit()
}

// User의 email
fun setUserEmail(ctx: Context, email: String) {
val editor = getSharedPreferences(ctx)!!.edit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.example.shape_up_2022.simulation
package com.example.shape_up_2022.common

import android.content.DialogInterface
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.example.shape_up_2022.common.MyPageActivity
import androidx.appcompat.app.AlertDialog
import com.example.shape_up_2022.R
import com.example.shape_up_2022.achieve.AchieveActivity
import com.example.shape_up_2022.common.MainActivity
import com.example.shape_up_2022.databinding.SimulationMainBinding
import com.example.shape_up_2022.simulation.*
import com.example.shape_up_2022.todo.TodoActivity

class SimulationActivity : AppCompatActivity() {
Expand Down Expand Up @@ -137,4 +139,29 @@ class SimulationActivity : AppCompatActivity() {
}

}

override fun onStart() {
super.onStart()


val eventHandler = object : DialogInterface.OnClickListener {
override fun onClick(p0: DialogInterface?, p1: Int) {
if(p1 == DialogInterface.BUTTON_POSITIVE) {
val intent = Intent(this@SimulationActivity, MainActivity::class.java)
startActivity(intent)
finish()
}
}
}
var builder = AlertDialog.Builder(this)
.setTitle("가족 그룹에 가입되어 있지 않은 사용자")
.setIcon(R.drawable.maltese)
.setMessage("가족 그룹에 먼저 가입해주세요.")
.setPositiveButton("확인", eventHandler)
.setCancelable(false)

if(SaveSharedPreference.getFamliyID(this)!! == ""){
builder.show()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MyApplication: Application() {
var networkServiceAuth: NetworkServiceAuth
val retrofitAuth: Retrofit
get() = Retrofit.Builder()
.baseUrl("http://ec2-13-124-250-65.ap-northeast-2.compute.amazonaws.com:5000/")
.baseUrl("http://192.168.219.108:5000/")
.addConverterFactory(GsonConverterFactory.create())
.build()
// "http://ec2-13-124-250-65.ap-northeast-2.compute.amazonaws.com:5000/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ interface NetworkServiceAuth {
@Body body: JoinFamilyReq,
): Call<JoinFamilyRes>

@PUT("api/users/completeTest")
fun completeTest(
@Body body: CompleteTestReq,
): Call<CompleteTestRes>

}

data class RegisterReq(val name: String, val email: String, val password: String)
Expand All @@ -43,3 +48,6 @@ data class AddFamilyRes(val success: String)

data class JoinFamilyReq(val familyCode: String, val email: String)
data class JoinFamilyRes(val success: String, val message: String)

data class CompleteTestReq(val userID: String)
data class CompleteTestRes(val success: String, val message: String)
Loading

0 comments on commit 217d2e2

Please sign in to comment.