瀏覽代碼

little refactoring

Ethosa 3 年之前
父節點
當前提交
d461fdb385

+ 6 - 0
app/src/main/java/com/ethosa/ktc/activities/AlbumActivity.kt

@@ -16,6 +16,9 @@ import jp.wasabeef.glide.transformations.BlurTransformation
 import okhttp3.Call
 import okhttp3.Response
 
+/**
+ * Provides album behavior.
+ */
 class AlbumActivity(
     private val spanCount: Int = 2
 ) : AppCompatActivity(), CollegeCallback {
@@ -46,6 +49,9 @@ class AlbumActivity(
         college.fetchAlbumById(intent.getStringExtra("id")!!, this)
     }
 
+    /**
+     * Fetches album content
+     */
     override fun onResponse(call: Call, response: Response) {
         // Parse JSON
         val json = response.body?.string()

+ 3 - 0
app/src/main/java/com/ethosa/ktc/activities/MainActivity.kt

@@ -8,6 +8,9 @@ import androidx.navigation.ui.setupWithNavController
 import com.ethosa.ktc.R
 import com.ethosa.ktc.databinding.ActivityMainBinding
 
+/**
+ * The main app activity.
+ */
 class MainActivity : AppCompatActivity() {
     private lateinit var binding: ActivityMainBinding
 

+ 33 - 30
app/src/main/java/com/ethosa/ktc/activities/WallPostActivity.kt

@@ -16,7 +16,10 @@ import com.google.gson.Gson
 import okhttp3.Call
 import okhttp3.Response
 
-class WallPostActivity : AppCompatActivity() {
+/**
+ * Provides Wall post behavior
+ */
+class WallPostActivity : AppCompatActivity(), CollegeCallback {
 
     private lateinit var binding: ActivityWallPostBinding
     private val college: CollegeApi = CollegeApi()
@@ -38,35 +41,35 @@ class WallPostActivity : AppCompatActivity() {
             .into(binding.toolbarImage)
 
         // Fetches post data.
-        college.fetchNewById(
-            intent.getStringExtra("id")!!.toInt(),
-            object : CollegeCallback {
-                override fun onResponse(call: Call, response: Response) {
-                    // Parse JSON
-                    val body = response.body?.string()
-                    val new = Gson().fromJson(body, New::class.java)
-                    // Create animation object
-                    val animate = ObjectAnimator.ofFloat(
-                        binding.content.progressBar, "alpha", 1f, 0f
-                    )
-                    animate.duration = 500
-                    // Fix <img/> tag
-                    new.body = new.body.replace(
-                        "src=\"/", "src=\"http://www.kansk-tc.ru/"
-                    )
-                    runOnUiThread {
-                        // Render HTML tags
-                        binding.content.body.text = HtmlCompat.fromHtml(
-                            new.body,
-                            HtmlCompat.FROM_HTML_MODE_LEGACY,
-                            HtmlImageGetter(resources, binding.content.body),
-                            null
-                        )
-                        // cancel progress
-                        animate.start()
-                    }
-                }
-            }
+        college.fetchNewById(intent.getStringExtra("id")!!.toInt(), this)
+    }
+
+    /**
+     * Fetches a news data
+     */
+    override fun onResponse(call: Call, response: Response) {
+        // Parse JSON
+        val body = response.body?.string()
+        val new = Gson().fromJson(body, New::class.java)
+        // Create animation object
+        val animate = ObjectAnimator.ofFloat(
+            binding.content.progressBar, "alpha", 1f, 0f
+        )
+        animate.duration = 500
+        // Fix <img/> tag
+        new.body = new.body.replace(
+            "src=\"/", "src=\"http://www.kansk-tc.ru/"
         )
+        runOnUiThread {
+            // Render HTML tags
+            binding.content.body.text = HtmlCompat.fromHtml(
+                new.body,
+                HtmlCompat.FROM_HTML_MODE_LEGACY,
+                HtmlImageGetter(resources, binding.content.body),
+                null
+            )
+            // cancel progress
+            animate.start()
+        }
     }
 }