-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/ST10204902/PurrsonalTrainer …
…into dev
- Loading branch information
Showing
22 changed files
with
480 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ava/za/co/varsitycollege/st10204902/purrsonaltrainer/adapters/SwipableComponentAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package za.co.varsitycollege.st10204902.purrsonaltrainer.adapters | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import za.co.varsitycollege.st10204902.purrsonaltrainer.R | ||
|
||
class SwipableComponentAdapter( | ||
private val itemList: List<Int>, // Assuming using drawable resource IDs | ||
private val onItemPressed: (Int) -> Unit // Callback for when an avatar is selected | ||
) : RecyclerView.Adapter<SwipableComponentAdapter.AvatarViewHolder>() { | ||
|
||
inner class AvatarViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
private val avatarImageView: ImageView = itemView.findViewById(R.id.swipable_item_image) | ||
|
||
fun bind(avatarResId: Int) { | ||
avatarImageView.setImageResource(avatarResId) | ||
itemView.setOnClickListener { | ||
onItemPressed(avatarResId) | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AvatarViewHolder { | ||
val view = LayoutInflater.from(parent.context) | ||
.inflate(R.layout.item_swipable_component, parent, false) | ||
return AvatarViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: AvatarViewHolder, position: Int) { | ||
holder.bind(itemList[position]) | ||
} | ||
|
||
override fun getItemCount(): Int = itemList.size | ||
} |
39 changes: 39 additions & 0 deletions
39
...ain/java/za/co/varsitycollege/st10204902/purrsonaltrainer/components/SwipeSelectorView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package za.co.varsitycollege.st10204902.purrsonaltrainer.components | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.widget.FrameLayout | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import za.co.varsitycollege.st10204902.purrsonaltrainer.R | ||
import za.co.varsitycollege.st10204902.purrsonaltrainer.adapters.SwipableComponentAdapter | ||
|
||
class SwipeSelectorView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0 | ||
) : FrameLayout(context, attrs, defStyleAttr) { | ||
|
||
private val viewPager: ViewPager2 | ||
private var adapter: SwipableComponentAdapter? = null | ||
|
||
init { | ||
// Inflate the layout | ||
val view = LayoutInflater.from(context) | ||
.inflate(R.layout.component_swipable_selector, this, true) | ||
viewPager = view.findViewById(R.id.viewPager) | ||
} | ||
|
||
fun setItems(avatarList: List<Int>, onAvatarSelected: (Int) -> Unit) { | ||
adapter = SwipableComponentAdapter(avatarList, onAvatarSelected) | ||
viewPager.adapter = adapter | ||
} | ||
|
||
fun getCurrentItemPosition(): Int { | ||
return viewPager.currentItem | ||
} | ||
|
||
fun setCurrentItemPosition(position: Int, smoothScroll: Boolean = true) { | ||
viewPager.setCurrentItem(position, smoothScroll) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.