Преглед изворни кода

Remove Thumb/Outline/Bookmark View adaptor 'lateinit' keyword

cooperku_kdanmobile пре 5 година
родитељ
комит
72e2947d2f

+ 3 - 3
reader/src/main/java/com/kdanmobile/reader/screen/view/BookmarkView.kt

@@ -17,7 +17,7 @@ import kotlinx.android.synthetic.main.view_bookmark.view.*
 import java.util.*
 
 class BookmarkView: RelativeLayout {
-    private lateinit var adapter: BookmarkAdapter
+    private var adapter: BookmarkAdapter? = null
     private var pdfInfoHandler: PdfInfoHandler? = null
     private var bookmarkHandler: BookmarkHandler? = null
 
@@ -43,7 +43,7 @@ class BookmarkView: RelativeLayout {
         id_km_bookmark_recycler.layoutManager = LinearLayoutManager(context)
         id_km_bookmark_recycler.addOnItemTouchListener(object : OnRecyclerItemClickListener(id_km_bookmark_recycler) {
             override fun onItemClick(viewHolder: RecyclerView.ViewHolder) {
-                val bookmark = adapter.getItem(viewHolder.adapterPosition)
+                val bookmark = adapter?.getItem(viewHolder.adapterPosition)
                 if (null != bookmark) {
                     pdfInfoHandler?.setCurrentPage(bookmark.pageNum)
                 }
@@ -74,7 +74,7 @@ class BookmarkView: RelativeLayout {
             if (bookmarkItems.isNotEmpty()) {
                 Arrays.sort(bookmarkItems) { lhs, rhs -> if (lhs.pageNum > rhs.pageNum) 1 else -1 }
             }
-            adapter.setOutlineItems(bookmarkItems)
+            adapter?.setOutlineItems(bookmarkItems)
         } catch (e: Exception) {
             e.printStackTrace()
         }

+ 2 - 2
reader/src/main/java/com/kdanmobile/reader/screen/view/OutlineView.kt

@@ -15,7 +15,7 @@ import io.reactivex.schedulers.Schedulers
 import kotlinx.android.synthetic.main.view_outline.view.*
 
 class OutlineView: RelativeLayout {
-    private lateinit var adapter: OutlineAdapter
+    private var adapter: OutlineAdapter? = null
     private var pdfInfoHandler: PdfInfoHandler? = null
     private var disposable: Disposable? = null
 
@@ -35,7 +35,7 @@ class OutlineView: RelativeLayout {
         LayoutInflater.from(context).inflate(R.layout.view_outline, this)
 
         lv_viewPdfReaderOutline_.setOnItemClickListener { _, _, position, _ ->
-            val item = adapter.getItem(position)
+            val item = adapter?.getItem(position)
             if (null != item) {
                 pdfInfoHandler?.setCurrentPage(item.page)
             }

+ 3 - 3
reader/src/main/java/com/kdanmobile/reader/screen/view/ThumbnailView.kt

@@ -14,7 +14,7 @@ import com.kdanmobile.reader.widget.drag.OnRecyclerItemClickListener
 import kotlinx.android.synthetic.main.view_thumbnail.view.*
 
 class ThumbnailView: RelativeLayout {
-    private lateinit var adapter: ThumbnailAdapter
+    private var adapter: ThumbnailAdapter? = null
     private var currentPage = 0
     private var pdfInfoHandler: PdfInfoHandler? = null
 
@@ -55,7 +55,7 @@ class ThumbnailView: RelativeLayout {
 
         adapter = ThumbnailAdapter(pdfInfoHandler, thumbnailHandler)
         id_km_thumb_recycler.adapter = adapter
-        currentPage = pdfInfoHandler?.getCurrentPage()
+        currentPage = pdfInfoHandler.getCurrentPage()
         onScrollToPosition(currentPage, true)
     }
 
@@ -63,7 +63,7 @@ class ThumbnailView: RelativeLayout {
         currentPage = position
 
         if (notify) {
-            adapter.setCurrentPage(position)
+            adapter?.setCurrentPage(position)
         }
 
         if (null != id_km_thumb_recycler) {