Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Feat: Add ScrollView for reordering apps screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis8 authored Aug 10, 2024
1 parent 5f3eec5 commit 145909e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -118,14 +120,7 @@ class ReorderHomeAppsFragment : Fragment() {
DragEvent.ACTION_DROP -> {
// Remove highlighting
targetView.background = null
return true
}
DragEvent.ACTION_DRAG_ENDED -> {
// Remove highlighting when the drag ends
targetView.background = null
return true
}
else -> {

// Extract the dragged TextView
val draggedTextView = event.localState as TextView

Expand All @@ -134,8 +129,14 @@ class ReorderHomeAppsFragment : Fragment() {
val targetIndex = (targetView.parent as ViewGroup).indexOfChild(targetView)
reorderApps(draggedIndex, targetIndex)

return false
return true
}
DragEvent.ACTION_DRAG_ENDED -> {
// Remove highlighting when the drag ends
targetView.background = null
return true
}
else -> return false
}
}

Expand Down Expand Up @@ -220,5 +221,8 @@ class ReorderHomeAppsFragment : Fragment() {
true
}
}

// Scroll to the top of the list after updating
(binding.homeAppsLayout.parent as? ScrollView)?.scrollTo(0, 0)
}
}
25 changes: 16 additions & 9 deletions app/src/main/res/layout/fragment_reorder_home_apps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<LinearLayout
android:id="@+id/pageLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="24dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="24dp"
Expand All @@ -34,15 +34,22 @@
android:textSize="@dimen/date_size" />

<!-- Home apps-->
<LinearLayout
android:id="@+id/homeAppsLayout"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingBottom="80dp"
android:paddingTop="112dp" />
android:layout_height="0dp"
android:layout_weight="1">

<LinearLayout
android:id="@+id/homeAppsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingHorizontal="20dp"
android:paddingBottom="80dp"
android:paddingTop="112dp" />

</ScrollView>
</LinearLayout>

</FrameLayout>

0 comments on commit 145909e

Please sign in to comment.