Skip to content

Commit

Permalink
AIDEA775#58 link to ig bimo
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianYbarra committed Aug 21, 2023
1 parent 0658596 commit d578320
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 16 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/com/uncmorfi/data/network/MenuParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/uncmorfi/shared/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
22 changes: 21 additions & 1 deletion app/src/main/java/com/uncmorfi/shared/Helper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -231,4 +251,4 @@ fun TextView.updateVisibility() {

inline fun <T> LifecycleOwner.observe(liveData: LiveData<T>, crossinline body: (T) -> Unit) {
liveData.observe(this, { body.invoke(it) })
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/uncmorfi/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ class HomeFragment : Fragment() {
requireActivity().setTitle(R.string.app_name)
}

}
}
29 changes: 29 additions & 0 deletions app/src/main/java/com/uncmorfi/ui/menu/InformationMessageView.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
12 changes: 11 additions & 1 deletion app/src/main/java/com/uncmorfi/ui/menu/MenuFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MenuFragment : Fragment() {
swipeRefresh.init { viewModel.forceRefreshMenu() }
initRecyclerAndAdapter()
initMenu()
initInformationMessage()

observe(viewModel.getMenu()) { menu ->
adapter.updateMenu(menu)
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_outline_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>
36 changes: 25 additions & 11 deletions app/src/main/res/layout/fragment_menu.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.menu.MenuFragment"
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
tools:context=".ui.menu.MenuFragment">

<com.uncmorfi.ui.menu.InformationMessageView
android:id="@+id/informationCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
style="@style/MaterialCard"
app:rippleColor="@null"
app:cardBackgroundColor="@color/primary_text"/>

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/informationCard">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/menuRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:clipToPadding="false"
android:nestedScrollingEnabled="false"
android:scrollbars="none"
android:paddingTop="8dp"
android:paddingBottom="64dp"
tools:listitem="@layout/item_menu">
</androidx.recyclerview.widget.RecyclerView>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
tools:listitem="@layout/item_menu" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
47 changes: 47 additions & 0 deletions app/src/main/res/layout/view_information_message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:parentTag="com.google.android.material.card.MaterialCardView"
tools:backgroundTint="@color/primary_text">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">

<ImageView
android:id="@+id/informationMessageImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_outline_info"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/informationMessageTextView"
app:layout_constraintBottom_toBottomOf="@id/informationMessageTextView"
app:tint="@color/white" />

<TextView
android:id="@+id/informationMessageTextView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:textColor="@color/white"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
app:layout_constraintBottom_toTopOf="@id/informationMessageButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/informationMessageImageView"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/informationMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.Button.TextButton"
app:layout_constraintTop_toBottomOf="@id/informationMessageTextView"
app:layout_constraintEnd_toEndOf="@id/informationMessageTextView"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</merge>
5 changes: 4 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,7 @@
<string name="saved">Guardado</string>
<string name="clean">Limpiar</string>
<string name="cleaned">Limpiado</string>
</resources>

<string name="menu_information">"Por el momento el menu se publica a diario en las historias de Instagram de Bienestar Estudiantil"</string>
<string name="go">Ir</string>
</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@
<string name="notify_reserve_text">Reserve your serving in the dinning room!</string>

<!-- Any -->

<string name="action_browser">Open with&#8230;</string>
<string name="save">Save</string>
<string name="saved">Saved</string>
<string name="clean">Clean</string>
<string name="cleaned">Cleaned</string>

<string name="menu_information">"Currently, the menu is published daily on the Instagram stories of Bienestar Estudiantil"</string>
<string name="go">Go</string>

</resources>
</resources>

0 comments on commit d578320

Please sign in to comment.