|
@@ -21,6 +21,7 @@ import androidx.core.text.HtmlCompat
|
21
|
21
|
import androidx.core.widget.TextViewCompat
|
22
|
22
|
import androidx.recyclerview.widget.RecyclerView
|
23
|
23
|
import fr.forum_thalie.tsumugi.R
|
|
24
|
+import fr.forum_thalie.tsumugi.newsDisplayDatePattern
|
24
|
25
|
import java.io.IOException
|
25
|
26
|
import java.io.InputStream
|
26
|
27
|
import java.net.URL
|
|
@@ -84,7 +85,7 @@ class ImageGetterAsyncTask(
|
84
|
85
|
|
85
|
86
|
}
|
86
|
87
|
|
87
|
|
-class NewsAdapter(private val dataSet: ArrayList<News>, private val c: Context
|
|
88
|
+class NewsAdapter(private val dataSet: ArrayList<News>, private val c: Context, private val vm: NewsViewModel
|
88
|
89
|
/*,
|
89
|
90
|
context: Context,
|
90
|
91
|
resource: Int,
|
|
@@ -125,23 +126,34 @@ class NewsAdapter(private val dataSet: ArrayList<News>, private val c: Context
|
125
|
126
|
|
126
|
127
|
header.text = HtmlCompat.fromHtml(dataSet[position].header, HtmlCompat.FROM_HTML_MODE_LEGACY).replace(Regex("\n"), " ")
|
127
|
128
|
author.text = "| ${dataSet[position].author}"
|
128
|
|
- val sdf = SimpleDateFormat("dd MMM yyyy", Locale.getDefault())
|
|
129
|
+ val sdf = SimpleDateFormat(newsDisplayDatePattern, Locale.getDefault())
|
129
|
130
|
date.text = sdf.format(dataSet[position].date)
|
130
|
131
|
TextViewCompat.setAutoSizeTextTypeWithDefaults(author, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM)
|
131
|
132
|
|
132
|
|
- val spanned = HtmlCompat.fromHtml(
|
133
|
|
- dataSet[position].text,
|
134
|
|
- HtmlCompat.FROM_HTML_MODE_LEGACY,
|
135
|
|
- ImageGetter { source ->
|
136
|
|
- val d = LevelListDrawable()
|
137
|
|
- val empty: Drawable? = ContextCompat.getDrawable(c, R.drawable.exo_icon_play)
|
138
|
|
-
|
139
|
|
- d.addLevel(0, 0, empty!!)
|
140
|
|
- d.setBounds(0, 0, empty.intrinsicWidth, empty.intrinsicHeight)
|
141
|
|
- ImageGetterAsyncTask(c, source, d).execute(text)
|
142
|
|
- d
|
143
|
|
- }, null
|
144
|
|
- )
|
|
133
|
+ val spanned = // the trick is to avoid loading images when the adapter is called with preloading.
|
|
134
|
+ if (vm.isPreLoadingNews) {
|
|
135
|
+ HtmlCompat.fromHtml(
|
|
136
|
+ dataSet[position].text,
|
|
137
|
+ HtmlCompat.FROM_HTML_MODE_LEGACY)
|
|
138
|
+ } else {
|
|
139
|
+ HtmlCompat.fromHtml(
|
|
140
|
+ dataSet[position].text,
|
|
141
|
+ HtmlCompat.FROM_HTML_MODE_LEGACY,
|
|
142
|
+ ImageGetter { source ->
|
|
143
|
+ val d = LevelListDrawable()
|
|
144
|
+ /*
|
|
145
|
+ val empty: Drawable? = ContextCompat.getDrawable(c, R.drawable.exo_icon_play)
|
|
146
|
+ d.addLevel(0, 0, empty!!)
|
|
147
|
+ d.setBounds(0, 0, empty.intrinsicWidth, empty.intrinsicHeight)
|
|
148
|
+ */
|
|
149
|
+ ImageGetterAsyncTask(c, source, d).execute(text)
|
|
150
|
+ d
|
|
151
|
+ }, null
|
|
152
|
+ )
|
|
153
|
+ }
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
145
|
157
|
text.text = spanned
|
146
|
158
|
text.movementMethod = LinkMovementMethod.getInstance()
|
147
|
159
|
}
|