Skip to content

Commit

Permalink
REM-845 - And selected tab marker on Note creation screen
Browse files Browse the repository at this point in the history
  • Loading branch information
naz013 committed Mar 16, 2024
1 parent c0b301f commit b2491b2
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class GoogleTaskViewModel(
}

fun initDefaults() {
onDateSet(LocalDate.now())
onTimeSet(LocalTime.now())
_dateState.postValue(DateState.NoDate)
_timeState.postValue(TimeState.NoTime)
}

fun onDateStateChanged(enabled: Boolean) {
Expand Down Expand Up @@ -334,13 +334,15 @@ class GoogleTaskViewModel(
data class SelectedDate(
val formattedDate: String
) : DateState()

data object NoDate : DateState()
}

sealed class TimeState {
data class SelectedTime(
val formattedTime: String
) : TimeState()

data object NoTime : TimeState()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,44 +137,60 @@ class CreateNoteActivity :
}
}

private val tabController = TabController(
object : TabController.Listener {
override fun onTabSelected(tab: TabController.Tab) {
binding.colorLayout.gone()
binding.fontLayout.gone()
binding.reminderLayout.gone()
when (tab) {
TabController.Tab.FONT -> {
binding.fontLayout.visible()
}
private lateinit var tabController: TabController

TabController.Tab.COLOR -> {
binding.colorLayout.visible()
}
override fun inflateBinding() = ActivityCreateNoteBinding.inflate(layoutInflater)

TabController.Tab.REMINDER -> {
binding.reminderLayout.visible()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

TabController.Tab.NONE -> {
tabController = TabController(
tabs = listOf(
TabController.TabView(
TabController.Tab.COLOR,
binding.colorSelectorView
),
TabController.TabView(
TabController.Tab.REMINDER,
binding.reminderSelectorView
),
TabController.TabView(
TabController.Tab.FONT,
binding.fontSelectorView
)
),
listener = object : TabController.Listener {
override fun onTabSelected(tab: TabController.Tab) {
binding.colorLayout.gone()
binding.fontLayout.gone()
binding.reminderLayout.gone()
when (tab) {
TabController.Tab.FONT -> {
binding.fontLayout.visible()
}

TabController.Tab.COLOR -> {
binding.colorLayout.visible()
}

TabController.Tab.REMINDER -> {
binding.reminderLayout.visible()
}

TabController.Tab.NONE -> {
}
}
}
}

override fun onShow() {
binding.expandedLayout.visible()
}
override fun onShow() {
binding.expandedLayout.visible()
}

override fun onHide() {
binding.expandedLayout.gone()
override fun onHide() {
binding.expandedLayout.gone()
}
}
}
)

override fun inflateBinding() = ActivityCreateNoteBinding.inflate(layoutInflater)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
)

lifecycle.addObserver(photoSelectionUtil)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,62 @@
package com.elementary.tasks.notes.create

import android.view.View
import com.elementary.tasks.core.utils.ui.visibleGone

class TabController(
private val tabs: List<TabView>,
private val listener: Listener
) {

private var prevTab: Tab = Tab.NONE
private var currentTab: Tab = Tab.NONE
private var tabVisible = false

fun hide() {
if (tabVisible) {
listener.onHide()
setSelectorVisible(false, currentTab)
}
currentTab = Tab.NONE
tabVisible = false
}

fun isTabVisible(): Boolean = tabVisible

fun onTabClick(tab: Tab) {
if (prevTab == tab) {
if (currentTab == tab) {
if (tabVisible) {
listener.onHide()
} else {
listener.onShow()
}
setSelectorVisible(!tabVisible, currentTab)
tabVisible = !tabVisible
} else {
if (tabVisible) {
listener.onHide()
listener.onTabSelected(tab)
listener.onShow()
} else {
listener.onTabSelected(tab)
listener.onShow()
setSelectorVisible(false, currentTab)
}

listener.onTabSelected(tab)
listener.onShow()
setSelectorVisible(true, tab)

tabVisible = true
}
prevTab = tab
currentTab = tab
}

private fun setSelectorVisible(visible: Boolean, tab: Tab) {
tabs.firstOrNull { it.tab == tab }?.run {
selectorView.visibleGone(visible)
}
}

data class TabView(
val tab: Tab,
val selectorView: View
)

enum class Tab {
COLOR,
FONT,
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/note_tab_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<stroke
android:width="0dp"
android:color="#000000" />

<solid android:color="#000000" />

<corners android:radius="5dp" />

</shape>
83 changes: 67 additions & 16 deletions app/src/main/res/layout/activity_create_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
<View
android:layout_width="match_parent"
android:layout_height="112dp" />

</LinearLayout>

</androidx.core.widget.NestedScrollView>

<com.google.android.material.card.MaterialCardView
Expand Down Expand Up @@ -127,15 +129,33 @@

</FrameLayout>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/colorButton"
<FrameLayout
android:layout_width="56dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/acc_select_color"
android:scaleType="centerInside"
app:srcCompat="@drawable/ic_fluent_color_background" />
android:layout_marginStart="8dp">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/colorButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/acc_select_color"
android:scaleType="centerInside"
app:srcCompat="@drawable/ic_fluent_color_background" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/colorSelectorView"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/note_tab_selector"
android:visibility="gone"
tools:visibility="visible" />

</FrameLayout>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imageButton"
Expand Down Expand Up @@ -165,26 +185,57 @@
android:id="@+id/reminderDotView"
android:layout_width="6dp"
android:layout_height="6dp"
android:layout_gravity="bottom|end"
android:layout_gravity="end"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/note_reminder_dot"
android:visibility="gone"
tools:visibility="visible" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/reminderSelectorView"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/note_tab_selector"
android:visibility="gone"
tools:visibility="visible" />

</FrameLayout>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/fontButton"
<FrameLayout
android:layout_width="56dp"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/acc_change_text_font_style"
android:scaleType="centerInside"
app:srcCompat="@drawable/ic_fluent_text" />
android:layout_marginStart="8dp">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/fontButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/acc_change_text_font_style"
android:scaleType="centerInside"
app:srcCompat="@drawable/ic_fluent_text" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/fontSelectorView"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/note_tab_selector"
android:visibility="gone"
tools:visibility="visible" />

</FrameLayout>

</LinearLayout>

</HorizontalScrollView>

<LinearLayout
Expand Down

0 comments on commit b2491b2

Please sign in to comment.