Skip to content

Commit ad35a8e

Browse files
committed
Implement Andrew feedback
1 parent e72963a commit ad35a8e

8 files changed

Lines changed: 94 additions & 110 deletions

File tree

PennMobile/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
android:exported="true"
5959
android:label="@string/app_name"
6060
android:screenOrientation="portrait"
61+
android:configChanges="uiMode"
6162
android:windowSoftInputMode="adjustPan">
6263
<intent-filter>
6364
<action android:name="android.intent.action.MAIN" />

PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,6 @@ class MainActivity : AppCompatActivity() {
158158

159159
override fun onConfigurationChanged(newConfig: Configuration) {
160160
super.onConfigurationChanged(newConfig)
161-
162-
// Delay so that UI is properly rendered. Force consistency
163-
Handler(Looper.getMainLooper()).postDelayed({
164-
val currentPosition = binding.include.mainViewPager.currentItem
165-
166-
val menuItemId =
167-
when (currentPosition) {
168-
MainPagerAdapter.HOME_POSITION -> R.id.nav_home
169-
MainPagerAdapter.DINING_POSITION -> R.id.nav_dining
170-
MainPagerAdapter.GSR_POSITION -> R.id.nav_gsr
171-
MainPagerAdapter.LAUNDRY_POSITION -> R.id.nav_laundry
172-
MainPagerAdapter.MORE_POSITION -> R.id.nav_more
173-
else -> R.id.nav_home
174-
}
175-
176-
binding.include.expandableBottomBar.selectedItemId = menuItemId
177-
}, 100)
178161
}
179162

180163
/**
@@ -197,6 +180,13 @@ class MainActivity : AppCompatActivity() {
197180

198181
private fun onExpandableBottomNavigationItemSelected() {
199182
binding.include.expandableBottomBar.setOnNavigationItemSelectedListener { item ->
183+
// Only pop the UA fragment if it's on the back stack — leaves other
184+
// fragments (dining detail, GSR booking, etc.) untouched.
185+
fragmentManager.popBackStack(
186+
"student_resources",
187+
FragmentManager.POP_BACK_STACK_INCLUSIVE,
188+
)
189+
200190
val position =
201191
when (item.itemId) {
202192
R.id.nav_home -> MainPagerAdapter.HOME_POSITION
@@ -341,6 +331,30 @@ class MainActivity : AppCompatActivity() {
341331
}
342332
}
343333

334+
fun fragmentTransact(
335+
fragment: Fragment?,
336+
popBackStack: Boolean,
337+
backStackName: String? = null,
338+
) {
339+
if (fragment != null) {
340+
runOnUiThread {
341+
try {
342+
if (popBackStack) {
343+
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
344+
}
345+
fragmentManager
346+
.beginTransaction()
347+
.replace(R.id.content_frame, fragment)
348+
.addToBackStack(backStackName)
349+
.setTransition(FragmentTransaction.TRANSIT_NONE)
350+
.commit()
351+
} catch (e: IllegalStateException) {
352+
// ignore
353+
}
354+
}
355+
}
356+
}
357+
344358
override fun onRequestPermissionsResult(
345359
requestCode: Int,
346360
permissions: Array<String>,

PennMobile/src/main/java/com/pennapps/labs/pennmobile/home/fragments/HomeFragment.kt

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.view.LayoutInflater
77
import android.view.View
88
import android.view.ViewGroup
99
import androidx.appcompat.widget.Toolbar
10-
import androidx.compose.material3.MaterialTheme
1110
import androidx.compose.ui.platform.ViewCompositionStrategy
1211
import androidx.coordinatorlayout.widget.CoordinatorLayout
1312
import androidx.fragment.app.Fragment
@@ -21,6 +20,7 @@ import com.pennapps.labs.pennmobile.MainActivity
2120
import com.pennapps.labs.pennmobile.R
2221
import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager
2322
import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior
23+
import com.pennapps.labs.pennmobile.compose.presentation.theme.AppTheme
2424
import com.pennapps.labs.pennmobile.databinding.FragmentHomeBinding
2525
import com.pennapps.labs.pennmobile.home.HomepageViewModel
2626
import com.pennapps.labs.pennmobile.home.adapters.HomeAdapter
@@ -73,28 +73,6 @@ class HomeFragment : Fragment() {
7373
) {
7474
super.onViewCreated(view, savedInstanceState)
7575

76-
/* Mildly suspicious idea to hide the RecyclerView until blurviews (for news and posts) are
77-
done processing. Processing the blurviews is slow and makes the app looks sloppy. Ideally
78-
this is replaced by something less hacky (such as using a ListView instead) though perhaps
79-
it is simpler to just remove the blur altogether.
80-
81-
This takes advantage of a RecyclerView idiosyncracy: when a RecyclerView resides inside a
82-
nested scrollview, all of the elements are inflated:
83-
https://stackoverflow.com/questions/44453846/recyclerview-inside-nestedscrollview-causes-recyclerview-to-inflate-all-elements
84-
https://www.reddit.com/r/androiddev/comments/d8gi9v/recyclerview_inside_nestedscrollview_causes/
85-
86-
This is can be used to figure out when the blurviews are finished processing.
87-
88-
Since when the adapter is set in getHomePage, onBindViewHolder() is called for each cell.
89-
Thus, for the news and post cells which use blur, when the blur is finished processing,
90-
the adapter notifies homepageViewModel. When both blurs are processed, the blurViewsLoaded
91-
liveData in the ViewModel is toggled to true which HomeFragment observes.
92-
93-
If in the future, the homepage is stuck on loading forever, this might be why. To remove
94-
this functionality and stop waiting for the blur views to finish, just remove the observer
95-
below and change getHomePage() so that when HomeAdapter is set, homeCellsRv.visibility is
96-
set to View.VISIBLE instead of View.INVISIBLE and hide loadingPanel
97-
*/
9876
toolbar = mActivity.findViewById(R.id.toolbar)
9977
binding.homeCellsRv.layoutManager =
10078
LinearLayoutManager(
@@ -103,12 +81,10 @@ class HomeFragment : Fragment() {
10381
false,
10482
)
10583

106-
// Entry-point card for the Student Resources page. Tapping it pushes
107-
// StudentResourcesFragment onto the back stack.
10884
binding.studentResourcesEntry.apply {
10985
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
11086
setContent {
111-
MaterialTheme {
87+
AppTheme {
11288
StudentResourcesEntryCard(
11389
onClick = { openStudentResources() },
11490
)
@@ -149,7 +125,11 @@ class HomeFragment : Fragment() {
149125
}
150126

151127
private fun openStudentResources() {
152-
mActivity.fragmentTransact(StudentResourcesFragment(), false)
128+
mActivity.fragmentTransact(
129+
StudentResourcesFragment(),
130+
false,
131+
backStackName = "student_resources",
132+
)
153133
}
154134

155135
private fun getOnline(): Boolean {

PennMobile/src/main/java/com/pennapps/labs/pennmobile/studentresources/ResourceItem.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ import androidx.compose.material3.Text
2424
import androidx.compose.runtime.Composable
2525
import androidx.compose.ui.Alignment
2626
import androidx.compose.ui.Modifier
27-
import androidx.compose.ui.graphics.Color
2827
import androidx.compose.ui.platform.LocalContext
2928
import androidx.compose.ui.text.font.FontWeight
3029
import androidx.compose.ui.unit.dp
3130
import androidx.compose.ui.unit.sp
31+
import androidx.core.net.toUri
3232

33-
/**
34-
* A single resource block: title, description, phone chips, website/location chips,
35-
* and an optional bullet list of what the resource offers.
36-
*/
3733
@OptIn(ExperimentalLayoutApi::class)
3834
@Composable
3935
fun ResourceItem(
@@ -53,7 +49,6 @@ fun ResourceItem(
5349
color = MaterialTheme.colorScheme.onSurface,
5450
)
5551

56-
// Phone chips — styled as the blue pills in the mockup.
5752
if (resource.contacts.isNotEmpty()) {
5853
FlowRow(
5954
horizontalArrangement = Arrangement.spacedBy(8.dp),
@@ -65,7 +60,7 @@ fun ResourceItem(
6560
onClick = {
6661
val intent =
6762
Intent(Intent.ACTION_DIAL).apply {
68-
data = Uri.parse("tel:${contact.number}")
63+
data = "tel:${contact.number}".toUri()
6964
}
7065
context.startActivity(intent)
7166
},
@@ -74,7 +69,6 @@ fun ResourceItem(
7469
}
7570
}
7671

77-
// Website + location chips — the gray pills.
7872
if (resource.website != null || resource.locationUrl != null) {
7973
FlowRow(
8074
horizontalArrangement = Arrangement.spacedBy(8.dp),
@@ -129,6 +123,7 @@ fun ResourceItem(
129123
Text(
130124
text = "",
131125
style = MaterialTheme.typography.bodyMedium,
126+
color = MaterialTheme.colorScheme.onSurface,
132127
modifier = Modifier.width(16.dp),
133128
)
134129
Text(
@@ -151,8 +146,8 @@ private fun PhoneChip(
151146
) {
152147
Surface(
153148
shape = RoundedCornerShape(8.dp),
154-
color = Color(0xFFE6F4FE), // pale blue pill, matches mockup
155-
contentColor = Color(0xFF0B6BCB), // readable blue text
149+
color = MaterialTheme.colorScheme.secondary.copy(alpha = 0.15f),
150+
contentColor = MaterialTheme.colorScheme.secondary,
156151
modifier = modifier.clickable(onClick = onClick),
157152
) {
158153
Row(

PennMobile/src/main/java/com/pennapps/labs/pennmobile/studentresources/StudentResourcesData.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import androidx.compose.material.icons.filled.Psychology
1010
import androidx.compose.material.icons.filled.Security
1111
import androidx.compose.ui.graphics.vector.ImageVector
1212

13-
/**
14-
* Data models for the UA Student Resources guide.
15-
* Content sourced from: https://sites.google.com/view/undergraduate-assembly/home
16-
*/
17-
13+
// UA Resources data from https://sites.google.com/view/undergraduate-assembly/home
1814
data class ResourceCategory(
1915
val id: String,
2016
val title: String,
@@ -31,11 +27,6 @@ data class Resource(
3127
val bullets: List<String> = emptyList(),
3228
)
3329

34-
/**
35-
* A phone contact. [label] is what shows on the chip
36-
* (e.g. "Call (215) 898-7021 (24/7 help)"). [number] is the
37-
* dial-able digits only (e.g. "2158987021").
38-
*/
3930
data class Contact(
4031
val label: String,
4132
val number: String,

PennMobile/src/main/java/com/pennapps/labs/pennmobile/studentresources/StudentResourcesEntryCard.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ import androidx.compose.runtime.Composable
2222
import androidx.compose.ui.Alignment
2323
import androidx.compose.ui.Modifier
2424
import androidx.compose.ui.draw.clip
25-
import androidx.compose.ui.graphics.Color
2625
import androidx.compose.ui.text.font.FontWeight
2726
import androidx.compose.ui.unit.dp
2827
import androidx.compose.ui.unit.sp
2928

30-
/**
31-
* Small entry point card shown on the home feed. Tapping it navigates to
32-
* the full StudentResourcesScreen.
33-
*/
3429
@Composable
3530
fun StudentResourcesEntryCard(
3631
onClick: () -> Unit,
@@ -53,19 +48,17 @@ fun StudentResourcesEntryCard(
5348
modifier = Modifier.padding(horizontal = 16.dp, vertical = 16.dp),
5449
verticalAlignment = Alignment.CenterVertically,
5550
) {
56-
// UA logo tile — Penn navy block with "UA" text. Swap for an
57-
// Image(painterResource(R.drawable.ua_logo), ...) if you have an asset.
5851
Box(
5952
modifier =
6053
Modifier
6154
.size(44.dp)
6255
.clip(RoundedCornerShape(6.dp))
63-
.background(Color(0xFF011F5B)),
56+
.background(MaterialTheme.colorScheme.primary),
6457
contentAlignment = Alignment.Center,
6558
) {
6659
Text(
6760
text = "UA",
68-
color = Color.White,
61+
color = MaterialTheme.colorScheme.onPrimary,
6962
fontWeight = FontWeight.Bold,
7063
fontSize = 18.sp,
7164
)
@@ -76,6 +69,7 @@ fun StudentResourcesEntryCard(
7669
text = "Student Resources",
7770
style = MaterialTheme.typography.titleMedium,
7871
fontWeight = FontWeight.SemiBold,
72+
color = MaterialTheme.colorScheme.onSurface,
7973
)
8074
Text(
8175
text = "Support services, hotlines, and help available to Penn students",

PennMobile/src/main/java/com/pennapps/labs/pennmobile/studentresources/StudentResourcesFragment.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@ import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
7-
import androidx.compose.material3.MaterialTheme
87
import androidx.compose.ui.platform.ComposeView
98
import androidx.compose.ui.platform.ViewCompositionStrategy
109
import androidx.fragment.app.Fragment
10+
import com.pennapps.labs.pennmobile.compose.presentation.theme.AppTheme
1111

12-
/**
13-
* Hosts the full StudentResourcesScreen. Pushed onto the back stack via
14-
* MainActivity.fragmentTransact() from the home page entry card. The back
15-
* button defers to the activity's back dispatcher, which handles the back
16-
* stack plus bottom-bar visibility.
17-
*/
1812
class StudentResourcesFragment : Fragment() {
1913
override fun onCreateView(
2014
inflater: LayoutInflater,
2115
container: ViewGroup?,
2216
savedInstanceState: Bundle?,
2317
): View =
2418
ComposeView(requireContext()).apply {
25-
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
19+
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)
2620
setContent {
27-
MaterialTheme {
21+
AppTheme {
2822
StudentResourcesScreen(
2923
onBack = { requireActivity().onBackPressedDispatcher.onBackPressed() },
3024
)

0 commit comments

Comments
 (0)