Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewBinding Migration #629

Merged
merged 35 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
845de03
Dining Adapter Binding Implementation
baronhsieh2005 Sep 28, 2024
9bb12c3
UniversityEventAdapter Binding Implementation
baronhsieh2005 Sep 28, 2024
a25d77a
GSRReservationAdapter Change to ViewBinding
baronhsieh2005 Sep 28, 2024
12c958b
AboutAdapter ViewBinding Implementation
baronhsieh2005 Sep 28, 2024
4c875a3
Fling Adapter ViewBinding Implementation
baronhsieh2005 Sep 28, 2024
9c32fcf
HomeGsrBuildingAdapter ViewBinding Implementation (but seems to be ne…
baronhsieh2005 Sep 28, 2024
a48af7b
Warning Cleaning
baronhsieh2005 Sep 28, 2024
2027003
GsrRoomAdapter ViewBinding Implementation
baronhsieh2005 Sep 28, 2024
1aaa409
GSRRservationsFragement LoadingPanel Redefine
baronhsieh2005 Sep 28, 2024
267ed8e
GSRRservationsFragement LoadingPanel Redefine
baronhsieh2005 Sep 28, 2024
9cdd415
GSRRservationsAdapter transition to ViewBinding
baronhsieh2005 Sep 28, 2024
7b627ac
Implement ViewBinding in MoreFragment
baronhsieh2005 Sep 28, 2024
9197ca1
initAppBar modifications
baronhsieh2005 Sep 28, 2024
1a8b9c6
linting
baronhsieh2005 Sep 29, 2024
72eb287
LaundryFragment loadingPanel fix
baronhsieh2005 Sep 29, 2024
fa9f315
DiningCardAdapter ViewBinding Implementation
baronhsieh2005 Sep 29, 2024
2a94c82
SupportFragment ToolBar Reimplementation (finally figured this jawn out)
baronhsieh2005 Sep 29, 2024
ada39e3
MenuFragment toolbar fix
baronhsieh2005 Sep 30, 2024
8d317d6
LaundrtMachine Adapter viewBinding + Switch to SwitchCompat for alarm…
baronhsieh2005 Sep 30, 2024
2728e00
Created ViewModels Folder (So it won't be too chaotic when I migrate …
baronhsieh2005 Oct 1, 2024
bf5e339
HomeAdapter Viewbinding implementation and ViewHolder creation (actua…
baronhsieh2005 Oct 2, 2024
104f3bd
DiningSettingsAdapter and SupportAdapter viewBinding implementation (…
baronhsieh2005 Oct 2, 2024
d85df72
ViewBinding and toolBar tweaks (Where do we even access this savecont…
baronhsieh2005 Oct 2, 2024
9c4db65
DiningSettings ToolBar fix
baronhsieh2005 Oct 2, 2024
a956a6c
DiningFragment and LaundrySettingsFragment toolbar, no_results, and l…
baronhsieh2005 Oct 2, 2024
faea174
HomeFragment viewbinding and toolbar/loadingpanel reimplementation
baronhsieh2005 Oct 4, 2024
b28891e
MainActivity ViewBinding Implementation
baronhsieh2005 Oct 4, 2024
b852b20
DiningHolder Redundant Internet Connectivity fix and HomeFragment aut…
baronhsieh2005 Oct 6, 2024
4f0fefe
Tweaked PennCourseAlertManageAlertsFragment so we don't directly call…
baronhsieh2005 Oct 6, 2024
e197865
ViewBinding immigration Complete!
baronhsieh2005 Oct 6, 2024
8052333
Small Tweaks on SavedState (so it uses the non-deprecated parcelize l…
baronhsieh2005 Oct 6, 2024
c7bce3b
loadingPanel and noResults fixes s.t they can be accessed directly by…
baronhsieh2005 Oct 6, 2024
3647511
HomeAdapter modifications such that Calendar, Dining, and Laundry cel…
baronhsieh2005 Oct 6, 2024
f5686b1
Merge branch 'main' into kotlin-extension-removal
baronhsieh2005 Oct 6, 2024
1a368dd
Small Menu Fragment tweak after merge
baronhsieh2005 Oct 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading