Skip to content

Commit

Permalink
ui tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaiiDango committed Dec 17, 2023
1 parent 584270b commit 9a9ce1c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 28 deletions.
11 changes: 0 additions & 11 deletions app/src/main/java/com/arn/scrobble/HomePagerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ class HomePagerFragment : BasePagerFragment() {
}
}

fun expandAppBar(tabPosition: Int) {
val appBar = (activity as MainActivity).binding.appBar

val expand = tabPosition == 0

appBar.updateHeight(expand)

if (expand && !appBar.isExpanded)
appBar.setExpanded(true, true)
}

private fun optionsMenuSelected(navView: NavigationView, menuItemId: Int) {
val navController = findNavController()
when (menuItemId) {
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/arn/scrobble/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.core.view.children
import androidx.core.view.isVisible
import androidx.core.view.setMargins
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -73,9 +72,6 @@ class MainActivity : AppCompatActivity(),
ColorPatchUtils.setTheme(this, billingViewModel.proStatus.value == true)
UiUtils.isTabletUi = resources.getBoolean(R.bool.is_tablet_ui)

// if (!BuildConfig.DEBUG)
FragmentManager.enablePredictiveBack(false)

binding = ContentMainBinding.inflate(layoutInflater)

if (UiUtils.isTabletUi) {
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/arn/scrobble/NavUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ object NavUtils {
}

activityBinding.bottomNav.setOnItemSelectedListener { menuItem ->

if (this@setupWithNavUi is HomePagerFragment)
activityBinding.appBar.setTag(
R.id.app_bar_can_change_size,
true
)

val itemId = menuItem.itemId - idOffset
if (itemId in adapter.tabMetadata.indices) {
binding.pager.setCurrentItem(itemId, true)
Expand Down Expand Up @@ -352,8 +359,6 @@ object NavUtils {
if (this@setupWithNavUi is HomePagerFragment) {
if (findNavController().currentDestination?.id == R.id.myHomePagerFragment)
prefs.lastHomePagerTab = position

expandAppBar(position)
}
}
}
Expand All @@ -363,6 +368,10 @@ object NavUtils {

binding.pager.addOnPageChangeListener(onPageChangeListener)
onPageChangeListener.onPageSelected(binding.pager.currentItem)
activityBinding.appBar.setTag(
R.id.app_bar_can_change_size,
true
)

arguments?.getInt(Stuff.ARG_TAB, -1)
?.coerceAtMost(adapter.count - 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import com.arn.scrobble.ui.ItemLongClickListener
import com.arn.scrobble.ui.PaletteTransition
import com.arn.scrobble.ui.SimpleHeaderDecoration
import com.arn.scrobble.ui.UiUtils
import com.arn.scrobble.ui.UiUtils.expandToHeroIfNeeded
import com.arn.scrobble.ui.UiUtils.memoryCacheKey
import com.arn.scrobble.ui.UiUtils.scrollToTopOnInsertToTop
import com.arn.scrobble.ui.UiUtils.setProgressCircleColors
Expand Down Expand Up @@ -172,6 +173,9 @@ open class ScrobblesFragment : Fragment(), ItemClickListener, ScrobblesAdapter.S
}
activity ?: return
viewModel.reemitColors()

coordinatorBinding.appBar.expandToHeroIfNeeded(true)

}

override fun onPause() {
Expand All @@ -190,6 +194,8 @@ open class ScrobblesFragment : Fragment(), ItemClickListener, ScrobblesAdapter.S
)
coordinatorBinding.sidebarNav.setBackgroundColor(bgColor)
coordinatorBinding.ctl.setStatusBarScrimColor(bgColor)

coordinatorBinding.appBar.expandToHeroIfNeeded(false)
}

private fun postInit() {
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/arn/scrobble/ui/UiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,18 @@ object UiUtils {
}
}

fun StatefulAppBar.expandToHeroIfNeeded(expand: Boolean) {
if (getTag(R.id.app_bar_can_change_size) != true)
return

updateHeight(expand)

if (expand && !isExpanded)
setExpanded(true, true)

setTag(R.id.app_bar_can_change_size, false)
}

fun PopupMenu.showWithIcons(iconTintColor: Int? = null) {
(menu as? MenuBuilder)?.showIcons(iconTintColor)
show()
Expand Down Expand Up @@ -458,7 +470,7 @@ object UiUtils {
App.prefs.drawerDataCached.profilePicUrl
else
userSerializable.getWebpImageURL(ImageSize.EXTRALARGE)

val request = ImageRequest.Builder(context)
.data(profilePicUrl?.ifEmpty { null }
?: initialsDrawable
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/layout_snowfall.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:layout_height="match_parent"
app:snowflakeAlphaMax="200"
app:snowflakeAlphaMin="50"
app:snowflakeAngleMax="30"
app:snowflakeAngleMax="10"
app:snowflakeSizeMax="7dp"
app:snowflakeSizeMin="1dp"
app:snowflakeSpeedMax="5"
Expand Down
19 changes: 10 additions & 9 deletions app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="main_fab" />
<item type="id" name="main_extended_fab" />
<item type="id" name="time" />
<item type="id" name="should_show_user" />
<item type="id" name="more_menu" />
<item type="id" name="hero_track" />
<item type="id" name="img_url" />
<item type="id" name="inited" />
<item type="id" name="raw_text" />
<item name="main_fab" type="id" />
<item name="main_extended_fab" type="id" />
<item name="time" type="id" />
<item name="should_show_user" type="id" />
<item name="more_menu" type="id" />
<item name="hero_track" type="id" />
<item name="img_url" type="id" />
<item name="inited" type="id" />
<item name="raw_text" type="id" />
<item name="app_bar_can_change_size" type="id" />
</resources>

0 comments on commit 9a9ce1c

Please sign in to comment.