Skip to content

Commit

Permalink
Merge pull request #629 from pennlabs/kotlin-extension-removal
Browse files Browse the repository at this point in the history
ViewBinding Migration
  • Loading branch information
baronhsieh2005 authored Oct 7, 2024
2 parents b34951a + 1a368dd commit 6efbbf9
Show file tree
Hide file tree
Showing 57 changed files with 1,147 additions and 920 deletions.
2 changes: 1 addition & 1 deletion PennMobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ plugins {
id 'com.google.gms.google-services'
id("com.google.firebase.crashlytics")
id 'jacoco'
id 'kotlin-parcelize'
}

apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-android"

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.DiningHall
import com.pennapps.labs.pennmobile.classes.Venue
import com.pennapps.labs.pennmobile.databinding.FragmentDiningBinding
import kotlinx.android.synthetic.main.loading_panel.loadingPanel
import kotlinx.android.synthetic.main.no_results.no_results
import rx.Observable
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -165,9 +163,9 @@ class DiningFragment : Fragment() {
mActivity.runOnUiThread {
getMenus(diningHalls)
val adapter = DiningAdapter(diningHalls)
loadingPanel?.visibility = View.GONE
binding.loadingPanel.root.visibility = View.GONE
if (diningHalls.size > 0) {
no_results?.visibility = View.GONE
binding.noResults.root.visibility = View.GONE
}

// Log non-fatal error to crashyltics if null
Expand All @@ -186,7 +184,7 @@ class DiningFragment : Fragment() {
Log.e("DiningFragment", "Error getting dining halls", it)
mActivity.runOnUiThread {
Log.e("Dining", "Could not load Dining page", it)
loadingPanel?.visibility = View.GONE
binding.loadingPanel.root.visibility = View.GONE
binding.diningSwiperefresh.isRefreshing = false
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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.dining_swiperefresh

class DiningHolderFragment : Fragment() {
lateinit var pagerAdapter: DiningPagerAdapter
Expand All @@ -33,9 +32,6 @@ class DiningHolderFragment : Fragment() {
): View {
_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()
// Inflate the layout for this fragment
return view
Expand Down Expand Up @@ -64,21 +60,8 @@ class DiningHolderFragment : Fragment() {
setTitle("Dining")
}

private fun getConnected() {
// displays banner if not connected
if (!isOnline(context)) {
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 {
binding.internetConnectionDiningHolder.visibility = View.GONE
}
}

override fun onResume() {
super.onResume()
getConnected()
mActivity.removeTabs()
mActivity.setTitle(R.string.dining)
mActivity.setSelectedTab(MainActivity.DINING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -19,7 +20,6 @@ import com.pennapps.labs.pennmobile.classes.DiningHall
import com.pennapps.labs.pennmobile.classes.DiningRequest
import com.pennapps.labs.pennmobile.classes.HomepageDataModel
import com.pennapps.labs.pennmobile.databinding.FragmentDiningPreferencesBinding
import kotlinx.android.synthetic.main.include_main.toolbar
import retrofit.ResponseCallback
import retrofit.RetrofitError
import retrofit.client.Response
Expand All @@ -31,6 +31,7 @@ class DiningSettingsFragment(
private lateinit var mActivity: MainActivity
private lateinit var mStudentLife: StudentLife
private lateinit var halls: List<DiningHall>
private lateinit var toolbar: Toolbar
private val dataModel: HomepageDataModel = dataModel

private var _binding: FragmentDiningPreferencesBinding? = null
Expand All @@ -43,8 +44,6 @@ class DiningSettingsFragment(
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
mActivity = activity as MainActivity
mActivity.toolbar.visibility = View.VISIBLE
mActivity.title = "Select Favorites"
mStudentLife = MainActivity.studentLifeInstance
mStudentLife = MainActivity.studentLifeInstance
}
Expand All @@ -68,6 +67,16 @@ class DiningSettingsFragment(
return v
}

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)
toolbar = mActivity.findViewById(R.id.toolbar)
toolbar.visibility = View.VISIBLE
mActivity.title = "Select Favorites"
}

override fun onCreateOptionsMenu(
menu: Menu,
inflater: MenuInflater,
Expand All @@ -76,7 +85,7 @@ class DiningSettingsFragment(
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
mActivity.toolbar.visibility = View.GONE
toolbar.visibility = View.GONE
when (item.itemId) {
android.R.id.home -> {
mActivity.onBackPressed()
Expand Down Expand Up @@ -120,7 +129,7 @@ class DiningSettingsFragment(
}

override fun onDestroyView() {
mActivity.toolbar.visibility = View.GONE
toolbar.visibility = View.GONE
if (!savedNewPrefs) restoreOriginal()
_binding = null
super.onDestroyView()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.pennapps.labs.pennmobile.adapters.GsrReservationsAdapter
import com.pennapps.labs.pennmobile.databinding.FragmentGsrReservationsBinding
import kotlinx.android.synthetic.main.loading_panel.loadingPanel

class GsrReservationsFragment : Fragment() {
private lateinit var mActivity: MainActivity
Expand Down Expand Up @@ -70,7 +69,7 @@ class GsrReservationsFragment : Fragment() {
binding.internetConnectionMessageGsrReservations.text = "Not Connected to Internet"
binding.internetConnectionGSRReservations.visibility = View.VISIBLE
binding.gsrReservationsRefreshLayout.isRefreshing = false
loadingPanel?.visibility = View.GONE
binding.loadingPanel.root.visibility = View.GONE
binding.gsrNoReservations.visibility = View.VISIBLE
} else {
binding.internetConnectionGSRReservations.visibility = View.GONE
Expand All @@ -84,7 +83,7 @@ class GsrReservationsFragment : Fragment() {
binding.internetConnectionGSRReservations.visibility = View.VISIBLE
binding.gsrReservationsRefreshLayout.isRefreshing = false
binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList())
loadingPanel?.visibility = View.GONE
binding.loadingPanel.root.visibility = View.GONE
binding.gsrNoReservations.visibility = View.VISIBLE
} else {
binding.internetConnectionGSRReservations.visibility = View.GONE
Expand All @@ -101,7 +100,7 @@ class GsrReservationsFragment : Fragment() {
try {
labs.getGsrReservations("Bearer $token").subscribe({ reservations ->
mActivity.runOnUiThread {
loadingPanel?.visibility = View.GONE
binding.loadingPanel.root.visibility = View.GONE

try {
binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList(reservations))
Expand All @@ -120,7 +119,7 @@ class GsrReservationsFragment : Fragment() {
mActivity.runOnUiThread {
Log.e("GsrReservationsFragment", "Error getting reservations", throwable)
throwable.printStackTrace()
loadingPanel?.visibility = View.GONE
binding.loadingPanel.root.visibility = View.GONE
try {
binding.gsrReservationsRv.adapter = GsrReservationsAdapter(ArrayList())
binding.gsrNoReservations.visibility = View.VISIBLE
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Handler
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
Expand All @@ -20,13 +21,6 @@ import com.pennapps.labs.pennmobile.classes.HomepageViewModel
import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior
import com.pennapps.labs.pennmobile.databinding.FragmentHomeBinding
import com.pennapps.labs.pennmobile.utils.Utils
import kotlinx.android.synthetic.main.fragment_home.view.appbar_home
import kotlinx.android.synthetic.main.fragment_home.view.date_view
import kotlinx.android.synthetic.main.fragment_home.view.home_cells_rv
import kotlinx.android.synthetic.main.fragment_home.view.home_refresh_layout
import kotlinx.android.synthetic.main.fragment_home.view.profile
import kotlinx.android.synthetic.main.include_main.toolbar
import kotlinx.android.synthetic.main.loading_panel.loadingPanel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand All @@ -35,6 +29,7 @@ import java.util.Locale
class HomeFragment : Fragment() {
private lateinit var mActivity: MainActivity
private lateinit var sharedPreferences: SharedPreferences
private lateinit var toolbar: Toolbar

private var _binding: FragmentHomeBinding? = null
val binding get() = _binding!!
Expand All @@ -55,30 +50,10 @@ class HomeFragment : Fragment() {
): View {
_binding = FragmentHomeBinding.inflate(inflater, container, false)
val view = binding.root

view.home_cells_rv.layoutManager =
LinearLayoutManager(
context,
LinearLayoutManager.VERTICAL,
false,
)

view.home_refresh_layout
.setColorSchemeResources(R.color.color_accent, R.color.color_primary)
view.home_refresh_layout
.setOnRefreshListener {
getHomePage()
}

initAppBar(view)
return view
}

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

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
Expand Down Expand Up @@ -107,11 +82,25 @@ class HomeFragment : Fragment() {
below and change getHomePage() so that when HomeAdapter is set, homeCellsRv.visibility is
set to View.VISIBLE instead of View.INVISIBLE and hide loadingPanel
*/
toolbar = mActivity.findViewById(R.id.toolbar)
binding.homeCellsRv.layoutManager =
LinearLayoutManager(
context,
LinearLayoutManager.VERTICAL,
false,
)

binding.homeRefreshLayout
.setColorSchemeResources(R.color.color_accent, R.color.color_primary)
binding.homeRefreshLayout
.setOnRefreshListener {
getHomePage()
}
homepageViewModel.resetBlurViews()
homepageViewModel.blurViewsLoaded.observe(viewLifecycleOwner) { loaded ->
if (loaded) {
binding.homeCellsRv.visibility = View.VISIBLE
loadingPanel?.visibility = View.GONE
binding.loadingPanel.root.visibility = View.GONE
}
}

Expand Down Expand Up @@ -141,7 +130,7 @@ class HomeFragment : Fragment() {
binding.homeCellsRv.setPadding(0, 90, 0, 0)
binding.internetConnectionHome.visibility = View.VISIBLE
binding.homeRefreshLayout.isRefreshing = false
loadingPanel?.visibility = View.GONE
binding.loadingPanel.root.visibility = View.GONE
return false
}

Expand Down Expand Up @@ -196,9 +185,10 @@ class HomeFragment : Fragment() {

override fun onResume() {
super.onResume()
getOnline()
mActivity.removeTabs()
this.setTitle(getString(R.string.home))
mActivity.toolbar.visibility = View.GONE
toolbar.visibility = View.GONE
val initials = sharedPreferences.getString(getString(R.string.initials), null)
if (!initials.isNullOrEmpty()) {
binding.initials.text = initials
Expand All @@ -219,22 +209,27 @@ class HomeFragment : Fragment() {
private fun initAppBar(view: View) {
val firstName = sharedPreferences.getString(getString(R.string.first_name), null)
firstName?.let {
view.date_view.text = "Welcome, $it!".toUpperCase(Locale.getDefault())
binding.dateView.text = "Welcome, $it!".toUpperCase(Locale.getDefault())
Handler().postDelayed(
{
view.date_view.text = Utils.getCurrentSystemTime()
binding.dateView.text = Utils.getCurrentSystemTime()
},
4000,
)
} ?: run {
view.date_view.text = Utils.getCurrentSystemTime()
binding.dateView.text = Utils.getCurrentSystemTime()
}
(
view.appbar_home.layoutParams
binding.appbarHome.layoutParams
as CoordinatorLayout.LayoutParams
).behavior = ToolbarBehavior()
view.profile.setOnClickListener {
binding.profile.setOnClickListener {
// TODO: Account Settings
}
}

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

0 comments on commit 6efbbf9

Please sign in to comment.