Skip to content

Commit

Permalink
Merge pull request #656 from DHD2280/beta
Browse files Browse the repository at this point in the history
Fixes for clock carousel and search preference
  • Loading branch information
Mahmud0808 authored Oct 25, 2024
2 parents c37fa4b + 4e3b53d commit 1014498
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,11 @@ abstract class BaseFragment : Fragment() {
}, viewLifecycleOwner, Lifecycle.State.RESUMED)
}

fun onSearchResultClicked(result: SearchPreferenceResult) {
open fun onSearchResultClicked(result: SearchPreferenceResult) {
for (searchableFragment in searchableFragments) {
if (searchableFragment.xml == result.resourceFile) {
replaceFragment(parentFragmentManager, searchableFragment.fragment)
var finalFragment: ControlledPreferenceFragmentCompat? = null
if (searchableFragment.fragment is LockscreenClockParent) {
finalFragment = LockscreenClockParent.getPreferenceFragment()
}
SearchPreferenceResult.highlight(finalFragment, result.key);
SearchPreferenceResult.highlight(parentFragmentManager as ControlledPreferenceFragmentCompat, result.key);
break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ abstract class ControlledPreferenceFragmentCompat : PreferenceFragmentCompat() {
var resultFragment: ControlledPreferenceFragmentCompat? = null
if (fragment is LockscreenClockParent) {
resultFragment = LockscreenClockParent.getPreferenceFragment()
fragment.scrollToPreference()
}
SearchPreferenceResult.highlight(resultFragment, result.key);
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ import com.drdisagree.iconify.R
import com.drdisagree.iconify.common.Preferences.LSCLOCK_STYLE
import com.drdisagree.iconify.common.Preferences.LSCLOCK_SWITCH
import com.drdisagree.iconify.common.Resources.LOCKSCREEN_CLOCK_LAYOUT
import com.drdisagree.iconify.common.Resources.searchableFragments
import com.drdisagree.iconify.config.RPrefs.getBoolean
import com.drdisagree.iconify.config.RPrefs.getInt
import com.drdisagree.iconify.config.RPrefs.putBoolean
import com.drdisagree.iconify.config.RPrefs.putInt
import com.drdisagree.iconify.databinding.FragmentXposedLockscreenClockBinding
import com.drdisagree.iconify.ui.activities.MainActivity.Companion.replaceFragment
import com.drdisagree.iconify.ui.base.BaseFragment
import com.drdisagree.iconify.ui.base.ControlledPreferenceFragmentCompat
import com.drdisagree.iconify.ui.models.ClockCarouselItemViewModel
import com.drdisagree.iconify.ui.preferences.preferencesearch.SearchPreferenceResult
import com.drdisagree.iconify.ui.utils.ViewHelper.setHeader
import com.drdisagree.iconify.ui.views.ClockCarouselView
import com.drdisagree.iconify.utils.SystemUtils
Expand Down Expand Up @@ -147,6 +150,17 @@ class LockscreenClockParent : BaseFragment() {
}, 50)
}

override fun onSearchResultClicked(result: SearchPreferenceResult) {
for (searchableFragment in searchableFragments) {
if (searchableFragment.xml == result.resourceFile) {
replaceFragment(parentFragmentManager, searchableFragment.fragment)
scrollToPreference()
SearchPreferenceResult.highlight(lockscreenClockFragment, result.key);
break
}
}
}

private fun loadAndSetWallpaper() {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
val bitmap = loadWallpaper(requireContext(), isLockscreen = true).await()
Expand All @@ -172,6 +186,12 @@ class LockscreenClockParent : BaseFragment() {
requireActivity().requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}

fun scrollToPreference() {
Handler(Looper.getMainLooper()).postDelayed({
binding?.scrollView!!.smoothScrollTo(0, binding.fragmentContainer.top)
}, 180)
}

companion object {

private val lockscreenClockFragment = LockscreenClock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.constraintlayout.helper.widget.Carousel
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.view.doOnPreDraw
Expand All @@ -33,6 +34,8 @@ class ClockCarouselView(
private var offCenterClockScaleView: View? = null
private var toCenterCardView: View? = null
private var offCenterCardView: View? = null
private var toCenterTextView: View? = null
private var offCenterTextView: View? = null

init {
val clockCarousel = LayoutInflater.from(context).inflate(R.layout.clock_carousel, this)
Expand Down Expand Up @@ -143,6 +146,12 @@ class ClockCarouselView(
if (endId == R.id.next) R.id.clock_scale_view_3
else R.id.clock_scale_view_1
)
offCenterTextView = motionLayout.findViewById(R.id.clock_style_2)
toCenterTextView =
motionLayout.findViewById(
if (endId == R.id.next) R.id.clock_style_3
else R.id.clock_style_1
)
}

private fun prepareCardView(motionLayout: MotionLayout, endId: Int) {
Expand All @@ -151,11 +160,19 @@ class ClockCarouselView(
motionLayout.findViewById(
if (endId == R.id.next) R.id.item_card_3 else R.id.item_card_1
)
offCenterTextView = motionLayout.findViewById(R.id.clock_style_2)
toCenterTextView =
motionLayout.findViewById(
if (endId == R.id.next) R.id.clock_style_3
else R.id.clock_style_1
)
}

private fun onCardViewTransition(progress: Float) {
offCenterCardView?.alpha = getShowingAlpha(progress)
toCenterCardView?.alpha = getHidingAlpha(progress)
toCenterTextView?.alpha = getShowingAlphaText(progress)
offCenterTextView?.alpha = getHidingAlphaText(progress)
}

private fun onDynamicClockViewTransition(progress: Float) {
Expand Down Expand Up @@ -232,6 +249,9 @@ class ClockCarouselView(
val clockHostView =
getClockHostViewId(viewRoot.id)?.let { viewRoot.findViewById(it) as? ClockHostView }
?: return
val clockTextView =
getClockTextId(viewRoot.id)?.let { viewRoot.findViewById(it) as? View }
?: return

// Add the clock view to the clock host view
clockHostView.removeAllViews()
Expand All @@ -247,19 +267,23 @@ class ClockCarouselView(
// Accessibility
viewRoot.contentDescription = getContentDescription(index)
viewRoot.isSelected = isMiddleView
(clockTextView as TextView).text = clocks[index].clockName

initializeDynamicClockView(
isMiddleView,
clockScaleView,
clockHostView
clockHostView,
clockTextView
)
cardView.alpha = if (isMiddleView) 0f else 1f
clockTextView.alpha = if (isMiddleView) 1f else 0f
}

private fun initializeDynamicClockView(
isMiddleView: Boolean,
clockScaleView: View,
clockHostView: ClockHostView,
clockTextView: View
) {
clockHostView.doOnPreDraw {
it.pivotX = it.width / 2F
Expand All @@ -269,9 +293,11 @@ class ClockCarouselView(
if (isMiddleView) {
clockScaleView.scaleX = 1f
clockScaleView.scaleY = 1f
clockTextView.alpha = 1f
} else {
clockScaleView.scaleX = CLOCK_CAROUSEL_VIEW_SCALE
clockScaleView.scaleY = CLOCK_CAROUSEL_VIEW_SCALE
clockTextView.alpha = 0f
}
}

Expand Down Expand Up @@ -308,6 +334,14 @@ class ClockCarouselView(
// card won't overlap the preview.
fun getHidingAlpha(progress: Float) = max(1f - progress * 4, 0f)

// This makes the card only starts to reveal in the last quarter of the trip so
// the card won't overlap the preview.
fun getShowingAlphaText(progress: Float) = max(progress - 0.75f, 0f) * 4

// This makes the card starts to hide in the first quarter of the trip so the
// card won't overlap the preview.
fun getHidingAlphaText(progress: Float) = max(1f - progress * 4, 0f)

fun getClockHostViewId(rootViewId: Int): Int? {
return when (rootViewId) {
R.id.item_view_0 -> R.id.clock_host_view_0
Expand Down Expand Up @@ -341,6 +375,17 @@ class ClockCarouselView(
}
}

fun getClockTextId(rootViewId: Int): Int? {
return when (rootViewId) {
R.id.item_view_0 -> R.id.clock_style_0
R.id.item_view_1 -> R.id.clock_style_1
R.id.item_view_2 -> R.id.clock_style_2
R.id.item_view_3 -> R.id.clock_style_3
R.id.item_view_4 -> R.id.clock_style_4
else -> null
}
}

fun isMiddleView(rootViewId: Int): Boolean {
return rootViewId == R.id.item_view_2
}
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/res/layout/clock_carousel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
android:layout_gravity="center"
android:clipChildren="false" />
</com.drdisagree.iconify.ui.widgets.FixedWidthDisplayRatioFrameLayout>

<TextView
android:id="@+id/clock_style_0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center_horizontal"/>

</FrameLayout>

<FrameLayout
Expand Down Expand Up @@ -72,6 +80,14 @@
android:layout_gravity="center"
android:clipChildren="false" />
</com.drdisagree.iconify.ui.widgets.FixedWidthDisplayRatioFrameLayout>

<TextView
android:id="@+id/clock_style_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center_horizontal"/>

</FrameLayout>

<FrameLayout
Expand Down Expand Up @@ -108,6 +124,14 @@
android:layout_gravity="center"
android:clipChildren="false" />
</com.drdisagree.iconify.ui.widgets.FixedWidthDisplayRatioFrameLayout>

<TextView
android:id="@+id/clock_style_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center_horizontal"/>

</FrameLayout>

<FrameLayout
Expand Down Expand Up @@ -141,7 +165,16 @@
android:layout_height="match_parent"
android:layout_gravity="center"
android:clipChildren="false" />

</com.drdisagree.iconify.ui.widgets.FixedWidthDisplayRatioFrameLayout>

<TextView
android:id="@+id/clock_style_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center_horizontal"/>

</FrameLayout>

<FrameLayout
Expand Down Expand Up @@ -176,6 +209,14 @@
android:layout_gravity="center"
android:clipChildren="false" />
</com.drdisagree.iconify.ui.widgets.FixedWidthDisplayRatioFrameLayout>

<TextView
android:id="@+id/clock_style_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:gravity="center_horizontal" />

</FrameLayout>

<androidx.constraintlayout.helper.widget.Carousel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
tools:context=".ui.fragments.xposed.LockscreenClockParent">

<com.drdisagree.iconify.ui.widgets.HorizontalTouchMovementAwareNestedScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
Expand Down

0 comments on commit 1014498

Please sign in to comment.