From e5c585e221ef5b8bc6af92981d5a6f3d1d650ff3 Mon Sep 17 00:00:00 2001 From: meiron03 Date: Fri, 15 Dec 2023 02:53:12 -0500 Subject: [PATCH] Get rid of some of the warnings we have. Cleaning code is mildly therapeutic :). --- .../labs/pennmobile/DiningInfoFragment.kt | 9 --- .../labs/pennmobile/DiningInsightsFragment.kt | 7 +-- .../labs/pennmobile/DiningSettingsFragment.kt | 3 +- .../labs/pennmobile/FitnessHolderFragment.kt | 2 +- .../pennmobile/FitnessPreferencesFragment.kt | 1 - .../pennapps/labs/pennmobile/GsrFragment.kt | 28 ++++----- .../pennmobile/GsrReservationsFragment.kt | 3 +- .../labs/pennmobile/GsrTabbedFragment.kt | 2 +- .../pennapps/labs/pennmobile/HomeFragment.kt | 25 ++------ .../labs/pennmobile/HuntsmanGSRLogin.kt | 21 +------ .../labs/pennmobile/LaundryFragment.kt | 4 +- .../pennmobile/LaundrySettingsFragment.kt | 2 +- .../pennapps/labs/pennmobile/LoginFragment.kt | 2 +- .../labs/pennmobile/LoginWebviewFragment.kt | 61 ++----------------- .../pennapps/labs/pennmobile/MainActivity.kt | 3 - .../pennapps/labs/pennmobile/MenuFragment.kt | 4 +- .../pennapps/labs/pennmobile/NewsFragment.kt | 12 ++-- .../PennCourseAlertCreateAlertFragment.kt | 2 +- .../PennCourseAlertHolderFragment.kt | 2 +- .../PennCourseAlertManageAlertsFragment.kt | 11 ++-- .../labs/pennmobile/PottruckFragment.kt | 9 ++- .../labs/pennmobile/adapters/AboutAdapter.kt | 2 +- .../labs/pennmobile/adapters/DiningAdapter.kt | 4 +- .../pennmobile/adapters/DiningCardAdapter.kt | 6 +- .../adapters/DiningInsightsCardAdapter.kt | 2 - .../pennmobile/adapters/DiningPagerAdapter.kt | 2 +- .../adapters/FitnessHeaderAdapter.kt | 1 - .../adapters/FitnessPagerAdapter.kt | 1 - .../pennmobile/adapters/GsrBuildingAdapter.kt | 2 +- .../labs/pennmobile/adapters/HomeAdapter.kt | 4 +- .../pennmobile/adapters/PhoneSaveAdapter.kt | 1 - .../pennmobile/adapters/PollOptionAdapter.kt | 10 +-- .../adapters/RegistrationsAdapter.kt | 2 +- 33 files changed, 66 insertions(+), 184 deletions(-) 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 877bf1f01..7cb6378a8 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInfoFragment.kt @@ -1,8 +1,6 @@ package com.pennapps.labs.pennmobile -import android.content.Context import android.graphics.Color -import android.net.ConnectivityManager import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -113,13 +111,6 @@ class DiningInfoFragment : Fragment() { return vertical } - private val isNetworkAvailable: Boolean - get() { - val connectivityManager = mActivity.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - val activeNetworkInfo = connectivityManager.activeNetworkInfo - return activeNetworkInfo != null && activeNetworkInfo.isConnected - } - override fun onDestroyView() { setHasOptionsMenu(false) super.onDestroyView() 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 c681c70c2..5d228aed7 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt @@ -45,7 +45,7 @@ class DiningInsightsFragment : Fragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + savedInstanceState: Bundle?): View { _binding = FragmentDiningInsightsBinding.inflate(inflater, container, false) val view = binding.root @@ -101,9 +101,6 @@ class DiningInsightsFragment : Fragment() { } } - override fun onResume() { - super.onResume() - } private fun refresh() { val accessToken = networkManager.getAccessToken() @@ -127,7 +124,7 @@ class DiningInsightsFragment : Fragment() { private fun getInsights(accessToken: String?) { if (!isOnline(context)) { binding.internetConnectionDiningInsights.setBackgroundColor(resources.getColor(R.color.darkRedBackground)) - binding.internetConnectionMessageDiningInsights.setText("Not Connected to Internet") + binding.internetConnectionMessageDiningInsights.text = "Not Connected to Internet" binding.internetConnectionDiningInsights.visibility = View.VISIBLE binding.diningInsightsRefresh.isRefreshing = false return 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 a201f0208..b8afc827f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningSettingsFragment.kt @@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment import androidx.preference.PreferenceManager import androidx.recyclerview.widget.LinearLayoutManager import com.pennapps.labs.pennmobile.adapters.DiningSettingsAdapter -import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.DiningHall import com.pennapps.labs.pennmobile.classes.DiningRequest @@ -37,7 +36,7 @@ class DiningSettingsFragment : Fragment() { mActivity.hideBottomBar() } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { _binding = FragmentDiningPreferencesBinding.inflate(inflater, container, false) val v = binding.root binding.diningHallRv.layoutManager = LinearLayoutManager(context, diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt index ff655e2d2..9a2f20dcc 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt @@ -33,7 +33,7 @@ class FitnessHolderFragment: Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { super.onCreateView(inflater, container, savedInstanceState) _binding = FragmentFitnessHolderBinding.inflate(inflater, container, false) return binding.root diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessPreferencesFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessPreferencesFragment.kt index 0b6cc0ce7..d7827840a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessPreferencesFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessPreferencesFragment.kt @@ -1,7 +1,6 @@ package com.pennapps.labs.pennmobile import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup 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 f7042b4c7..d5cbff375 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt @@ -2,7 +2,6 @@ package com.pennapps.labs.pennmobile import android.app.DatePickerDialog import android.app.TimePickerDialog -import android.os.Build import android.os.Bundle import android.util.Log import androidx.fragment.app.Fragment @@ -12,11 +11,9 @@ import android.view.View import android.view.ViewGroup import android.widget.* import android.widget.AdapterView.OnItemSelectedListener -import androidx.annotation.RequiresApi import androidx.preference.PreferenceManager import com.google.firebase.analytics.FirebaseAnalytics import com.pennapps.labs.pennmobile.adapters.GsrBuildingAdapter -import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.GSRContainer import com.pennapps.labs.pennmobile.classes.GSRRoom @@ -99,7 +96,6 @@ class GsrFragment : Fragment() { _binding = null } - @RequiresApi(Build.VERSION_CODES.M) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { selectDateButton = binding.gsrSelectDate selectTimeButton = binding.gsrSelectTime @@ -144,7 +140,7 @@ class GsrFragment : Fragment() { // Launch Time Picker Dialog val timePickerDialog = TimePickerDialog(activity, - TimePickerDialog.OnTimeSetListener { _, hourOfDay, minute -> + { _, hourOfDay, minute -> // Update hour + minute selectedDateTime = DateTime(selectedDateTime.year, selectedDateTime.monthOfYear, selectedDateTime.dayOfMonth, hourOfDay, minute) @@ -165,7 +161,7 @@ class GsrFragment : Fragment() { val mDay = c.get(Calendar.DAY_OF_MONTH) val datePickerDialog = DatePickerDialog(mActivity, - DatePickerDialog.OnDateSetListener { _, year, monthOfYear, dayOfMonth -> + { _, year, monthOfYear, dayOfMonth -> //account for index starting at 0 val entryMonth = monthOfYear + 1 @@ -207,9 +203,9 @@ class GsrFragment : Fragment() { private fun updateStatus() { mActivity.mNetworkManager.getAccessToken { val sp = PreferenceManager.getDefaultSharedPreferences(activity) - bearerToken = sp.getString(getString(R.string.access_token), "").toString(); + bearerToken = sp.getString(getString(R.string.access_token), "").toString() - if (bearerToken.isNullOrEmpty()) { + if (bearerToken.isEmpty()) { Toast.makeText(activity, "You are not logged in!", Toast.LENGTH_LONG).show() } else { mStudentLife.isWharton( @@ -240,14 +236,14 @@ class GsrFragment : Fragment() { populateDropDownGSR() } } - var gsrLocation = gsrLocationDropDown.selectedItem.toString() + val gsrLocation = gsrLocationDropDown.selectedItem.toString() val location = mapGSR(gsrLocation) val gid = mapGID(gsrLocation) mActivity.mNetworkManager.getAccessToken { val sp = PreferenceManager.getDefaultSharedPreferences(activity) - bearerToken = sp.getString(getString(R.string.access_token), "").toString(); + bearerToken = sp.getString(getString(R.string.access_token), "").toString() - if (location.isNullOrEmpty() || bearerToken.isNullOrEmpty()) { + if (location.isEmpty() || bearerToken.isEmpty()) { showNoResults() } else { // display loading screen if user did not use swipe refresh @@ -287,9 +283,9 @@ class GsrFragment : Fragment() { mActivity.mNetworkManager.getAccessToken { val sp = PreferenceManager.getDefaultSharedPreferences(activity) - bearerToken = sp.getString(getString(R.string.access_token), "").toString(); + bearerToken = sp.getString(getString(R.string.access_token), "").toString() - Log.i("GsrFragment", "Bearer Token: $bearerToken"); + Log.i("GsrFragment", "Bearer Token: $bearerToken") Log.i("GsrFragment", "Wharton Status: $isWharton") mStudentLife.gsrRoom( @@ -331,7 +327,7 @@ class GsrFragment : Fragment() { } binding.gsrRoomsList.adapter = (context?.let { - GsrBuildingAdapter(it, mGSRS, location.toString(), (durationDropDown.selectedItemPosition + 1) * 30, sortByTime) + GsrBuildingAdapter(it, mGSRS, location, (durationDropDown.selectedItemPosition + 1) * 30, sortByTime) }) @@ -426,9 +422,9 @@ class GsrFragment : Fragment() { // go through all the rooms while (i < numLocations) { val locationName = locations[i]?.name ?: "" - if (locationName.isNullOrEmpty()) { + if (locationName.isEmpty()) { Log.w("Empty location name", - locations[i].id ?: locations[i].gid.toString()); + locations[i].id ?: locations[i].gid.toString()) } gsrHashMap[locationName] = locations[i].id gsrGIDHashMap[locationName] = locations[i].gid diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt index c1799e422..b7ae60fe6 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrReservationsFragment.kt @@ -15,7 +15,6 @@ import android.view.View import android.view.ViewGroup import com.google.firebase.analytics.FirebaseAnalytics import com.pennapps.labs.pennmobile.adapters.GsrReservationsAdapter -import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager import com.pennapps.labs.pennmobile.databinding.FragmentGsrReservationsBinding import kotlinx.android.synthetic.main.loading_panel.loadingPanel @@ -43,7 +42,7 @@ class GsrReservationsFragment : Fragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + savedInstanceState: Bundle?): View { _binding = FragmentGsrReservationsBinding.inflate(inflater, container, false) val view = binding.root diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrTabbedFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrTabbedFragment.kt index 13e135a1c..8d333b320 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrTabbedFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrTabbedFragment.kt @@ -21,7 +21,7 @@ class GsrTabbedFragment : Fragment() { private val binding get() = _binding!! override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + savedInstanceState: Bundle?): View { // Inflate the layout for this fragment _binding = FragmentGsrTabsBinding.inflate(inflater, container, false) val view = binding.root diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt index 528f87017..da8a8df65 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HomeFragment.kt @@ -61,7 +61,7 @@ class HomeFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { _binding = FragmentHomeBinding.inflate(inflater, container, false) val view = binding.root @@ -203,9 +203,9 @@ class HomeFragment : Fragment() { venues.add(1442) venues.add(636) } else { - list?.forEach({ + list?.forEach { it.id?.let { it1 -> venues.add(it1) } - }) + } } diningCellInfo.venues = venues @@ -272,7 +272,6 @@ class HomeFragment : Fragment() { studentLife.getLaundryPref(bearerToken).subscribe({ preferences -> mActivity.runOnUiThread { - val venues = mutableListOf() val laundryCell = HomeCell() laundryCell.type = "laundry" val laundryCellInfo = HomeCellInfo() @@ -418,7 +417,7 @@ class HomeFragment : Fragment() { this.setTitle(getString(R.string.home)) mActivity.toolbar.visibility = View.GONE val initials = sharedPreferences.getString(getString(R.string.initials), null) - if (initials != null && initials.isNotEmpty()) { + if (!initials.isNullOrEmpty()) { binding.initials.text = initials } else { binding.profileBackground.setImageDrawable( @@ -452,20 +451,4 @@ class HomeFragment : Fragment() { //TODO: Account Settings } } - - /** - * Show a SnackBar message right below the app bar - */ - @Suppress("DEPRECATION") - private fun displaySnack(view: View, text: String) { - (view as ViewGroup).showSneakerToast(message = text, doOnRetry = { }, sneakerColor = R.color.sneakerBlurColorOverlay) - } - - enum class Cells { - POLLS, NEWS, DINING, CALENDAR, LAUNDRY, POSTS - } - - - - } \ No newline at end of file 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 b60f446f0..2ac1fce01 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HuntsmanGSRLogin.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/HuntsmanGSRLogin.kt @@ -13,7 +13,6 @@ import android.webkit.CookieManager import android.webkit.WebView import android.webkit.WebViewClient import android.widget.Toast -import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.GSRBookingResult import com.pennapps.labs.pennmobile.databinding.FragmentHuntsmanGsrloginBinding @@ -52,7 +51,7 @@ class HuntsmanGSRLogin : Fragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + savedInstanceState: Bundle?): View { // Inflate the layout for this fragment _binding = FragmentHuntsmanGsrloginBinding.inflate(inflater, container, false) return binding.root @@ -100,7 +99,7 @@ class HuntsmanGSRLogin : Fragment() { editor.apply() if (startTime.substring(9,13) == "2330") { val newDay = endTime[7] + 1 - var newEndTime = endTime.substring(0,7) + newDay + endTime.substring(8,endTime.length) + val newEndTime = endTime.substring(0,7) + newDay + endTime.substring(8,endTime.length) endTime = newEndTime } bookHuntsmanGSR(bearerToken, sessionid) @@ -168,20 +167,4 @@ class HuntsmanGSRLogin : Fragment() { ) } } - - companion object { - - fun newInstance(gsrID: String, gsrLocationCode: String, startTime: String, endTime: String, gid: Int, roomName: String): HuntsmanGSRLogin { - val fragment = HuntsmanGSRLogin() - val args = Bundle() - args.putString("gsrID", gsrID) - args.putString("gsrLocationCode", gsrLocationCode) - args.putString("startTime", startTime) - args.putString("endTime", endTime) - args.putInt("gid", gid) - args.putString("roomName", roomName) - fragment.arguments = args - return fragment - } - } } 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 1c36c7480..e44bdee00 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundryFragment.kt @@ -200,10 +200,10 @@ class LaundryFragment : Fragment() { if (laundryRoomsResult.size == count) { // sort laundry rooms data by hall name - roomsDataResult.sortWith(Comparator { usage1, usage2 -> usage2.id - usage1.id }) + roomsDataResult.sortWith { usage1, usage2 -> usage2.id - usage1.id } // sort laundry rooms by name - laundryRoomsResult.sortWith(Comparator { room1, room2 -> room2.id - room1.id }) + laundryRoomsResult.sortWith { room1, room2 -> room2.id - room1.id } // update UI mActivity.runOnUiThread { 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 22a488e63..8e9de7b7a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LaundrySettingsFragment.kt @@ -51,7 +51,7 @@ class LaundrySettingsFragment : Fragment() { FirebaseAnalytics.getInstance(mContext).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { _binding = FragmentLaundrySettingsBinding.inflate(inflater, container, false) val view = binding.root 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 85f18706d..fac99e7b3 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginFragment.kt @@ -28,7 +28,7 @@ class LoginFragment : Fragment() { mActivity.closeKeyboard() } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { _binding = FragmentLoginBinding.inflate(inflater, container, false) val v = binding.root 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 fc0376807..82c730e1a 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/LoginWebviewFragment.kt @@ -21,19 +21,16 @@ import com.pennapps.labs.pennmobile.api.Platform.platformBaseUrl import com.pennapps.labs.pennmobile.classes.AccessTokenResponse import com.pennapps.labs.pennmobile.classes.Account import com.pennapps.labs.pennmobile.classes.GetUserResponse -import com.pennapps.labs.pennmobile.classes.SaveAccountResponse import org.apache.commons.lang3.RandomStringUtils import retrofit.Callback import retrofit.RetrofitError import retrofit.client.Response import java.nio.charset.Charset -import java.security.KeyStore import java.security.MessageDigest import java.util.* import javax.crypto.Cipher import javax.crypto.KeyGenerator import javax.crypto.SecretKey -import javax.crypto.spec.IvParameterSpec class LoginWebviewFragment : Fragment() { @@ -109,30 +106,8 @@ class LoginWebviewFragment : Fragment() { val spEditor = sp.edit() spEditor.putString("penn_password", encryptedPassword) spEditor.apply() - spEditor.commit() spEditor.putString("encryptionIv", Base64.getEncoder().encodeToString(encryptionIv)) spEditor.apply() - spEditor.commit() - } - - private fun getDecodedPassword(): String? { - val base64EncryptedPassword = sp.getString("penn_password", "null") - val base64EncryptionIv = sp.getString("encryptionIv", "null") - - val encryptionIv = Base64.getDecoder().decode(base64EncryptionIv) - val encryptedPassword = Base64.getDecoder().decode(base64EncryptedPassword) - - val keyStore = KeyStore.getInstance("AndroidKeyStore") - keyStore.load(null) - - val secretkey = keyStore.getKey("Key", null) as SecretKey - val cipher = Cipher.getInstance( - KeyProperties.KEY_ALGORITHM_AES + "/" + - KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7 - ) - cipher.init(Cipher.DECRYPT_MODE, secretkey, IvParameterSpec(encryptionIv)) - val passwordBytes = cipher.doFinal(encryptedPassword) - return String(passwordBytes, Charset.forName("UTF-8")) } private fun saveUsername(username: String) { @@ -170,16 +145,12 @@ class LoginWebviewFragment : Fragment() { initiateAuthentication(authCode) } if (url.contains("weblogin") && url.contains("pennkey")) { - webView.evaluateJavascript("document.getElementById('pennname').value;", ValueCallback { s -> - if (s != null || s != "null") { - saveUsername(s) - } - }) - webView.evaluateJavascript("document.getElementById('password').value;", ValueCallback { s -> - if (s != null || s != "null") { - encryptPassword(s) - } - }) + webView.evaluateJavascript("document.getElementById('pennname').value;") { s -> + saveUsername(s) + } + webView.evaluateJavascript("document.getElementById('password').value;") { s -> + encryptPassword(s) + } } return super.shouldOverrideUrlLoading(view, url) } @@ -248,26 +219,6 @@ class LoginWebviewFragment : Fragment() { }) } - private fun saveAccount(account: Account, pennkey: String, accessToken: String?) { - // warning this network call is unsafe - mStudentLife.saveAccount("Bearer $accessToken", pennkey, account, object : Callback { - - override fun success(t: SaveAccountResponse?, response: Response?) { - val editor = sp.edit() - editor.putString(getString(R.string.accountID), t?.accountID) - editor.apply() - // After saving the account, go to homepage - mActivity.startHomeFragment() - } - - override fun failure(error: RetrofitError) { - Log.e("Accounts", "Error saving account $error", error) - Toast.makeText(mActivity, "Error logging in", Toast.LENGTH_SHORT).show() - mActivity.startLoginFragment() - } - }) - } - private fun getCodeChallenge(codeVerifier: String): String { // Hash the code verifier 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 78480c835..dcbc6e8c9 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt @@ -263,9 +263,6 @@ class MainActivity : AppCompatActivity() { val HOME_ID = R.id.nav_home val GSR_ID = R.id.nav_gsr - val DINING_ID = R.id.nav_dining - val LAUNDRY_ID = R.id.nav_laundry - val MORE_ID = R.id.nav_more private var mStudentLife: StudentLife? = null private var mPlatform: Platform? = null 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 cf470bafd..0c94eb45f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MenuFragment.kt @@ -39,7 +39,7 @@ class MenuFragment : Fragment() { val foodItems = StringBuilder() // for design purposes for (i in station.items.indices) { val txt = station.items[i].title - foodItems.append(txt?.get(0)?.toUpperCase()) + foodItems.append(txt?.get(0)?.uppercaseChar()) foodItems.append(txt?.substring(1, txt.length)) if (i < station.items.size - 1) { foodItems.append("\n") @@ -74,7 +74,7 @@ class MenuFragment : Fragment() { return myFragment } - override fun getPageTitle(position: Int): CharSequence? { + override fun getPageTitle(position: Int): CharSequence { return headers[position] } 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 e065488f2..2e8d09edb 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/NewsFragment.kt @@ -148,7 +148,7 @@ class NewsFragment : ListFragment() { } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { _binding = FragmentNewsBinding.inflate(inflater, container, false) return binding.root } @@ -215,18 +215,18 @@ class NewsFragment : ListFragment() { override fun onResume() { super.onResume() - val mActivity : MainActivity? = activity as MainActivity - mActivity?.removeTabs() - mActivity?.setTitle(R.string.news) + val mActivity : MainActivity = activity as MainActivity + mActivity.removeTabs() + mActivity.setTitle(R.string.news) val initials = sharedPreferences.getString(getString(R.string.initials), null) - if (initials != null && initials.isNotEmpty()) { + if (!initials.isNullOrEmpty()) { binding.initials.text = initials } else { binding.profileBackground.setImageDrawable( resources.getDrawable (R.drawable.ic_guest_avatar, context?.theme)) } - mActivity?.setSelectedTab(MainActivity.MORE) + mActivity.setSelectedTab(MainActivity.MORE) } override fun onDestroyView() { 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 3f8928c49..52a01218d 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt @@ -37,7 +37,7 @@ class PennCourseAlertCreateAlertFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { // Inflate the layout for this fragment _binding = FragmentPennCourseAlertCreateAlertBinding.inflate(inflater, container, false) return binding.root diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertHolderFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertHolderFragment.kt index 3c7460f7f..a03c72dd1 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertHolderFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertHolderFragment.kt @@ -30,7 +30,7 @@ class PennCourseAlertHolderFragment : Fragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { // Inflate the layout for this fragment _binding = FragmentPennCourseAlertHolderBinding.inflate(inflater, container, false) val view = binding.root 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 3d18bf6cd..f943368ef 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertManageAlertsFragment.kt @@ -16,7 +16,6 @@ import android.widget.Toast import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout @@ -71,7 +70,7 @@ class PennCourseAlertManageAlertsFragment : Fragment(), RegistrationsAdapter.OnI recyclerView.adapter = adapter - viewModel.userRegistrations.observe(viewLifecycleOwner, Observer { list -> + viewModel.userRegistrations.observe(viewLifecycleOwner) { list -> run { Log.i("PCA", "list size is ${list.size}") adapter.submitList(null) @@ -85,7 +84,7 @@ class PennCourseAlertManageAlertsFragment : Fragment(), RegistrationsAdapter.OnI noAlertsMessage.visibility = View.GONE } } - }) + } viewModel.retrieveRegistrations() @@ -155,14 +154,14 @@ class PennCourseAlertManageAlertsFragment : Fragment(), RegistrationsAdapter.OnI Log.i("PCA_RV", "Item $position clicked") } - override fun onClosedNotificationsSwitchClick(position: Int, onClosedNotificatons: Boolean) { + override fun onClosedNotificationsSwitchClick(position: Int, onClosedNotifications: Boolean) { val id = adapter.currentList[position].id.toString() Log.i( "PCA_RV", "Item $position closedNoti" + - " clicked with closed noti set to $onClosedNotificatons" + " clicked with closed noti set to $onClosedNotifications" ) if (subscribed_switch.isChecked) { - viewModel.switchOnClosedNotifications(id, onClosedNotificatons) + viewModel.switchOnClosedNotifications(id, onClosedNotifications) } else { notify_closed_switch.isChecked = false Toast.makeText( 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 237bf09be..c47a2df49 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt @@ -19,7 +19,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.google.android.material.appbar.AppBarLayout import com.pennapps.labs.pennmobile.adapters.FitnessAdapter import com.pennapps.labs.pennmobile.adapters.FitnessHeaderAdapter -import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager import com.pennapps.labs.pennmobile.api.StudentLife import com.pennapps.labs.pennmobile.classes.FitnessPreferenceViewModel import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior @@ -55,7 +54,7 @@ class PottruckFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { mActivity.hideBottomBar() _binding = FragmentPottruckBinding.inflate(inflater, container, false) return binding.root @@ -76,16 +75,16 @@ class PottruckFragment : Fragment() { swipeRefresh.setColorSchemeResources(R.color.color_accent, R.color.color_primary) recyclerView.layoutManager = LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false) - swipeRefresh.setOnRefreshListener { getFitnessRooms(view) } + swipeRefresh.setOnRefreshListener { getFitnessRooms() } // populate the title/date of the app bar initAppBar() // populate recyclerview - getFitnessRooms(view) + getFitnessRooms() } - private fun getFitnessRooms(view: View) { + private fun getFitnessRooms() { //displays banner if not connected if (!getConnected()) return 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 69fe4b2c4..7de4cedcc 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 @@ -25,7 +25,7 @@ class AboutAdapter(private var members: ArrayList) override fun onBindViewHolder(holder: TeamViewHolder, position: Int) { holder.view.name_tv?.text = members[position] - var imageId = when (members[position]) { + val imageId = when (members[position]) { "Marta GarcĂ­a Ferreiro" -> R.drawable.marta "Varun Ramakrishnan" -> R.drawable.varun "Anna Wang" -> R.drawable.anna 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 16ff30d20..cdff503a8 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 @@ -57,7 +57,7 @@ class DiningAdapter(private var diningHalls: List) : RecyclerView.Ad if (diningHall.openMeal() != "all" && diningHall.openMeal() != null) { holder.hallStatus?.setText(getOpenStatusLabel(diningHall.openMeal() ?: "")) } - holder.hallHours?.text = diningHall.openTimes().toLowerCase() + holder.hallHours?.text = diningHall.openTimes().lowercase() } else { holder.hallStatus?.setText(R.string.dining_hall_closed) holder.hallStatus?.background = ContextCompat.getDrawable(context, R.drawable.label_red) @@ -65,7 +65,7 @@ class DiningAdapter(private var diningHalls: List) : RecyclerView.Ad if (openTimes.isEmpty()) { holder.hallHours?.setText(R.string.dining_closed) } else { - holder.hallHours?.text = diningHall.openTimes().toLowerCase() + holder.hallHours?.text = diningHall.openTimes().lowercase() } } // Load the menu for each dining hall 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 ebeff969e..fdf6afb7d 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 @@ -36,7 +36,7 @@ class DiningCardAdapter(halls: ArrayList) : RecyclerView.Adapter) : RecyclerView.Adapter) : RecyclerView.Adapter) : holder.itemView.home_card_rv.adapter = GsrReservationsAdapter(ArrayList(reservations)) } - @RequiresApi(Build.VERSION_CODES.O) private fun bindDiningCell(holder: ViewHolder, cell: HomeCell) { holder.itemView.home_card_title.text = "Favorites" holder.itemView.home_card_subtitle.text = "DINING HALLS" @@ -367,6 +364,7 @@ class HomeAdapter(private var cells: ArrayList) : holder.itemView.home_card_rv.adapter = HomeGsrBuildingAdapter(ArrayList(buildings)) } + @OptIn(DelicateCoroutinesApi::class) private fun bindPostCell(holder: ViewHolder, cell: HomeCell) { val info = cell.info val post = cell.info?.post 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 9bed7aacf..79608b0f2 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 @@ -16,7 +16,6 @@ class PhoneSaveAdapter(context: Context, contacts: List, s: MutableLis private val state: BooleanArray = BooleanArray(size) override fun getView(pos: Int, view: View?, parent: ViewGroup): View { - //var view = view val currentPerson = getItem(pos) val view = view ?: inflater.inflate(R.layout.phone_save_list_item, parent, false) 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 e8e71d36d..4bd44899c 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 @@ -2,13 +2,10 @@ package com.pennapps.labs.pennmobile.adapters import android.content.Context import android.graphics.Color -import android.os.Build import android.view.LayoutInflater import android.view.MotionEvent import android.view.View -import android.view.View.OnTouchListener import android.view.ViewGroup -import androidx.annotation.RequiresApi import androidx.recyclerview.widget.RecyclerView import com.pennapps.labs.pennmobile.R import com.pennapps.labs.pennmobile.classes.Poll @@ -26,7 +23,6 @@ class PollOptionAdapter(private var pollOptions: ArrayList, private return ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.poll_list_item, parent, false)) } - @RequiresApi(Build.VERSION_CODES.O) override fun onBindViewHolder(holder: ViewHolder, position: Int) { val pollOption = pollOptions[position] bindPollOption(holder, pollOption) @@ -49,7 +45,7 @@ class PollOptionAdapter(private var pollOptions: ArrayList, private var startX : Float? = null var startY : Float? = null - holder.itemView.seek_bar?.setOnTouchListener(OnTouchListener { v, event -> + holder.itemView.seek_bar?.setOnTouchListener { v, event -> when (event.action) { MotionEvent.ACTION_DOWN -> { startX = event.x @@ -64,7 +60,7 @@ class PollOptionAdapter(private var pollOptions: ArrayList, private } } } - true }) + true } if(pollOption.selected) { holder.itemView.tv_option?.setTextColor(mContext.resources.getColor(R.color.color_secondary)) holder.itemView.tv_percent?.setTextColor(mContext.resources.getColor(R.color.color_secondary)) @@ -83,7 +79,7 @@ class PollOptionAdapter(private var pollOptions: ArrayList, private val votePercent = (pollOption.voteCount.div(poll.totalVotes.toDouble())) * 100 holder.itemView.tv_percent?.text = String.format("%.2f%%", votePercent) holder.itemView.seek_bar?.progress = round(votePercent).toInt() - holder.itemView.seek_bar?.setOnTouchListener(OnTouchListener { v, event -> true }) + holder.itemView.seek_bar?.setOnTouchListener { v, event -> true } } } 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 4d7e5130c..97677bc83 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 @@ -60,7 +60,7 @@ class RegistrationsAdapter(private val listener: OnItemClickListener): subscribedSwitch.isChecked = !registration.cancelled notifyClosedSwitch.isChecked = (registration.closeNotification && !registration.cancelled) - if (!registration.lastNotificationSentAt.isNullOrEmpty()) { + if (registration.lastNotificationSentAt.isNotEmpty()) { lastNotified.text = formatDate(registration.lastNotificationSentAt) }