Skip to content

Commit

Permalink
Merge pull request #180 from ST10204902/profile-setup-implementation
Browse files Browse the repository at this point in the history
implemented profile setup
  • Loading branch information
joshua-harvey authored Nov 2, 2024
2 parents fc531d0 + 2764372 commit 1916e1c
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

1 change: 0 additions & 1 deletion .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,7 @@ dependencies {
androidTestImplementation("androidx.test.ext:junit:1.1.5") // AndroidX JUnit extensions
androidTestImplementation("androidx.test:runner:1.6.2") // AndroidX Test Runner

// For swipeable component
implementation("androidx.viewpager2:viewpager2:1.0.0")

}
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
}
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)
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package za.co.varsitycollege.st10204902.purrsonaltrainer.screens.login_register

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import za.co.varsitycollege.st10204902.purrsonaltrainer.backend.UserManager
import za.co.varsitycollege.st10204902.purrsonaltrainer.components.SwipeSelectorView
import za.co.varsitycollege.st10204902.purrsonaltrainer.databinding.ActivityProfileSetupBinding
import za.co.varsitycollege.st10204902.purrsonaltrainer.screens.HomeActivity
import za.co.varsitycollege.st10204902.purrsonaltrainer.services.CatAvatarList
import za.co.varsitycollege.st10204902.purrsonaltrainer.services.navigateTo

class ProfileSetupActivity : AppCompatActivity() {
private lateinit var binding: ActivityProfileSetupBinding
private lateinit var catSwipableView: SwipeSelectorView // custom component for choosing cats

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
Expand All @@ -19,8 +24,17 @@ class ProfileSetupActivity : AppCompatActivity() {
// Cat name entered by the user (for whoever needs this)
val catName = binding.profileSetupCatName.text

// CatAvatarSetup
val swipableSelector = binding.profileSetupCatSwipeSelector
swipableSelector.setItems(CatAvatarList) {}

// Navigation from next button
binding.profileSetupNext.setOnClickListener {
// Add the cat information to Firebase
UserManager.updateCatName(catName.toString())
UserManager.updateCatURI(swipableSelector.getCurrentItemPosition().toString())
Toast.makeText(this, swipableSelector.getCurrentItemPosition().toString(), Toast.LENGTH_SHORT).show()

navigateTo(this, HomeActivity::class.java, null)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package za.co.varsitycollege.st10204902.purrsonaltrainer.services

import za.co.varsitycollege.st10204902.purrsonaltrainer.R

// Add Cat Avatars Here
val CatAvatarList = listOf(
R.drawable.cat_placeholder,
R.drawable.cat_placeholder
)
Binary file added app/src/main/res/drawable/cat_placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/swipe_arrow_left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/swipe_arrow_right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 8 additions & 10 deletions app/src/main/res/layout/activity_profile_setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scaleType="centerCrop"
app:srcCompat="@drawable/bg_paws_and_fish"/>
app:srcCompat="@drawable/bg_paws_and_fish" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:paddingVertical="30dp">

<za.co.varsitycollege.st10204902.purrsonaltrainer.frontend_logic.GradientTextView
<za.co.varsitycollege.st10204902.purrsonaltrainer.frontend_logic.GradientEditText
android:id="@+id/profile_setup_cat_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -36,14 +37,11 @@
app:strokeColor="@color/default_stroke_color"
app:strokeWidth="15dp" />

<TextView
<za.co.varsitycollege.st10204902.purrsonaltrainer.components.SwipeSelectorView
android:id="@+id/profile_setup_cat_swipe_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/comboBoxGrey"
android:text="Cat selection placeholder"
android:textAlignment="center"
android:gravity="center"/>
android:layout_height="0dp"
android:layout_weight="1"/>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/profile_setup_next"
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/layout/component_swipable_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeableSelectorRoot"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/swipe_arrow_left"
android:layout_gravity="center_vertical|start"/>

<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/swipe_arrow_right"
android:layout_gravity="center_vertical|end"/>
</FrameLayout>
12 changes: 12 additions & 0 deletions app/src/main/res/layout/item_swipable_component.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<ImageView
android:id="@+id/swipable_item_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside" />
</FrameLayout>

0 comments on commit 1916e1c

Please sign in to comment.