added date in news
parent
99961e8a4e
commit
cc1603fcff
|
|
@ -8,11 +8,12 @@ import android.widget.TextView
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.core.content.ContextCompat.startActivity
|
|
||||||
import androidx.core.text.HtmlCompat
|
import androidx.core.text.HtmlCompat
|
||||||
import androidx.core.widget.TextViewCompat
|
import androidx.core.widget.TextViewCompat
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import fr.forum_thalie.tsumugi.R
|
import fr.forum_thalie.tsumugi.R
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class NewsAdapter(private val dataSet: ArrayList<News>, private val c: Context
|
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 text = holder.itemView.findViewById<TextView>(R.id.news_text)
|
||||||
val author = holder.itemView.findViewById<TextView>(R.id.news_author)
|
val author = holder.itemView.findViewById<TextView>(R.id.news_author)
|
||||||
val header = holder.itemView.findViewById<TextView>(R.id.news_header)
|
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.text = dataSet[position].title
|
||||||
title.setOnClickListener {
|
title.setOnClickListener {
|
||||||
val i = Intent(Intent.ACTION_VIEW)
|
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)
|
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"), " ")
|
header.text = HtmlCompat.fromHtml(dataSet[position].header, HtmlCompat.FROM_HTML_MODE_LEGACY).replace(Regex("\n"), " ")
|
||||||
author.text = "| ${dataSet[position].author}"
|
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)
|
TextViewCompat.setAutoSizeTextTypeWithDefaults(author, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,11 +71,12 @@ class NewsViewModel : ViewModel() {
|
||||||
news.text = item.content ?: ""
|
news.text = item.content ?: ""
|
||||||
news.header = item.description ?: ""
|
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)
|
newsArray.add(news)
|
||||||
}
|
}
|
||||||
// The list contains all article's data. For example you can use it for your adapter.
|
// The list contains all article's data. For example you can use it for your adapter.
|
||||||
|
|
|
||||||
|
|
@ -344,7 +344,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
app:layout_constraintGuide_percent="0.5" />
|
app:layout_constraintGuide_percent="0.58" />
|
||||||
|
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
|
|
@ -379,7 +379,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
app:layout_constraintGuide_percent="0.40" />
|
app:layout_constraintGuide_percent="0.33" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Guideline
|
<androidx.constraintlayout.widget.Guideline
|
||||||
android:id="@+id/splitHorizontalLayout"
|
android:id="@+id/splitHorizontalLayout"
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/news_header"
|
android:id="@+id/news_header"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:textStyle="italic"
|
android:textStyle="italic"
|
||||||
|
|
@ -42,8 +42,21 @@
|
||||||
android:layout_marginBottom="16dp"
|
android:layout_marginBottom="16dp"
|
||||||
app:layout_constraintTop_toBottomOf="@id/news_title"
|
app:layout_constraintTop_toBottomOf="@id/news_title"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
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_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintBottom_toTopOf="@id/news_text"
|
app:layout_constraintBottom_toTopOf="@id/news_text"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue