Bladeren bron

added date in news

yattoz 4 jaren geleden
bovenliggende
commit
cc1603fcff

+ 5 - 1
app/src/main/java/fr/forum_thalie/tsumugi/ui/news/NewsAdapter.kt Bestand weergeven

@@ -8,11 +8,12 @@ import android.widget.TextView
8 8
 import android.view.LayoutInflater
9 9
 import android.view.ViewGroup
10 10
 import androidx.constraintlayout.widget.ConstraintLayout
11
-import androidx.core.content.ContextCompat.startActivity
12 11
 import androidx.core.text.HtmlCompat
13 12
 import androidx.core.widget.TextViewCompat
14 13
 import androidx.recyclerview.widget.RecyclerView
15 14
 import fr.forum_thalie.tsumugi.R
15
+import java.text.SimpleDateFormat
16
+import java.util.*
16 17
 import kotlin.collections.ArrayList
17 18
 
18 19
 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
48 49
         val text = holder.itemView.findViewById<TextView>(R.id.news_text)
49 50
         val author = holder.itemView.findViewById<TextView>(R.id.news_author)
50 51
         val header = holder.itemView.findViewById<TextView>(R.id.news_header)
52
+        val date = holder.itemView.findViewById<TextView>(R.id.news_date)
51 53
         title.text = dataSet[position].title
52 54
         title.setOnClickListener {
53 55
             val i = Intent(Intent.ACTION_VIEW)
@@ -57,6 +59,8 @@ class NewsAdapter(private val dataSet: ArrayList<News>, private val c: Context
57 59
         text.text = HtmlCompat.fromHtml(dataSet[position].text, HtmlCompat.FROM_HTML_MODE_LEGACY)
58 60
         header.text = HtmlCompat.fromHtml(dataSet[position].header, HtmlCompat.FROM_HTML_MODE_LEGACY).replace(Regex("\n"), " ")
59 61
         author.text = "| ${dataSet[position].author}"
62
+        val sdf = SimpleDateFormat("dd MMM yyyy", Locale.getDefault())
63
+        date.text = sdf.format(dataSet[position].date)
60 64
         TextViewCompat.setAutoSizeTextTypeWithDefaults(author, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM)
61 65
     }
62 66
 

+ 4 - 3
app/src/main/java/fr/forum_thalie/tsumugi/ui/news/NewsViewModel.kt Bestand weergeven

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

+ 2 - 2
app/src/main/res/layout/fragment_nowplaying.xml Bestand weergeven

@@ -344,7 +344,7 @@
344 344
             android:layout_width="wrap_content"
345 345
             android:layout_height="wrap_content"
346 346
             android:orientation="horizontal"
347
-            app:layout_constraintGuide_percent="0.5" />
347
+            app:layout_constraintGuide_percent="0.58" />
348 348
 
349 349
 
350 350
         <ImageButton
@@ -379,7 +379,7 @@
379 379
         android:layout_width="wrap_content"
380 380
         android:layout_height="wrap_content"
381 381
         android:orientation="horizontal"
382
-        app:layout_constraintGuide_percent="0.40" />
382
+        app:layout_constraintGuide_percent="0.33" />
383 383
 
384 384
     <androidx.constraintlayout.widget.Guideline
385 385
     android:id="@+id/splitHorizontalLayout"

+ 14 - 1
app/src/main/res/layout/news_view.xml Bestand weergeven

@@ -34,7 +34,7 @@
34 34
 
35 35
     <TextView
36 36
         android:id="@+id/news_header"
37
-        android:layout_width="match_parent"
37
+        android:layout_width="0dp"
38 38
         android:layout_height="wrap_content"
39 39
         android:textSize="12sp"
40 40
         android:textStyle="italic"
@@ -42,8 +42,21 @@
42 42
         android:layout_marginBottom="16dp"
43 43
         app:layout_constraintTop_toBottomOf="@id/news_title"
44 44
         app:layout_constraintStart_toStartOf="parent"
45
+        app:layout_constraintEnd_toStartOf="@id/news_date"
46
+        app:layout_constraintBottom_toTopOf="@id/news_text"
47
+        />
48
+
49
+    <TextView
50
+        android:id="@+id/news_date"
51
+        android:layout_width="wrap_content"
52
+        android:layout_height="wrap_content"
53
+        android:gravity="end|center_vertical"
54
+        android:textAlignment="textEnd"
55
+        app:layout_constraintTop_toBottomOf="@id/news_title"
56
+        app:layout_constraintStart_toEndOf="@id/news_header"
45 57
         app:layout_constraintEnd_toEndOf="parent"
46 58
         app:layout_constraintBottom_toTopOf="@id/news_text"
59
+
47 60
         />
48 61
 
49 62
     <TextView