Skip to content

Commit

Permalink
More:
Browse files Browse the repository at this point in the history
- Change icons to match iOS (I couldn't find a suitable fitness icon)
Fitness:
- Add Fitness to the more tab.
- Wrap necessary fitness API calls in getAccessToken()
- Fix the internet connection refreshing
  • Loading branch information
meiron03 committed Oct 17, 2023
1 parent 169ee04 commit bcea48a
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ interface CloseListener {

class FitnessPreferencesFragment(private val dataModel: FitnessPreferenceViewModel,
private val listener: CloseListener) : DialogFragment() {

private lateinit var mActivity : MainActivity
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
mActivity = activity as MainActivity
return inflater.inflate(R.layout.fragment_fitness_preferences, container, false)
}

Expand All @@ -42,7 +45,7 @@ class FitnessPreferencesFragment(private val dataModel: FitnessPreferenceViewMod
val saveText : TextView = view.findViewById(R.id.fitness_fragment_pref_save)
saveText.setOnClickListener {
dataModel.updatePositionMap()
dataModel.updateRemotePreferences()
dataModel.updateRemotePreferences(mActivity)
listener.updateAdapters()

dialog?.dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.google.android.material.appbar.AppBarLayout
import com.pennapps.labs.pennmobile.adapters.FitnessAdapter
import com.pennapps.labs.pennmobile.adapters.FitnessHeaderAdapter
import com.pennapps.labs.pennmobile.adapters.HomeAdapter
import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.FitnessAdapterDataModel
import com.pennapps.labs.pennmobile.classes.FitnessPreferenceViewModel
Expand Down Expand Up @@ -58,6 +59,7 @@ class PottruckFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
mActivity.hideBottomBar()
return inflater.inflate(R.layout.fragment_pottruck, container, false)
}

Expand Down Expand Up @@ -93,27 +95,36 @@ class PottruckFragment : Fragment() {

dataModel = FitnessPreferenceViewModel(mActivity, mStudentLife, sortedRooms)


mActivity.runOnUiThread {
val sp = PreferenceManager.getDefaultSharedPreferences(mActivity)
val context = mActivity.applicationContext
val bearerToken = "Bearer " + sp.getString(context.getString(R.string.access_token), "").toString()

mStudentLife.getFitnessPreferences(bearerToken).subscribe({ favorites ->
mActivity.runOnUiThread {
for (roomId in favorites) {
dataModel.addId(roomId)
OAuth2NetworkManager(mActivity).getAccessToken {
val sp = PreferenceManager.getDefaultSharedPreferences(mActivity)
val context = mActivity.applicationContext
val bearerToken =
"Bearer " + sp.getString(context.getString(R.string.access_token), "")
.toString()

mStudentLife.getFitnessPreferences(bearerToken).subscribe({ favorites ->
mActivity.runOnUiThread {
for (roomId in favorites) {
dataModel.addId(roomId)
}
dataModel.updatePositionMap()

setAdapters()
}
}, { throwable ->
mActivity.runOnUiThread {
// empty preferences
setAdapters()
Log.e(
"Pottruck Fragment",
"Could not load Fitness Preferences",
throwable
)
}
dataModel.updatePositionMap()

setAdapters()
}
}, { throwable ->
mActivity.runOnUiThread {
// empty preferences
setAdapters()
Log.e("Pottruck Fragment", "Could not load Fitness Preferences", throwable)
}
})
})
}
}
}, {
Log.e("PottruckFragment", "Error getting fitness rooms", it)
Expand Down Expand Up @@ -167,8 +178,10 @@ class PottruckFragment : Fragment() {
connectionMessage.text = getString(R.string.internet_error)
connectionToolbar.visibility = View.VISIBLE
loadingPanel.visibility = View.GONE
swipeRefresh.isRefreshing = false
return false
}
internetConnectionHome?.visibility = View.GONE
connectionToolbar.visibility = View.GONE
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MainPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle?)
HOME_POSITION-> HomeFragment()
DINING_POSITION-> DiningHolderFragment()
GSR_POSITION-> GsrTabbedFragment()
LAUNDRY_POSITION-> PottruckFragment()
LAUNDRY_POSITION-> LaundryFragment()
MORE_POSITION-> MoreFragment()
else -> HomeFragment()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.pennapps.labs.pennmobile.classes
import android.app.Activity
import android.util.Log
import androidx.preference.PreferenceManager
import com.pennapps.labs.pennmobile.MainActivity
import com.pennapps.labs.pennmobile.R
import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager
import com.pennapps.labs.pennmobile.api.StudentLife
import retrofit.ResponseCallback
import retrofit.RetrofitError
Expand Down Expand Up @@ -87,21 +89,30 @@ class FitnessPreferenceViewModel(private val activity: Activity,
favoriteRooms.addAll(prevFavoriteRooms)
}

fun updateRemotePreferences() {
fun updateRemotePreferences(mActivity : MainActivity) {
val sp = PreferenceManager.getDefaultSharedPreferences(activity)
val context = activity.applicationContext
val bearerToken = "Bearer " + sp.getString(context.getString(R.string.access_token), "").toString()

studentLife.sendFitnessPref(bearerToken, FitnessRequest(ArrayList(favoriteRooms)),
object : ResponseCallback() {
override fun success(response: Response) {
Log.i("Fitness Preference View Model", "fitness preferences saved")
}
override fun failure(error: RetrofitError) {
Log.e("Fitness Preference View Model", "Error saving fitness " +
"preferences: $error", error)
}
})

OAuth2NetworkManager(mActivity).getAccessToken {

val bearerToken =
"Bearer " + sp.getString(context.getString(R.string.access_token), "").toString()


studentLife.sendFitnessPref(bearerToken, FitnessRequest(ArrayList(favoriteRooms)),
object : ResponseCallback() {
override fun success(response: Response) {
Log.i("Fitness Preference View Model", "fitness preferences saved")
}

override fun failure(error: RetrofitError) {
Log.e(
"Fitness Preference View Model", "Error saving fitness " +
"preferences: $error", error
)
}
})
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ class PreferenceFragment : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}

val fitnessFeaturePref: Preference? = findPreference("pref_fitness_feature")
fitnessFeaturePref?.setOnPreferenceClickListener {
mActivity.supportFragmentManager.beginTransaction()
.replace(R.id.content_frame, PottruckFragment())
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
return@setOnPreferenceClickListener true
}


val pennLabsPref: Preference? = findPreference("pref_labs_link")
pennLabsPref?.setOnPreferenceClickListener {
openLink(PennLabs)
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.
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.
3 changes: 2 additions & 1 deletion PennMobile/src/main/res/layout/fragment_pottruck.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@color/white">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_home_holder"
Expand Down
14 changes: 11 additions & 3 deletions PennMobile/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,35 @@

<Preference
android:id="@+id/pref_news_feature"
app:icon="@drawable/ic_news_setting"
app:icon="@drawable/ic_news2"
app:iconSpaceReserved="false"
app:key="pref_news_feature"
app:title="News" />

<Preference
android:id="@+id/pref_contact_feature"
android:hapticFeedbackEnabled="true"
app:icon="@drawable/ic_contacts_setting"
app:icon="@drawable/ic_contacts2"
app:iconSpaceReserved="false"
app:key="pref_contacts_feature"
app:title="Penn Contacts" />

<Preference
android:id="@+id/pref_about_feature"
android:hapticFeedbackEnabled="true"
app:icon="@drawable/ic_about_setting"
app:icon="@drawable/ic_about2"
app:iconSpaceReserved="false"
app:key="pref_about_feature"
app:title="About" />

<Preference
android:id="@+id/pref_fitness_feature"
android:hapticFeedbackEnabled="true"
app:icon="@drawable/ic_fitness2"
app:iconSpaceReserved="false"
app:key="pref_fitness_feature"
app:title="Fitness" />


</PreferenceCategory>

Expand Down

0 comments on commit bcea48a

Please sign in to comment.