Archived
Links in canteen news are now fetched and can be clicked
This commit is contained in:
@@ -514,7 +514,7 @@ class StwParser(application: Application) {
|
|||||||
private fun Document.retrieveNews(): String = try {
|
private fun Document.retrieveNews(): String = try {
|
||||||
getElementsByClass("field__items")[0]
|
getElementsByClass("field__items")[0]
|
||||||
.getElementsByTag("p")[0]
|
.getElementsByTag("p")[0]
|
||||||
.text()
|
.html()
|
||||||
} catch (e: IndexOutOfBoundsException) {
|
} catch (e: IndexOutOfBoundsException) {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.denizk0461.weserplaner.sheet
|
package com.denizk0461.weserplaner.sheet
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.text.Html
|
||||||
|
import android.text.method.LinkMovementMethod
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.core.text.HtmlCompat
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import com.denizk0461.weserplaner.R
|
import com.denizk0461.weserplaner.R
|
||||||
import com.denizk0461.weserplaner.data.viewBinding
|
import com.denizk0461.weserplaner.data.viewBinding
|
||||||
@@ -45,17 +48,6 @@ class TextSheet : AppSheet(R.layout.sheet_text) {
|
|||||||
if (contentId == -1) {
|
if (contentId == -1) {
|
||||||
binding.textHeader.text = header
|
binding.textHeader.text = header
|
||||||
binding.textContent.text = content
|
binding.textContent.text = content
|
||||||
// } else (when (contentId) {
|
|
||||||
// // Observe LiveData if corresponding ID has been passed
|
|
||||||
// TextSheetContentId.OPENING_HOURS -> viewModel.getCanteen()
|
|
||||||
// TextSheetContentId.NEWS -> viewModel.getCanteen()
|
|
||||||
// else -> throw InvalidContentIdException()
|
|
||||||
// }).observe(viewLifecycleOwner) { observedContent ->
|
|
||||||
// // Show the content
|
|
||||||
// binding.textContent.text = (observedContent ?: "")
|
|
||||||
// // If the content is empty, tell the user
|
|
||||||
// .ifBlank { emptyContentStringFor(contentId) }
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
viewModel.getCanteen().observe(viewLifecycleOwner) { canteen ->
|
viewModel.getCanteen().observe(viewLifecycleOwner) { canteen ->
|
||||||
when (contentId) {
|
when (contentId) {
|
||||||
@@ -71,9 +63,10 @@ class TextSheet : AppSheet(R.layout.sheet_text) {
|
|||||||
binding.textHeader.text = getString(
|
binding.textHeader.text = getString(
|
||||||
R.string.text_sheet_news_title, canteen.canteen
|
R.string.text_sheet_news_title, canteen.canteen
|
||||||
)
|
)
|
||||||
binding.textContent.text = canteen.news.ifBlank {
|
binding.textContent.text = Html.fromHtml(canteen.news.ifBlank {
|
||||||
getString(R.string.text_sheet_news_empty)
|
getString(R.string.text_sheet_news_empty)
|
||||||
}
|
}, HtmlCompat.FROM_HTML_MODE_LEGACY)
|
||||||
|
binding.textContent.movementMethod = LinkMovementMethod.getInstance()
|
||||||
}
|
}
|
||||||
else -> {} // should not occur
|
else -> {} // should not occur
|
||||||
}
|
}
|
||||||
@@ -93,16 +86,4 @@ class TextSheet : AppSheet(R.layout.sheet_text) {
|
|||||||
binding.buttonCancel.visibility = View.GONE
|
binding.buttonCancel.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves a string to show to the user if the content is empty.
|
|
||||||
*
|
|
||||||
* @param contentId used to determine which string res should be used
|
|
||||||
* @return localised string to show the user
|
|
||||||
*/
|
|
||||||
private fun emptyContentStringFor(contentId: Int) = getString(when (contentId) {
|
|
||||||
TextSheetContentId.OPENING_HOURS -> R.string.text_sheet_opening_hours_empty
|
|
||||||
TextSheetContentId.NEWS -> R.string.text_sheet_news_empty
|
|
||||||
else -> R.string.error_generic
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,6 @@
|
|||||||
android:id="@+id/text_content"
|
android:id="@+id/text_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:autoLink="web"
|
|
||||||
android:layout_marginHorizontal="24dp"
|
android:layout_marginHorizontal="24dp"
|
||||||
android:layout_marginBottom="24dp"/>
|
android:layout_marginBottom="24dp"/>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user