Parcourir la source

fix base64 image lol

Ethosa il y a 2 ans
Parent
commit
d03380ea7c

+ 2 - 2
app/build.gradle

@@ -10,8 +10,8 @@ android {
         applicationId "com.ethosa.ktc"
         minSdk 21
         targetSdk 32
-        versionCode 22
-        versionName "0.8.11"
+        versionCode 23
+        versionName "0.8.12"
         ndk {
             abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
         }

+ 6 - 1
app/src/main/java/com/ethosa/ktc/college/news/LastNews.kt

@@ -9,4 +9,9 @@ import androidx.annotation.Keep
 data class LastNews(
     val anonce: List<News>,
     val news: List<News>
-)
+) {
+    fun catch() {
+        for (new in news) new.catch()
+        for (new in anonce) new.catch()
+    }
+}

+ 8 - 2
app/src/main/java/com/ethosa/ktc/college/news/News.kt

@@ -16,6 +16,12 @@ data class News(
     val title: String,
     var body: String,
     val date: String,
-    val image: String,
+    var image: String,
     val id: String
-)
+) {
+    fun catch() {
+        if ("data:image" in image || image.length > 256) {
+            image = ""
+        }
+    }
+}

+ 1 - 1
app/src/main/java/com/ethosa/ktc/ui/adapters/NewsAdapter.kt

@@ -75,9 +75,9 @@ class NewsAdapter(
         binding.root.setOnClickListener {
             // Go to WallPostActivity
             val intent = Intent(binding.root.context, WallPostActivity::class.java)
+            intent.putExtra("image", new.image)
             intent.putExtra("id", new.id)
             intent.putExtra("title", new.title)
-            intent.putExtra("image", new.image)
             binding.root.context.startActivity(intent)
         }
     }

+ 1 - 0
app/src/main/java/com/ethosa/ktc/ui/adapters/NewsStoriesAdapter.kt

@@ -39,6 +39,7 @@ class NewsStoriesAdapter(
     override fun onBindViewHolder(holder: ViewHolder, pos: Int) {
         val binding = holder.binding
         val new = items[pos]
+        new.catch()
 
         // Download image and blurs it.
         Glide.with(binding.root)

+ 2 - 1
app/src/main/java/com/ethosa/ktc/ui/fragments/NewsFragment.kt

@@ -62,6 +62,7 @@ class NewsFragment : Fragment(), CollegeCallback {
         // Parse JSON
         val jsonString = response.body?.string()
         val news = Gson().fromJson(jsonString, LastNews::class.java)
+        news.catch()
         // Create animation object
         val animate = ObjectAnimator.ofFloat(
             _binding?.progressLoad, "alpha",
@@ -69,7 +70,7 @@ class NewsFragment : Fragment(), CollegeCallback {
         ).setDuration(500)
         activity?.runOnUiThread {
             animate.start()
-            _binding?.news?.adapter = NewsAdapter(news.anonce + news.news)
+            _binding?.news?.adapter = NewsAdapter(news.news + news.anonce)
             _binding?.newsStories?.adapter = NewsStoriesAdapter(
                 (news.anonce + news.news)
                     .filter { it.image != "" }