Skip to content

Commit

Permalink
start migrating from Kotlin Synthetics to view bindings bc that shit …
Browse files Browse the repository at this point in the history
  • Loading branch information
meiron03 committed Nov 1, 2023
1 parent 6c584f4 commit 40d5e98
Show file tree
Hide file tree
Showing 28 changed files with 486 additions and 483 deletions.
3 changes: 3 additions & 0 deletions PennMobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ android {
}
release {}
}
buildFeatures {
viewBinding true
}
compileSdkVersion 33
buildToolsVersion '29.0.3'
defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.gif.GifDrawable
import com.bumptech.glide.request.RequestListener
import com.pennapps.labs.pennmobile.adapters.AboutAdapter
import kotlinx.android.synthetic.main.fragment_about.view.*
import com.pennapps.labs.pennmobile.databinding.FragmentAboutBinding

class AboutFragment : Fragment() {

private lateinit var mActivity: MainActivity
private lateinit var sharedPreferences: SharedPreferences

private var _binding: FragmentAboutBinding? = null
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mActivity = activity as MainActivity
Expand All @@ -35,9 +38,10 @@ class AboutFragment : Fragment() {
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_about, container, false)
_binding = FragmentAboutBinding.inflate(inflater, container, false)
val view = binding.root

val gif = view.logo_gif_iv?.drawable
val gif = binding.logoGifIv
if (gif is AnimatedVectorDrawable) {
gif.start()
} else {
Expand All @@ -49,25 +53,25 @@ class AboutFragment : Fragment() {
resource.setLoopCount(1)
return false
}
}).into(view.logo_gif_iv)
}).into(binding.logoGifIv)
}

view.our_team_rv?.layoutManager = GridLayoutManager(context, 3)
view.alumni_rv?.layoutManager = GridLayoutManager(context, 3)
binding.ourTeamRv.layoutManager = GridLayoutManager(context, 3)
binding.alumniRv.layoutManager = GridLayoutManager(context, 3)
val members = arrayListOf("Rohan Chhaya", "Julius Snipes", "Aaron Mei", "Trini Feng", "Vedha Avali")
val alumni = arrayListOf("Marta García Ferreiro", "Varun Ramakrishnan", "Sahit Penmatcha",
"Anna Wang", "Sophia Ye", "Awad Irfan", "Liz Powell", "Davies Lumumba", "Anna Jiang", "Ali Krema")
view.our_team_rv?.adapter = AboutAdapter(members)
view.alumni_rv?.adapter = AboutAdapter(alumni)
binding.ourTeamRv.adapter = AboutAdapter(members)
binding.alumniRv.adapter = AboutAdapter(alumni)

ViewCompat.setNestedScrollingEnabled(view.our_team_rv, false)
ViewCompat.setNestedScrollingEnabled(binding.ourTeamRv, false)

view.learn_more_btn?.setOnClickListener {
binding.learnMoreBtn.setOnClickListener {
val i = Intent(Intent.ACTION_VIEW, Uri.parse("https://pennlabs.org"))
startActivity(i)
}

view.licenses_btn?.setOnClickListener {
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.Theme_AppCompat_Light_Dialog_Alert)
Expand All @@ -84,6 +88,11 @@ class AboutFragment : Fragment() {
return view
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

override fun onResume() {
super.onResume()
val mActivity : MainActivity = activity as MainActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import androidx.preference.PreferenceManager
import com.pennapps.labs.pennmobile.api.OAuth2NetworkManager
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.GSRBookingResult
import kotlinx.android.synthetic.main.gsr_details_book.*
import kotlinx.android.synthetic.main.gsr_details_book.view.*
import kotlinx.android.synthetic.main.loading_panel.*
import com.pennapps.labs.pennmobile.databinding.GsrDetailsBookBinding
import retrofit.Callback
import retrofit.RetrofitError
import retrofit.client.Response


class BookGsrFragment : Fragment() {
private var _binding: GsrDetailsBookBinding? = null
private val binding get() = _binding!!

// fields for booking
internal lateinit var firstNameEt: EditText
Expand Down Expand Up @@ -69,12 +69,13 @@ class BookGsrFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val v = inflater.inflate(R.layout.gsr_details_book, container, false)
_binding = GsrDetailsBookBinding.inflate(inflater, container, false)
val view = binding.root

firstNameEt = v.first_name
lastNameEt = v.last_name
emailEt = v.gsr_email
submit = v.submit_gsr
firstNameEt = binding.firstName
lastNameEt = binding.lastName
emailEt = binding.gsrEmail
submit = binding.submitGsr

// get user email and name from shared preferences if it's already saved
val sp = PreferenceManager.getDefaultSharedPreferences(activity)
Expand All @@ -96,11 +97,16 @@ class BookGsrFragment : Fragment() {
} else {
submit.isClickable = false
submit.background.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY)
loading?.visibility = View.VISIBLE
binding.loading.loadingPanel.visibility = View.VISIBLE
bookGSR(Integer.parseInt(gsrID), gsrLocationCode, startTime, endTime, gid, roomId, roomName)
}
}
return v
return view
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

private fun bookGSR(gsrId: Int, gsrLocationCode: String, startTime: String?, endTime: String?, gid: Int, roomId: Int, roomName: String) {
Expand Down Expand Up @@ -155,15 +161,15 @@ class BookGsrFragment : Fragment() {
Log.e("BookGsrFragment", "GSR booking failed with " + result.getError())
}
// go back to GSR fragment
loading?.visibility = View.GONE
binding.loading.loadingPanel.visibility = View.GONE
activity?.onBackPressed()
}

override fun failure(error: RetrofitError) {
//If any error occurred displaying the error as toast
Log.e("BookGSRFragment", "Error booking gsr", error)
Toast.makeText(activity, "An error has occurred. Please try again.", Toast.LENGTH_LONG).show()
loading?.visibility = View.GONE
binding.loading.loadingPanel.visibility = View.GONE
activity?.onBackPressed()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import androidx.preference.PreferenceManager
import com.pennapps.labs.pennmobile.api.CampusExpress
import com.pennapps.labs.pennmobile.classes.Account
import com.pennapps.labs.pennmobile.classes.CampusExpressAccessTokenResponse
import kotlinx.android.synthetic.main.fragment_login_webview.view.*
import org.apache.commons.lang3.RandomStringUtils
import retrofit.Callback
import retrofit.RetrofitError
Expand Down Expand Up @@ -77,7 +76,7 @@ class CampusExpressLoginFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
webView = view.findViewById(R.id.webView)
headerLayout = view.linear_layout
headerLayout = view.findViewById(R.id.linear_layout)
cancelButton = view.findViewById(R.id.cancel_button)
val uri = Uri.parse(campusExpressAuthUrl)
.buildUpon()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import com.pennapps.labs.pennmobile.adapters.DiningAdapter
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.DiningHall
import com.pennapps.labs.pennmobile.classes.Venue
import kotlinx.android.synthetic.main.fragment_dining.*
import kotlinx.android.synthetic.main.fragment_dining.internetConnectionDining
import kotlinx.android.synthetic.main.fragment_dining.internetConnection_message_dining
import kotlinx.android.synthetic.main.fragment_dining.view.*
import com.pennapps.labs.pennmobile.databinding.FragmentDiningBinding
import kotlinx.android.synthetic.main.loading_panel.*
import kotlinx.android.synthetic.main.no_results.*
import rx.Observable
Expand All @@ -33,6 +30,9 @@ class DiningFragment : Fragment() {
private lateinit var mActivity: MainActivity
private lateinit var mStudentLife: StudentLife

private var _binding : FragmentDiningBinding? = null
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mStudentLife = MainActivity.studentLifeInstance
Expand All @@ -53,14 +53,20 @@ class DiningFragment : Fragment() {
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val v = inflater.inflate(R.layout.fragment_dining, container, false)
v.dining_swiperefresh?.setColorSchemeResources(R.color.color_accent, R.color.color_primary)
v.dining_halls_recycler_view?.layoutManager = LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false)
v.dining_swiperefresh.setOnRefreshListener { getDiningHalls() }
_binding = FragmentDiningBinding.inflate(inflater, container, false)
val v = binding.root
binding.diningSwiperefresh.setColorSchemeResources(R.color.color_accent, R.color.color_primary)
binding.diningHallsRecyclerView.layoutManager = LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false)
binding.diningSwiperefresh.setOnRefreshListener { getDiningHalls() }
// initAppBar(v)
return v
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
getDiningHalls()
Expand Down Expand Up @@ -125,11 +131,11 @@ class DiningFragment : Fragment() {

//displays banner if not connected
if (!isOnline(context)) {
internetConnectionDining?.setBackgroundColor(resources.getColor(R.color.darkRedBackground))
internetConnection_message_dining?.text = "Not Connected to Internet"
internetConnectionDining?.visibility = View.VISIBLE
binding.internetConnectionDining.setBackgroundColor(resources.getColor(R.color.darkRedBackground))
binding.internetConnectionMessageDining.text = "Not Connected to Internet"
binding.internetConnectionDining.visibility = View.VISIBLE
} else {
internetConnectionDining?.visibility = View.GONE
binding.internetConnectionDining.visibility = View.GONE
}

// Map each item in the list of venues to a Venue Observable, then map each Venue to a DiningHall Observable
Expand All @@ -144,20 +150,20 @@ class DiningFragment : Fragment() {
mActivity.runOnUiThread {
getMenus(diningHalls)
val adapter = DiningAdapter(diningHalls)
dining_halls_recycler_view?.adapter = adapter
binding.diningHallsRecyclerView.adapter = adapter
loadingPanel?.visibility = View.GONE
if (diningHalls.size > 0) {
no_results?.visibility = View.GONE
}
dining_swiperefresh?.isRefreshing = false
view?.let {displaySnack(it, "Just Updated")}
binding.diningSwiperefresh.isRefreshing = false
view?.let {displaySnack("Just Updated")}
}
}, {
Log.e("DiningFragment", "Error getting dining halls", it)
mActivity.runOnUiThread {
Log.e("Dining", "Could not load Dining page", it)
loadingPanel?.visibility = View.GONE
dining_swiperefresh?.isRefreshing = false
binding.diningSwiperefresh.isRefreshing = false
}
})
}
Expand All @@ -174,8 +180,8 @@ class DiningFragment : Fragment() {
* Shows SnackBar message right below the app bar
*/
@Suppress("DEPRECATION")
private fun displaySnack(view: View, text: String) {
val snackBar = Snackbar.make(view.snack_bar_dining, text, Snackbar.LENGTH_SHORT)
private fun displaySnack(text: String) {
val snackBar = Snackbar.make(binding.snackBarDining, text, Snackbar.LENGTH_SHORT)
snackBar.setTextColor(resources.getColor(R.color.white, context?.theme))
snackBar.setBackgroundTint(resources.getColor(R.color.penn_mobile_grey, context?.theme))
// SnackBar message and action TextViews are placed inside a LinearLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.pennapps.labs.pennmobile.adapters.DiningPagerAdapter
import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior
import com.pennapps.labs.pennmobile.databinding.FragmentDiningHolderBinding
import com.pennapps.labs.pennmobile.utils.Utils
import kotlinx.android.synthetic.main.fragment_dining.view.*
import kotlinx.android.synthetic.main.fragment_dining_holder.*
import kotlinx.android.synthetic.main.fragment_dining_holder.view.*
import kotlinx.android.synthetic.main.fragment_dining.view.dining_swiperefresh


class DiningHolderFragment : Fragment() {

lateinit var pagerAdapter: DiningPagerAdapter
private lateinit var mActivity: MainActivity

private var _binding : FragmentDiningHolderBinding? = null
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mActivity = activity as MainActivity
Expand All @@ -28,21 +30,27 @@ class DiningHolderFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_dining_holder, container, false)
_binding = FragmentDiningHolderBinding.inflate(inflater, container, false)
val view = binding.root
view.dining_swiperefresh?.setOnRefreshListener { getConnected() }
view.dining_swiperefresh?.setColorSchemeResources(R.color.color_accent, R.color.color_primary)
getConnected()
initAppBar(view)
initAppBar()
// Inflate the layout for this fragment
return view
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
pagerAdapter = DiningPagerAdapter(childFragmentManager, lifecycle)
pager?.adapter = pagerAdapter
pager.isUserInputEnabled = false
TabLayoutMediator(tabLayout, pager) { tab, position ->
binding.pager.adapter = pagerAdapter
binding.pager.isUserInputEnabled = false
TabLayoutMediator(binding.tabLayout, binding.pager) { tab, position ->
if (position == 0) {
tab.text = "Dining Halls"
} else {
Expand All @@ -55,12 +63,12 @@ class DiningHolderFragment : Fragment() {
private fun getConnected() {
//displays banner if not connected
if (!isOnline(context)) {
internetConnectionDiningHolder?.setBackgroundColor(resources.getColor(R.color.darkRedBackground))
internetConnection_message_dining_holder?.text = getString(R.string.internet_error)
internetConnectionDiningHolder?.visibility = View.VISIBLE
binding.internetConnectionDiningHolder.setBackgroundColor(resources.getColor(R.color.darkRedBackground))
binding.internetConnectionMessageDiningHolder.text = getString(R.string.internet_error)
binding.internetConnectionDiningHolder.visibility = View.VISIBLE
//loadingPanel?.visibility = View.GONE
} else {
internetConnectionDiningHolder?.visibility = View.GONE
binding.internetConnectionDiningHolder?.visibility = View.GONE
}
}

Expand All @@ -72,13 +80,13 @@ class DiningHolderFragment : Fragment() {
mActivity.setSelectedTab(MainActivity.DINING)
}

private fun initAppBar(view: View) {
(view.appbar_home_holder.layoutParams as CoordinatorLayout.LayoutParams).behavior = ToolbarBehavior()
view.date_view.text = Utils.getCurrentSystemTime()
private fun initAppBar() {
(binding.appbarHomeHolder.layoutParams as CoordinatorLayout.LayoutParams).behavior = ToolbarBehavior()
binding.dateView.text = Utils.getCurrentSystemTime()
}

private fun setTitle(title: CharSequence) {
title_view.text = title
binding.titleView.text = title
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.fragment.app.Fragment
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.DiningHall
import com.pennapps.labs.pennmobile.classes.VenueInterval
import kotlinx.android.synthetic.main.fragment_dining_info.view.*
import org.joda.time.format.DateTimeFormat

/**
Expand All @@ -27,6 +26,7 @@ class DiningInfoFragment : Fragment() {
private lateinit var mActivity: MainActivity
private lateinit var mStudentLife: StudentLife


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mDiningHall = arguments?.getParcelable("DiningHall")
Expand All @@ -37,7 +37,7 @@ class DiningInfoFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val v = inflater.inflate(R.layout.fragment_dining_info, container, false)
v.setBackgroundColor(Color.WHITE)
menuParent = v.dining_hours
menuParent = v.findViewById(R.id.dining_hours)
fillInfo()
return v
}
Expand Down
Loading

0 comments on commit 40d5e98

Please sign in to comment.