Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// fragments/HomeSlidingToolbar.kt
package com.pennapps.labs.pennmobile.fragments

import android.content.Context
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.preference.PreferenceManager
import com.pennapps.labs.pennmobile.R
import com.pennapps.labs.pennmobile.data_classes.HomeSlidingToolbarElement
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import references the incorrect package name. It should be com.pennapps.labs.pennmobile.home.classes.HomeSlidingToolbarElement to match the actual file location.

Suggested change
import com.pennapps.labs.pennmobile.data_classes.HomeSlidingToolbarElement
import com.pennapps.labs.pennmobile.home.classes.HomeSlidingToolbarElement

Copilot uses AI. Check for mistakes.

import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.style.TextAlign

val homeSlidingToolbarItems = listOf(
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_dining_square,
title = "Dining",
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_gsr_square,
title = "GSR",
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_laundry_square,
title = "Laundry",
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_news2,
title = "News",
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_contacts2,
title = "Contacts", // TODO Confirm rename from Penn Contacts
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_fitness2,
title = "Fitness",
),
)

@Composable
fun HomeSlidingToolbar(context: Context = LocalContext.current, onFeatureClick: (Int) -> Unit) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
val firstName = sharedPreferences.getString(context.getString(R.string.first_name), null) ?: "Guest"
val textColor = if (isSystemInDarkTheme()) {
colorResource(id = R.color.color_primary_light)
} else {
colorResource(id = R.color.color_primary_dark)
}

Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Spacer(Modifier.padding(10.dp))
Text(
text = "Welcome, $firstName!",
fontSize = 24.sp,
color = textColor,
fontWeight = FontWeight.Bold,
)
Spacer(Modifier.padding(10.dp))
LazyRow {
item{
Spacer(modifier = Modifier.width(8.dp))
}
items(homeSlidingToolbarItems.size) { index ->
HomeSlidingToolbarItem(index, onFeatureClick)
}
item{
Spacer(modifier = Modifier.width(8.dp))
}
}
}
}

@Composable
fun HomeSlidingToolbarItem(
index: Int,
onFeatureClick: (Int) -> Unit
) {
val feature = homeSlidingToolbarItems[index]
val lastPaddingEnd = if (index == homeSlidingToolbarItems.size - 1) 12.dp else 0.dp
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable lastPaddingEnd is declared but never used. It should either be applied to the layout or removed if not needed.

Suggested change
val lastPaddingEnd = if (index == homeSlidingToolbarItems.size - 1) 12.dp else 0.dp

Copilot uses AI. Check for mistakes.


// Set the textColor and backgroundColor
val textColor = colorResource(R.color.gray)
val backgroundColor = if (isSystemInDarkTheme()) {
colorResource(id = R.color.color_background_dark)
} else {
colorResource(id = R.color.color_background)
}

Box(
modifier = Modifier
.padding(6.dp)
.shadow(8.dp, RoundedCornerShape(20.dp)),
contentAlignment = Alignment.TopCenter
) {
Column(
modifier = Modifier
.clip(RoundedCornerShape(20.dp))
.background(backgroundColor)
.clickable { onFeatureClick(index) }
.size(90.dp, 130.dp)
.padding(8.dp),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
// Icon Container
Image(
painter = painterResource(id = feature.iconRes),
contentDescription = feature.title,
modifier = Modifier
.padding(top = 8.dp)
.size(70.dp)
.align(Alignment.CenterHorizontally)
)
Spacer(modifier = Modifier.height(15.dp))
Text(
text = feature.title,
color = textColor,
fontWeight = FontWeight.Bold,
fontSize = 13.sp,
textAlign = TextAlign.Center
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class MainActivity : AppCompatActivity() {
val HOME_ID = R.id.nav_home
val GSR_ID = R.id.nav_gsr
val DINING_ID = R.id.nav_dining
val LAUNDRY_ID = R.id.nav_laundry

private var mStudentLife: StudentLife? = null
private var mPlatform: Platform? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.pennapps.labs.pennmobile.data_classes

import androidx.annotation.DrawableRes
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
Comment on lines +4 to +5
Copy link
Preview

Copilot AI Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports for Color and ImageVector are unused in the data class. They should be removed to keep the imports clean.

Suggested change
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector

Copilot uses AI. Check for mistakes.


data class HomeSlidingToolbarElement(
@DrawableRes val iconRes: Int,
val title: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -20,9 +21,12 @@ import com.pennapps.labs.pennmobile.R
import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager
import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior
import com.pennapps.labs.pennmobile.databinding.FragmentHomeBinding
import com.pennapps.labs.pennmobile.fragments.HomeSlidingToolbar
import com.pennapps.labs.pennmobile.gsr.fragments.PottruckFragment
import com.pennapps.labs.pennmobile.home.HomepageViewModel
import com.pennapps.labs.pennmobile.home.adapters.HomeAdapter
import com.pennapps.labs.pennmobile.isOnline
import com.pennapps.labs.pennmobile.more.fragments.SupportFragment
import com.pennapps.labs.pennmobile.utils.Utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -86,6 +90,14 @@ class HomeFragment : Fragment() {
set to View.VISIBLE instead of View.INVISIBLE and hide loadingPanel
*/
toolbar = mActivity.findViewById(R.id.toolbar)

// Set up the ComposeView
binding.composeToolbar.setContent {
HomeSlidingToolbar { index ->
handleFeatureClick(index)
}
}

binding.homeCellsRv.layoutManager =
LinearLayoutManager(
context,
Expand Down Expand Up @@ -125,6 +137,38 @@ class HomeFragment : Fragment() {
getHomePage()
}

private fun handleFeatureClick(index: Int) {
when (index) {
0 -> mActivity.setTab(MainActivity.DINING_ID)
1 -> mActivity.setTab(MainActivity.GSR_ID)
2 -> mActivity.setTab(MainActivity.LAUNDRY_ID)
3 -> {
mActivity.supportFragmentManager
.beginTransaction()
.replace(R.id.content_frame, NewsFragment())
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
}
4 -> {
mActivity.supportFragmentManager
.beginTransaction()
.replace(R.id.content_frame, SupportFragment())
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
}
5 -> {
mActivity.supportFragmentManager
.beginTransaction()
.replace(R.id.content_frame, PottruckFragment())
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
}
}
}

private fun getOnline(): Boolean {
// displays banner if not connected
if (!isOnline(context)) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 PennMobile/src/main/res/drawable/ic_gsr_square.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 PennMobile/src/main/res/drawable/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions PennMobile/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@

</androidx.appcompat.widget.Toolbar>

<!-- TODO add in the toolbar here -->
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/internetConnectionHome" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_cells_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/compose_toolbar"
android:scrollbars="none"
app:layout_constraintTop_toTopOf="parent" />

Expand Down
1 change: 1 addition & 0 deletions PennMobile/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<color name="star_color_on">#f4b400</color>

<color name="color_background">#FFFFFF</color>
<color name="color_background_dark">#1b1b1b</color>
<color name="avail_color_green">#8BC34A</color>
<color name="avail_color_red">#F44336</color>

Expand Down
Loading