allow creating tasks through the FAB icon

This commit is contained in:
tibbi 2022-02-21 16:18:54 +01:00
parent 73a3933099
commit a57bc39766
4 changed files with 116 additions and 7 deletions

View File

@ -12,6 +12,7 @@ import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.provider.ContactsContract.CommonDataKinds
import android.provider.ContactsContract.Contacts
import android.provider.ContactsContract.Data
@ -92,10 +93,34 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
checkWhatsNewDialog()
calendar_fab.beVisibleIf(config.storedView != YEARLY_VIEW && config.storedView != WEEKLY_VIEW)
calendar_fab.setOnClickListener {
if (config.allowCreatingTasks) {
if (fab_extended_overlay.isVisible()) {
openNewEvent()
Handler().postDelayed({
hideExtendedFab()
}, 300)
} else {
showExtendedFab()
}
} else {
openNewEvent()
}
}
fab_extended_overlay.setOnClickListener {
hideExtendedFab()
}
fab_task_icon.setOnClickListener {
hideKeyboard()
val lastFragment = currentFragments.last()
val allowChangingDay = lastFragment !is DayFragmentsHolder && lastFragment !is MonthDayFragmentsHolder
launchNewEventIntent(lastFragment.getNewEventDayCode(), allowChangingDay)
Intent(this, TaskActivity::class.java).apply {
startActivity(this)
}
Handler().postDelayed({
hideExtendedFab()
}, 300)
}
storeStateVariables()
@ -159,6 +184,12 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
storeStateVariables()
updateWidgets()
updateTextColors(calendar_coordinator)
fab_extended_overlay.background = ColorDrawable(config.backgroundColor.adjustAlpha(0.8f))
fab_event_label.setTextColor(config.textColor)
fab_task_label.setTextColor(config.textColor)
fab_task_icon.drawable.applyColorFilter(mStoredAdjustedPrimaryColor.getContrastColor())
fab_task_icon.background.applyColorFilter(mStoredAdjustedPrimaryColor)
search_holder.background = ColorDrawable(config.backgroundColor)
checkSwipeRefreshAvailability()
@ -201,6 +232,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
if (fab_extended_overlay.isVisible()) {
hideExtendedFab()
}
menu.apply {
findItem(R.id.refresh_caldav_calendars).isVisible = config.caldavSync
findItem(R.id.filter).isVisible = mShouldFilterBeVisible
@ -210,6 +245,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (fab_extended_overlay.isVisible()) {
hideExtendedFab()
}
when (item.itemId) {
R.id.change_view -> showViewDialog()
R.id.go_to_today -> goToToday()
@ -233,10 +272,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
override fun onBackPressed() {
swipe_refresh_layout.isRefreshing = false
checkSwipeRefreshAvailability()
if (currentFragments.size > 1) {
removeTopFragment()
} else {
super.onBackPressed()
when {
fab_extended_overlay.isVisible() -> hideExtendedFab()
currentFragments.size > 1 -> removeTopFragment()
else -> super.onBackPressed()
}
}
@ -872,6 +911,25 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
else -> dayCode
}
private fun showExtendedFab() {
arrayOf(fab_event_label, fab_extended_overlay, fab_task_icon, fab_task_label).forEach {
it.fadeIn()
}
}
private fun hideExtendedFab() {
arrayOf(fab_event_label, fab_extended_overlay, fab_task_icon, fab_task_label).forEach {
it.fadeOut()
}
}
private fun openNewEvent() {
hideKeyboard()
val lastFragment = currentFragments.last()
val allowChangingDay = lastFragment !is DayFragmentsHolder && lastFragment !is MonthDayFragmentsHolder
launchNewEventIntent(lastFragment.getNewEventDayCode(), allowChangingDay)
}
fun openMonthFromYearly(dateTime: DateTime) {
if (currentFragments.last() is MonthFragmentsHolder) {
return

View File

@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
<path android:fillColor="#FFFFFF" android:pathData="M21.29 5.89l-10 10c-0.39 0.39-1.02 0.39-1.41 0l-2.83-2.83c-0.39-0.39-0.39-1.02 0-1.41 0.39-0.39 1.02-0.39 1.41 0l2.12 2.12 9.29-9.29c0.39-0.39 1.02-0.39 1.41 0 0.4 0.39 0.4 1.02 0.01 1.41zm-5.52-3.15c-1.69-0.69-3.61-0.93-5.61-0.57-4.07 0.73-7.32 4.01-8.01 8.08C1.01 17 6.63 22.78 13.34 21.91c3.96-0.51 7.28-3.46 8.32-7.31 0.4-1.47 0.44-2.89 0.21-4.22-0.13-0.8-1.12-1.11-1.7-0.54-0.23 0.23-0.33 0.57-0.27 0.89 0.22 1.33 0.12 2.75-0.52 4.26-1.16 2.71-3.68 4.7-6.61 4.97-5.1 0.47-9.33-3.85-8.7-8.98 0.43-3.54 3.28-6.42 6.81-6.91 1.73-0.24 3.37 0.09 4.77 0.81 0.39 0.2 0.86 0.13 1.17-0.18 0.48-0.48 0.36-1.29-0.24-1.6-0.27-0.12-0.54-0.25-0.81-0.36z"/>
</vector>

View File

@ -23,6 +23,53 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="@+id/fab_extended_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/fab_event_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/event"
android:textSize="@dimen/big_text_size"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/calendar_fab"
app:layout_constraintEnd_toStartOf="@+id/calendar_fab"
app:layout_constraintTop_toTopOf="@+id/calendar_fab" />
<ImageView
android:id="@+id/fab_task_icon"
android:layout_width="@dimen/secondary_fab_size"
android:layout_height="@dimen/secondary_fab_size"
android:layout_marginBottom="@dimen/activity_margin"
android:alpha="0"
android:background="@drawable/circle_background"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_task_vector"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/calendar_fab"
app:layout_constraintEnd_toEndOf="@id/calendar_fab"
app:layout_constraintStart_toStartOf="@id/calendar_fab" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/fab_task_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/task"
android:textSize="@dimen/big_text_size"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/fab_task_icon"
app:layout_constraintEnd_toStartOf="@+id/calendar_fab"
app:layout_constraintTop_toTopOf="@+id/fab_task_icon" />
<com.simplemobiletools.commons.views.MyFloatingActionButton
android:id="@+id/calendar_fab"
android:layout_width="wrap_content"

View File

@ -4,6 +4,7 @@
<dimen name="yearly_padding_half">3dp</dimen>
<dimen name="yearly_padding_full">6dp</dimen>
<dimen name="circle_stroke_width">2dp</dimen>
<dimen name="secondary_fab_size">40dp</dimen>
<dimen name="monthly_day_height">40dp</dimen>