Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[둘리] 뷰 챌린지 미션 3단계 제출합니다. #51

Merged
merged 7 commits into from
Oct 12, 2023
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
16 changes: 2 additions & 14 deletions app/src/main/java/woowacourse/paint/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MainActivity : AppCompatActivity() {
with(toolButtonBinding) {
onClick = viewModel::pickTool
drawingTool = toolAssigned
name = getString(toolAssigned.toUiModel().toolNameId)
drawingToolName = getString(toolAssigned.toUiModel().toolNameId)
}
toolButtons.add(toolButtonBinding)
}
Expand All @@ -94,20 +94,8 @@ class MainActivity : AppCompatActivity() {
private fun setupColors() {
binding.rvColors.adapter = adapter
binding.rvColors.setHasFixedSize(true)
binding.rvColors.addItemDecoration(SpaceItemDecoration(getSpace()))
binding.rvColors.addItemDecoration(SpaceItemDecoration(25))
tmdgh1592 marked this conversation as resolved.
Show resolved Hide resolved
}

private fun getSpace(): Int {
val colorWidth = resources.getDimensionPixelSize(R.dimen.color_item_size)
val display = this.applicationContext?.resources?.displayMetrics
val deviceWidth = display?.widthPixels

deviceWidth?.let {
return (deviceWidth - (colorWidth * 5)) / 4
}
return 10
}

private fun setupWidthSlider() {
binding.rsWidthChanger.valueFrom = MainViewModel.MIN_WIDTH
binding.rsWidthChanger.valueTo = MainViewModel.MAX_WIDTH
Expand Down
126 changes: 126 additions & 0 deletions app/src/main/res/layout-sw600dp-land/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>

<data>

<variable
name="viewModel"
type="woowacourse.paint.MainViewModel" />

<import type="woowacourse.paint.PaintChangingState" />

<import type="woowacourse.paint.canvas.DrawingTool" />

<import type="android.view.View" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
xmlns:tools="http:https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.Toolbar
android:id="@+id/tb_paint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/iv_redo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="18dp"
android:src="@drawable/ic_redo_24" />

<ImageView
android:id="@+id/iv_undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="14dp"
android:src="@drawable/ic_undo_24" />

<ImageView
android:id="@+id/iv_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="20dp"
android:src="@drawable/ic_clear_24" />

</androidx.appcompat.widget.Toolbar>


<woowacourse.paint.canvas.CanvasView
android:id="@+id/cv_canvas"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tb_paint" />

<LinearLayout
android:id="@+id/ll_tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tb_paint" />

<com.google.android.material.slider.RangeSlider
android:id="@+id/rs_width_changer"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:visibility="@{viewModel.paintChangingState == PaintChangingState.WIDTH_CHANGING &amp;&amp; viewModel.selectedDrawingTool.hasWidth ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toEndOf="@id/btn_change_color"
app:layout_constraintTop_toBottomOf="@id/tb_paint" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_colors"
android:layout_width="500dp"
tmdgh1592 marked this conversation as resolved.
Show resolved Hide resolved
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:visibility="@{viewModel.paintChangingState == PaintChangingState.COLOR_CHANGING &amp;&amp; viewModel.selectedDrawingTool.hasColor ? View.VISIBLE : View.GONE}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintStart_toEndOf="@id/btn_change_color"
app:layout_constraintTop_toBottomOf="@id/tb_paint"
tools:listitem="@layout/item_color_palette" />

<Button
android:id="@+id/btn_change_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/purple_500"
android:onClick="@{() -> viewModel.setSettingState(PaintChangingState.COLOR_CHANGING)}"
android:text="@string/main_change_color"
android:visibility="@{viewModel.selectedDrawingTool.hasColor ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toEndOf="@id/ll_tools"
app:layout_constraintTop_toBottomOf="@id/tb_paint" />

<Button
android:id="@+id/btn_change_width"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/purple_500"
android:onClick="@{() -> viewModel.setSettingState(PaintChangingState.WIDTH_CHANGING)}"
android:text="@string/main_change_thickness"
android:visibility="@{viewModel.selectedDrawingTool.hasWidth ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toEndOf="@id/ll_tools"
app:layout_constraintTop_toBottomOf="@id/btn_change_color" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
27 changes: 27 additions & 0 deletions app/src/main/res/layout-sw600dp-land/item_tool.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>

<data>

<variable
name="drawingTool"
type="woowacourse.paint.canvas.DrawingTool" />

<variable
name="drawingToolName"
type="String" />

<variable
name="onClick"
type="kotlin.jvm.functions.Function1" />
</data>

<Button xmlns:android="http:https://schemas.android.com/apk/res/android"
android:id="@+id/btn_pen"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/brush_selected"
android:onClick="@{() -> onClick.invoke(drawingTool)}"
android:text="@{drawingToolName}" />
</layout>
39 changes: 26 additions & 13 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
android:id="@+id/tb_paint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@color/white">
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/iv_redo"
Expand Down Expand Up @@ -63,19 +60,33 @@
android:id="@+id/cv_canvas"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/rs_width_changer"
app:layout_constraintBottom_toTopOf="@id/ll_tools"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tb_paint" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/gl_start"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="@dimen/drawing_options_start_margin_percent" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/gl_end"
tmdgh1592 marked this conversation as resolved.
Show resolved Hide resolved
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="@dimen/drawing_options_end_margin_percent" />

<com.google.android.material.slider.RangeSlider
android:id="@+id/rs_width_changer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="@{viewModel.paintChangingState == PaintChangingState.WIDTH_CHANGING &amp;&amp; viewModel.selectedDrawingTool.hasWidth ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toTopOf="@id/btn_change_width"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintEnd_toStartOf="@id/gl_end"
app:layout_constraintStart_toEndOf="@id/gl_start" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_colors"
Expand All @@ -85,32 +96,34 @@
android:visibility="@{viewModel.paintChangingState == PaintChangingState.COLOR_CHANGING &amp;&amp; viewModel.selectedDrawingTool.hasColor ? View.VISIBLE : View.GONE}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@id/btn_change_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/gl_end"
app:layout_constraintStart_toEndOf="@id/gl_start"
tools:listitem="@layout/item_color_palette" />

<Button
android:id="@+id/btn_change_color"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/purple_500"
android:onClick="@{() -> viewModel.setSettingState(PaintChangingState.COLOR_CHANGING)}"
android:text="@string/main_change_color"
android:visibility="@{viewModel.selectedDrawingTool.hasColor ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toTopOf="@id/ll_tools"
app:layout_constraintEnd_toStartOf="@id/btn_change_width"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toEndOf="@id/gl_start" />

<Button
android:id="@+id/btn_change_width"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:backgroundTint="@color/purple_500"
android:onClick="@{() -> viewModel.setSettingState(PaintChangingState.WIDTH_CHANGING)}"
android:text="@string/main_change_thickness"
android:visibility="@{viewModel.selectedDrawingTool.hasWidth ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toTopOf="@id/ll_tools"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@id/gl_end"
app:layout_constraintStart_toEndOf="@id/btn_change_color" />

<LinearLayout
Expand All @@ -120,8 +133,8 @@
android:gravity="center_horizontal"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintEnd_toStartOf="@id/gl_end"
app:layout_constraintStart_toEndOf="@id/gl_start" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
9 changes: 6 additions & 3 deletions app/src/main/res/layout/item_tool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<layout>

<data>

<variable
name="drawingTool"
type="woowacourse.paint.canvas.DrawingTool" />

<variable
name="name"
name="drawingToolName"
type="String" />

<variable
Expand All @@ -17,10 +18,12 @@

<Button xmlns:android="http:https://schemas.android.com/apk/res/android"
android:id="@+id/btn_pen"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:textSize="12sp"
android:backgroundTint="@color/brush_selected"
android:onClick="@{() -> onClick.invoke(drawingTool)}"
android:text="@{name}" />
android:text="@{drawingToolName}" />
</layout>
10 changes: 8 additions & 2 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http:https://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Paint" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Paint" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand All @@ -10,7 +10,13 @@
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor">@color/black</item>
<!-- Customize your theme here. -->
<item name="toolbarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/black</item>
<item name="titleTextColor">@color/white</item>
</style>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values-sw600dp/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="color_item_size">70dp</dimen>
<dimen name="drawing_options_start_margin_percent">0.2</dimen>
<dimen name="drawing_options_end_margin_percent">0.8</dimen>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="color_item_size">70dp</dimen>
<dimen name="drawing_options_start_margin_percent">0.0</dimen>
<dimen name="drawing_options_end_margin_percent">1.0</dimen>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="toolbarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:background">@color/purple_500</item>
<item name="titleTextColor">@color/white</item>
</style>
</resources>