diff --git a/.github/workflows/android-workflow.yaml b/.github/workflows/android-workflow.yaml index 7528d20f..95f99d97 100644 --- a/.github/workflows/android-workflow.yaml +++ b/.github/workflows/android-workflow.yaml @@ -165,7 +165,7 @@ jobs: - name: Install ktlint run: | - curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.2.1/ktlint + curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.3.1/ktlint chmod a+x ktlint sudo mv ktlint /usr/local/bin/ diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/AboutFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/AboutFragment.kt index 5b9cb547..97925d11 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/AboutFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/AboutFragment.kt @@ -48,29 +48,31 @@ class AboutFragment : Fragment() { if (gif is AnimatedVectorDrawable) { gif.start() } else { - Glide.with(this).asGif().load(R.drawable.logo_gif_transparent).listener( - object : RequestListener { - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: com.bumptech.glide.request.target.Target?, - isFirstResource: Boolean, - ): Boolean { - return false - } + Glide + .with(this) + .asGif() + .load(R.drawable.logo_gif_transparent) + .listener( + object : RequestListener { + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: com.bumptech.glide.request.target.Target?, + isFirstResource: Boolean, + ): Boolean = false - override fun onResourceReady( - resource: GifDrawable, - model: Any, - target: com.bumptech.glide.request.target.Target?, - dataSource: DataSource, - isFirstResource: Boolean, - ): Boolean { - resource.setLoopCount(1) - return false - } - }, - ).into(binding.logoGifIv) + override fun onResourceReady( + resource: GifDrawable, + model: Any, + target: com.bumptech.glide.request.target.Target?, + dataSource: DataSource, + isFirstResource: Boolean, + ): Boolean { + resource.setLoopCount(1) + return false + } + }, + ).into(binding.logoGifIv) } binding.ourTeamRv.layoutManager = GridLayoutManager(context, 3) @@ -103,7 +105,8 @@ class AboutFragment : Fragment() { binding.licensesBtn.setOnClickListener { val webView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_licenses, null) as WebView webView.loadUrl("file:///android_asset/open_source_licenses.html") - AlertDialog.Builder(mActivity, R.style.AppTheme_AppBarOverlay_Light) + AlertDialog + .Builder(mActivity, R.style.AppTheme_AppBarOverlay_Light) .setTitle(getString(R.string.action_licenses)) .setView(webView) .setPositiveButton(android.R.string.ok, null) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/BookGsrFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/BookGsrFragment.kt index b91578a0..c512372a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/BookGsrFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/BookGsrFragment.kt @@ -91,14 +91,16 @@ class BookGsrFragment : Fragment() { emailEt.setText(email) submit.setOnClickListener { - if (firstNameEt.text.toString().matches("".toRegex()) || lastNameEt.text.toString().matches("".toRegex()) || + if (firstNameEt.text.toString().matches("".toRegex()) || + lastNameEt.text.toString().matches("".toRegex()) || emailEt.text.toString().matches("".toRegex()) ) { - Toast.makeText( - activity, - "Please fill in all fields before booking", - Toast.LENGTH_LONG, - ).show() + Toast + .makeText( + activity, + "Please fill in all fields before booking", + Toast.LENGTH_LONG, + ).show() } else if (!emailEt.text.toString().matches("""\w+@(seas\.|sas\.|wharton\.|nursing\.)?upenn\.edu""".toRegex())) { Toast.makeText(activity, "Please enter a valid Penn email", Toast.LENGTH_LONG).show() } else { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/CampusExpressLoginFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/CampusExpressLoginFragment.kt index 1de2c988..165d0ebc 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/CampusExpressLoginFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/CampusExpressLoginFragment.kt @@ -57,9 +57,7 @@ class CampusExpressLoginFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ): View? { - return inflater.inflate(R.layout.fragment_campus_express_login, container, false) - } + ): View? = inflater.inflate(R.layout.fragment_campus_express_login, container, false) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -86,7 +84,8 @@ class CampusExpressLoginFragment : Fragment() { headerLayout = view.findViewById(R.id.linear_layout) cancelButton = view.findViewById(R.id.cancel_button) val uri = - Uri.parse(campusExpressAuthUrl) + Uri + .parse(campusExpressAuthUrl) .buildUpon() .appendQueryParameter("response_type", "code") .appendQueryParameter("client_id", clientID) @@ -135,7 +134,8 @@ class CampusExpressLoginFragment : Fragment() { private fun goToDiningInsights(refresh: Boolean) { if (refresh) { val fragment = DiningInsightsFragment() - parentFragmentManager.beginTransaction() + parentFragmentManager + .beginTransaction() .replace(R.id.campus_express_page, fragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .addToBackStack(null) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt index 4f445185..b1c98c9d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt @@ -154,13 +154,13 @@ class DiningFragment : Fragment() { // Map each item in the list of venues to a Venue Observable, then map each Venue to a DiningHall Observable try { - mStudentLife.venues() + mStudentLife + .venues() .flatMap { venues -> Observable.from(venues) } .flatMap { venue -> val hall = createHall(venue) Observable.just(hall) - } - .toList() + }.toList() .subscribe({ diningHalls -> mActivity.runOnUiThread { getMenus(diningHalls) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHallWidget.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHallWidget.kt index c68fb431..eb3bee62 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHallWidget.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHallWidget.kt @@ -111,7 +111,8 @@ class DiningHallWidget : AppWidgetProvider() { okHttpClient.setWriteTimeout(35, TimeUnit.SECONDS) // Write timeout val restAdapter = - RestAdapter.Builder() + RestAdapter + .Builder() .setConverter(GsonConverter(gson)) .setClient(OkClient(okHttpClient)) .setEndpoint("https://pennmobile.org/api") diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.kt index 2f3f6eba..b08ece10 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.kt @@ -59,9 +59,7 @@ class DiningInfoFragment : Fragment() { } } - private fun hasMeals(day: VenueInterval): Boolean { - return day.meals.isNotEmpty() - } + private fun hasMeals(day: VenueInterval): Boolean = day.meals.isNotEmpty() private fun addDiningHour( day: VenueInterval, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt index 61ee1fb9..4f9a3dea 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt @@ -75,7 +75,8 @@ class DiningInsightsFragment : Fragment() { val accessToken = networkManager.getAccessToken() if (accessToken == "") { val fragment = CampusExpressLoginFragment() - parentFragmentManager.beginTransaction() + parentFragmentManager + .beginTransaction() .replace(R.id.dining_insights_page, fragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .addToBackStack("DiningInsightsFragment") @@ -112,7 +113,8 @@ class DiningInsightsFragment : Fragment() { if (accessToken == "") { binding.diningInsightsRefresh.isRefreshing = false val fragment = CampusExpressLoginFragment() - parentFragmentManager.beginTransaction() + parentFragmentManager + .beginTransaction() .replace(R.id.dining_insights_page, fragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .addToBackStack("DiningInsightsFragment") diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt index 3e392abb..9e154db0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt @@ -25,7 +25,9 @@ import retrofit.RetrofitError import retrofit.client.Response import rx.Observable -class DiningSettingsFragment(dataModel: HomepageDataModel) : Fragment() { +class DiningSettingsFragment( + dataModel: HomepageDataModel, +) : Fragment() { private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLife private lateinit var halls: List @@ -93,13 +95,13 @@ class DiningSettingsFragment(dataModel: HomepageDataModel) : Fragment() { // Map each item in the list of venues to a Venue Observable, then map each Venue to a DiningHall Observable originalPreferences = dataModel.getDiningHallPrefs() try { - mStudentLife.venues() + mStudentLife + .venues() .flatMap { venues -> Observable.from(venues) } .flatMap { venue -> val hall = DiningFragment.createHall(venue) Observable.just(hall) - } - .toList() + }.toList() .subscribe({ diningHalls -> mActivity.runOnUiThread { halls = diningHalls @@ -162,11 +164,12 @@ class DiningSettingsFragment(dataModel: HomepageDataModel) : Fragment() { override fun failure(error: RetrofitError) { Log.e("Dining", "Error saving dining preferences: $error") - Toast.makeText( - mActivity, - "Error saving dining preferences", - Toast.LENGTH_SHORT, - ).show() + Toast + .makeText( + mActivity, + "Error saving dining preferences", + Toast.LENGTH_SHORT, + ).show() } }, ) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FlingFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FlingFragment.kt index 116afdc2..8a10c15e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FlingFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FlingFragment.kt @@ -58,7 +58,7 @@ class FlingFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ): View? { + ): View { // Inflate the layout for this fragment _binding = FragmentFlingBinding.inflate(inflater, container, false) val view = binding.root @@ -75,13 +75,15 @@ class FlingFragment : Fragment() { }, { activity?.runOnUiThread { - Toast.makeText( - activity, - "Could not retrieve Spring Fling schedule", - Toast.LENGTH_LONG - ).show() + Toast + .makeText( + activity, + "Could not retrieve Spring Fling schedule", + Toast.LENGTH_LONG, + ).show() } - }) + }, + ) } catch (e: Exception) { e.printStackTrace() } @@ -96,8 +98,8 @@ class FlingFragment : Fragment() { override fun onResume() { super.onResume() - val mActivity: MainActivity? = activity as MainActivity - mActivity?.removeTabs() - mActivity?.setTitle(R.string.spring_fling) + val mActivity: MainActivity = activity as MainActivity + mActivity.removeTabs() + mActivity.setTitle(R.string.spring_fling) } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrBuildingHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrBuildingHolder.kt index 77483c68..72a89f5d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrBuildingHolder.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrBuildingHolder.kt @@ -6,7 +6,9 @@ import androidx.recyclerview.widget.RecyclerView import kotlinx.android.synthetic.main.gsr_building.view.gsr_availability_in_building import kotlinx.android.synthetic.main.gsr_building.view.gsr_building_name -class GsrBuildingHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { +class GsrBuildingHolder( + itemView: View, +) : RecyclerView.ViewHolder(itemView) { internal var gsrBuildingName: TextView? = null internal var recyclerView: RecyclerView? = null diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt index 5f87e855..38fe7a43 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt @@ -116,11 +116,12 @@ class GsrFragment : Fragment() { ArrayAdapter(mActivity, R.layout.gsr_spinner_item, arrayOf("30m", "60m", "90m", "120m")) whartonDurationAdapter = ArrayAdapter(mActivity, R.layout.gsr_spinner_item, arrayOf("30m", "60m", "90m")) - biotechDurationAdapter = ArrayAdapter( - mActivity, - R.layout.gsr_spinner_item, - arrayOf("30m", "60m", "90m", "120m", "150m", "180m") - ) + biotechDurationAdapter = + ArrayAdapter( + mActivity, + R.layout.gsr_spinner_item, + arrayOf("30m", "60m", "90m", "120m", "150m", "180m"), + ) // update user status by getting the bearer token and checking wharton status updateStatus() @@ -191,13 +192,14 @@ class GsrFragment : Fragment() { val entryMonth = monthOfYear + 1 // Update year + month + day - selectedDateTime = DateTime( - year, - entryMonth, - dayOfMonth, - selectedDateTime.hourOfDay, - selectedDateTime.minuteOfHour - ) + selectedDateTime = + DateTime( + year, + entryMonth, + dayOfMonth, + selectedDateTime.hourOfDay, + selectedDateTime.minuteOfHour, + ) // Display the selected date; use Joda to do the formatting work selectDateButton.text = selectedDateTime.toString(spinnerDateFormatter) @@ -229,7 +231,7 @@ class GsrFragment : Fragment() { // handle swipe to refresh binding.gsrRefreshLayout.setColorSchemeResources( R.color.color_accent, - R.color.color_primary + R.color.color_primary, ) binding.gsrRefreshLayout.setOnRefreshListener { updateStatus() @@ -247,10 +249,10 @@ class GsrFragment : Fragment() { Toast.makeText(activity, "You are not logged in!", Toast.LENGTH_LONG).show() } else { try { - mStudentLife.isWharton( - "Bearer $bearerToken", - ) - ?.subscribe( + mStudentLife + .isWharton( + "Bearer $bearerToken", + )?.subscribe( { status -> isWharton = status.isWharton }, @@ -299,11 +301,12 @@ class GsrFragment : Fragment() { if (!isWharton && (location == "ARB" || location == "JMHH")) { showNoResults() if (!calledByRefreshLayout) { - Toast.makeText( - activity, - "You need to have a Wharton pennkey to access Wharton GSRs", - Toast.LENGTH_LONG, - ).show() + Toast + .makeText( + activity, + "You need to have a Wharton pennkey to access Wharton GSRs", + Toast.LENGTH_LONG, + ).show() } } else { noResultsPanel.visibility = View.GONE @@ -335,13 +338,13 @@ class GsrFragment : Fragment() { Log.i("GsrFragment", "Wharton Status: $isWharton") try { - mStudentLife.gsrRoom( - "Bearer $bearerToken", - location, - gId, - adjustedDateString, - ) - ?.subscribe( + mStudentLife + .gsrRoom( + "Bearer $bearerToken", + location, + gId, + adjustedDateString, + )?.subscribe( { gsr -> activity?.let { activity -> activity.runOnUiThread { @@ -377,16 +380,16 @@ class GsrFragment : Fragment() { } binding.gsrRoomsList.adapter = ( - context?.let { - GsrBuildingAdapter( - it, - mGSRS, - location, - (durationDropDown.selectedItemPosition + 1) * 30, - sortByTime, - ) - } + context?.let { + GsrBuildingAdapter( + it, + mGSRS, + location, + (durationDropDown.selectedItemPosition + 1) * 30, + sortByTime, ) + } + ) mGSRS = ArrayList() selectDateButton.isClickable = true @@ -477,7 +480,8 @@ class GsrFragment : Fragment() { private fun populateDropDownGSR() { try { - mStudentLife.location() + mStudentLife + .location() ?.subscribe( { locations -> activity?.let { activity -> @@ -581,10 +585,11 @@ class GsrFragment : Fragment() { ) { // change possible durations depending on the location var durationPos = durationDropDown.selectedItemPosition - if (durationPos >= 3 && ( - gsrLocationDropDown.selectedItem.toString() == "Huntsman" || - gsrLocationDropDown.selectedItem.toString() == "Academic Research" - ) + if (durationPos >= 3 && + ( + gsrLocationDropDown.selectedItem.toString() == "Huntsman" || + gsrLocationDropDown.selectedItem.toString() == "Academic Research" + ) ) { durationPos = 2 } else if (durationPos > 3 && gsrLocationDropDown.selectedItem.toString() != "Biotech Commons") { @@ -662,16 +667,17 @@ class GsrFragment : Fragment() { } // can't find existing GSR. Create new object if (!encountered) { - val newGSRObject = GSRContainer( - gsrName, - GSRTimeRange, - GSRStartTime, - GSRElementId, - gid, - roomId, - start, - end - ) + val newGSRObject = + GSRContainer( + gsrName, + GSRTimeRange, + GSRStartTime, + GSRElementId, + gid, + roomId, + start, + end, + ) mGSRS.add(newGSRObject) } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrPagerAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrPagerAdapter.kt index ae194158..c7f4d588 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrPagerAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrPagerAdapter.kt @@ -4,7 +4,9 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter -class GsrPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) { +class GsrPagerAdapter( + fm: FragmentManager, +) : FragmentPagerAdapter(fm) { override fun getItem(position: Int): Fragment { return when (position) { 0 -> { @@ -15,9 +17,7 @@ class GsrPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) { } } - override fun getCount(): Int { - return 2 - } + override fun getCount(): Int = 2 override fun getPageTitle(position: Int): CharSequence { return when (position) { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt index f488bd9d..1157a143 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrRoomHolder.kt @@ -10,7 +10,9 @@ import kotlinx.android.synthetic.main.gsr_room.view.gsr_room import kotlinx.android.synthetic.main.gsr_room.view.gsr_start_time import kotlinx.android.synthetic.main.gsr_room.view.locationId -class GsrRoomHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { +class GsrRoomHolder( + itemView: View, +) : RecyclerView.ViewHolder(itemView) { internal var gsrRoom: LinearLayout = itemView.gsr_room internal var gsrStartTime: TextView = itemView.gsr_start_time internal var gsrEndTime: TextView = itemView.gsr_end_time diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HuntsmanGSRLogin.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HuntsmanGSRLogin.kt index e8340b15..da77f8a2 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HuntsmanGSRLogin.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HuntsmanGSRLogin.kt @@ -139,11 +139,13 @@ class HuntsmanGSRLogin : Fragment() { ) { // Display the output as a toast if (result?.getResults() == true) { - Toast.makeText(mActivity, "GSR successfully booked", Toast.LENGTH_LONG) + Toast + .makeText(mActivity, "GSR successfully booked", Toast.LENGTH_LONG) .show() } else { Log.e("HuntsmanGSRLogin", "GSR booking failed: " + result?.getError()) - Toast.makeText(mActivity, "GSR booking failed", Toast.LENGTH_LONG) + Toast + .makeText(mActivity, "GSR booking failed", Toast.LENGTH_LONG) .show() val sp = PreferenceManager.getDefaultSharedPreferences(mActivity) val editor = sp.edit() @@ -153,7 +155,8 @@ class HuntsmanGSRLogin : Fragment() { // redirect user val gsrFragment = GsrTabbedFragment() val fragmentManager = mActivity.supportFragmentManager - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.content_frame, gsrFragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .commit() @@ -170,7 +173,8 @@ class HuntsmanGSRLogin : Fragment() { // redirect user val gsrFragment = GsrTabbedFragment() val fragmentManager = mActivity.supportFragmentManager - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.content_frame, gsrFragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .commit() diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryBroadcastReceiver.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryBroadcastReceiver.kt index addb3555..d7d0a21a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryBroadcastReceiver.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryBroadcastReceiver.kt @@ -27,7 +27,12 @@ class LaundryBroadcastReceiver : BroadcastReceiver() { } notificationID = id + 1 val builder = StringBuilder() - builder.append("A ").append(machineType).append(" in ").append(roomName).append(" is available!") + builder + .append("A ") + .append(machineType) + .append(" in ") + .append(roomName) + .append(" is available!") val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager // build notification @@ -42,7 +47,8 @@ class LaundryBroadcastReceiver : BroadcastReceiver() { channel.lightColor = ContextCompat.getColor(context, R.color.color_primary) notificationManager.createNotificationChannel(channel) mBuilder = - NotificationCompat.Builder(context, channel.id) + NotificationCompat + .Builder(context, channel.id) .setSmallIcon(R.drawable.ic_bottom_nav_laundry_grey) .setContentTitle(context.getString(R.string.app_name)) .setContentText(builder) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt index 68bbfd2b..871cc00f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt @@ -137,7 +137,8 @@ class LaundryFragment : Fragment() { val bearerToken = "Bearer " + sharedPreferences - .getString(getString(R.string.access_token), "").toString() + .getString(getString(R.string.access_token), "") + .toString() laundryViewModel.getFavorites(mStudentLife, bearerToken) } } @@ -148,7 +149,8 @@ class LaundryFragment : Fragment() { binding.dateView.text = Utils.getCurrentSystemTime() binding.laundryPreferences.setOnClickListener { val fragmentManager = mActivity.supportFragmentManager - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.content_frame, LaundrySettingsFragment()) .addToBackStack("Laundry Settings Fragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt index c96982a1..7bcf49df 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt @@ -104,7 +104,8 @@ class LaundrySettingsFragment : Fragment() { val bearerToken = "Bearer " + sharedPreferences - .getString(getString(R.string.access_token), "").toString() + .getString(getString(R.string.access_token), "") + .toString() laundryViewModel.setFavoritesFromToggled(mStudentLife, bearerToken) } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginFragment.kt index 0037c5fe..b526f3a4 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginFragment.kt @@ -38,33 +38,36 @@ class LoginFragment : Fragment() { val fragmentManager = mActivity.supportFragmentManager val gif = R.drawable.login_background - Glide.with(this).asGif().load(gif).listener( - object : RequestListener { - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: com.bumptech.glide.request.target.Target?, - isFirstResource: Boolean, - ): Boolean { - return false - } + Glide + .with(this) + .asGif() + .load(gif) + .listener( + object : RequestListener { + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: com.bumptech.glide.request.target.Target?, + isFirstResource: Boolean, + ): Boolean = false - override fun onResourceReady( - resource: GifDrawable, - model: Any, - target: com.bumptech.glide.request.target.Target?, - dataSource: DataSource, - isFirstResource: Boolean, - ): Boolean { - resource.setLoopCount(1) - return false - } - }, - ).into(binding.backgroundIv) + override fun onResourceReady( + resource: GifDrawable, + model: Any, + target: com.bumptech.glide.request.target.Target?, + dataSource: DataSource, + isFirstResource: Boolean, + ): Boolean { + resource.setLoopCount(1) + return false + } + }, + ).into(binding.backgroundIv) binding.loginButton.setOnClickListener { val fragment = LoginWebviewFragment() - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.content_frame, fragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .commit() diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt index 8686cb58..fb9f8269 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt @@ -57,9 +57,7 @@ class LoginWebviewFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ): View? { - return inflater.inflate(R.layout.fragment_login_webview, container, false) - } + ): View? = inflater.inflate(R.layout.fragment_login_webview, container, false) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -132,7 +130,8 @@ class LoginWebviewFragment : Fragment() { private fun createSecretKey(): SecretKey? { val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore") keyGenerator.init( - KeyGenParameterSpec.Builder("Key", KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT) + KeyGenParameterSpec + .Builder("Key", KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT) .setBlockModes(KeyProperties.BLOCK_MODE_CBC) .setUserAuthenticationRequired(false) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt index 1d9995d2..e7b1ca4f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt @@ -98,7 +98,11 @@ class MainActivity : AppCompatActivity() { supportActionBar?.setHomeButtonEnabled(false) mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this) - val policy = StrictMode.ThreadPolicy.Builder().permitAll().build() + val policy = + StrictMode.ThreadPolicy + .Builder() + .permitAll() + .build() StrictMode.setThreadPolicy(policy) onExpandableBottomNavigationItemSelected() @@ -194,7 +198,8 @@ class MainActivity : AppCompatActivity() { // change the fragment only if we're not already on the login fragment if (currentFragment == null || currentFragment::class != fragment::class) { fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.content_frame, fragment) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .commit() @@ -245,7 +250,8 @@ class MainActivity : AppCompatActivity() { if (popBackStack) { fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) } - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.content_frame, fragment) .addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_NONE) @@ -272,8 +278,10 @@ class MainActivity : AppCompatActivity() { } override fun setTitle(title: CharSequence) { - appbar.findViewById(R.id.toolbar) - .findViewById(R.id.toolbar_title).text = title + appbar + .findViewById(R.id.toolbar) + .findViewById(R.id.toolbar_title) + .text = title } override fun onBackPressed() { @@ -319,7 +327,8 @@ class MainActivity : AppCompatActivity() { val gsonBuilder = GsonBuilder() val gson = gsonBuilder.create() val restAdapter = - RestAdapter.Builder() + RestAdapter + .Builder() .setConverter(GsonConverter(gson)) .setLogLevel(RestAdapter.LogLevel.FULL) .setLog(AndroidLog("Campus Express")) @@ -337,7 +346,8 @@ class MainActivity : AppCompatActivity() { val gsonBuilder = GsonBuilder() val gson = gsonBuilder.create() val restAdapter = - RestAdapter.Builder() + RestAdapter + .Builder() .setConverter(GsonConverter(gson)) .setLogLevel(RestAdapter.LogLevel.FULL) .setLog(AndroidLog("Platform")) @@ -352,14 +362,16 @@ class MainActivity : AppCompatActivity() { get() { if (mStudentLifeRf2 == null) { val okHttpClient = - OkHttpClient.Builder() + OkHttpClient + .Builder() .connectTimeout(35, TimeUnit.SECONDS) .readTimeout(35, TimeUnit.SECONDS) .writeTimeout(35, TimeUnit.SECONDS) .build() val retrofit = - Retrofit.Builder() + Retrofit + .Builder() .baseUrl("https://pennmobile.org/api/") .client(okHttpClient) .addConverterFactory(ScalarsConverterFactory.create()) @@ -427,7 +439,8 @@ class MainActivity : AppCompatActivity() { okHttpClient.setReadTimeout(35, TimeUnit.SECONDS) // Read timeout okHttpClient.setWriteTimeout(35, TimeUnit.SECONDS) // Write timeout val restAdapter = - RestAdapter.Builder() + RestAdapter + .Builder() .setConverter(GsonConverter(gson)) .setClient(OkClient(okHttpClient)) .setEndpoint("https://pennmobile.org/api") @@ -472,10 +485,12 @@ fun ViewGroup.showSneakerToast( ) { val sneaker = Sneaker.with(this) val view = - LayoutInflater.from(this.context) + LayoutInflater + .from(this.context) .inflate(R.layout.custom_sneaker_view, sneaker.getView(), false) - view.blurView.setupWith(this) + view.blurView + .setupWith(this) .setFrameClearDrawable(ColorDrawable(Color.TRANSPARENT)) .setBlurRadius(10f) .setOverlayColor(resources.getColor(sneakerColor)) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt index 07c90e83..f9e34fd6 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt @@ -22,7 +22,9 @@ class MenuFragment : Fragment() { private lateinit var mActivity: MainActivity private var pageAdapter: PagerAdapter? = null - inner class TabAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) { + inner class TabAdapter( + fm: FragmentManager, + ) : FragmentStatePagerAdapter(fm) { // for each meal: {name of station: arraylist of foods at the station} var foods: ArrayList>> = ArrayList() @@ -77,13 +79,9 @@ class MenuFragment : Fragment() { return myFragment } - override fun getPageTitle(position: Int): CharSequence { - return headers[position] - } + override fun getPageTitle(position: Int): CharSequence = headers[position] - override fun getCount(): Int { - return foods.size - } + override fun getCount(): Int = foods.size } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewsFragment.kt index 19ddf0c0..35249c62 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewsFragment.kt @@ -71,7 +71,12 @@ class NewsFragment : ListFragment() { } } - internal inner class NewsSite(val name: String, val url: String, val description: String, val image: Int) { + internal inner class NewsSite( + val name: String, + val url: String, + val description: String, + val image: Int, + ) { override fun toString() = name } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt index bcc70cc8..36d5d386 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt @@ -87,8 +87,15 @@ class PennCourseAlertCreateAlertFragment : Fragment() { viewModel.userInfo.observe( viewLifecycleOwner, Observer { - val formattedPhoneNumber = viewModel.userInfo.value?.profile?.phone?.drop(2) - val email = viewModel.userInfo.value?.profile?.email + val formattedPhoneNumber = + viewModel.userInfo.value + ?.profile + ?.phone + ?.drop(2) + val email = + viewModel.userInfo.value + ?.profile + ?.email phoneNumberEditText.text = Editable.Factory.getInstance().newEditable(formattedPhoneNumber ?: "") @@ -169,10 +176,13 @@ class PennCourseAlertCreateAlertFragment : Fragment() { }, ) courseListView.onItemClickListener = - OnItemClickListener { _, _, position, _ -> // when item selected from list + OnItemClickListener { _, _, position, _ -> + // when item selected from list // set selected item on textView courseSpinner.text = - courseSpinnerAdapter.getItem(position).toString() + courseSpinnerAdapter + .getItem(position) + .toString() .substringBefore(" -") viewModel.getSections(courseSpinner.text.toString(), sectionSpinnerAdapter) // Dismiss dialog @@ -182,7 +192,8 @@ class PennCourseAlertCreateAlertFragment : Fragment() { sectionSpinner.setOnClickListener { if (sectionSpinnerAdapter.isEmpty) { - Toast.makeText(context, "Select course number first!", Toast.LENGTH_SHORT) + Toast + .makeText(context, "Select course number first!", Toast.LENGTH_SHORT) .show() } else { dialog = Dialog(requireContext()) @@ -230,10 +241,13 @@ class PennCourseAlertCreateAlertFragment : Fragment() { }, ) sectionListView.onItemClickListener = - OnItemClickListener { _, _, position, _ -> // when item selected from list + OnItemClickListener { _, _, position, _ -> + // when item selected from list // set selected item on textView sectionSpinner.text = - sectionSpinnerAdapter.getItem(position).toString() + sectionSpinnerAdapter + .getItem(position) + .toString() .substringBefore(" -") viewModel.selectedSection = sectionSpinnerAdapter.getItem(position)!! viewModel.isSectionSelected = true @@ -246,11 +260,12 @@ class PennCourseAlertCreateAlertFragment : Fragment() { alertButton.setOnClickListener { if (emailEditText.text.isEmpty()) { - Toast.makeText( - context, - "Please enter your email address for alert purposes", - Toast.LENGTH_SHORT, - ).show() + Toast + .makeText( + context, + "Please enter your email address for alert purposes", + Toast.LENGTH_SHORT, + ).show() } else if (phoneNumberEditText.text.isNotEmpty() && !isValidNumber( phoneNumberEditText.text.toString(), @@ -258,21 +273,24 @@ class PennCourseAlertCreateAlertFragment : Fragment() { ) { // If phoneNumberEditText is not empty and the entered number is not valid, // show a toast message - Toast.makeText( - context, - "Please enter a valid US number (or leave the field empty)", - Toast.LENGTH_SHORT, - ).show() + Toast + .makeText( + context, + "Please enter a valid US number (or leave the field empty)", + Toast.LENGTH_SHORT, + ).show() } else { // If email is not empty and phone number (if entered) is valid if (viewModel.isSectionSelected) { // If a course section is selected if (emailEditText.text.toString() != viewModel.userInfo.value - ?.profile?.email || + ?.profile + ?.email || phoneNumberEditText.text.toString() != viewModel.userInfo.value - ?.profile?.phone + ?.profile + ?.phone ) { // If the entered email or phone number is different from the // stored values, update the user info @@ -298,11 +316,12 @@ class PennCourseAlertCreateAlertFragment : Fragment() { viewModel.clearSelectedSection() } else { // If no course section is selected, prompt user to select a section - Toast.makeText( - context, - "Please select a course section", - Toast.LENGTH_SHORT, - ).show() + Toast + .makeText( + context, + "Please select a course section", + Toast.LENGTH_SHORT, + ).show() } } } @@ -311,12 +330,12 @@ class PennCourseAlertCreateAlertFragment : Fragment() { viewLifecycleOwner, Observer { if (it) { - Toast.makeText( - context, - "Registration Created Successfully!", - Toast.LENGTH_SHORT, - ) - .show() + Toast + .makeText( + context, + "Registration Created Successfully!", + Toast.LENGTH_SHORT, + ).show() viewModel.onSuccessToastDone() } }, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt index 44511b5f..296c788c 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt @@ -24,7 +24,9 @@ import com.pennapps.labs.pennmobile.viewmodels.PennCourseAlertViewModel import kotlinx.android.synthetic.main.pca_registration_list_item.notify_closed_switch import kotlinx.android.synthetic.main.pca_registration_list_item.subscribed_switch -class PennCourseAlertManageAlertsFragment : Fragment(), RegistrationsAdapter.OnItemClickListener { +class PennCourseAlertManageAlertsFragment : + Fragment(), + RegistrationsAdapter.OnItemClickListener { private val viewModel: PennCourseAlertViewModel by activityViewModels() private lateinit var recyclerView: RecyclerView private lateinit var adapter: RegistrationsAdapter @@ -123,11 +125,12 @@ class PennCourseAlertManageAlertsFragment : Fragment(), RegistrationsAdapter.OnI alert.cancel() } } else { - Toast.makeText( - context, - "You do not have any registrations yet!", - Toast.LENGTH_SHORT, - ).show() + Toast + .makeText( + context, + "You do not have any registrations yet!", + Toast.LENGTH_SHORT, + ).show() } } swipeRefresh = view.findViewById(R.id.pca_manage_swiperefresh) @@ -169,11 +172,12 @@ class PennCourseAlertManageAlertsFragment : Fragment(), RegistrationsAdapter.OnI viewModel.switchOnClosedNotifications(id, onClosedNotifications) } else { notify_closed_switch.isChecked = false - Toast.makeText( - context, - "Please toggle alert first to perform this action!", - Toast.LENGTH_SHORT, - ).show() + Toast + .makeText( + context, + "Please toggle alert first to perform this action!", + Toast.LENGTH_SHORT, + ).show() } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt index bc85213f..39257746 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt @@ -107,9 +107,7 @@ class PottruckFragment : Fragment() { val sp = PreferenceManager.getDefaultSharedPreferences(mActivity) val context = mActivity.applicationContext val bearerToken = - "Bearer " + - sp.getString(context.getString(R.string.access_token), "") - .toString() + "Bearer " + sp.getString(context.getString(R.string.access_token), "").toString() mStudentLife.getFitnessPreferences(bearerToken).subscribe({ favorites -> mActivity.runOnUiThread { @@ -196,8 +194,8 @@ class PottruckFragment : Fragment() { connectionToolbar.setBackgroundColor( ContextCompat.getColor( requireContext(), - R.color.darkRedBackground - ) + R.color.darkRedBackground, + ), ) connectionMessage.text = getString(R.string.internet_error) connectionToolbar.visibility = View.VISIBLE diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SaveContactsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SaveContactsFragment.kt index ae47f7a0..7d13daaa 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SaveContactsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SaveContactsFragment.kt @@ -106,20 +106,23 @@ class SaveContactsFragment : ListFragment() { val ops = ArrayList() val id = ops.size ops.add( - ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) + ContentProviderOperation + .newInsert(ContactsContract.RawContacts.CONTENT_URI) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null) .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null) .build(), ) ops.add( - ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + ContentProviderOperation + .newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, id) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, p.name) .build(), ) ops.add( - ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + ContentProviderOperation + .newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, id) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, p.phone) @@ -136,11 +139,12 @@ class SaveContactsFragment : ListFragment() { Toast.makeText(mActivity, "Could not save contacts", Toast.LENGTH_SHORT).show() } } - Toast.makeText( - mActivity, - selected.size.toString() + " contact" + (if (selected.size > 1 || selected.size == 0) "s" else "") + " saved", - Toast.LENGTH_SHORT, - ).show() + Toast + .makeText( + mActivity, + selected.size.toString() + " contact" + (if (selected.size > 1 || selected.size == 0) "s" else "") + " saved", + Toast.LENGTH_SHORT, + ).show() mActivity.onBackPressed() } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SupportFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SupportFragment.kt index 97b17637..ee0435e6 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SupportFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/SupportFragment.kt @@ -68,7 +68,8 @@ class SupportFragment : ListFragment() { R.id.support_contacts_add -> { val frag = SaveContactsFragment() val fragmentManager = mActivity.supportFragmentManager - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.save_contacts_fragment, frag, "SAVE_CONTACTS_FRAGMENT") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .addToBackStack(null) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt index 1218d5fd..c4a9e42d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/AboutAdapter.kt @@ -9,8 +9,9 @@ import com.pennapps.labs.pennmobile.R import kotlinx.android.synthetic.main.team_member.view.name_tv import kotlinx.android.synthetic.main.team_member.view.person_iv -class AboutAdapter(private var members: ArrayList) : - RecyclerView.Adapter() { +class AboutAdapter( + private var members: ArrayList, +) : RecyclerView.Adapter() { private lateinit var mContext: Context override fun onCreateViewHolder( @@ -22,9 +23,7 @@ class AboutAdapter(private var members: ArrayList) : return TeamViewHolder(view) } - override fun getItemCount(): Int { - return members.count() - } + override fun getItemCount(): Int = members.count() override fun onBindViewHolder( holder: TeamViewHolder, @@ -55,7 +54,9 @@ class AboutAdapter(private var members: ArrayList) : if (imageId != null) holder.view.person_iv?.setImageResource(imageId) } - inner class TeamViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class TeamViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { val view = itemView } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt index ce403754..3449ca25 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningAdapter.kt @@ -29,7 +29,9 @@ import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_status import rx.android.schedulers.AndroidSchedulers import java.util.Collections -class DiningAdapter(private var diningHalls: List) : RecyclerView.Adapter() { +class DiningAdapter( + private var diningHalls: List, +) : RecyclerView.Adapter() { private lateinit var mStudentLife: StudentLife private lateinit var loaded: BooleanArray private lateinit var sortBy: String @@ -62,7 +64,12 @@ class DiningAdapter(private var diningHalls: List) : RecyclerView.Ad holder.hallNameTV?.text = diningHall.name holder.hallNameTV?.isSelected = true - Picasso.get().load(diningHall.image).fit().centerCrop().into(holder.hallImage) + Picasso + .get() + .load(diningHall.image) + .fit() + .centerCrop() + .into(holder.hallImage) if (diningHall.isOpen) { holder.hallStatus?.background = ContextCompat.getDrawable(context, R.drawable.label_green) @@ -84,7 +91,8 @@ class DiningAdapter(private var diningHalls: List) : RecyclerView.Ad if (diningHall.isResidential && !loaded[position]) { holder.progressBar?.visibility = View.VISIBLE try { - mStudentLife.daily_menu(diningHall.id) + mStudentLife + .daily_menu(diningHall.id) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ newDiningHall -> diningHall.sortMeals(newDiningHall.menus) @@ -111,7 +119,8 @@ class DiningAdapter(private var diningHalls: List) : RecyclerView.Ad fragment.arguments = args val fragmentManager = mainActivity.supportFragmentManager - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.content_frame, fragment, "DINING_INFO_FRAGMENT") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .addToBackStack(null) @@ -121,8 +130,8 @@ class DiningAdapter(private var diningHalls: List) : RecyclerView.Ad } // Converts the String representation of a meal name to its corresponding resource ID - private fun getOpenStatusLabel(openMeal: String): Int { - return when (openMeal) { + private fun getOpenStatusLabel(openMeal: String): Int = + when (openMeal) { "Breakfast" -> R.string.dining_hall_breakfast "Brunch" -> R.string.dining_hall_brunch "Lunch" -> R.string.dining_hall_lunch @@ -130,11 +139,8 @@ class DiningAdapter(private var diningHalls: List) : RecyclerView.Ad "Late Night" -> R.string.dining_hall_late_night else -> R.string.dining_hall_open } - } - override fun getItemCount(): Int { - return diningHalls.size - } + override fun getItemCount(): Int = diningHalls.size private inner class MenuComparator : Comparator { override fun compare( @@ -168,7 +174,9 @@ class DiningAdapter(private var diningHalls: List) : RecyclerView.Ad } } - class DiningViewHolder(view: View) : RecyclerView.ViewHolder(view) { + class DiningViewHolder( + view: View, + ) : RecyclerView.ViewHolder(view) { val layout: ConstraintLayout? = view.dining_list_item_layout val hallNameTV: TextView? = view.item_dining_name val hallStatus: TextView? = view.item_dining_status diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningCardAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningCardAdapter.kt index 9f1b43cd..d1028443 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningCardAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningCardAdapter.kt @@ -26,7 +26,9 @@ import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_name import kotlinx.android.synthetic.main.dining_list_item.view.item_dining_status import rx.android.schedulers.AndroidSchedulers -class DiningCardAdapter(halls: ArrayList) : RecyclerView.Adapter() { +class DiningCardAdapter( + halls: ArrayList, +) : RecyclerView.Adapter() { private var favoriteHalls: ArrayList = halls private lateinit var itemImage: ImageView private lateinit var itemName: TextView @@ -42,7 +44,12 @@ class DiningCardAdapter(halls: ArrayList) : RecyclerView.Adapter) : RecyclerView.Adapter currentHall.sortMeals(newDiningHall.menus) @@ -85,7 +93,8 @@ class DiningCardAdapter(halls: ArrayList) : RecyclerView.Adapter) : RecyclerView.Adapter) : RecyclerView.Adapter R.string.dining_hall_breakfast "Brunch" -> R.string.dining_hall_brunch "Lunch" -> R.string.dining_hall_lunch @@ -120,9 +127,10 @@ class DiningCardAdapter(halls: ArrayList) : RecyclerView.Adapter R.string.dining_hall_late_night else -> R.string.dining_hall_open } - } - inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class ViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { init { itemImage = itemView.item_dining_image itemName = itemView.item_dining_name diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningHallWidgetAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningHallWidgetAdapter.kt index 925e3aa4..4dd10a38 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningHallWidgetAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningHallWidgetAdapter.kt @@ -19,9 +19,7 @@ import rx.Observable // https://programmer.group/app-widgets-details-four-remoteviews-remoteviews-service-and-remoteviews-factory.html class DiningHallWidgetAdapter : RemoteViewsService() { - override fun onGetViewFactory(p0: Intent): RemoteViewsFactory { - return DiningWidgetFactory(applicationContext, p0) - } + override fun onGetViewFactory(p0: Intent): RemoteViewsFactory = DiningWidgetFactory(applicationContext, p0) // The appwidget RemoteViewsFactory updates the data on the appwidget by: // 1. onUpdate automatically called every 30 minutes (in DiningHallWidget class) @@ -29,7 +27,10 @@ class DiningHallWidgetAdapter : RemoteViewsService() { // 3. In onCreate, the function getWidgetDiningHalls is called // 4. getWidgetDiningHall makes a network request to update diningHall data and calls notifyAppWidgetViewDataChanged, which then calls // getViewAt() and updates the UI of the widget). - class DiningWidgetFactory(private val context: Context, intent: Intent) : RemoteViewsFactory { + class DiningWidgetFactory( + private val context: Context, + intent: Intent, + ) : RemoteViewsFactory { private var mDiningRequest: DiningRequest? = null private var appWidgetId: Int = intent.getIntExtra( @@ -56,9 +57,7 @@ class DiningHallWidgetAdapter : RemoteViewsService() { override fun onDestroy() { } - override fun getCount(): Int { - return dataSet.size - } + override fun getCount(): Int = dataSet.size override fun getViewAt(position: Int): RemoteViews { val views = RemoteViews(context.packageName, R.layout.dining_hall_widget_item) @@ -98,32 +97,24 @@ class DiningHallWidgetAdapter : RemoteViewsService() { return views } - override fun getLoadingView(): RemoteViews? { - return null - } + override fun getLoadingView(): RemoteViews? = null - override fun getViewTypeCount(): Int { - return 1 - } + override fun getViewTypeCount(): Int = 1 - override fun getItemId(position: Int): Long { - return position.toLong() - } + override fun getItemId(position: Int): Long = position.toLong() - override fun hasStableIds(): Boolean { - return true - } + override fun hasStableIds(): Boolean = true private fun getWidgetDiningHalls() { try { if (mDiningRequest != null) { - mDiningRequest!!.venues() + mDiningRequest!! + .venues() .flatMap { venues -> Observable.from(venues) } .flatMap { venue -> val hall = createHall(venue) Observable.just(hall) - } - .toList() + }.toList() .subscribe { diningHalls -> dataSet = diningHalls val appWidgetManager: AppWidgetManager = @@ -137,8 +128,8 @@ class DiningHallWidgetAdapter : RemoteViewsService() { } } - private fun getOpenStatusLabel(openMeal: String): Int { - return when (openMeal) { + private fun getOpenStatusLabel(openMeal: String): Int = + when (openMeal) { "Breakfast" -> R.string.dining_hall_breakfast "Brunch" -> R.string.dining_hall_brunch "Lunch" -> R.string.dining_hall_lunch @@ -146,7 +137,6 @@ class DiningHallWidgetAdapter : RemoteViewsService() { "Late Night" -> R.string.dining_hall_late_night else -> R.string.dining_hall_open } - } companion object { fun createHall(venue: Venue): DiningHall { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningInsightsCardAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningInsightsCardAdapter.kt index 6881efd2..40c498d6 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningInsightsCardAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningInsightsCardAdapter.kt @@ -33,8 +33,9 @@ import java.util.Locale import kotlin.collections.ArrayList import kotlin.math.roundToInt -class DiningInsightsCardAdapter(private var cells: ArrayList) : - RecyclerView.Adapter() { +class DiningInsightsCardAdapter( + private var cells: ArrayList, +) : RecyclerView.Adapter() { private lateinit var mContext: Context private lateinit var mActivity: MainActivity @@ -93,11 +94,11 @@ class DiningInsightsCardAdapter(private var cells: ArrayList) } } - override fun getItemCount(): Int { - return cells.size - } + override fun getItemCount(): Int = cells.size - inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class ViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { val view = itemView } @@ -255,13 +256,12 @@ class DiningInsightsCardAdapter(private var cells: ArrayList) tvGuestSwipesAmount.text = guestSwipes.toString() } - private fun getPredictionSlope(amounts: List): Float { - return if (amounts.size <= 1) { + private fun getPredictionSlope(amounts: List): Float = + if (amounts.size <= 1) { 0f } else { (amounts[amounts.size - 1] - amounts[0]) / (amounts.size - 1) } - } private fun setData( amounts: List, @@ -397,8 +397,9 @@ class DiningInsightsCardAdapter(private var cells: ArrayList) return Utils.addDaysToDateMMMdd(START_DAY_OF_SEMESTER, actualValuesSize + i) } - class ClaimsXAxisValueFormatter(var datesList: List) : - ValueFormatter() { + class ClaimsXAxisValueFormatter( + var datesList: List, + ) : ValueFormatter() { override fun getAxisLabel( value: Float, axis: AxisBase, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningPagerAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningPagerAdapter.kt index ac574676..d220b0c3 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningPagerAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningPagerAdapter.kt @@ -7,18 +7,18 @@ import androidx.viewpager2.adapter.FragmentStateAdapter import com.pennapps.labs.pennmobile.DiningFragment import com.pennapps.labs.pennmobile.DiningInsightsFragment -class DiningPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle?) : FragmentStateAdapter(fragmentManager, lifecycle!!) { - override fun createFragment(position: Int): Fragment { - return if (position == 0) { +class DiningPagerAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle?, +) : FragmentStateAdapter(fragmentManager, lifecycle!!) { + override fun createFragment(position: Int): Fragment = + if (position == 0) { DiningFragment() } else { DiningInsightsFragment() } - } - override fun getItemCount(): Int { - return COUNT - } + override fun getItemCount(): Int = COUNT override fun getItemId(position: Int): Long { if (position == HOME_POSITION) { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningSettingsAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningSettingsAdapter.kt index c9ffc577..84df0b3b 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningSettingsAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningSettingsAdapter.kt @@ -13,8 +13,9 @@ import com.pennapps.labs.pennmobile.classes.DiningHall import kotlinx.android.synthetic.main.laundry_settings_child_item.view.laundry_favorite_switch import kotlinx.android.synthetic.main.laundry_settings_child_item.view.laundry_room_name -class DiningSettingsAdapter(private var diningHalls: List) : - RecyclerView.Adapter() { +class DiningSettingsAdapter( + private var diningHalls: List, +) : RecyclerView.Adapter() { private lateinit var mContext: Context private lateinit var sp: SharedPreferences @@ -28,9 +29,7 @@ class DiningSettingsAdapter(private var diningHalls: List) : return DiningSettingsViewHolder(view) } - override fun getItemCount(): Int { - return diningHalls.count() - } + override fun getItemCount(): Int = diningHalls.count() override fun onBindViewHolder( holder: DiningSettingsViewHolder, @@ -51,7 +50,9 @@ class DiningSettingsAdapter(private var diningHalls: List) : } } - inner class DiningSettingsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class DiningSettingsViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { val view = itemView } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessAdapter.kt index ede7f8bf..c87b5c50 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessAdapter.kt @@ -41,13 +41,17 @@ import java.time.LocalTime import java.time.ZonedDateTime import java.time.format.DateTimeFormatter -class FitnessAdapter(private val isFavorite: Boolean, private val dataModel: FitnessAdapterDataModel) : - RecyclerView.Adapter() { +class FitnessAdapter( + private val isFavorite: Boolean, + private val dataModel: FitnessAdapterDataModel, +) : RecyclerView.Adapter() { private lateinit var mActivity: Activity private lateinit var mContext: Context private lateinit var mStudentLife: StudentLife - class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) { + class ViewHolder( + val view: View, + ) : RecyclerView.ViewHolder(view) { val mainView: ConstraintLayout = view.findViewById(R.id.fitness_list_info_layout) val roomView: TextView = view.findViewById(R.id.item_fitness_name) val statusView: TextView = view.findViewById(R.id.item_fitness_status) @@ -177,7 +181,8 @@ class FitnessAdapter(private val isFavorite: Boolean, private val dataModel: Fit view.visibility = View.VISIBLE view.alpha = 0.0f - view.animate() + view + .animate() .alpha(1.0f) val rotate = @@ -223,7 +228,8 @@ class FitnessAdapter(private val isFavorite: Boolean, private val dataModel: Fit mStudentLife = MainActivity.studentLifeInstance val view = - LayoutInflater.from(parent.context) + LayoutInflater + .from(parent.context) .inflate(R.layout.fitness_list_item, parent, false) return ViewHolder(view) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessHeaderAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessHeaderAdapter.kt index 2baf7707..428d6e0a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessHeaderAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessHeaderAdapter.kt @@ -7,8 +7,12 @@ import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.R -class FitnessHeaderAdapter(private val text: String) : RecyclerView.Adapter() { - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { +class FitnessHeaderAdapter( + private val text: String, +) : RecyclerView.Adapter() { + class ViewHolder( + view: View, + ) : RecyclerView.ViewHolder(view) { val headerView: TextView init { @@ -21,15 +25,14 @@ class FitnessHeaderAdapter(private val text: String) : RecyclerView.Adapter() { - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { +class FitnessPreferenceAdapter( + private val dataModel: FitnessAdapterDataModel, +) : RecyclerView.Adapter() { + class ViewHolder( + view: View, + ) : RecyclerView.ViewHolder(view) { val v: View val imv: ImageView val textView: TextView @@ -28,15 +31,14 @@ class FitnessPreferenceAdapter(private val dataModel: FitnessAdapterDataModel) : viewType: Int, ): ViewHolder { val view = - LayoutInflater.from(parent.context) + LayoutInflater + .from(parent.context) .inflate(R.layout.fitness_preference_list_item, parent, false) return ViewHolder(view) } - override fun getItemCount(): Int { - return dataModel.getTot() - } + override fun getItemCount(): Int = dataModel.getTot() override fun onBindViewHolder( holder: ViewHolder, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt index 314725f7..408e7e62 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FlingRecyclerViewAdapter.kt @@ -24,9 +24,7 @@ class FlingRecyclerViewAdapter( ) : RecyclerView.Adapter() { private val timeFormatter: DateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis() - override fun getItemCount(): Int { - return sampleData.size - } + override fun getItemCount(): Int = sampleData.size override fun onCreateViewHolder( parent: ViewGroup, @@ -60,7 +58,9 @@ class FlingRecyclerViewAdapter( } } - class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + class ViewHolder( + view: View, + ) : RecyclerView.ViewHolder(view) { internal var flingviewImage: ImageView? = view.flingview_image internal var flingviewName: TextView? = view.flingview_name internal var flingviewDescription: TextView? = view.flingview_description diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt index 92d77b63..5f6a07ec 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt @@ -22,7 +22,8 @@ class GsrBuildingAdapter( viewType: Int, ): GsrBuildingHolder { val view = - LayoutInflater.from(parent.context) + LayoutInflater + .from(parent.context) .inflate(R.layout.gsr_building, parent, false) return GsrBuildingHolder(view) } @@ -110,7 +111,5 @@ class GsrBuildingAdapter( } } - override fun getItemCount(): Int { - return gsrs.size - } + override fun getItemCount(): Int = gsrs.size } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt index 6a6dedc0..9d31dd12 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrReservationsAdapter.kt @@ -26,8 +26,9 @@ import retrofit.ResponseCallback import retrofit.RetrofitError import retrofit.client.Response -class GsrReservationsAdapter(private var reservations: ArrayList) : - RecyclerView.Adapter() { +class GsrReservationsAdapter( + private var reservations: ArrayList, +) : RecyclerView.Adapter() { private lateinit var mContext: Context override fun onCreateViewHolder( @@ -56,7 +57,12 @@ class GsrReservationsAdapter(private var reservations: ArrayList // huntsman reservation responses don't have an image url so we set it here val imageUrl = reservation.info?.get("thumbnail") ?: "https://s3.us-east-2.amazonaws.com/labs.api/dining/MBA+Cafe.jpg" - Picasso.get().load(imageUrl).fit().centerCrop().into(holder.itemView.gsr_reservation_iv) + Picasso + .get() + .load(imageUrl) + .fit() + .centerCrop() + .into(holder.itemView.gsr_reservation_iv) holder.itemView.gsr_reservation_location_tv.text = roomName holder.itemView.gsr_reservation_date_tv.text = day + "\n" + fromHour + "-" + toHour @@ -99,7 +105,8 @@ class GsrReservationsAdapter(private var reservations: ArrayList run { if (reservations.size == 0) { var intent = Intent("refresh") - LocalBroadcastManager.getInstance(mContext) + LocalBroadcastManager + .getInstance(mContext) .sendBroadcast(intent) } else { notifyItemRemoved(position) @@ -113,11 +120,12 @@ class GsrReservationsAdapter(private var reservations: ArrayList "Error canceling gsr reservation", error, ) - Toast.makeText( - mContext, - "Error deleting your GSR reservation.", - LENGTH_SHORT, - ).show() + Toast + .makeText( + mContext, + "Error deleting your GSR reservation.", + LENGTH_SHORT, + ).show() } }, ) @@ -133,11 +141,11 @@ class GsrReservationsAdapter(private var reservations: ArrayList } } - override fun getItemCount(): Int { - return reservations.size - } + override fun getItemCount(): Int = reservations.size - inner class GsrReservationViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class GsrReservationViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { val view = itemView } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt index ab4c9b99..6c82f8b0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrRoomAdapter.kt @@ -51,7 +51,8 @@ class GsrRoomAdapter( roomName, ) val fragmentManager = (context as MainActivity).supportFragmentManager - fragmentManager.beginTransaction() + fragmentManager + .beginTransaction() .replace(R.id.content_frame, bookGsrFragment) .addToBackStack("GSR Fragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) @@ -74,7 +75,5 @@ class GsrRoomAdapter( } } - override fun getItemCount(): Int { - return timeRanges.size - } + override fun getItemCount(): Int = timeRanges.size } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt index 445decb1..d13d24c5 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeAdapter.kt @@ -89,8 +89,9 @@ import retrofit.RetrofitError import retrofit.client.Response import rx.Observable -class HomeAdapter(private val dataModel: HomepageDataModel) : - RecyclerView.Adapter() { +class HomeAdapter( + private val dataModel: HomepageDataModel, +) : RecyclerView.Adapter() { private lateinit var mContext: Context private lateinit var mActivity: MainActivity private lateinit var mStudentLife: StudentLife @@ -129,19 +130,19 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : return when (viewType) { NEWS -> { ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_news_card, parent, false) + LayoutInflater.from(mContext).inflate(R.layout.home_news_card, parent, false), ) } POST -> { ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_post_card, parent, false) + LayoutInflater.from(mContext).inflate(R.layout.home_post_card, parent, false), ) } FEATURE -> { ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_post_card, parent, false) + LayoutInflater.from(mContext).inflate(R.layout.home_post_card, parent, false), ) } @@ -151,19 +152,19 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : GSR_BOOKING -> { ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_gsr_card, parent, false) + LayoutInflater.from(mContext).inflate(R.layout.home_gsr_card, parent, false), ) } NOT_SUPPORTED -> { ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.empty_view, parent, false) + LayoutInflater.from(mContext).inflate(R.layout.empty_view, parent, false), ) } else -> { ViewHolder( - LayoutInflater.from(mContext).inflate(R.layout.home_base_card, parent, false) + LayoutInflater.from(mContext).inflate(R.layout.home_base_card, parent, false), ) } } @@ -187,11 +188,11 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : } } - override fun getItemCount(): Int { - return dataModel.getSize() - } + override fun getItemCount(): Int = dataModel.getSize() - inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class ViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { val view = itemView } @@ -219,20 +220,21 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : holder.itemView.home_card_subtitle.text = "DINING HALLS" holder.itemView.dining_prefs_btn.visibility = View.VISIBLE holder.itemView.dining_prefs_btn.setOnClickListener { - mActivity.supportFragmentManager.beginTransaction() + mActivity.supportFragmentManager + .beginTransaction() .replace(R.id.content_frame, DiningSettingsFragment(dataModel)) .addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .commit() } try { - mStudentLife.venues() + mStudentLife + .venues() .flatMap { venues -> Observable.from(venues) } .flatMap { venue -> val hall = DiningFragment.createHall(venue) Observable.just(hall) - } - .toList() + }.toList() .subscribe { diningHalls -> mActivity.runOnUiThread { val favorites: ArrayList = arrayListOf() @@ -266,7 +268,9 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : holder.itemView.home_news_subtitle.text = article?.subtitle holder.itemView.home_news_timestamp.text = article?.timestamp?.trim() - Glide.with(mContext).load(article?.imageUrl) + Glide + .with(mContext) + .load(article?.imageUrl) .fitCenter() .centerCrop() .into(holder.itemView.home_news_iv) @@ -274,7 +278,13 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : /** Adds dynamically generated accent color from the fetched image to the news card */ var accentColor: Int = getColor(mContext, R.color.black) mActivity.lifecycleScope.launch(Dispatchers.Default) { - val bitmap = Glide.with(mContext).load(article?.imageUrl).submit().get().toBitmap() + val bitmap = + Glide + .with(mContext) + .load(article?.imageUrl) + .submit() + .get() + .toBitmap() // Create palette from bitmap fun createPaletteSync(bitmap: Bitmap): Palette = Palette.from(bitmap).generate() @@ -290,22 +300,22 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : ) DrawableCompat.setTint( DrawableCompat.wrap(holder.itemView.news_info_icon.drawable), - it + it, ) DrawableCompat.setTint( DrawableCompat.wrap(holder.itemView.dot_divider.drawable), - it + it, ) holder.itemView.button.setTextColor(ColorUtils.setAlphaComponent(it, 150)) DrawableCompat.setTint( DrawableCompat.wrap(holder.itemView.button.background), - it + it, ) holder.itemView.home_news_title.setTextColor( ColorUtils.setAlphaComponent( it, - 150 - ) + 150, + ), ) holder.itemView.home_news_subtitle.setTextColor(it) holder.itemView.home_news_timestamp.setTextColor(it) @@ -343,7 +353,8 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : } /** Sets up blur view on news card */ - holder.itemView.blurView.setupWith(holder.itemView.news_card_container) + holder.itemView.blurView + .setupWith(holder.itemView.news_card_container) .setFrameClearDrawable(ColorDrawable(getColor(mContext, R.color.white))) .setBlurRadius(25f) @@ -469,18 +480,26 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : holder.itemView.home_post_source.text = "Penn Labs" // post?.clubCode?.capitalize() val time = post.startDate?.substring(5, 7) + " / " + - post.startDate?.substring(8, 10) + " - " + - post.expireDate?.substring(5, 7) + " / " + - post.expireDate?.substring(8, 10) + post.startDate?.substring(8, 10) + " - " + + post.expireDate?.substring(5, 7) + " / " + + post.expireDate?.substring(8, 10) holder.itemView.home_post_timestamp.text = time - Glide.with(mContext).load(post.imageUrl) + Glide + .with(mContext) + .load(post.imageUrl) .fitCenter() .centerCrop() .into(holder.itemView.home_post_iv) /** Adds dynamically generated accent color from the fetched image to the news card */ var accentColor: Int = getColor(mContext, R.color.black) mActivity.lifecycleScope.launch(Dispatchers.Default) { - val bitmap = Glide.with(mContext).load(post.imageUrl).submit().get().toBitmap() + val bitmap = + Glide + .with(mContext) + .load(post.imageUrl) + .submit() + .get() + .toBitmap() // Create palette from bitmap fun createPaletteSync(bitmap: Bitmap): Palette = Palette.from(bitmap).generate() @@ -516,7 +535,8 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : } } /** Sets up blur view on post card */ - holder.itemView.postBlurView.setupWith(holder.itemView.post_card_container) + holder.itemView.postBlurView + .setupWith(holder.itemView.post_card_container) .setFrameClearDrawable(ColorDrawable(getColor(mContext, R.color.white))) .setBlurRadius(25f) /** Post clicking logic if there exists a URL **/ @@ -585,11 +605,12 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : var isSelected = false poll.options.forEach { isSelected = isSelected || it.selected } if (!isSelected) { - Toast.makeText( - mActivity, - "Need to select an option to vote", - Toast.LENGTH_SHORT, - ).show() + Toast + .makeText( + mActivity, + "Need to select an option to vote", + Toast.LENGTH_SHORT, + ).show() return@setOnClickListener } poll.isVisible = true @@ -627,7 +648,6 @@ class HomeAdapter(private val dataModel: HomepageDataModel) : } catch (e: Exception) { e.printStackTrace() } - } } } else { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt index 620385f8..d9e6b1c6 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrBuildingAdapter.kt @@ -15,8 +15,9 @@ import com.pennapps.labs.pennmobile.R import kotlinx.android.synthetic.main.home_gsr_building.view.home_gsr_building_iv import kotlinx.android.synthetic.main.home_gsr_building.view.home_gsr_building_tv -class HomeGsrBuildingAdapter(private var buildings: ArrayList) : - RecyclerView.Adapter() { +class HomeGsrBuildingAdapter( + private var buildings: ArrayList, +) : RecyclerView.Adapter() { private lateinit var mContext: Context override fun onCreateViewHolder( @@ -46,11 +47,11 @@ class HomeGsrBuildingAdapter(private var buildings: ArrayList) : } } - override fun getItemCount(): Int { - return buildings.size - } + override fun getItemCount(): Int = buildings.size - inner class HomeGsrBuildingViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class HomeGsrBuildingViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { val view = itemView } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt index 60cc9223..29a72509 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt @@ -19,7 +19,9 @@ import kotlinx.android.synthetic.main.gsr_list_item.view.item_gsr_location import org.joda.time.format.DateTimeFormat import org.joda.time.format.DateTimeFormatter -class HomeGsrReservationAdapter(reservations: List) : RecyclerView.Adapter() { +class HomeGsrReservationAdapter( + reservations: List, +) : RecyclerView.Adapter() { private var activeReservations: List = reservations private lateinit var itemImage: ImageView @@ -44,7 +46,12 @@ class HomeGsrReservationAdapter(reservations: List) : RecyclerVi val toHour = to.toString("h:mm a") val imageUrl = currentReservation.info?.get("thumbnail") ?: "https://s3.us-east-2.amazonaws.com/labs.api/dining/MBA+Cafe.jpg" - Picasso.get().load(imageUrl).fit().centerCrop().into(holder.itemView.item_gsr_image) + Picasso + .get() + .load(imageUrl) + .fit() + .centerCrop() + .into(holder.itemView.item_gsr_image) holder.itemView.item_gsr_location.text = location holder.itemView.item_gsr_date.text = day + "\n" + fromHour + "-" + toHour @@ -62,9 +69,7 @@ class HomeGsrReservationAdapter(reservations: List) : RecyclerVi } } - override fun getItemCount(): Int { - return activeReservations.size - } + override fun getItemCount(): Int = activeReservations.size override fun onCreateViewHolder( parent: ViewGroup, @@ -78,7 +83,9 @@ class HomeGsrReservationAdapter(reservations: List) : RecyclerVi return ViewHolder(view) } - inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class ViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { init { itemImage = itemView.item_gsr_image itemLocation = itemView.item_gsr_location diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundryMachineAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundryMachineAdapter.kt index 2038008b..08cc23d0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundryMachineAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundryMachineAdapter.kt @@ -108,13 +108,15 @@ class LaundryMachineAdapter( } } - override fun getItemCount(): Int { - return mMachineDetails.size - } - - inner class CustomViewHolder(view: View, var context: Context, var machineDetails: List) : RecyclerView.ViewHolder( - view, - ) { + override fun getItemCount(): Int = mMachineDetails.size + + inner class CustomViewHolder( + view: View, + var context: Context, + var machineDetails: List, + ) : RecyclerView.ViewHolder( + view, + ) { var machineView: ImageView? = view.laundry_machine_image_view var timeTextView: TextView? = view.min_left_time var notificationBell: LottieAnimationView = view.bell_notification_icon diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundrySettingsAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundrySettingsAdapter.kt index ee843b1e..281844ed 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundrySettingsAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/LaundrySettingsAdapter.kt @@ -26,39 +26,25 @@ class LaundrySettingsAdapter( dataModel.setToggled() } - override fun getGroupCount(): Int { - return dataModel.getGroupCount() - } + override fun getGroupCount(): Int = dataModel.getGroupCount() - override fun getChildrenCount(i: Int): Int { - return dataModel.getChildrenCount(i) - } + override fun getChildrenCount(i: Int): Int = dataModel.getChildrenCount(i) - override fun getGroup(i: Int): Any { - return dataModel.getGroup(i) - } + override fun getGroup(i: Int): Any = dataModel.getGroup(i) override fun getChild( i: Int, i1: Int, - ): Any { - return dataModel.getChild(i, i1) - } + ): Any = dataModel.getChild(i, i1) - override fun getGroupId(i: Int): Long { - return i.toLong() - } + override fun getGroupId(i: Int): Long = i.toLong() override fun getChildId( i: Int, i1: Int, - ): Long { - return i1.toLong() - } + ): Long = i1.toLong() - override fun hasStableIds(): Boolean { - return false - } + override fun hasStableIds(): Boolean = false // view for the laundry buildings override fun getGroupView( @@ -163,9 +149,7 @@ class LaundrySettingsAdapter( override fun isChildSelectable( i: Int, i1: Int, - ): Boolean { - return false - } + ): Boolean = false private fun updateSwitches() { if (dataModel.isFull()) { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/MainPagerAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/MainPagerAdapter.kt index 193ee43a..d90d8bac 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/MainPagerAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/MainPagerAdapter.kt @@ -10,9 +10,12 @@ import com.pennapps.labs.pennmobile.HomeFragment import com.pennapps.labs.pennmobile.LaundryFragment import com.pennapps.labs.pennmobile.morefragments.MoreFragment -class MainPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle?) : FragmentStateAdapter(fragmentManager, lifecycle!!) { - override fun createFragment(position: Int): Fragment { - return when (position) { +class MainPagerAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle?, +) : FragmentStateAdapter(fragmentManager, lifecycle!!) { + override fun createFragment(position: Int): Fragment = + when (position) { HOME_POSITION -> HomeFragment() DINING_POSITION -> DiningHolderFragment() GSR_POSITION -> GsrTabbedFragment() @@ -20,15 +23,10 @@ class MainPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle?) MORE_POSITION -> MoreFragment() else -> HomeFragment() } - } - override fun getItemCount(): Int { - return COUNT - } + override fun getItemCount(): Int = COUNT - override fun getItemId(position: Int): Long { - return if (position < COUNT) position.toLong() else createFragment(position).hashCode().toLong() - } + override fun getItemId(position: Int): Long = if (position < COUNT) position.toLong() else createFragment(position).hashCode().toLong() companion object { const val HOME_POSITION = 0 diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PennCourseAlertPagerAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PennCourseAlertPagerAdapter.kt index 3e709c61..8055c154 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PennCourseAlertPagerAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PennCourseAlertPagerAdapter.kt @@ -5,18 +5,17 @@ import androidx.viewpager2.adapter.FragmentStateAdapter import com.pennapps.labs.pennmobile.PennCourseAlertCreateAlertFragment import com.pennapps.labs.pennmobile.PennCourseAlertManageAlertsFragment -class PennCourseAlertPagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) { - override fun getItemCount(): Int { - return COUNT - } +class PennCourseAlertPagerAdapter( + fragment: Fragment, +) : FragmentStateAdapter(fragment) { + override fun getItemCount(): Int = COUNT - override fun createFragment(position: Int): Fragment { - return if (position == CREATE_ALERT_POSITION) { + override fun createFragment(position: Int): Fragment = + if (position == CREATE_ALERT_POSITION) { PennCourseAlertCreateAlertFragment() } else { PennCourseAlertManageAlertsFragment() } - } companion object { private const val CREATE_ALERT_POSITION = 0 diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PhoneSaveAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PhoneSaveAdapter.kt index bc44156a..b34c9ec3 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PhoneSaveAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PhoneSaveAdapter.kt @@ -12,11 +12,16 @@ import kotlinx.android.synthetic.main.phone_save_list_item.view.support_name import kotlinx.android.synthetic.main.phone_save_list_item.view.support_phone import kotlinx.android.synthetic.main.phone_save_list_item.view.support_phone_icon -class PhoneSaveAdapter(context: Context, contacts: List, s: MutableList, size: Int) : ArrayAdapter( - context, - R.layout.phone_save_list_item, - contacts, -) { +class PhoneSaveAdapter( + context: Context, + contacts: List, + s: MutableList, + size: Int, +) : ArrayAdapter( + context, + R.layout.phone_save_list_item, + contacts, + ) { private val inflater: LayoutInflater = LayoutInflater.from(context) private val selections: MutableList = s private val state: BooleanArray = BooleanArray(size) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt index 67865603..7ef1f488 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/PollOptionAdapter.kt @@ -40,17 +40,15 @@ class PollOptionAdapter( bindPollOption(holder, pollOption) } - override fun getItemCount(): Int { - return pollOptions.size - } + override fun getItemCount(): Int = pollOptions.size - inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class ViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { val view = itemView } - override fun getItemViewType(position: Int): Int { - return 0 - } + override fun getItemViewType(position: Int): Int = 0 private fun bindPollOption( holder: ViewHolder, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/RegistrationsAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/RegistrationsAdapter.kt index 33cb1134..bf4a1ac8 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/RegistrationsAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/RegistrationsAdapter.kt @@ -13,8 +13,9 @@ import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.PennCourseAlertRegistration -class RegistrationsAdapter(private val listener: OnItemClickListener) : - ListAdapter< +class RegistrationsAdapter( + private val listener: OnItemClickListener, +) : ListAdapter< PennCourseAlertRegistration, RegistrationsAdapter.ViewHolder, >(RegistrationDiffCallBack()) { @@ -38,8 +39,9 @@ class RegistrationsAdapter(private val listener: OnItemClickListener) : holder.bindTo(getItem(position)) } - inner class ViewHolder(registrationView: View) : - RecyclerView.ViewHolder(registrationView), + inner class ViewHolder( + registrationView: View, + ) : RecyclerView.ViewHolder(registrationView), View.OnClickListener { var courseIdText: TextView var isOpenText: TextView @@ -121,7 +123,8 @@ class RegistrationsAdapter(private val listener: OnItemClickListener) : private fun formatDate(date: String): String { val formattedDate = "Last Notified " - return formattedDate.plus(date.slice(5..6)) + return formattedDate + .plus(date.slice(5..6)) .plus("/") .plus(date.slice(8..9)) .plus("/") diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SupportAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SupportAdapter.kt index 91530e7e..6a3015bc 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SupportAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/SupportAdapter.kt @@ -13,7 +13,10 @@ import kotlinx.android.synthetic.main.support_list_item.view.support_name import kotlinx.android.synthetic.main.support_list_item.view.support_phone import kotlinx.android.synthetic.main.support_list_item.view.support_phone_icon -class SupportAdapter(context: Context, contacts: List) : ArrayAdapter(context, R.layout.support_list_item, contacts) { +class SupportAdapter( + context: Context, + contacts: List, +) : ArrayAdapter(context, R.layout.support_list_item, contacts) { private val inflater: LayoutInflater = LayoutInflater.from(context) override fun getView( diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt index a56a9452..738c21b1 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/UniversityEventAdapter.kt @@ -12,8 +12,9 @@ import com.pennapps.labs.pennmobile.classes.CalendarEvent import kotlinx.android.synthetic.main.university_event.view.event_month import kotlinx.android.synthetic.main.university_event.view.event_name_tv -class UniversityEventAdapter(private var events: ArrayList) : - RecyclerView.Adapter() { +class UniversityEventAdapter( + private var events: ArrayList, +) : RecyclerView.Adapter() { private lateinit var mContext: Context override fun onCreateViewHolder( @@ -54,11 +55,11 @@ class UniversityEventAdapter(private var events: ArrayList) : }*/ } - override fun getItemCount(): Int { - return events.size - } + override fun getItemCount(): Int = events.size - inner class UniversityEventViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + inner class UniversityEventViewHolder( + itemView: View, + ) : RecyclerView.ViewHolder(itemView) { val view = itemView } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/CampusExpressNetworkManager.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/CampusExpressNetworkManager.kt index 586ca85f..9fc49778 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/CampusExpressNetworkManager.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/CampusExpressNetworkManager.kt @@ -6,7 +6,9 @@ import com.pennapps.labs.pennmobile.R import java.util.Calendar import java.util.Date -class CampusExpressNetworkManager(private var mActivity: MainActivity) { +class CampusExpressNetworkManager( + private var mActivity: MainActivity, +) { private val sp = PreferenceManager.getDefaultSharedPreferences(mActivity) val editor = sp?.edit() diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt index b495e3fc..6690a1c1 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/OAuth2NetworkManager.kt @@ -15,7 +15,9 @@ import retrofit.RetrofitError import retrofit.client.Response import java.util.Calendar -class OAuth2NetworkManager(private var mActivity: MainActivity) { +class OAuth2NetworkManager( + private var mActivity: MainActivity, +) { private var mStudentLife = MainActivity.studentLifeInstance private val sp = PreferenceManager.getDefaultSharedPreferences(mActivity) val editor = sp?.edit() diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/PennCourseAlertApiService.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/PennCourseAlertApiService.kt index fcd76bb3..b06b5dc5 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/PennCourseAlertApiService.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/api/PennCourseAlertApiService.kt @@ -25,14 +25,16 @@ import java.util.concurrent.TimeUnit private const val BASE_URL = "https://penncoursealert.com" var okHttpClient: OkHttpClient = - OkHttpClient.Builder() + OkHttpClient + .Builder() .connectTimeout(1, TimeUnit.MINUTES) .readTimeout(30, TimeUnit.SECONDS) .writeTimeout(15, TimeUnit.SECONDS) .build() private val retrofit = - Retrofit.Builder() + Retrofit + .Builder() .client(okHttpClient) .addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/AppWidgetAlarm.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/AppWidgetAlarm.kt index c5d494db..053db955 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/AppWidgetAlarm.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/AppWidgetAlarm.kt @@ -8,7 +8,9 @@ import com.pennapps.labs.pennmobile.DiningHallWidget import java.util.Calendar // An AlarmManager for app widget testing (Shortens the update time) -class AppWidgetAlarm(private val mContext: Context) { +class AppWidgetAlarm( + private val mContext: Context, +) { val alarmId: Int = 0 val internalMillis: Int = 100000 diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Article.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Article.kt index e9b68c62..1f3e3641 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Article.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Article.kt @@ -33,8 +33,8 @@ class Article { @Expose val articleUrl: String? = null - override fun equals(other: Any?): Boolean { - return when (other) { + override fun equals(other: Any?): Boolean = + when (other) { is Article -> { this.imageUrl == other.imageUrl && this.source == other.source && @@ -44,7 +44,6 @@ class Article { this.articleUrl == other.articleUrl } else -> false } - } override fun hashCode(): Int { // lazy hash function but we don't use this method anyways diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/CalendarCell.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/CalendarCell.kt index 377be5d2..f4c62cf6 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/CalendarCell.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/CalendarCell.kt @@ -1,6 +1,8 @@ package com.pennapps.labs.pennmobile.classes -data class CalendarCell(val events: List) : HomeCell() { +data class CalendarCell( + val events: List, +) : HomeCell() { init { type = "calendar" } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/CalendarEvent.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/CalendarEvent.kt index 12985ba6..74220822 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/CalendarEvent.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/CalendarEvent.kt @@ -12,13 +12,12 @@ class CalendarEvent { @Expose var date: String? = null - override fun equals(other: Any?): Boolean { - return when (other) { + override fun equals(other: Any?): Boolean = + when (other) { is CalendarEvent -> { this.name == other.name && this.date == other.date } else -> false } - } override fun hashCode(): Int { // lazy hash function but we don't use this method anyways diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Course.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Course.kt index 2e08b205..86882475 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Course.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Course.kt @@ -24,7 +24,5 @@ data class Course( @SerializedName("instructor_quality") val instructorQuality: Double = 0.0, ) { - override fun toString(): String { - return this.id + " - " + this.title - } + override fun toString(): String = this.id + " - " + this.title } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningCell.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningCell.kt index 494ba717..c40259f9 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningCell.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningCell.kt @@ -1,6 +1,8 @@ package com.pennapps.labs.pennmobile.classes -data class DiningCell(val venues: List) : HomeCell() { +data class DiningCell( + val venues: List, +) : HomeCell() { init { type = "dining" } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningHall.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningHall.kt index 4ccd0555..d669caa0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningHall.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningHall.kt @@ -54,9 +54,7 @@ open class DiningHall : Parcelable { this.menus.sortedWith(comparator) } - override fun describeContents(): Int { - return 0 - } + override fun describeContents(): Int = 0 override fun writeToParcel( dest: Parcel, @@ -121,8 +119,8 @@ open class DiningHall : Parcelable { return builder.toString() } - private fun getFormattedTime(time: DateTime): String { - return if (time.toString("mm") == "00") { + private fun getFormattedTime(time: DateTime): String = + if (time.toString("mm") == "00") { if (isResidential) { time.toString("h") } else { @@ -135,7 +133,6 @@ open class DiningHall : Parcelable { time.toString("h:mm a") } } - } val isOpen: Boolean get() { @@ -161,7 +158,9 @@ open class DiningHall : Parcelable { * Created by Adel on 12/18/14. * Class for a single menu, ie. Lunch, Dinner */ - open class Menu protected constructor(`in`: Parcel) : Parcelable { + open class Menu protected constructor( + `in`: Parcel, + ) : Parcelable { @SerializedName("service") var name: String = `in`.readString() ?: "" @@ -171,9 +170,7 @@ open class DiningHall : Parcelable { @SerializedName("venue") var venue: DiningVenue? = null - override fun describeContents(): Int { - return 0 - } + override fun describeContents(): Int = 0 override fun writeToParcel( dest: Parcel, @@ -183,13 +180,9 @@ open class DiningHall : Parcelable { } companion object CREATOR : Parcelable.Creator { - override fun createFromParcel(`in`: Parcel): Menu? { - return Menu(`in`) - } + override fun createFromParcel(`in`: Parcel): Menu? = Menu(`in`) - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } + override fun newArray(size: Int): Array = arrayOfNulls(size) } } @@ -223,12 +216,8 @@ open class DiningHall : Parcelable { } companion object CREATOR : Parcelable.Creator { - override fun createFromParcel(parcel: Parcel): DiningHall { - return DiningHall(parcel) - } + override fun createFromParcel(parcel: Parcel): DiningHall = DiningHall(parcel) - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } + override fun newArray(size: Int): Array = arrayOfNulls(size) } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningMarkerView.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningMarkerView.kt index e4f0e97e..5e07d974 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningMarkerView.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningMarkerView.kt @@ -12,7 +12,10 @@ import com.pennapps.labs.pennmobile.adapters.DiningInsightsCardAdapter import java.text.SimpleDateFormat import kotlin.math.roundToInt -class DiningMarkerView(context: Context, layoutResource: Int) : MarkerView(context, layoutResource) { +class DiningMarkerView( + context: Context, + layoutResource: Int, +) : MarkerView(context, layoutResource) { companion object { private const val DINING_DOLLARS_PREDICTIONS = 2 private const val DINING_SWIPES_PREDICTIONS = 3 @@ -63,7 +66,5 @@ class DiningMarkerView(context: Context, layoutResource: Int) : MarkerView(conte } // This is used to reposition the marker - override fun getOffset(): MPPointF { - return MPPointF(0.0F, (-height / 6).toFloat()) - } + override fun getOffset(): MPPointF = MPPointF(0.0F, (-height / 6).toFloat()) } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningRequest.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningRequest.kt index 2a2afc35..91f12192 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningRequest.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningRequest.kt @@ -1,5 +1,7 @@ package com.pennapps.labs.pennmobile.classes -class DiningRequest(favoriteDiningHalls: ArrayList) { +class DiningRequest( + favoriteDiningHalls: ArrayList, +) { var venues: ArrayList = favoriteDiningHalls } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessPreferenceViewModel.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessPreferenceViewModel.kt index 1b7490de..e22117fa 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessPreferenceViewModel.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessPreferenceViewModel.kt @@ -48,17 +48,11 @@ class FitnessPreferenceViewModel( return roomList[positionMap[position + favoriteRooms.size]] } - override fun getTot(): Int { - return roomTot - } + override fun getTot(): Int = roomTot - override fun getRoomAll(roomId: Int): FitnessRoom { - return roomList[roomId] - } + override fun getRoomAll(roomId: Int): FitnessRoom = roomList[roomId] - override fun isFavorite(roomId: Int): Boolean { - return favoriteRooms.contains(roomId) - } + override fun isFavorite(roomId: Int): Boolean = favoriteRooms.contains(roomId) fun clearFavorites() { favoriteRooms.clear() @@ -112,7 +106,7 @@ class FitnessPreferenceViewModel( Log.e( "Fitness Preference View Model", "Error saving fitness " + - "preferences: $error", + "preferences: $error", error, ) } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessRequest.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessRequest.kt index ba9cfb6c..de1b9969 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessRequest.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessRequest.kt @@ -1,5 +1,7 @@ package com.pennapps.labs.pennmobile.classes -class FitnessRequest(favoriteFitnessRooms: ArrayList) { +class FitnessRequest( + favoriteFitnessRooms: ArrayList, +) { var rooms: ArrayList = favoriteFitnessRooms } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRBookingResult.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRBookingResult.kt index a165a9dd..ed8efeb8 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRBookingResult.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRBookingResult.kt @@ -16,15 +16,9 @@ class GSRBookingResult { @Expose private val error: String? = null - fun getDetail(): String? { - return detail - } + fun getDetail(): String? = detail - fun getResults(): Boolean? { - return results - } + fun getResults(): Boolean? = results - fun getError(): String? { - return error - } + fun getError(): String? = error } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRCell.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRCell.kt index 776e9470..69feba67 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRCell.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRCell.kt @@ -1,6 +1,8 @@ package com.pennapps.labs.pennmobile.classes -data class GSRCell(val reservations: List) : HomeCell() { +data class GSRCell( + val reservations: List, +) : HomeCell() { init { type = "gsr_booking" } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRReservation.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRReservation.kt index fa720cb8..1f38faf7 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRReservation.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRReservation.kt @@ -38,11 +38,14 @@ class GSRReservation { @JvmField var info: Map? = null - override fun equals(other: Any?): Boolean { - return other is GSRReservation && this.bookingId == other.bookingId && this.name == other.name && - this.fromDate == other.fromDate && this.toDate == other.toDate && this.gid == other.gid && + override fun equals(other: Any?): Boolean = + other is GSRReservation && + this.bookingId == other.bookingId && + this.name == other.name && + this.fromDate == other.fromDate && + this.toDate == other.toDate && + this.gid == other.gid && this.lid == other.lid - } override fun hashCode(): Int { var result = (bookingId?.hashCode() ?: 0) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/HomepageViewModel.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/HomepageViewModel.kt index b0f8169c..8ac8515e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/HomepageViewModel.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/HomepageViewModel.kt @@ -23,7 +23,9 @@ import java.util.concurrent.CountDownLatch * posts) have finished loaded. */ -class HomepageViewModel : HomepageDataModel, ViewModel() { +class HomepageViewModel : + ViewModel(), + HomepageDataModel { companion object { private const val NUM_CELLS = 7 private const val NUM_CELLS_LOGGED_IN = NUM_CELLS @@ -47,7 +49,9 @@ class HomepageViewModel : HomepageDataModel, ViewModel() { private val homepageCells = mutableListOf() private val cellMutex = Mutex() - data class ItemUpdateEvents(val positions: List = emptyList()) + data class ItemUpdateEvents( + val positions: List = emptyList(), + ) private val _updateState = MutableStateFlow(ItemUpdateEvents()) val updateState: StateFlow = _updateState.asStateFlow() @@ -421,9 +425,7 @@ class HomepageViewModel : HomepageDataModel, ViewModel() { * Since homepageCells is always populated, it should always have NUM_CELLS cells. The idea is * that we keep the unused cells empty. */ - override fun getSize(): Int { - return NUM_CELLS - } + override fun getSize(): Int = NUM_CELLS override fun getCell(position: Int): HomeCell { // be careful to not read an old value diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/LaundryCell.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/LaundryCell.kt index e74c8aa8..f44690b9 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/LaundryCell.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/LaundryCell.kt @@ -1,6 +1,8 @@ package com.pennapps.labs.pennmobile.classes -data class LaundryCell(val roomId: Int) : HomeCell() { +data class LaundryCell( + val roomId: Int, +) : HomeCell() { init { type = "laundry" } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/MachineDetail.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/MachineDetail.kt index d662f64b..8bff87b6 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/MachineDetail.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/MachineDetail.kt @@ -24,11 +24,10 @@ class MachineDetail : Comparable { @Expose val type: String? = null - override fun compareTo(machineDetail: MachineDetail): Int { - return when { + override fun compareTo(machineDetail: MachineDetail): Int = + when { (timeRemaining == machineDetail.timeRemaining) -> 0 (timeRemaining > machineDetail.timeRemaining) -> 1 else -> -1 } - } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/NewsCell.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/NewsCell.kt index 452c5362..47c2bf7c 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/NewsCell.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/NewsCell.kt @@ -1,6 +1,8 @@ package com.pennapps.labs.pennmobile.classes -data class NewsCell(val article: Article) : HomeCell() { +data class NewsCell( + val article: Article, +) : HomeCell() { init { type = "news" } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Poll.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Poll.kt index 31f1137a..17b52b14 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Poll.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Poll.kt @@ -54,11 +54,14 @@ class Poll { @Expose var isVisible: Boolean = false - override fun equals(other: Any?): Boolean { - return other is Poll && this.id == other.id && this.totalVotes == other.totalVotes && - this.question == other.question && this.options.size == other.options.size && - this.options.containsAll(other.options) && other.options.containsAll(this.options) - } + override fun equals(other: Any?): Boolean = + other is Poll && + this.id == other.id && + this.totalVotes == other.totalVotes && + this.question == other.question && + this.options.size == other.options.size && + this.options.containsAll(other.options) && + other.options.containsAll(this.options) // @Expose // var homeAdapter : HomeAdapter? = null diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollCell.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollCell.kt index 1645913f..c259874a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollCell.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollCell.kt @@ -1,6 +1,8 @@ package com.pennapps.labs.pennmobile.classes -class PollCell(poll: Poll) : HomeCell() { +class PollCell( + poll: Poll, +) : HomeCell() { var poll: Poll init { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollOption.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollOption.kt index de60f4d3..755ad029 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollOption.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollOption.kt @@ -24,10 +24,11 @@ class PollOption { var isVisible: Boolean = false - override fun equals(other: Any?): Boolean { - return other is PollOption && this.choice == other.choice && this.id == other.id && + override fun equals(other: Any?): Boolean = + other is PollOption && + this.choice == other.choice && + this.id == other.id && this.voteCount == other.voteCount - } override fun hashCode(): Int { var result = id ?: 0 diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Post.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Post.kt index 9c6b2256..323fcbc4 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Post.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Post.kt @@ -64,10 +64,9 @@ class Post { @Expose internal val targetPopulations: List? = null - override fun toString(): String { - return id.toString() + ", " + + override fun toString(): String = + id.toString() + ", " + clubCode + "" - } override fun equals(other: Any?): Boolean { // note: targetPopulations is not included because it's unused and structural diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PostCell.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PostCell.kt index 46f10578..7ecab6ee 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PostCell.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PostCell.kt @@ -1,6 +1,8 @@ package com.pennapps.labs.pennmobile.classes -data class PostCell(val post: Post) : HomeCell() { +data class PostCell( + val post: Post, +) : HomeCell() { init { type = "post" } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Venue.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Venue.kt index e2b3b59e..e7d7767a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Venue.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Venue.kt @@ -50,11 +50,7 @@ class Venue { return intervals } - fun allHours(): List { - return hours - } + fun allHours(): List = hours - fun getExtras(): List? { - return extras - } + fun getExtras(): List? = extras } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableBottomBar.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableBottomBar.kt index 294ee5c2..52b400e4 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableBottomBar.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableBottomBar.kt @@ -113,25 +113,29 @@ class ExpandableBottomBar itemInactiveColor = typedArray.getColor(R.styleable.ExpandableBottomBar_exb_itemInactiveColor, Color.BLACK) menuItemHorizontalMargin = - typedArray.getDimension( - R.styleable.ExpandableBottomBar_exb_item_horizontal_margin, - 5F.toPx(), - ).toInt() + typedArray + .getDimension( + R.styleable.ExpandableBottomBar_exb_item_horizontal_margin, + 5F.toPx(), + ).toInt() menuItemVerticalMargin = - typedArray.getDimension( - R.styleable.ExpandableBottomBar_exb_item_vertical_margin, - 5F.toPx(), - ).toInt() + typedArray + .getDimension( + R.styleable.ExpandableBottomBar_exb_item_vertical_margin, + 5F.toPx(), + ).toInt() menuHorizontalPadding = - typedArray.getDimension( - R.styleable.ExpandableBottomBar_exb_item_horizontal_padding, - 15F.toPx(), - ).toInt() + typedArray + .getDimension( + R.styleable.ExpandableBottomBar_exb_item_horizontal_padding, + 15F.toPx(), + ).toInt() menuVerticalPadding = - typedArray.getDimension( - R.styleable.ExpandableBottomBar_exb_item_vertical_padding, - 10F.toPx(), - ).toInt() + typedArray + .getDimension( + R.styleable.ExpandableBottomBar_exb_item_vertical_padding, + 10F.toPx(), + ).toInt() val backgroundColor = typedArray.getColor(R.styleable.ExpandableBottomBar_exb_backgroundColor, Color.WHITE) @@ -264,7 +268,8 @@ class ExpandableBottomBar val selectedStateColorList = ColorStateList(backgroundStates, colors) val viewController = - ExpandableItemViewController.Builder(menuItem) + ExpandableItemViewController + .Builder(menuItem) .itemMargins(menuHorizontalPadding, menuVerticalPadding) .itemBackground(backgroundCornerRadius, backgroundOpacity) .itemsColors(selectedStateColorList) @@ -275,8 +280,7 @@ class ExpandableBottomBar } else { onItemReselectedListener?.invoke(v, menuItem) } - } - .build(context) + }.build(context) if (selectedItemId == menuItem.itemId) { viewController.select() @@ -317,7 +321,8 @@ class ExpandableBottomBar val selectedItemId = state.selectedItem val viewController = expandableBottomBar - .viewControllers.getValue(selectedItemId) + .viewControllers + .getValue(selectedItemId) expandableBottomBar.onItemSelected(viewController.menuItem) } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableBottomBarMenuItem.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableBottomBarMenuItem.kt index a132e9c5..e2afdded 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableBottomBarMenuItem.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableBottomBarMenuItem.kt @@ -18,7 +18,10 @@ data class ExpandableBottomBarMenuItem( val text: CharSequence, @ColorInt val activeColor: Int, ) { - class ItemBuildRequest internal constructor(private val builder: Builder, private val context: Context) { + class ItemBuildRequest internal constructor( + private val builder: Builder, + private val context: Context, + ) { @IdRes private var itemId: Int = 0 @@ -87,7 +90,9 @@ data class ExpandableBottomBarMenuItem( /** * Class-helper to create expandable bottom bar menu items */ - class Builder(private val context: Context) { + class Builder( + private val context: Context, + ) { internal val items = mutableListOf() fun addItem() = ItemBuildRequest(this, context) @@ -102,7 +107,12 @@ data class ExpandableBottomBarMenuItem( @DrawableRes iconId: Int, @StringRes textId: Int, @ColorInt activeColor: Int, - ) = ItemBuildRequest(this, context).id(itemId).icon(iconId).textRes(textId).color(activeColor).create() + ) = ItemBuildRequest(this, context) + .id(itemId) + .icon(iconId) + .textRes(textId) + .color(activeColor) + .create() fun build(): List = items } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableItemViewController.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableItemViewController.kt index fb4fddc2..3932789a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableItemViewController.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/ExpandableItemViewController.kt @@ -81,13 +81,12 @@ internal open class ExpandableItemViewController( } @VisibleForTesting - internal open fun createHighlightedMenuShape(): Drawable { - return DrawableHelper.createShapeDrawable( + internal open fun createHighlightedMenuShape(): Drawable = + DrawableHelper.createShapeDrawable( menuItem.activeColor, backgroundCornerRadius, backgroundOpacity, ) - } fun attachTo( parent: ConstraintLayout, @@ -144,7 +143,9 @@ internal open class ExpandableItemViewController( cl.applyTo(parent) } - class Builder(private val menuItem: ExpandableBottomBarMenuItem) { + class Builder( + private val menuItem: ExpandableBottomBarMenuItem, + ) { @Px private var itemVerticalPadding: Int = 0 @@ -237,31 +238,34 @@ internal open class ExpandableItemViewController( } val itemLayoutParams = - LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT, - ).apply { - gravity = Gravity.CENTER - setMargins(0, 0, 0, 0) - } + LinearLayout + .LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT, + ).apply { + gravity = Gravity.CENTER + setMargins(0, 0, 0, 0) + } val textLayoutParams = - LinearLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT, - ).apply { - gravity = Gravity.CENTER - setMargins(0, 24, 0, 12) - } + LinearLayout + .LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT, + ).apply { + gravity = Gravity.CENTER + setMargins(0, 24, 0, 12) + } val indicatorLayoutParams = - LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT, - ).apply { - gravity = Gravity.CENTER - setMargins(0, 0, 0, 0) - } + LinearLayout + .LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT, + ).apply { + gravity = Gravity.CENTER + setMargins(0, 0, 0, 0) + } val imageView = ImageView(context).apply { @@ -289,13 +293,14 @@ internal open class ExpandableItemViewController( } val highlightLayoutParams = - FrameLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT, - Gravity.BOTTOM, - ).apply { - setMargins(0, 0, 0, 0) - } + FrameLayout + .LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT, + Gravity.BOTTOM, + ).apply { + setMargins(0, 0, 0, 0) + } val frameView = FrameLayout(context).apply { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/behavior/ExpandableBottomBarScrollableBehavior.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/behavior/ExpandableBottomBarScrollableBehavior.kt index b65940d3..e0ec103c 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/behavior/ExpandableBottomBarScrollableBehavior.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/behavior/ExpandableBottomBarScrollableBehavior.kt @@ -10,8 +10,7 @@ import com.pennapps.labs.pennmobile.components.floatingbottombar.utils.clamp class ExpandableBottomBarScrollableBehavior( context: Context, attributeSet: AttributeSet, -) : - ExpandableBottomBarBehavior(context, attributeSet) { +) : ExpandableBottomBarBehavior(context, attributeSet) { override fun onStartNestedScroll( coordinatorLayout: CoordinatorLayout, child: V, @@ -19,9 +18,7 @@ class ExpandableBottomBarScrollableBehavior( target: View, axes: Int, type: Int, - ): Boolean { - return axes == ViewCompat.SCROLL_AXIS_VERTICAL - } + ): Boolean = axes == ViewCompat.SCROLL_AXIS_VERTICAL override fun onNestedPreScroll( coordinatorLayout: CoordinatorLayout, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/parsers/ExpandableBottomBarParser.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/parsers/ExpandableBottomBarParser.kt index 775a5dcd..bf2c0c2d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/parsers/ExpandableBottomBarParser.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/parsers/ExpandableBottomBarParser.kt @@ -8,7 +8,9 @@ import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.components.floatingbottombar.ExpandableBottomBarMenuItem import org.xmlpull.v1.XmlPullParser -internal class ExpandableBottomBarParser(private val context: Context) { +internal class ExpandableBottomBarParser( + private val context: Context, +) { companion object { private const val NO_ID = 0 private const val NO_TEXT = "" diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/utils/Dimens.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/utils/Dimens.kt index 39ea8b8f..2ab0e34d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/utils/Dimens.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/utils/Dimens.kt @@ -11,13 +11,13 @@ import androidx.annotation.Px * @return value in pixels */ @Px -internal fun Int.toPx(): Int { - return TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, - this.toFloat(), - Resources.getSystem().displayMetrics, - ).toInt() -} +internal fun Int.toPx(): Int = + TypedValue + .applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + this.toFloat(), + Resources.getSystem().displayMetrics, + ).toInt() /** * Converts values to its real pixel size @@ -25,10 +25,9 @@ internal fun Int.toPx(): Int { * * @return value in pixels */ -internal fun Float.toPx(): Float { - return TypedValue.applyDimension( +internal fun Float.toPx(): Float = + TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics, ) -} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/utils/MathHelper.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/utils/MathHelper.kt index 6137b250..da1cfab2 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/utils/MathHelper.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/floatingbottombar/utils/MathHelper.kt @@ -4,9 +4,7 @@ internal fun > clamp( value: T, min: T, max: T, -): T { - return max(min, min(value, max)) -} +): T = max(min, min(value, max)) internal fun > max( value1: T, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/Sneaker.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/Sneaker.kt index 2856a36d..d4bc23b8 100755 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/Sneaker.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/Sneaker.kt @@ -1,556 +1,556 @@ -package com.pennapps.labs.pennmobile.components.sneaker - -import android.app.Activity -import android.content.Context -import android.graphics.Color -import android.graphics.Typeface -import android.graphics.drawable.Drawable -import android.os.Build -import android.os.Handler -import android.view.Gravity -import android.view.View -import android.view.ViewGroup -import android.view.animation.AnimationUtils -import android.widget.LinearLayout -import androidx.annotation.DrawableRes -import androidx.coordinatorlayout.widget.CoordinatorLayout -import androidx.core.content.ContextCompat -import androidx.fragment.app.Fragment -import androidx.lifecycle.LifecycleObserver -import com.google.android.material.appbar.AppBarLayout -import com.pennapps.labs.pennmobile.R -import com.pennapps.labs.pennmobile.components.sneaker.intf.OnSneakerClickListener -import com.pennapps.labs.pennmobile.components.sneaker.intf.OnSneakerDismissListener - -/** - * Sneaker is a third party replacement for android's native toasts. - * Original project can be found here: https://github.com/Hamadakram/Sneaker - * Created by Hammad Akram on 5/24/2017. - * - * Modified for PennMobile by Davies Lumumba on 7/25/2020 - * */ -class Sneaker(private var context: Context) : View.OnClickListener, LifecycleObserver { - private val defaultValue = -100000 - private var mIconDrawable: Drawable? = null - private var mBackgroundColor = defaultValue - private var mHeight = defaultValue - private var mIconColorFilterColor = defaultValue - private var mIconSize = 24 - private var mTitle = "" - private var mMessage = "" - private var mTitleColor = defaultValue - private var mMessageColor = defaultValue - private var mAutoHide = true - private var mDuration = 3000 - private var mIsCircular = false - private var mListener: OnSneakerClickListener? = null - private var mDismissListener: OnSneakerDismissListener? = null - private var mTypeFace: Typeface? = null - private var mCornerRadius = defaultValue - private var mMargin = defaultValue - private var targetView: ViewGroup? = null - private var isActivity: Boolean = false - private val sneakerView by lazy { SneakerView(context) } - - companion object { - /** - * Create Sneaker instance - * - * @param activity - * @return Sneaker instance - */ - @JvmStatic - fun with(activity: Activity): Sneaker { - return Sneaker(activity).also { - it.setTargetView(activity) - } - } - - /** - * Create Sneaker instance - * - * @param fragment - * @return Sneaker instance - */ - @JvmStatic - fun with(fragment: Fragment): Sneaker { - return Sneaker(fragment.requireContext()).also { - it.setTargetView(fragment) - } - } - - /** - * Create Sneaker instance - * - * @param viewGroup - * @return Sneaker instance - */ - @JvmStatic - fun with(viewGroup: ViewGroup): Sneaker { - return Sneaker(viewGroup.context).also { - it.setTargetView(viewGroup) - } - } - } - - private fun setTargetView(targetView: Any) { - this.targetView = - when (targetView) { - is Activity -> { - isActivity = true - targetView.window?.decorView as ViewGroup - } - is Fragment -> targetView.view as ViewGroup - is ViewGroup -> targetView - else -> null - } - } - - /** - * Hides the sneaker - */ - fun hide() { - removeView(sneakerView) - mDismissListener?.onDismiss() - } - - /** - * Sets the title of the sneaker - * - * @param title string value of title - * @return - */ - fun setTitle(title: String): Sneaker { - mTitle = title - return this.also { mTitle = title } - } - - /** - * Sets the title of the sneaker with color - * - * @param title string value of title - * @param color Color resource for title text - * @return - */ - fun setTitle( - title: String, - color: Int, - ): Sneaker { - mTitle = title - mTitleColor = - try { - ContextCompat.getColor(context, color) - } catch (e: Exception) { - color - } - return this - } - - /** - * Sets the message to sneaker - * - * @param message String value of message - * @return - */ - fun setMessage(message: String): Sneaker { - mMessage = message - return this - } - - /** - * Sets the message to sneaker with color - * - * @param message String value of message - * @param color Color resource for message text - * @return - */ - fun setMessage( - message: String, - color: Int, - ): Sneaker { - mMessage = message - mMessageColor = - try { - ContextCompat.getColor(context, color) - } catch (e: Exception) { - color - } - return this - } - - /** - * Sets the icon to sneaker - * - * @param icon Icon resource for sneaker - * @return - */ - fun setIcon( - @DrawableRes icon: Int, - ): Sneaker { - setIcon(icon, defaultValue, false) - return this - } - - /** - * Sets the icon to sneaker - * - * @param icon Icon drawable for sneaker - * @return - */ - fun setIcon(icon: Drawable): Sneaker { - setIcon(icon, defaultValue, false) - return this - } - - /** - * Sets the icon to sneaker with circular option - * - * @param icon - * @param isCircular If icon is round or not - * @return - */ - fun setIcon( - @DrawableRes icon: Int, - isCircular: Boolean, - ): Sneaker { - setIcon(icon, defaultValue, isCircular) - return this - } - - /** - * Sets the icon to sneaker with circular option - * - * @param icon - * @param isCircular If icon is round or not - * @return - */ - fun setIcon( - icon: Drawable, - isCircular: Boolean, - ): Sneaker { - setIcon(icon, defaultValue, isCircular) - return this - } - - fun setIcon( - @DrawableRes icon: Int, - tintColor: Int, - ): Sneaker { - setIcon(icon, tintColor, false) - return this - } - - fun setIcon( - icon: Drawable, - tintColor: Int, - ): Sneaker { - setIcon(icon, tintColor, false) - return this - } - - /** - * Sets the icon to sneaker with circular option and icon tint - * - * @param icon - * @param tintColor Icon tint color - * @param isCircular If icon is round or not - * @return - */ - fun setIcon( - @DrawableRes icon: Int, - tintColor: Int, - isCircular: Boolean, - ): Sneaker { - mIconDrawable = ContextCompat.getDrawable(context, icon) - mIsCircular = isCircular - mIconColorFilterColor = Utils.getColor(context, tintColor) - return this - } - - /** - * Sets the icon to sneaker with circular option and icon tint - * - * @param icon - * @param tintColor Icon tint color - * @param isCircular If icon is round or not - * @return - */ - fun setIcon( - icon: Drawable, - tintColor: Int, - isCircular: Boolean, - ): Sneaker { - mIconDrawable = icon - mIsCircular = isCircular - mIconColorFilterColor = Utils.getColor(context, tintColor) - return this - } - - /** - * Sets the size of the icon. - * - * @param size New icon size. - */ - fun setIconSize(size: Int): Sneaker { - mIconSize = size - return this - } - - /** - * Sets the corner radius for round corner sneaker. - * - * @param radius Corner radius. - */ - fun setCornerRadius(radius: Int): Sneaker { - setCornerRadius(radius, defaultValue) - return this - } - - /** - * Sets the corner radius for round corner sneaker with margin. - * - * @param radius Corner radius. - * @param margin margin. - */ - fun setCornerRadius( - radius: Int, - margin: Int, - ): Sneaker { - mCornerRadius = radius - mMargin = margin - return this - } - - /** - * Disable/Enable auto hiding sneaker - * - * @param autoHide - * @return - */ - fun autoHide(autoHide: Boolean): Sneaker { - mAutoHide = autoHide - return this - } - - /** - * Sets the height to sneaker - * - * @param height Height value for sneaker - * @return - */ - fun setHeight(height: Int): Sneaker { - mHeight = height - return this - } - - /** - * Sets the duration for sneaker. - * After this duration sneaker will disappear - * - * @param duration - * @return - */ - fun setDuration(duration: Int): Sneaker { - mDuration = duration - return this - } - - /** - * Sets the click listener to sneaker - * - * @param listener - * @return - */ - fun setOnSneakerClickListener(listener: OnSneakerClickListener): Sneaker { - mListener = listener - return this - } - - /** - * Sets the dismiss listener to sneaker - */ - fun setOnSneakerDismissListener(listener: OnSneakerDismissListener): Sneaker { - mDismissListener = listener - return this - } - - /** - * Set font for title and message - * - * @param typeface - * @return - */ - fun setTypeface(typeface: Typeface): Sneaker { - mTypeFace = typeface - return this - } - - /** - * Shows sneaker with custom color - * - * @param backgroundColor Color resource for sneaker background color - */ - fun sneak(backgroundColor: Int) { - mBackgroundColor = - try { - ContextCompat.getColor(context, backgroundColor) - } catch (e: Exception) { - backgroundColor - } - sneakView() - } - - /** - * Shows warning sneaker with fixed icon, background color and icon color. - * Icons, background and text colors for this are not customizable - */ - fun sneakWarning() { - mBackgroundColor = Color.parseColor("#ffc100") - mTitleColor = Color.parseColor("#000000") - mMessageColor = Color.parseColor("#000000") - mIconColorFilterColor = Color.parseColor("#000000") - mIconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_warning) - - sneakView() - } - - /** - * Shows error sneaker with fixed icon, background color and icon color. - * Icons, background and text colors for this are not customizable - */ - fun sneakError() { - mBackgroundColor = Color.parseColor("#ff0000") - mTitleColor = Color.parseColor("#FFFFFF") - mMessageColor = Color.parseColor("#FFFFFF") - mIconColorFilterColor = Color.parseColor("#FFFFFF") - mIconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_error) - - sneakView() - } - - /** - * Shows success sneaker with fixed icon, background color and icon color. - * Icons, background and text colors for this are not customizable - */ - fun sneakSuccess() { - mBackgroundColor = Color.parseColor("#2bb600") - mTitleColor = Color.parseColor("#FFFFFF") - mMessageColor = Color.parseColor("#FFFFFF") - mIconColorFilterColor = Color.parseColor("#FFFFFF") - mIconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_success) - - sneakView() - } - - /** - * Creates the view and sneaks in - */ - private fun sneakView() { - // Main layout - targetView?.let { - val layoutParams = - CoordinatorLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT, - ) - if (mMargin != defaultValue) { - val margin = Utils.convertToDp(context, mMargin.toFloat()) - layoutParams.setMargins(margin, margin, margin, margin) - } - - layoutParams.behavior = AppBarLayout.ScrollingViewBehavior() - layoutParams.anchorGravity = Gravity.BOTTOM - - with(sneakerView) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - elevation = 6f - } - - this.layoutParams = layoutParams - orientation = LinearLayout.HORIZONTAL - gravity = Gravity.CENTER_VERTICAL - setPadding(46, if (isActivity) Utils.getStatusBarHeight(it) else 0, 46, 0) - setBackground(mBackgroundColor, mCornerRadius) - setIcon(mIconDrawable, Utils.convertToDp(context, mIconSize.toFloat()), mIconColorFilterColor) - setTextContent(mTitle, mTitleColor, mMessage, mMessageColor, mTypeFace) - setOnClickListener(this@Sneaker) - } - removeExistingSneakerView(it) - it.addView(sneakerView, 0) - - sneakerView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.popup_show)) - if (mAutoHide) { - val handler = Handler() - handler.removeCallbacks { } - handler.postDelayed({ - removeView(sneakerView) - mDismissListener?.onDismiss() - }, mDuration.toLong()) - } - } - } - - fun sneakCustom(layout: View): Sneaker { - sneakerView.setCustomView(layout) - val layoutParams = - CoordinatorLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT, - ) - layoutParams.behavior = AppBarLayout.ScrollingViewBehavior() - layoutParams.anchorGravity = Gravity.BOTTOM - layoutParams.bottomMargin = Utils.convertToDp(context, 52f) - with(sneakerView) { - this.layoutParams = layoutParams - } - - targetView?.let { - removeExistingSneakerView(it) - it.addView(sneakerView) - - sneakerView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.popup_show)) - if (mAutoHide) { - val handler = Handler() - handler.removeCallbacks { } - handler.postDelayed({ - removeView(sneakerView) - mDismissListener?.onDismiss() - }, mDuration.toLong()) - } - } - return this - } - - /** - * Gets the existing sneaker and removes before adding new one - * - * @param parent - */ - private fun removeExistingSneakerView(parent: ViewGroup) { - parent.findViewById(R.id.mainLayout)?.let { - removeView(it, false) - } - } - - private fun removeView( - view: View?, - animate: Boolean = true, - ) { - view?.let { - if (animate) it.startAnimation(AnimationUtils.loadAnimation(context, R.anim.popup_hide)) - targetView?.removeView(it) - } - } - - /** - * Sneaker on click - * - * @param view - */ - override fun onClick(view: View) { - mListener?.onSneakerClick(view) - removeView(sneakerView) - } - - fun getView(): ViewGroup = sneakerView -} +package com.pennapps.labs.pennmobile.components.sneaker + +import android.app.Activity +import android.content.Context +import android.graphics.Color +import android.graphics.Typeface +import android.graphics.drawable.Drawable +import android.os.Build +import android.os.Handler +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.view.animation.AnimationUtils +import android.widget.LinearLayout +import androidx.annotation.DrawableRes +import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.lifecycle.LifecycleObserver +import com.google.android.material.appbar.AppBarLayout +import com.pennapps.labs.pennmobile.R +import com.pennapps.labs.pennmobile.components.sneaker.intf.OnSneakerClickListener +import com.pennapps.labs.pennmobile.components.sneaker.intf.OnSneakerDismissListener + +/** + * Sneaker is a third party replacement for android's native toasts. + * Original project can be found here: https://github.com/Hamadakram/Sneaker + * Created by Hammad Akram on 5/24/2017. + * + * Modified for PennMobile by Davies Lumumba on 7/25/2020 + * */ +class Sneaker( + private var context: Context, +) : View.OnClickListener, + LifecycleObserver { + private val defaultValue = -100000 + private var mIconDrawable: Drawable? = null + private var mBackgroundColor = defaultValue + private var mHeight = defaultValue + private var mIconColorFilterColor = defaultValue + private var mIconSize = 24 + private var mTitle = "" + private var mMessage = "" + private var mTitleColor = defaultValue + private var mMessageColor = defaultValue + private var mAutoHide = true + private var mDuration = 3000 + private var mIsCircular = false + private var mListener: OnSneakerClickListener? = null + private var mDismissListener: OnSneakerDismissListener? = null + private var mTypeFace: Typeface? = null + private var mCornerRadius = defaultValue + private var mMargin = defaultValue + private var targetView: ViewGroup? = null + private var isActivity: Boolean = false + private val sneakerView by lazy { SneakerView(context) } + + companion object { + /** + * Create Sneaker instance + * + * @param activity + * @return Sneaker instance + */ + @JvmStatic + fun with(activity: Activity): Sneaker = + Sneaker(activity).also { + it.setTargetView(activity) + } + + /** + * Create Sneaker instance + * + * @param fragment + * @return Sneaker instance + */ + @JvmStatic + fun with(fragment: Fragment): Sneaker = + Sneaker(fragment.requireContext()).also { + it.setTargetView(fragment) + } + + /** + * Create Sneaker instance + * + * @param viewGroup + * @return Sneaker instance + */ + @JvmStatic + fun with(viewGroup: ViewGroup): Sneaker = + Sneaker(viewGroup.context).also { + it.setTargetView(viewGroup) + } + } + + private fun setTargetView(targetView: Any) { + this.targetView = + when (targetView) { + is Activity -> { + isActivity = true + targetView.window?.decorView as ViewGroup + } + is Fragment -> targetView.view as ViewGroup + is ViewGroup -> targetView + else -> null + } + } + + /** + * Hides the sneaker + */ + fun hide() { + removeView(sneakerView) + mDismissListener?.onDismiss() + } + + /** + * Sets the title of the sneaker + * + * @param title string value of title + * @return + */ + fun setTitle(title: String): Sneaker { + mTitle = title + return this.also { mTitle = title } + } + + /** + * Sets the title of the sneaker with color + * + * @param title string value of title + * @param color Color resource for title text + * @return + */ + fun setTitle( + title: String, + color: Int, + ): Sneaker { + mTitle = title + mTitleColor = + try { + ContextCompat.getColor(context, color) + } catch (e: Exception) { + color + } + return this + } + + /** + * Sets the message to sneaker + * + * @param message String value of message + * @return + */ + fun setMessage(message: String): Sneaker { + mMessage = message + return this + } + + /** + * Sets the message to sneaker with color + * + * @param message String value of message + * @param color Color resource for message text + * @return + */ + fun setMessage( + message: String, + color: Int, + ): Sneaker { + mMessage = message + mMessageColor = + try { + ContextCompat.getColor(context, color) + } catch (e: Exception) { + color + } + return this + } + + /** + * Sets the icon to sneaker + * + * @param icon Icon resource for sneaker + * @return + */ + fun setIcon( + @DrawableRes icon: Int, + ): Sneaker { + setIcon(icon, defaultValue, false) + return this + } + + /** + * Sets the icon to sneaker + * + * @param icon Icon drawable for sneaker + * @return + */ + fun setIcon(icon: Drawable): Sneaker { + setIcon(icon, defaultValue, false) + return this + } + + /** + * Sets the icon to sneaker with circular option + * + * @param icon + * @param isCircular If icon is round or not + * @return + */ + fun setIcon( + @DrawableRes icon: Int, + isCircular: Boolean, + ): Sneaker { + setIcon(icon, defaultValue, isCircular) + return this + } + + /** + * Sets the icon to sneaker with circular option + * + * @param icon + * @param isCircular If icon is round or not + * @return + */ + fun setIcon( + icon: Drawable, + isCircular: Boolean, + ): Sneaker { + setIcon(icon, defaultValue, isCircular) + return this + } + + fun setIcon( + @DrawableRes icon: Int, + tintColor: Int, + ): Sneaker { + setIcon(icon, tintColor, false) + return this + } + + fun setIcon( + icon: Drawable, + tintColor: Int, + ): Sneaker { + setIcon(icon, tintColor, false) + return this + } + + /** + * Sets the icon to sneaker with circular option and icon tint + * + * @param icon + * @param tintColor Icon tint color + * @param isCircular If icon is round or not + * @return + */ + fun setIcon( + @DrawableRes icon: Int, + tintColor: Int, + isCircular: Boolean, + ): Sneaker { + mIconDrawable = ContextCompat.getDrawable(context, icon) + mIsCircular = isCircular + mIconColorFilterColor = Utils.getColor(context, tintColor) + return this + } + + /** + * Sets the icon to sneaker with circular option and icon tint + * + * @param icon + * @param tintColor Icon tint color + * @param isCircular If icon is round or not + * @return + */ + fun setIcon( + icon: Drawable, + tintColor: Int, + isCircular: Boolean, + ): Sneaker { + mIconDrawable = icon + mIsCircular = isCircular + mIconColorFilterColor = Utils.getColor(context, tintColor) + return this + } + + /** + * Sets the size of the icon. + * + * @param size New icon size. + */ + fun setIconSize(size: Int): Sneaker { + mIconSize = size + return this + } + + /** + * Sets the corner radius for round corner sneaker. + * + * @param radius Corner radius. + */ + fun setCornerRadius(radius: Int): Sneaker { + setCornerRadius(radius, defaultValue) + return this + } + + /** + * Sets the corner radius for round corner sneaker with margin. + * + * @param radius Corner radius. + * @param margin margin. + */ + fun setCornerRadius( + radius: Int, + margin: Int, + ): Sneaker { + mCornerRadius = radius + mMargin = margin + return this + } + + /** + * Disable/Enable auto hiding sneaker + * + * @param autoHide + * @return + */ + fun autoHide(autoHide: Boolean): Sneaker { + mAutoHide = autoHide + return this + } + + /** + * Sets the height to sneaker + * + * @param height Height value for sneaker + * @return + */ + fun setHeight(height: Int): Sneaker { + mHeight = height + return this + } + + /** + * Sets the duration for sneaker. + * After this duration sneaker will disappear + * + * @param duration + * @return + */ + fun setDuration(duration: Int): Sneaker { + mDuration = duration + return this + } + + /** + * Sets the click listener to sneaker + * + * @param listener + * @return + */ + fun setOnSneakerClickListener(listener: OnSneakerClickListener): Sneaker { + mListener = listener + return this + } + + /** + * Sets the dismiss listener to sneaker + */ + fun setOnSneakerDismissListener(listener: OnSneakerDismissListener): Sneaker { + mDismissListener = listener + return this + } + + /** + * Set font for title and message + * + * @param typeface + * @return + */ + fun setTypeface(typeface: Typeface): Sneaker { + mTypeFace = typeface + return this + } + + /** + * Shows sneaker with custom color + * + * @param backgroundColor Color resource for sneaker background color + */ + fun sneak(backgroundColor: Int) { + mBackgroundColor = + try { + ContextCompat.getColor(context, backgroundColor) + } catch (e: Exception) { + backgroundColor + } + sneakView() + } + + /** + * Shows warning sneaker with fixed icon, background color and icon color. + * Icons, background and text colors for this are not customizable + */ + fun sneakWarning() { + mBackgroundColor = Color.parseColor("#ffc100") + mTitleColor = Color.parseColor("#000000") + mMessageColor = Color.parseColor("#000000") + mIconColorFilterColor = Color.parseColor("#000000") + mIconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_warning) + + sneakView() + } + + /** + * Shows error sneaker with fixed icon, background color and icon color. + * Icons, background and text colors for this are not customizable + */ + fun sneakError() { + mBackgroundColor = Color.parseColor("#ff0000") + mTitleColor = Color.parseColor("#FFFFFF") + mMessageColor = Color.parseColor("#FFFFFF") + mIconColorFilterColor = Color.parseColor("#FFFFFF") + mIconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_error) + + sneakView() + } + + /** + * Shows success sneaker with fixed icon, background color and icon color. + * Icons, background and text colors for this are not customizable + */ + fun sneakSuccess() { + mBackgroundColor = Color.parseColor("#2bb600") + mTitleColor = Color.parseColor("#FFFFFF") + mMessageColor = Color.parseColor("#FFFFFF") + mIconColorFilterColor = Color.parseColor("#FFFFFF") + mIconDrawable = ContextCompat.getDrawable(context, R.drawable.ic_success) + + sneakView() + } + + /** + * Creates the view and sneaks in + */ + private fun sneakView() { + // Main layout + targetView?.let { + val layoutParams = + CoordinatorLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT, + ) + if (mMargin != defaultValue) { + val margin = Utils.convertToDp(context, mMargin.toFloat()) + layoutParams.setMargins(margin, margin, margin, margin) + } + + layoutParams.behavior = AppBarLayout.ScrollingViewBehavior() + layoutParams.anchorGravity = Gravity.BOTTOM + + with(sneakerView) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + elevation = 6f + } + + this.layoutParams = layoutParams + orientation = LinearLayout.HORIZONTAL + gravity = Gravity.CENTER_VERTICAL + setPadding(46, if (isActivity) Utils.getStatusBarHeight(it) else 0, 46, 0) + setBackground(mBackgroundColor, mCornerRadius) + setIcon(mIconDrawable, Utils.convertToDp(context, mIconSize.toFloat()), mIconColorFilterColor) + setTextContent(mTitle, mTitleColor, mMessage, mMessageColor, mTypeFace) + setOnClickListener(this@Sneaker) + } + removeExistingSneakerView(it) + it.addView(sneakerView, 0) + + sneakerView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.popup_show)) + if (mAutoHide) { + val handler = Handler() + handler.removeCallbacks { } + handler.postDelayed({ + removeView(sneakerView) + mDismissListener?.onDismiss() + }, mDuration.toLong()) + } + } + } + + fun sneakCustom(layout: View): Sneaker { + sneakerView.setCustomView(layout) + val layoutParams = + CoordinatorLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT, + ) + layoutParams.behavior = AppBarLayout.ScrollingViewBehavior() + layoutParams.anchorGravity = Gravity.BOTTOM + layoutParams.bottomMargin = Utils.convertToDp(context, 52f) + with(sneakerView) { + this.layoutParams = layoutParams + } + + targetView?.let { + removeExistingSneakerView(it) + it.addView(sneakerView) + + sneakerView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.popup_show)) + if (mAutoHide) { + val handler = Handler() + handler.removeCallbacks { } + handler.postDelayed({ + removeView(sneakerView) + mDismissListener?.onDismiss() + }, mDuration.toLong()) + } + } + return this + } + + /** + * Gets the existing sneaker and removes before adding new one + * + * @param parent + */ + private fun removeExistingSneakerView(parent: ViewGroup) { + parent.findViewById(R.id.mainLayout)?.let { + removeView(it, false) + } + } + + private fun removeView( + view: View?, + animate: Boolean = true, + ) { + view?.let { + if (animate) it.startAnimation(AnimationUtils.loadAnimation(context, R.anim.popup_hide)) + targetView?.removeView(it) + } + } + + /** + * Sneaker on click + * + * @param view + */ + override fun onClick(view: View) { + mListener?.onSneakerClick(view) + removeView(sneakerView) + } + + fun getView(): ViewGroup = sneakerView +} diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/SneakerView.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/SneakerView.kt index 5989ca2f..f5db856b 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/SneakerView.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/SneakerView.kt @@ -12,7 +12,9 @@ import androidx.appcompat.widget.AppCompatImageView import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.components.sneaker.Utils.customView -internal class SneakerView(context: Context?) : LinearLayout(context) { +internal class SneakerView( + context: Context?, +) : LinearLayout(context) { init { id = R.id.mainLayout layoutParams = LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/Utils.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/Utils.kt index 13555eaa..0638123f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/Utils.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/components/sneaker/Utils.kt @@ -12,15 +12,14 @@ internal object Utils { * * @return */ - fun getStatusBarHeight(activityDecorView: ViewGroup?): Int { - return if (activityDecorView != null) { + fun getStatusBarHeight(activityDecorView: ViewGroup?): Int = + if (activityDecorView != null) { val rectangle = Rect() activityDecorView.getWindowVisibleDisplayFrame(rectangle) rectangle.top } else { 0 } - } fun convertToDp( context: Context, @@ -56,11 +55,10 @@ internal object Utils { fun getColor( context: Context, color: Int, - ): Int { - return try { + ): Int = + try { ContextCompat.getColor(context, color) } catch (e: Exception) { color } - } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt index 675d103d..bf073268 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/MoreFragment.kt @@ -43,7 +43,8 @@ class MoreFragment : Fragment() { savedInstanceState: Bundle?, ) { super.onViewCreated(view, savedInstanceState) - childFragmentManager.beginTransaction() + childFragmentManager + .beginTransaction() .replace(R.id.more_frame, PreferenceFragment()) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) .commit() @@ -60,7 +61,8 @@ class MoreFragment : Fragment() { override fun onResume() { val initials = - PreferenceManager.getDefaultSharedPreferences(mActivity) + PreferenceManager + .getDefaultSharedPreferences(mActivity) .getString(getString(R.string.initials), null) if (initials != null && initials.isNotEmpty()) { this.initials.text = initials diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/PreferenceFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/PreferenceFragment.kt index dd887229..1880b88d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/PreferenceFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/morefragments/PreferenceFragment.kt @@ -101,7 +101,8 @@ class PreferenceFragment : PreferenceFragmentCompat() { val newsFeaturePref: Preference? = findPreference("pref_news_feature") newsFeaturePref?.setOnPreferenceClickListener { - mActivity.supportFragmentManager.beginTransaction() + mActivity.supportFragmentManager + .beginTransaction() .replace(R.id.content_frame, NewsFragment()) .addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) @@ -111,7 +112,8 @@ class PreferenceFragment : PreferenceFragmentCompat() { val contactsFeaturePref: Preference? = findPreference("pref_contacts_feature") contactsFeaturePref?.setOnPreferenceClickListener { - mActivity.supportFragmentManager.beginTransaction() + mActivity.supportFragmentManager + .beginTransaction() .replace(R.id.content_frame, SupportFragment()) .addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) @@ -121,7 +123,8 @@ class PreferenceFragment : PreferenceFragmentCompat() { val aboutFeaturePref: Preference? = findPreference("pref_about_feature") aboutFeaturePref?.setOnPreferenceClickListener { - mActivity.supportFragmentManager.beginTransaction() + mActivity.supportFragmentManager + .beginTransaction() .replace(R.id.content_frame, AboutFragment()) .addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) @@ -131,7 +134,8 @@ class PreferenceFragment : PreferenceFragmentCompat() { val fitnessFeaturePref: Preference? = findPreference("pref_fitness_feature") fitnessFeaturePref?.setOnPreferenceClickListener { - mActivity.supportFragmentManager.beginTransaction() + mActivity.supportFragmentManager + .beginTransaction() .replace(R.id.content_frame, PottruckFragment()) .addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) @@ -211,7 +215,8 @@ class PreferenceFragment : PreferenceFragmentCompat() { text.add(sharedPreference.getString(getString(R.string.email_address), null)) val alert: CustomAlertDialogue.Builder = - CustomAlertDialogue.Builder(activity) + CustomAlertDialogue + .Builder(activity) .setStyle(CustomAlertDialogue.Style.INPUT) .setTitle("Contact Info") .setMessage("This information is used when booking GSRs and when displaying your name on the app.") @@ -246,8 +251,7 @@ class PreferenceFragment : PreferenceFragmentCompat() { ) } dialog.dismiss() - } - .setNegativeText("Cancel") + }.setNegativeText("Cancel") .setNegativeColor(stream.customalert.R.color.negative) .setOnNegativeClicked { _, dialog -> dialog.dismiss() } .setLineInputHint(hints) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/utils/Utils.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/utils/Utils.kt index 45a62793..426f55bb 100755 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/utils/Utils.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/utils/Utils.kt @@ -12,11 +12,11 @@ import java.util.Locale object Utils { /** Get current formatted system time */ @JvmStatic - fun getCurrentSystemTime(): String { - return SimpleDateFormat("EEEE, MMM d", Locale.getDefault()).format( - Date(), - ).toUpperCase(Locale.getDefault()) - } + fun getCurrentSystemTime(): String = + SimpleDateFormat("EEEE, MMM d", Locale.getDefault()) + .format( + Date(), + ).toUpperCase(Locale.getDefault()) /** * Converts dps to pixels nicely. @@ -35,11 +35,12 @@ object Utils { return try { (dp * (metrics.densityDpi / 160f)).toInt() } catch (ignored: NoSuchFieldError) { - TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, - dp, - metrics, - ).toInt() + TypedValue + .applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + dp, + metrics, + ).toInt() } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewmodels/LaundryViewModel.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewmodels/LaundryViewModel.kt index 11395453..1421d03d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewmodels/LaundryViewModel.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewmodels/LaundryViewModel.kt @@ -274,32 +274,20 @@ class LaundryViewModel : ViewModel() { return (curToggled.size >= MAX_NUM_ROOMS).xor(origState) } - fun getGroupCount(): Int { - return laundryHalls.size - } + fun getGroupCount(): Int = laundryHalls.size - fun getChildrenCount(i: Int): Int { - return laundryRooms[laundryHalls[i]]!!.size - } + fun getChildrenCount(i: Int): Int = laundryRooms[laundryHalls[i]]!!.size - fun getGroup(i: Int): Any { - return laundryHalls[i] - } + fun getGroup(i: Int): Any = laundryHalls[i] fun getChild( i: Int, i1: Int, - ): Any { - return laundryRooms[laundryHalls[i]]!![i1] - } + ): Any = laundryRooms[laundryHalls[i]]!![i1] - fun getRooms(hallName: String): List? { - return laundryRooms[hallName] - } + fun getRooms(hallName: String): List? = laundryRooms[hallName] - fun isChecked(roomId: Int): Boolean { - return curToggled.contains(roomId) - } + fun isChecked(roomId: Int): Boolean = curToggled.contains(roomId) fun isFull() = (curToggled.size >= MAX_NUM_ROOMS) } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewmodels/PennCourseAlertViewModel.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewmodels/PennCourseAlertViewModel.kt index 66c68c6d..2ac54c1e 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewmodels/PennCourseAlertViewModel.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/viewmodels/PennCourseAlertViewModel.kt @@ -52,7 +52,8 @@ class PennCourseAlertViewModel : ViewModel() { autoResubscribe = true, closeNotification = notifyWhenClosed, ) - PennCourseAlertApi.retrofitService.createRegistration(registrationBody, bearerToken) + PennCourseAlertApi.retrofitService + .createRegistration(registrationBody, bearerToken) .enqueue( object : Callback { override fun onResponse( @@ -82,7 +83,8 @@ class PennCourseAlertViewModel : ViewModel() { ) { var response = "" // using search type course for query optimization - PennCourseAlertApi.retrofitService.getCourses("current", id, "course") + PennCourseAlertApi.retrofitService + .getCourses("current", id, "course") .enqueue( object : Callback> { override fun onResponse( @@ -110,7 +112,8 @@ class PennCourseAlertViewModel : ViewModel() { fun retrieveRegistrations() { var internalResponse = "" - PennCourseAlertApi.retrofitService.getAllRegistrations(bearerToken) + PennCourseAlertApi.retrofitService + .getAllRegistrations(bearerToken) .enqueue( object : Callback> { override fun onFailure( @@ -151,7 +154,8 @@ class PennCourseAlertViewModel : ViewModel() { var response = "" // using search type course for query optimization - PennCourseAlertApi.retrofitService.getSections("current", courseId) + PennCourseAlertApi.retrofitService + .getSections("current", courseId) .enqueue( object : Callback> { override fun onResponse( @@ -199,7 +203,8 @@ class PennCourseAlertViewModel : ViewModel() { closeNotifications = false, resubscribe = false, ) - PennCourseAlertApi.retrofitService.updateRegistrationById(id, updateBody, bearerToken) + PennCourseAlertApi.retrofitService + .updateRegistrationById(id, updateBody, bearerToken) .enqueue( object : Callback { override fun onResponse( @@ -231,7 +236,8 @@ class PennCourseAlertViewModel : ViewModel() { resubscribe = true, autoResubscribe = true, ) - PennCourseAlertApi.retrofitService.updateRegistrationById(id, updateBody, bearerToken) + PennCourseAlertApi.retrofitService + .updateRegistrationById(id, updateBody, bearerToken) .enqueue( object : Callback { override fun onResponse( @@ -262,7 +268,8 @@ class PennCourseAlertViewModel : ViewModel() { val updateBody = PennCourseAlertUpdateBody(closeNotifications = notifyWhenClosed) - PennCourseAlertApi.retrofitService.updateRegistrationById(id, updateBody, bearerToken) + PennCourseAlertApi.retrofitService + .updateRegistrationById(id, updateBody, bearerToken) .enqueue( object : Callback { override fun onResponse( @@ -295,7 +302,8 @@ class PennCourseAlertViewModel : ViewModel() { closeNotifications = false, resubscribe = false, ) - PennCourseAlertApi.retrofitService.updateRegistrationById(id, updateBody, bearerToken) + PennCourseAlertApi.retrofitService + .updateRegistrationById(id, updateBody, bearerToken) .enqueue( object : Callback { override fun onResponse( @@ -319,7 +327,8 @@ class PennCourseAlertViewModel : ViewModel() { fun getRegistrationById(id: String) { var internalResponse = "" - PennCourseAlertApi.retrofitService.getRegistrationById(id, bearerToken) + PennCourseAlertApi.retrofitService + .getRegistrationById(id, bearerToken) .enqueue( object : Callback { override fun onResponse( @@ -354,7 +363,8 @@ class PennCourseAlertViewModel : ViewModel() { ) { var internalResponse = "" val profile = Profile(true, phone = phone, email = email) - PennCourseAlertApi.retrofitService.updateInfo(profile, bearerToken) + PennCourseAlertApi.retrofitService + .updateInfo(profile, bearerToken) .enqueue( object : Callback { override fun onResponse( @@ -378,7 +388,8 @@ class PennCourseAlertViewModel : ViewModel() { fun getUserInfo() { var internalResponse = "" - PennCourseAlertApi.retrofitService.retrieveUser(bearerToken) + PennCourseAlertApi.retrofitService + .retrieveUser(bearerToken) .enqueue( object : Callback { override fun onResponse(