Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:theme="@style/Theme.NoBet"
tools:targetApi="31">
<activity
android:name=".presentatoin.screen.main.MainActivity"
android:name=".presentation.screen.main.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package kr.hs.anu.nobet.presentation.screen.main

import android.graphics.Color
import android.graphics.PorterDuff
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toDrawable
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import kr.hs.anu.nobet.R
import kr.hs.anu.nobet.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

private val viewModel: MainViewModel by viewModels()
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

// 버튼 상태값 읽고 값에 따라 상태 바꾸기
viewModel.btnState.observe(this) { btnState ->
// 차단 전원 버튼 색 변경
binding.layoutBlockBtn.setBackgroundResource(
if (btnState) R.drawable.block_btn_on else R.drawable.block_btn_background
)

// 차단된 사이트 수 텍스트 색 변경
val block_txt_color =
ContextCompat.getColor(this, if (btnState) R.color.red else R.color.gray)
binding.tvBlockNum.setTextColor(block_txt_color)

// 차단 전원 버튼 아이콘 색 변경
val power_icon_color =
ContextCompat.getColor(this, if (btnState) R.color.white else R.color.black)
binding.ivPower.setColorFilter(power_icon_color, PorterDuff.Mode.SRC_IN)

// 상담 정보 박스 색 변경
binding.layoutGamblingPreventInfoBox.setBackgroundResource(
if (btnState) R.drawable.gambling_prevent_info_box_on else R.drawable.gambling_prevent_info_box
)

// 방어중 타이틀 텍스트 변경
binding.tvViewTitle.text =
getString(if (btnState) R.string.on_view_title else R.string.off_view_title)
}

// 전원 버튼 클릭했을때 상태변화 함수 뷰 모델에서 호출
binding.layoutBlockBtn.setOnClickListener {
viewModel.toggle()
}

// 메뉴
binding.ivMenu.setOnClickListener {
showMenu(it)
}
}

// 메뉴 커스텀 함수
private fun showMenu(anchor: View) {
val popupMenu = LayoutInflater.from(anchor.context).inflate(R.layout.popup_menu, null)

val popupWindow = PopupWindow(
popupMenu,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true
)

// 다른 영역 클릭시 닫힘
popupWindow.isOutsideTouchable = true
popupWindow.elevation = 10f

// popupWindow를 감싸는 배경, 배경이 있어야 다른 영역 클릭시 닫힘
popupWindow.setBackgroundDrawable(Color.TRANSPARENT.toDrawable())

// 기존 뷰 아래에 띄우기
popupWindow.showAsDropDown(anchor, 0, 30)

// TODO 이동 처리는 다음 branch 에서 화면 만들고 거기서 이어줄 예정
popupMenu.findViewById<ConstraintLayout>(R.id.menu_login).setOnClickListener {
// TODO 로그인 화면으로 이동
Toast.makeText(anchor.context, "로그인 클릭됨", Toast.LENGTH_SHORT).show()
popupWindow.dismiss()
}

popupMenu.findViewById<ConstraintLayout>(R.id.menu_block_pass).setOnClickListener {
Toast.makeText(anchor.context, "차단 제외 하기", Toast.LENGTH_SHORT).show()
popupWindow.dismiss()
}

popupMenu.findViewById<ConstraintLayout>(R.id.menu_log).setOnClickListener {
Toast.makeText(anchor.context, "필터링 로그", Toast.LENGTH_SHORT).show()
popupWindow.dismiss()
}

popupMenu.findViewById<ConstraintLayout>(R.id.menu_report).setOnClickListener {
Toast.makeText(anchor.context, "문제 신고", Toast.LENGTH_SHORT).show()
popupWindow.dismiss()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kr.hs.anu.nobet.presentation.screen.main

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MainViewModel : ViewModel() {

// 버튼 상태
private val _btnState = MutableLiveData(false)
val btnState: LiveData<Boolean> = _btnState

// 버튼 상태 관리
fun toggle() {
_btnState.value = !(_btnState.value ?: false)
}
}

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/main/res/drawable/block_btn_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/gray" />
</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/block_btn_on.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/red" />
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/gambling_prevent_info_box.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<stroke android:width="1dp" android:color="@color/orange"/>
<corners android:radius="@dimen/radius_1" />
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/gambling_prevent_info_box_on.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<stroke android:width="1dp" android:color="@color/red"/>
<corners android:radius="@dimen/radius_1" />
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/menu_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="8dp" />
<stroke
android:width="1dp"
android:color="@color/red" />
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/menu_box_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="16dp"
android:topRightRadius="0dp" />
<solid android:color="#EEEEEE" />
</shape>
169 changes: 150 additions & 19 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,150 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentatoin.screen.main.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.screen.main.MainActivity">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_topBar"
android:layout_width="match_parent"
android:layout_height="54dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/iv_topbar_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:src="@drawable/top_bar_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/iv_menu"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="20dp"
android:src="@drawable/ic_menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/tv_top_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:fontFamily="@font/pretendard_regular"
android:text="@string/top_title"
android:textColor="@color/gray"
android:textSize="@dimen/body_5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_topBar" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_block_btn"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="50dp"
android:background="@drawable/block_btn_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_top_title">

<ImageView
android:id="@+id/iv_power"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_power"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/tv_block_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="170dp"
android:fontFamily="@font/pretendard_regular"
android:text="총 차단된 사이트 수 : 0"
android:textColor="@color/gray"
android:textSize="@dimen/body_5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_block_btn" />

<TextView
android:id="@+id/tv_view_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="@font/pretendard_medium"
android:text="@string/off_view_title"
android:textSize="@dimen/body_2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_block_num" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_gambling_prevent_info_box"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_marginHorizontal="20dp"
android:layout_marginBottom="20dp"
android:background="@drawable/gambling_prevent_info_box"
android:paddingHorizontal="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/tv_num_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:fontFamily="@font/pretendard_medium"
android:text="@string/num_info"
android:textColor="@color/black"
android:textSize="@dimen/body_6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="@color/gray"
android:textSize="@dimen/body_5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_mobile"
app:layout_constraintStart_toEndOf="@id/tv_num_info"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:fontFamily="@font/pretendard_medium"
android:text="@string/mobile_info"
android:textColor="@color/blue"
android:textSize="@dimen/body_6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading