Archived
Added small hints to FetcherActivity.kt to help out the user
This commit is contained in:
@@ -2,6 +2,7 @@ package com.denizk0461.studip.activity
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
@@ -28,6 +29,9 @@ class FetcherActivity : FragmentActivity() {
|
||||
// View model
|
||||
private lateinit var viewModel: FetcherViewModel
|
||||
|
||||
// URL of the schedule
|
||||
private val scheduleUrl: String = "https://elearning.uni-bremen.de/dispatch.php/calendar/schedule"
|
||||
|
||||
/**
|
||||
* Enabling JavaScript is necessary to get the HTML source in this context. As the HTML can only
|
||||
* be accessed once the user has logged in, a simple HTML request would not suffice here.
|
||||
@@ -44,10 +48,14 @@ class FetcherActivity : FragmentActivity() {
|
||||
binding = ActivityFetcherBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
// Remind the user of the help button
|
||||
showToast(this, getString(R.string.toast_info_reminder))
|
||||
|
||||
// Enabling JavaScript. See comment above lint suppression for reason why this is done.
|
||||
binding.webview.settings.apply {
|
||||
javaScriptEnabled = true
|
||||
}
|
||||
|
||||
binding.webview.webViewClient = object : WebViewClient() {
|
||||
// Disallow redirecting to prevent the app from launching Chrome after the user logs in
|
||||
override fun shouldOverrideUrlLoading(
|
||||
@@ -56,6 +64,18 @@ class FetcherActivity : FragmentActivity() {
|
||||
): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) {
|
||||
// Check whether the button to save the timetable should be shown
|
||||
if (url?.contains(scheduleUrl) == true) {
|
||||
binding.fab.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.fab.visibility = View.GONE
|
||||
}
|
||||
|
||||
// Super call
|
||||
super.doUpdateVisitedHistory(view, url, isReload)
|
||||
}
|
||||
}
|
||||
|
||||
// Set up bottom app bar for various actions
|
||||
@@ -77,6 +97,7 @@ class FetcherActivity : FragmentActivity() {
|
||||
val bundle = Bundle()
|
||||
bundle.putString("header", getString(R.string.fetch_bar_help_sheet_title))
|
||||
bundle.putString("content", getString(R.string.fetch_bar_help_sheet_content))
|
||||
bundle.putBoolean("isCancellable", true)
|
||||
sheet.arguments = bundle
|
||||
}.show(supportFragmentManager, TextSheet::class.java.simpleName)
|
||||
true
|
||||
@@ -96,7 +117,7 @@ class FetcherActivity : FragmentActivity() {
|
||||
binding.fab.setOnClickListener {
|
||||
|
||||
if (binding.webview.url?.contains(
|
||||
"https://elearning.uni-bremen.de/dispatch.php/calendar/schedule"
|
||||
scheduleUrl
|
||||
) == true) {
|
||||
/*
|
||||
* Retrieve encoded HTML via JavaScript function. Encoding is done as otherwise not all
|
||||
|
||||
@@ -39,6 +39,7 @@ class MainActivity : FragmentActivity() {
|
||||
binding.navHostFragmentContentMain.getFragment<NavHostFragment>().findNavController()
|
||||
)
|
||||
|
||||
// Set up navigation component
|
||||
setNavigationGraph()
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ fun Resources.Theme.showErrorSnackBar(view: CoordinatorLayout, text: String, anc
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a [TextSheet] with text content added as arguments bundle.
|
||||
* Retrieve a cancellable [TextSheet] with text content added as arguments bundle.
|
||||
*
|
||||
* @param header header of the sheet
|
||||
* @param content text content of the sheet
|
||||
@@ -76,6 +76,7 @@ fun getTextSheet(header: String, content: String): TextSheet = TextSheet().also
|
||||
val bundle = Bundle()
|
||||
bundle.putString("header", header)
|
||||
bundle.putString("content", content)
|
||||
bundle.putBoolean("isCancellable", true)
|
||||
sheet.arguments = bundle
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,15 @@ class CanteenFragment : AppFragment() {
|
||||
// View model reference for providing access to the database
|
||||
private val viewModel: CanteenViewModel by viewModels()
|
||||
|
||||
/**
|
||||
* Locally saved opening hours to quickly access them without querying the database on every
|
||||
* opening of the bottom sheet.
|
||||
*/
|
||||
private var openingHours = ""
|
||||
|
||||
/**
|
||||
* Locally stored dates to populate the TabLayout with.
|
||||
*/
|
||||
private var dates: List<String> = listOf()
|
||||
|
||||
// Instantiate the view binding
|
||||
|
||||
@@ -65,12 +65,8 @@ class EventFragment : AppFragment() {
|
||||
// Set the view pager's current page to the current day, if the user chose this option
|
||||
if (viewModel.preferenceCurrentDay) {
|
||||
|
||||
/*
|
||||
* Determine the current day and go to the respective page.
|
||||
* BUG: this selects the correct tab and changes the page, but it doesn't highlight
|
||||
* the tab that has been selected. binding.viewPager.currentPage encounters the same bug
|
||||
*/
|
||||
binding.dayTabLayout.getTabAt(
|
||||
// Determine the current day and go to the respective page.
|
||||
binding.viewPager.setCurrentItem(
|
||||
when (Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
|
||||
Calendar.TUESDAY -> 1
|
||||
Calendar.WEDNESDAY -> 2
|
||||
@@ -79,11 +75,16 @@ class EventFragment : AppFragment() {
|
||||
Calendar.SATURDAY -> 5
|
||||
Calendar.SUNDAY -> 6
|
||||
else -> 0 // assume Monday
|
||||
}
|
||||
)?.select()
|
||||
}, false
|
||||
)
|
||||
}
|
||||
|
||||
// Set up button for adding a new event
|
||||
binding.fabAddEvent.setOnClickListener {
|
||||
/*
|
||||
* Open the bottom sheet used for editing an event, but tell the sheet that it will be
|
||||
* used for creating a new event instead.
|
||||
*/
|
||||
openBottomSheet(
|
||||
ScheduleUpdateSheet().also { sheet ->
|
||||
val bundle = Bundle()
|
||||
@@ -92,29 +93,17 @@ class EventFragment : AppFragment() {
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the layout changes (e.g. device rotation) but NOT when the fragment is selected
|
||||
* from the bottom navigation view.
|
||||
*/
|
||||
// override fun onSaveInstanceState(outState: Bundle) {
|
||||
// super.onSaveInstanceState(outState)
|
||||
//
|
||||
// outState.putInt(
|
||||
// "viewPagerCurrentPage",
|
||||
// binding.viewPager.currentItem
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// override fun onViewStateRestored(savedInstanceState: Bundle?) {
|
||||
// super.onViewStateRestored(savedInstanceState)
|
||||
//
|
||||
// // Retrieve
|
||||
// val restoredPage = savedInstanceState?.getInt("viewPagerCurrentPage") ?: 0
|
||||
//
|
||||
//// binding.viewPager.currentItem = restoredPage
|
||||
// }
|
||||
// Show the user a little message if they're opening the app for the first time
|
||||
if (viewModel.preferenceFirstLaunch) {
|
||||
|
||||
// Show toast
|
||||
// showToast(context, getString(R.string.toast_first_launch))
|
||||
|
||||
// Remember that the app has been launched before
|
||||
viewModel.preferenceFirstLaunch = false
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidate the view binding
|
||||
override fun onDestroyView() {
|
||||
|
||||
@@ -8,6 +8,11 @@ package com.denizk0461.studip.model
|
||||
*/
|
||||
enum class SettingsPreferences(val key: String) {
|
||||
|
||||
/**
|
||||
* Whether the user is launching this app for the first time.
|
||||
*/
|
||||
FIRST_LAUNCH("check_first_launch"),
|
||||
|
||||
/**
|
||||
* Which allergens the user wants displayed or hidden.
|
||||
*/
|
||||
|
||||
@@ -57,6 +57,7 @@ class DevCodeSheet : AppSheet(R.layout.sheet_dev_code) {
|
||||
"UE9XRUxM".d64 -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9XUGMtVkVxQlBISQ==".d64)
|
||||
"Q0FMTE1F".d64 -> launchLink("aHR0cHM6Ly95b3V0dS5iZS8xbTV1WnJNMnktMA==".d64)
|
||||
"SkFNSVJP".d64 -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9fMVZoT2c0N3ozNA==".d64)
|
||||
"TE9ORUxZ".d64 -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9uLURFNHNfc3d5Zw==".d64)
|
||||
"Qk9KQUNL".d64 -> {
|
||||
startActivity(Intent(context, ImageActivity::class.java).also { intent ->
|
||||
val bundle = Bundle()
|
||||
|
||||
@@ -23,16 +23,26 @@ class TextSheet : AppSheet(R.layout.sheet_text) {
|
||||
// Retrieve content for the window
|
||||
val content = arguments?.getString("content") ?: ""
|
||||
|
||||
// Set whether the sheet should be cancellable by actions such as swiping
|
||||
val isSheetCancellable = arguments?.getBoolean("isCancellable") == true
|
||||
|
||||
// Set text values
|
||||
binding.apply {
|
||||
textHeader.text = header
|
||||
textContent.text = content
|
||||
}
|
||||
|
||||
// Set up close button
|
||||
binding.buttonCancel.setOnClickListener {
|
||||
// Do nothing and dismiss the sheet
|
||||
dismiss()
|
||||
// Set up an appropriate close button depending on whether the sheet is cancellable
|
||||
if (isSheetCancellable) {
|
||||
// Set up a simple X button to be able to close the sheet
|
||||
binding.buttonCancel.visibility = View.VISIBLE
|
||||
binding.buttonCancel.setOnClickListener {
|
||||
// Do nothing and dismiss the sheet
|
||||
dismiss()
|
||||
}
|
||||
} else {
|
||||
// Show a more prominent button to close the sheet
|
||||
binding.buttonCancel.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,13 @@ class EventViewModel(app: Application) : AppViewModel(app) {
|
||||
val preferenceCurrentDay: Boolean
|
||||
get() = repo.getBooleanPreference(
|
||||
SettingsPreferences.CURRENT_DAY,
|
||||
defaultValue = true
|
||||
defaultValue = true,
|
||||
)
|
||||
|
||||
var preferenceFirstLaunch: Boolean
|
||||
get() = repo.getBooleanPreference(
|
||||
SettingsPreferences.FIRST_LAUNCH,
|
||||
defaultValue = true,
|
||||
)
|
||||
set(value) { repo.setPreference(SettingsPreferences.FIRST_LAUNCH, value) }
|
||||
}
|
||||
Reference in New Issue
Block a user