Browse Source

added date in news

yattoz 4 years ago
parent
commit
cc1603fcff

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

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

71
                     news.text = item.content ?: ""
71
                     news.text = item.content ?: ""
72
                     news.header = item.description ?: ""
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
                     newsArray.add(news)
80
                     newsArray.add(news)
80
                 }
81
                 }
81
                 // The list contains all article's data. For example you can use it for your adapter.
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 View File

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

+ 14 - 1
app/src/main/res/layout/news_view.xml View File

34
 
34
 
35
     <TextView
35
     <TextView
36
         android:id="@+id/news_header"
36
         android:id="@+id/news_header"
37
-        android:layout_width="match_parent"
37
+        android:layout_width="0dp"
38
         android:layout_height="wrap_content"
38
         android:layout_height="wrap_content"
39
         android:textSize="12sp"
39
         android:textSize="12sp"
40
         android:textStyle="italic"
40
         android:textStyle="italic"
42
         android:layout_marginBottom="16dp"
42
         android:layout_marginBottom="16dp"
43
         app:layout_constraintTop_toBottomOf="@id/news_title"
43
         app:layout_constraintTop_toBottomOf="@id/news_title"
44
         app:layout_constraintStart_toStartOf="parent"
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
         app:layout_constraintEnd_toEndOf="parent"
57
         app:layout_constraintEnd_toEndOf="parent"
46
         app:layout_constraintBottom_toTopOf="@id/news_text"
58
         app:layout_constraintBottom_toTopOf="@id/news_text"
59
+
47
         />
60
         />
48
 
61
 
49
     <TextView
62
     <TextView