added date in news

remotes/origin/devel
yattoz 2019-12-08 14:04:53 +01:00
parent 99961e8a4e
commit cc1603fcff
4 changed files with 25 additions and 7 deletions

View File

@ -8,11 +8,12 @@ import android.widget.TextView
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat.startActivity
import androidx.core.text.HtmlCompat
import androidx.core.widget.TextViewCompat
import androidx.recyclerview.widget.RecyclerView
import fr.forum_thalie.tsumugi.R
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
class NewsAdapter(private val dataSet: ArrayList<News>, private val c: Context
@ -48,6 +49,7 @@ class NewsAdapter(private val dataSet: ArrayList<News>, private val c: Context
val text = holder.itemView.findViewById<TextView>(R.id.news_text)
val author = holder.itemView.findViewById<TextView>(R.id.news_author)
val header = holder.itemView.findViewById<TextView>(R.id.news_header)
val date = holder.itemView.findViewById<TextView>(R.id.news_date)
title.text = dataSet[position].title
title.setOnClickListener {
val i = Intent(Intent.ACTION_VIEW)
@ -57,6 +59,8 @@ class NewsAdapter(private val dataSet: ArrayList<News>, private val c: Context
text.text = HtmlCompat.fromHtml(dataSet[position].text, HtmlCompat.FROM_HTML_MODE_LEGACY)
header.text = HtmlCompat.fromHtml(dataSet[position].header, HtmlCompat.FROM_HTML_MODE_LEGACY).replace(Regex("\n"), " ")
author.text = "| ${dataSet[position].author}"
val sdf = SimpleDateFormat("dd MMM yyyy", Locale.getDefault())
date.text = sdf.format(dataSet[position].date)
TextViewCompat.setAutoSizeTextTypeWithDefaults(author, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM)
}

View File

@ -71,11 +71,12 @@ class NewsViewModel : ViewModel() {
news.text = item.content ?: ""
news.header = item.description ?: ""
//val formatter6 = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
val formatter6 = SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH)
val dateString = item.pubDate.toString()
Log.d(tag, "$news --- ${dateString}")
//news.date = formatter6.parse(item.pubDate ?: Date().toString()) ?: Date()
news.date = formatter6.parse(dateString) ?: Date(0)
Log.d(tag, "$news - ${item.pubDate}")
newsArray.add(news)
}
// The list contains all article's data. For example you can use it for your adapter.

View File

@ -344,7 +344,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
app:layout_constraintGuide_percent="0.58" />
<ImageButton
@ -379,7 +379,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.40" />
app:layout_constraintGuide_percent="0.33" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/splitHorizontalLayout"

View File

@ -34,7 +34,7 @@
<TextView
android:id="@+id/news_header"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="italic"
@ -42,8 +42,21 @@
android:layout_marginBottom="16dp"
app:layout_constraintTop_toBottomOf="@id/news_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/news_date"
app:layout_constraintBottom_toTopOf="@id/news_text"
/>
<TextView
android:id="@+id/news_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="end|center_vertical"
android:textAlignment="textEnd"
app:layout_constraintTop_toBottomOf="@id/news_title"
app:layout_constraintStart_toEndOf="@id/news_header"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/news_text"
/>
<TextView