diff --git a/app/build.gradle b/app/build.gradle index 9726823a7d..fe684737b8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,9 +109,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'android.arch.lifecycle:reactivestreams:1.1.1' implementation 'android.arch.work:work-runtime-ktx:1.0.1' - // Note: Appcompat 1.4 breaks sandwich menu injected into toolbar by DrawerLayout - // upgrading this and or androidx.fragment:fragment-ktx will break the toolbar - implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.appcompat:appcompat:1.4.1' kapt 'androidx.lifecycle:lifecycle-compiler:2.4.1' kapt "androidx.room:room-compiler:$room_version" @@ -142,8 +140,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.anko:anko:0.10.8" implementation 'androidx.core:core-ktx:1.7.0' - // Note: upgrading this and or androidx.appcompat:appcompat will break the toolbar - implementation 'androidx.fragment:fragment-ktx:1.2.5' + implementation 'androidx.fragment:fragment-ktx:1.4.1' // Note: fix for internal androidx libraries using outdated WorkManager causing a crash implementation "androidx.work:work-runtime-ktx:2.7.1" diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/other/generic/activity/BaseNavigationActivity.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/other/generic/activity/BaseNavigationActivity.kt index fcbf495051..5440d453df 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/other/generic/activity/BaseNavigationActivity.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/other/generic/activity/BaseNavigationActivity.kt @@ -48,7 +48,7 @@ class BaseNavigationActivity : BaseActivity( private val fragmentCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() { override fun onFragmentStarted(fm: FragmentManager, f: Fragment) { - initDrawerToggle() + initDrawerToggle(f) updateDrawer() } } @@ -97,9 +97,9 @@ class BaseNavigationActivity : BaseActivity( } } - private fun initDrawerToggle() { + private fun initDrawerToggle(fragment: Fragment) { val drawerLayout = findViewById(R.id.drawer_layout) - val toolbar = findViewById(R.id.toolbar) + val toolbar = fragment.requireView().findViewById(R.id.toolbar) drawerToggle?.let { drawerLayout.removeDrawerListener(it) } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/other/generic/fragment/BaseFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/other/generic/fragment/BaseFragment.kt index 36a2413984..b916d33232 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/other/generic/fragment/BaseFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/other/generic/fragment/BaseFragment.kt @@ -48,9 +48,6 @@ abstract class BaseFragment( private var apiCall: Call? = null private var hadSuccessfulRequest = false - private val toolbar: Toolbar? - get() = requireActivity().findViewById(R.id.toolbar) - private val contentView: ViewGroup get() = requireActivity().findViewById(android.R.id.content).getChildAt(0) as ViewGroup @@ -80,7 +77,11 @@ abstract class BaseFragment( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - setupToolbar() + + view.findViewById(R.id.toolbar)?.let { + setupToolbar(it) + } + // If content is refreshable setup the SwipeRefreshLayout swipeRefreshLayout?.apply { setOnRefreshListener(this@BaseFragment) @@ -92,13 +93,8 @@ abstract class BaseFragment( } } - override fun onResume() { - super.onResume() - toolbar?.setTitle(titleResId) - } - - private fun setupToolbar() { - val toolbar = toolbar ?: return + private fun setupToolbar(toolbar: Toolbar) { + toolbar.setTitle(titleResId) baseActivity.setSupportActionBar(toolbar) baseActivity.supportActionBar?.let { diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/CalendarFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/CalendarFragment.kt index 9024b3fd8c..ccc131e8e6 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/CalendarFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/tumui/calendar/CalendarFragment.kt @@ -14,7 +14,6 @@ import android.view.View import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat.checkSelfPermission import com.alamkanak.weekview.DateTimeInterpreter -import com.alamkanak.weekview.WeekView import com.alamkanak.weekview.WeekViewDisplayable import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding import de.tum.`in`.tumcampusapp.R @@ -49,10 +48,6 @@ class CalendarFragment : FragmentForAccessingTumOnline( CalendarController(requireContext()) } - private val weekView: WeekView by lazy { - requireActivity().findViewById>(R.id.weekView) - } - private val showDate: DateTime? by lazy { val value = arguments?.getLong(Const.EVENT_TIME, -1) ?: -1 if (value != -1L) DateTime(value) else null @@ -86,25 +81,28 @@ class CalendarFragment : FragmentForAccessingTumOnline( override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - // The week view adds a horizontal bar below the Toolbar. When refreshing, the refresh - // spinner covers it. Therefore, we adjust the spinner's end position. - swipeRefreshLayout.let { - val startOffset = it.progressViewStartOffset - val endOffset = it.progressViewEndOffset - it.setProgressViewOffset(false, startOffset, endOffset) - } + with(binding) { + // The week view adds a horizontal bar below the Toolbar. When refreshing, the refresh + // spinner covers it. Therefore, we adjust the spinner's end position. + swipeRefreshLayout.let { + val startOffset = it.progressViewStartOffset + val endOffset = it.progressViewEndOffset + it.setProgressViewOffset(false, startOffset, endOffset) + } - weekView.setOnMonthChangeListener { startDate, endDate -> - val begin = DateTime(startDate) - val end = DateTime(endDate) - prepareCalendarItems(begin, end) - } + weekView.setOnMonthChangeListener { startDate, endDate -> + val begin = DateTime(startDate) + val end = DateTime(endDate) + prepareCalendarItems(begin, end) + } + + weekView.setOnEventClickListener { data, _ -> + openEvent(data as CalendarItem) + } - weekView.setOnEventClickListener { data, _ -> - openEvent(data) + todayButton.setOnClickListener { weekView.goToToday() } } - binding.todayButton.setOnClickListener { weekView.goToToday() } showDate?.let { openEvent(eventId) } isWeekMode = Utils.getSettingBool(requireContext(), Const.CALENDAR_WEEK_MODE, false) @@ -210,7 +208,7 @@ class CalendarFragment : FragmentForAccessingTumOnline( return true } R.id.action_create_event -> { - val currentDate = LocalDate(weekView.firstVisibleDate) + val currentDate = LocalDate(binding.weekView.firstVisibleDate) val intent = Intent(requireContext(), CreateEventActivity::class.java) intent.putExtra(Const.DATE, currentDate) startActivityForResult(intent, REQUEST_CREATE) @@ -430,23 +428,23 @@ class CalendarFragment : FragmentForAccessingTumOnline( if (isWeekMode) { icon = R.drawable.ic_outline_calendar_view_day_24px - weekView.numberOfVisibleDays = 5 + binding.weekView.numberOfVisibleDays = 5 } else { icon = R.drawable.ic_outline_view_column_24px - weekView.numberOfVisibleDays = 1 + binding.weekView.numberOfVisibleDays = 1 } // Go to current date or the one given in the intent showDate?.let { - weekView.goToDate(it.toGregorianCalendar()) - weekView.goToHour(it.hourOfDay) - } ?: weekView.goToCurrentTime() + binding.weekView.goToDate(it.toGregorianCalendar()) + binding.weekView.goToHour(it.hourOfDay) + } ?: binding.weekView.goToCurrentTime() menuItemSwitchView?.setIcon(icon) } private fun setupDateTimeInterpreter(shortDate: Boolean) { - weekView.dateTimeInterpreter = object : DateTimeInterpreter { + binding.weekView.dateTimeInterpreter = object : DateTimeInterpreter { private val timeFormat = DateTimeFormat.forPattern("HH:mm").withLocale(Locale.getDefault()) @@ -492,6 +490,12 @@ class CalendarFragment : FragmentForAccessingTumOnline( .show() } + override fun onDestroyView() { + super.onDestroyView() + menuItemSwitchView = null + menuItemFilterCanceled = null + } + companion object { private const val REQUEST_SYNC = 0 diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/openinghour/OpeningHoursListFragment.java b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/openinghour/OpeningHoursListFragment.java index 92fa9ccd48..83bdfe8904 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/openinghour/OpeningHoursListFragment.java +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/openinghour/OpeningHoursListFragment.java @@ -83,7 +83,7 @@ public void onSaveInstanceState(@NotNull Bundle outState) { public void onViewCreated(@NotNull View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - listView = requireActivity().findViewById(R.id.listView); + listView = view.findViewById(R.id.listView); listView.setOnItemClickListener(this); listView.setAdapter(adapter); diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/activity/EventsFragment.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/activity/EventsFragment.kt index dec897b14e..901ff0095f 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/activity/EventsFragment.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/ticket/activity/EventsFragment.kt @@ -41,7 +41,7 @@ class EventsFragment : FragmentForDownloadingExternal( super.onViewCreated(view, savedInstanceState) setupViewPager(binding.viewPager) - val eventTab = requireActivity().findViewById(R.id.event_tab) + val eventTab = view.findViewById(R.id.event_tab) eventTab.setupWithViewPager(binding.viewPager) eventTab.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {