From d578320ea2db8d10be31c320658be44c4f8052b2 Mon Sep 17 00:00:00 2001 From: JulianYbarra Date: Sat, 12 Aug 2023 17:20:33 -0300 Subject: [PATCH] #58 link to ig bimo --- .../com/uncmorfi/data/network/MenuParser.kt | 7 +++ .../java/com/uncmorfi/shared/Constants.kt | 2 + .../main/java/com/uncmorfi/shared/Helper.kt | 22 ++++++++- .../java/com/uncmorfi/ui/home/HomeFragment.kt | 2 +- .../ui/menu/InformationMessageView.kt | 29 ++++++++++++ .../java/com/uncmorfi/ui/menu/MenuFragment.kt | 12 ++++- app/src/main/res/drawable/ic_outline_info.xml | 5 ++ app/src/main/res/layout/fragment_menu.xml | 36 +++++++++----- .../res/layout/view_information_message.xml | 47 +++++++++++++++++++ app/src/main/res/values-es/strings.xml | 5 +- app/src/main/res/values/strings.xml | 6 ++- 11 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/com/uncmorfi/ui/menu/InformationMessageView.kt create mode 100644 app/src/main/res/drawable/ic_outline_info.xml create mode 100644 app/src/main/res/layout/view_information_message.xml diff --git a/app/src/main/java/com/uncmorfi/data/network/MenuParser.kt b/app/src/main/java/com/uncmorfi/data/network/MenuParser.kt index 8476816..bc4c2d9 100644 --- a/app/src/main/java/com/uncmorfi/data/network/MenuParser.kt +++ b/app/src/main/java/com/uncmorfi/data/network/MenuParser.kt @@ -9,6 +9,8 @@ import org.jsoup.nodes.Element import org.jsoup.parser.Parser import org.jsoup.safety.Safelist import java.time.LocalDate +import java.time.format.TextStyle +import java.util.Locale object MenuParser { @@ -29,6 +31,11 @@ object MenuParser { .last() .trim() + val currentMonth = currentDay.month.getDisplayName(TextStyle.FULL , Locale.getDefault()) + if(!month.contains(currentMonth,true)){ + return emptyList() + } + for (child in menu.children()) { if (child.childrenSize() == 0) continue diff --git a/app/src/main/java/com/uncmorfi/shared/Constants.kt b/app/src/main/java/com/uncmorfi/shared/Constants.kt index 66ca12a..8fcbd83 100644 --- a/app/src/main/java/com/uncmorfi/shared/Constants.kt +++ b/app/src/main/java/com/uncmorfi/shared/Constants.kt @@ -10,6 +10,8 @@ const val COCINA_URL = "http://comedor.unc.edu.ar/cocina.php" const val PROFILE_PIC_URL = "https://asiruws.unc.edu.ar/foto/" const val SANAVIRON_URL = "https://autogestion.sanaviron.unc.edu.ar/micuenta" +const val SEC_BIMO_INSTAGRAM = "bienestarunc" + const val ARG_CARD = "card" const val ARG_USER = "user" diff --git a/app/src/main/java/com/uncmorfi/shared/Helper.kt b/app/src/main/java/com/uncmorfi/shared/Helper.kt index 59a4d7b..4736e1e 100644 --- a/app/src/main/java/com/uncmorfi/shared/Helper.kt +++ b/app/src/main/java/com/uncmorfi/shared/Helper.kt @@ -3,6 +3,7 @@ package com.uncmorfi.shared import android.app.Activity import android.app.PendingIntent import android.app.PendingIntent.FLAG_IMMUTABLE +import android.content.ActivityNotFoundException import android.content.ClipData import android.content.ClipboardManager import android.content.Context @@ -162,6 +163,25 @@ fun Activity.openFacebook() { } } +fun Activity.openInstagram(user : String){ + val userUrl = "http://instagram.com/stories/$user/" + val url = "http://instagram.com/$user" + + val uri = Uri.parse(userUrl) + val intent = Intent(Intent.ACTION_VIEW, uri) + intent.setPackage("com.instagram.android") + + try { + ContextCompat.startActivity(this,intent,null) + } catch (e: ActivityNotFoundException) { + ContextCompat.startActivity(this, + Intent( + Intent.ACTION_VIEW, + Uri.parse(url) + ),null) + } +} + fun Activity.shareText(subject: String, text: String, title: String = "UNCmorfi"): Boolean { val i = Intent(Intent.ACTION_SEND) i.type = "text/plain" @@ -231,4 +251,4 @@ fun TextView.updateVisibility() { inline fun LifecycleOwner.observe(liveData: LiveData, crossinline body: (T) -> Unit) { liveData.observe(this, { body.invoke(it) }) -} +} \ No newline at end of file diff --git a/app/src/main/java/com/uncmorfi/ui/home/HomeFragment.kt b/app/src/main/java/com/uncmorfi/ui/home/HomeFragment.kt index 7386621..7627f9b 100644 --- a/app/src/main/java/com/uncmorfi/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/uncmorfi/ui/home/HomeFragment.kt @@ -134,4 +134,4 @@ class HomeFragment : Fragment() { requireActivity().setTitle(R.string.app_name) } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/uncmorfi/ui/menu/InformationMessageView.kt b/app/src/main/java/com/uncmorfi/ui/menu/InformationMessageView.kt new file mode 100644 index 0000000..ddf1201 --- /dev/null +++ b/app/src/main/java/com/uncmorfi/ui/menu/InformationMessageView.kt @@ -0,0 +1,29 @@ +package com.uncmorfi.ui.menu + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import com.google.android.material.card.MaterialCardView +import com.uncmorfi.R +import kotlinx.android.synthetic.main.view_information_message.view.informationMessageButton +import kotlinx.android.synthetic.main.view_information_message.view.informationMessageTextView + +class InformationMessageView @JvmOverloads constructor( + context: Context, + attr: AttributeSet? = null, + defStyleAttr: Int = 0 +) : MaterialCardView(context, attr, defStyleAttr) { + + init { + LayoutInflater.from(context).inflate(R.layout.view_information_message, this, true) + informationMessageButton.isClickable = false + } + + fun setMessage(message : String){ + informationMessageTextView.setText(message) + } + + fun setButtonText(buttonText : String){ + informationMessageButton.text = buttonText + } +} \ No newline at end of file diff --git a/app/src/main/java/com/uncmorfi/ui/menu/MenuFragment.kt b/app/src/main/java/com/uncmorfi/ui/menu/MenuFragment.kt index 1bec3be..eec3e47 100644 --- a/app/src/main/java/com/uncmorfi/ui/menu/MenuFragment.kt +++ b/app/src/main/java/com/uncmorfi/ui/menu/MenuFragment.kt @@ -39,6 +39,7 @@ class MenuFragment : Fragment() { swipeRefresh.init { viewModel.forceRefreshMenu() } initRecyclerAndAdapter() initMenu() + initInformationMessage() observe(viewModel.getMenu()) { menu -> adapter.updateMenu(menu) @@ -71,7 +72,6 @@ class MenuFragment : Fragment() { private fun initRecyclerAndAdapter() { menuRecyclerView.setHasFixedSize(true) val layoutManager = LinearLayoutManager(context) - layoutManager.stackFromEnd = true menuRecyclerView.layoutManager = layoutManager menuRecyclerView.isNestedScrollingEnabled = false } @@ -81,6 +81,16 @@ class MenuFragment : Fragment() { menuRecyclerView.adapter = adapter } + private fun initInformationMessage() { + informationCard.apply { + setMessage(getString(R.string.menu_information)) + setButtonText(getString(R.string.go)) + setOnClickListener { + requireActivity().openInstagram(SEC_BIMO_INSTAGRAM) + } + } + } + override fun onResume() { super.onResume() requireActivity().setTitle(R.string.navigation_menu) diff --git a/app/src/main/res/drawable/ic_outline_info.xml b/app/src/main/res/drawable/ic_outline_info.xml new file mode 100644 index 0000000..dca49ae --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_info.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_menu.xml b/app/src/main/res/layout/fragment_menu.xml index 0f22747..d7c8dfa 100644 --- a/app/src/main/res/layout/fragment_menu.xml +++ b/app/src/main/res/layout/fragment_menu.xml @@ -1,21 +1,35 @@ - + android:layout_height="match_parent" + tools:context=".ui.menu.MenuFragment"> + + + + - - - \ No newline at end of file + tools:listitem="@layout/item_menu" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_information_message.xml b/app/src/main/res/layout/view_information_message.xml new file mode 100644 index 0000000..b3560c7 --- /dev/null +++ b/app/src/main/res/layout/view_information_message.xml @@ -0,0 +1,47 @@ + + + + + + + + + +