Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
android: Use InboxRecyclerView's shiny new nested scrolling support
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Jan 17, 2021
1 parent 8bc2043 commit a21985b
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 63 deletions.
6 changes: 0 additions & 6 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions androidApp/src/main/java/press/editor/EditorView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import io.reactivex.rxkotlin.Observables
import io.reactivex.schedulers.Schedulers
import me.saket.cascade.CascadePopupMenu
import me.saket.cascade.overrideAllPopupMenus
import me.saket.inboxrecyclerview.page.ExpandablePageLayout
import me.saket.press.R
import me.saket.press.shared.editor.EditorEvent.NoteTextChanged
import me.saket.press.shared.editor.EditorOpenMode.NewNote
Expand All @@ -58,27 +57,25 @@ import me.saket.press.shared.editor.ToolbarIconKind.Unarchive
import me.saket.press.shared.editor.ToolbarMenuAction
import me.saket.press.shared.editor.ToolbarMenuItem
import me.saket.press.shared.editor.ToolbarSubMenu
import me.saket.press.shared.saveEditorContentOnClose
import me.saket.press.shared.listenRx
import me.saket.press.shared.preferences.UserPreferences
import me.saket.press.shared.saveEditorContentOnClose
import me.saket.press.shared.theme.AppTheme
import me.saket.press.shared.theme.DisplayUnits
import me.saket.press.shared.theme.TextStyles.mainBody
import me.saket.press.shared.theme.TextView
import me.saket.press.shared.theme.ThemePalette
import me.saket.press.shared.theme.applyStyle
import me.saket.press.shared.theme.from
import me.saket.press.shared.listenRx
import me.saket.press.shared.ui.models
import me.saket.wysiwyg.Wysiwyg
import me.saket.wysiwyg.formatting.TextSelection
import me.saket.wysiwyg.parser.node.HeadingLevel.H1
import me.saket.wysiwyg.style.WysiwygStyle
import me.saket.wysiwyg.widgets.addTextChangedListener
import press.extensions.doOnTextChange
import press.extensions.findParentOfType
import press.extensions.fromOreo
import press.extensions.getDrawable
import press.extensions.interceptPullToCollapseOnView
import press.extensions.showKeyboard
import press.extensions.textColor
import press.extensions.textSizePx
Expand Down Expand Up @@ -197,9 +194,6 @@ class EditorView @InflationInject constructor(
override fun onAttachedToWindow() {
super.onAttachedToWindow()

val page = findParentOfType<ExpandablePageLayout>()
page?.pullToCollapseInterceptor = interceptPullToCollapseOnView(scrollView)

editorEditText.doOnTextChange {
presenter.dispatch(NoteTextChanged(it.toString()))
}
Expand Down
20 changes: 0 additions & 20 deletions androidApp/src/main/java/press/extensions/InboxRecyclerView.ext.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
package press.extensions

import android.view.View
import me.saket.inboxrecyclerview.page.ExpandablePageLayout
import me.saket.inboxrecyclerview.page.InterceptResult.IGNORED
import me.saket.inboxrecyclerview.page.InterceptResult.INTERCEPTED
import me.saket.inboxrecyclerview.page.OnPullToCollapseInterceptor
import me.saket.inboxrecyclerview.page.SimplePageStateChangeCallbacks

fun interceptPullToCollapseOnView(scrollableView: View, toolbar: View? = null): OnPullToCollapseInterceptor {
return { downX, downY, upwardPull ->
if (toolbar?.locationOnScreen()?.contains(downX.toInt(), downY.toInt()) == true) {
IGNORED
} else {
if (scrollableView.locationOnScreen().contains(downX.toInt(), downY.toInt())) {
val directionInt = if (upwardPull) +1 else -1
val canScrollFurther = scrollableView.canScrollVertically(directionInt)
if (canScrollFurther) INTERCEPTED else IGNORED
} else {
IGNORED
}
}
}
}

inline fun ExpandablePageLayout.doOnExpand(crossinline action: () -> Unit) {
if (isExpanded) {
action()
Expand Down
6 changes: 0 additions & 6 deletions androidApp/src/main/java/press/home/HomeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers.mainThread
import me.saket.inboxrecyclerview.InboxRecyclerView
import me.saket.inboxrecyclerview.dimming.DimPainter
import me.saket.inboxrecyclerview.expander.InboxItemExpander
import me.saket.inboxrecyclerview.page.ExpandablePageLayout
import me.saket.press.R
import me.saket.press.shared.editor.EditorOpenMode.ExistingNote
import me.saket.press.shared.editor.EditorScreenKey
Expand All @@ -34,9 +33,7 @@ import me.saket.press.shared.localization.strings
import me.saket.press.shared.preferences.PreferencesScreenKey
import me.saket.press.shared.ui.ScreenKey
import me.saket.press.shared.ui.models
import press.extensions.findParentOfType
import press.extensions.getDrawable
import press.extensions.interceptPullToCollapseOnView
import press.extensions.second
import press.extensions.throttleFirst
import press.navigation.ScreenFocusChangeListener
Expand Down Expand Up @@ -130,9 +127,6 @@ class HomeView @InflationInject constructor(
.subscribe { row ->
navigator().lfg(row.screenKey())
}

val page = findParentOfType<ExpandablePageLayout>()
page?.pullToCollapseInterceptor = interceptPullToCollapseOnView(notesList)
}

override fun createScreenExpander(): InboxItemExpander<ScreenKey> {
Expand Down
10 changes: 0 additions & 10 deletions androidApp/src/main/java/press/preferences/PreferencesView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.squareup.contour.ContourLayout
import me.saket.inboxrecyclerview.InboxRecyclerView
import me.saket.inboxrecyclerview.dimming.DimPainter
import me.saket.inboxrecyclerview.expander.InboxItemExpander
import me.saket.inboxrecyclerview.page.ExpandablePageLayout
import me.saket.press.R
import me.saket.press.shared.localization.strings
import me.saket.press.shared.preferences.PreferenceCategory.AboutApp
Expand All @@ -21,8 +20,6 @@ import me.saket.press.shared.preferences.PreferenceCategory.Sync
import me.saket.press.shared.preferences.PreferenceCategoryItemModel
import me.saket.press.shared.preferences.PreferenceCategoryScreenKey
import me.saket.press.shared.ui.ScreenKey
import press.extensions.findParentOfType
import press.extensions.interceptPullToCollapseOnView
import press.navigation.navigator
import press.navigation.transitions.ExpandableScreenHost
import press.theme.themeAware
Expand Down Expand Up @@ -94,13 +91,6 @@ class PreferencesView(context: Context) : ContourLayout(context), ExpandableScre
)
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()

val page = findParentOfType<ExpandablePageLayout>()
page?.pullToCollapseInterceptor = interceptPullToCollapseOnView(categoryList)
}

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
// The note list is positioned in front of the toolbar so that its items can go
// over it, but RV steals all touch events even if there isn't a child under to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import com.squareup.contour.ContourLayout
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.inflation.InflationInject
import io.reactivex.android.schedulers.AndroidSchedulers.mainThread
import me.saket.inboxrecyclerview.page.ExpandablePageLayout
import me.saket.press.R
import me.saket.press.shared.localization.strings
import me.saket.press.shared.syncer.git.GitHost
import me.saket.press.shared.preferences.sync.setup.GitHostIntegrationEvent.CreateNewGitRepoClicked
import me.saket.press.shared.preferences.sync.setup.GitHostIntegrationEvent.GitRepositoryClicked
import me.saket.press.shared.preferences.sync.setup.GitHostIntegrationEvent.RetryClicked
Expand All @@ -31,11 +29,10 @@ import me.saket.press.shared.preferences.sync.setup.GitHostIntegrationUiModel
import me.saket.press.shared.preferences.sync.setup.GitHostIntegrationUiModel.SelectRepo
import me.saket.press.shared.preferences.sync.setup.GitHostIntegrationUiModel.ShowFailure
import me.saket.press.shared.preferences.sync.setup.GitHostIntegrationUiModel.ShowProgress
import me.saket.press.shared.syncer.git.GitHost
import me.saket.press.shared.ui.models
import press.extensions.doOnTextChange
import press.extensions.findParentOfType
import press.extensions.hideKeyboard
import press.extensions.interceptPullToCollapseOnView
import press.navigation.navigator
import press.navigation.screenKey
import press.theme.themeAware
Expand Down Expand Up @@ -154,9 +151,6 @@ class GitHostIntegrationView @InflationInject constructor(
.takeUntil(detaches())
.observeOn(mainThread())
.subscribe(::render)

val page = findParentOfType<ExpandablePageLayout>()
page?.pullToCollapseInterceptor = interceptPullToCollapseOnView(recyclerView)
}

private fun render(model: GitHostIntegrationUiModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.squareup.contour.ContourLayout
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.inflation.InflationInject
import io.reactivex.android.schedulers.AndroidSchedulers.mainThread
import me.saket.inboxrecyclerview.page.ExpandablePageLayout
import me.saket.press.R
import me.saket.press.shared.localization.strings
import me.saket.press.shared.preferences.sync.stats.SyncStatsForNerdsPresenter
Expand All @@ -19,8 +18,6 @@ import me.saket.press.shared.theme.TextStyles.mainBody
import me.saket.press.shared.theme.TextStyles.smallBody
import me.saket.press.shared.theme.TextView
import me.saket.press.shared.ui.models
import press.extensions.findParentOfType
import press.extensions.interceptPullToCollapseOnView
import press.extensions.textColor
import press.theme.themeAware
import press.widgets.PressToolbar
Expand Down Expand Up @@ -102,9 +99,6 @@ class SyncStatsForNerdsView @InflationInject constructor(
.takeUntil(detaches())
.observeOn(mainThread())
.subscribe(::render)

val page = findParentOfType<ExpandablePageLayout>()
page?.pullToCollapseInterceptor = interceptPullToCollapseOnView(logsScrollView)
}

private fun render(model: SyncStatsForNerdsUiModel) {
Expand Down

0 comments on commit a21985b

Please sign in to comment.