Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Fix onboarding prompts #369

Merged
merged 1 commit into from
Dec 19, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class HomePresenterImpl @Inject constructor(
*/
override fun onDestroy() {
dataManager.unsubscribe()
view.unbindResources()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ interface HomeView {
*/
fun showAgentsFilterPrompt(onPromptShown: () -> Unit)

fun unbindResources()

interface ViewListener {
fun onFavoritesSnackBarActionClicked()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package com.github.vase4kin.teamcityapp.home.view

import android.content.res.ColorStateList
import android.graphics.Point
import android.os.Handler
import android.os.Looper
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.graphics.Insets
import androidx.core.view.ViewCompat
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import com.github.vase4kin.teamcityapp.R
import com.github.vase4kin.teamcityapp.filter_bottom_sheet_dialog.filter.Filter
Expand All @@ -41,18 +44,21 @@ private const val TIME_PROMPT_DELAY = 500
*/
class HomeViewImpl(private val activity: AppCompatActivity) : HomeView {

private lateinit var snackBarParentView: View
private lateinit var parentView: View
private lateinit var fab: FloatingActionButton
private lateinit var toolbar: Toolbar
private var snackbar: Snackbar? = null
private var listener: HomeView.ViewListener? = null

private val handler = Handler(Looper.getMainLooper())
private val runnables = mutableListOf<Runnable>()

/**
* {@inheritDoc}
*/
override fun initViews(listener: HomeView.ViewListener?) {
this.listener = listener
snackBarParentView = activity.findViewById(android.R.id.content)
parentView = activity.findViewById(android.R.id.content)
fab = activity.findViewById(R.id.home_floating_action_button)
}

Expand All @@ -61,7 +67,7 @@ class HomeViewImpl(private val activity: AppCompatActivity) : HomeView {
*/
override fun showFavoritesInfoSnackbar() {
this.snackbar = Snackbar.make(
snackBarParentView,
parentView,
R.string.text_info_add,
Snackbar.LENGTH_LONG
)
Expand Down Expand Up @@ -95,7 +101,7 @@ class HomeViewImpl(private val activity: AppCompatActivity) : HomeView {
*/
override fun showFilterAppliedSnackBar() {
this.snackbar = Snackbar.make(
snackBarParentView,
parentView,
R.string.text_filters_applied,
Snackbar.LENGTH_LONG
)
Expand All @@ -108,7 +114,7 @@ class HomeViewImpl(private val activity: AppCompatActivity) : HomeView {
*/
override fun showAgentsFilterAppliedSnackBar() {
this.snackbar = Snackbar.make(
snackBarParentView,
parentView,
R.string.text_agents_filters_applied,
Snackbar.LENGTH_LONG
)
Expand All @@ -132,17 +138,36 @@ class HomeViewImpl(private val activity: AppCompatActivity) : HomeView {
.setCaptureTouchEventOutsidePrompt(true)
.setPromptStateChangeListener { _, _ -> listener.onPromptShown() }
// Show prompt
Handler(Looper.getMainLooper()).postDelayed(
{
val top = activity.resources.getDimension(R.dimen.dp_48)
val left = activity.resources.getDimension(R.dimen.dp_24)
navigationDrawerPrompt.setTarget(left, top)
navigationDrawerPrompt.show()
},
val runnable = Runnable {
val navigationDrawerLocationOnScreen = getNavigationDrawerLocationOnScreen()
navigationDrawerPrompt.setTarget(
navigationDrawerLocationOnScreen.x.toFloat(),
navigationDrawerLocationOnScreen.y.toFloat()
)
navigationDrawerPrompt.show()
}.also {
runnables.add(it)
}
handler.postDelayed(
runnable,
TIME_PROMPT_DELAY.toLong()
)
}

private fun getNavigationDrawerLocationOnScreen(): Point {
val centerOfDrawerImage = activity.resources.getDimensionPixelSize(R.dimen.dp_24)
val statusBarInsetsTop = getSystemWindowInsets().top
val top = statusBarInsetsTop + centerOfDrawerImage
return Point(centerOfDrawerImage, top)
}

private fun getSystemWindowInsets(): Insets {
val result = kotlin.runCatching {
ViewCompat.getRootWindowInsets(parentView)?.systemWindowInsets ?: Insets.NONE
}
return result.getOrNull() ?: Insets.NONE
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -219,6 +244,13 @@ class HomeViewImpl(private val activity: AppCompatActivity) : HomeView {
}.show()
}

override fun unbindResources() {
runnables.forEach {
handler.removeCallbacks(it)
}
runnables.clear()
}

private fun getBackgroundColor(): Int {
val elevation =
activity.resources.getDimension(R.dimen.dp_4)
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
android:id="@+id/home_floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dp_16"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/dp_16"
android:layout_marginBottom="@dimen/dp_72"
android:visibility="gone"
app:layout_anchor="@id/navigation"
app:layout_anchorGravity="right"
tools:src="@drawable/ic_favorite_white_24dp"
tools:visibility="visible" />

Expand All @@ -45,7 +45,6 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:labelVisibilityMode="labeled"
app:layout_insetEdge="bottom"
app:menu="@menu/menu_bottom_navigation" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
1 change: 1 addition & 0 deletions libraries/resources/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<dimen name="dp_32">32dp</dimen>
<dimen name="dp_38">38dp</dimen>
<dimen name="dp_48">48dp</dimen>
<dimen name="dp_72">72dp</dimen>
<dimen name="dp_96">96dp</dimen>
<dimen name="dp_124">124dp</dimen>

Expand Down