Skip to content

Commit

Permalink
Working homepage toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Akula112233 committed Oct 27, 2024
1 parent 40eef56 commit 9fe6500
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.Locale
import com.pennapps.labs.pennmobile.fragments.HomeSlidingToolbar
import androidx.fragment.app.FragmentTransaction
import com.pennapps.labs.pennmobile.adapters.MainPagerAdapter

class HomeFragment : Fragment() {
private lateinit var mActivity: MainActivity
Expand Down Expand Up @@ -83,6 +86,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 @@ -122,6 +133,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
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
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

// 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 @@ -313,6 +313,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 mStudentLifeRf2: StudentLifeRf2? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SupportFragment : ListFragment() {
private lateinit var toolbar: Toolbar

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
super.onCreate( savedInstanceState)

mActivity = activity as MainActivity
mActivity.closeKeyboard()
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

data class HomeSlidingToolbarElement(
@DrawableRes val iconRes: Int,
val title: String,
)
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 @@ -122,10 +122,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

0 comments on commit 9fe6500

Please sign in to comment.