Skip to content

Commit f755745

Browse files
update adapters
1 parent cc4f90e commit f755745

File tree

18 files changed

+51
-79
lines changed

18 files changed

+51
-79
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
app:layout_constraintBottom_toBottomOf="parent"
1919

2020
app:defaultNavHost="true"
21-
app:navGraph="@navigation/nav_graph_main"/>
21+
app:navGraph="@navigation/nav_graph_main_bottom_nav"/>
2222

2323
</androidx.constraintlayout.widget.ConstraintLayout>
2424
</layout>

buildSrc/src/main/java/Version.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object PluginVersion {
22
const val KOTLIN_VERSION = "1.4.0"
3-
const val GRADLE_VERSION = "4.1.0-rc02"
3+
const val GRADLE_VERSION = "4.1.0-rc03"
44

55
const val NAV_SAFE_ARGS_VERSION = "2.3.0"
66
const val KTLINT_VERSION = "9.3.0"

config/detekt/detekt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ complexity:
8181
LongMethod:
8282
active: true
8383
threshold: 60
84-
excludes: ['**/NavigationExtensions.kt']
84+
excludes: ['**/DynamicNavigationExtension.kt']
8585
LongParameterList:
8686
active: true
8787
functionThreshold: 6

features/home/src/main/java/com/smarttoolfactory/home/HomeFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class HomeFragment : DynamicNavigationFragment<FragmentHomeBinding>() {
7373
it?.let { event: Event<NavController?> ->
7474
event.getContentIfNotHandled()?.let { navController ->
7575
val appBarConfig = AppBarConfiguration(navController.graph)
76-
dataBinding!!.toolbar.setupWithNavController(navController, appBarConfig)
76+
dataBinding.toolbar.setupWithNavController(navController, appBarConfig)
7777
}
7878
}
7979
}

features/home/src/main/java/com/smarttoolfactory/home/adapter/PostListAdapter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ class PostDiffCallback : DiffUtil.ItemCallback<Post>() {
8282
oldItem: Post,
8383
newItem: Post
8484
): Boolean {
85-
return oldItem == newItem
85+
return oldItem.id == newItem.id
8686
}
8787

8888
override fun areContentsTheSame(
8989
oldItem: Post,
9090
newItem: Post
9191
): Boolean {
92-
return oldItem.id == newItem.id
92+
return oldItem == newItem
9393
}
9494
}

features/home/src/main/java/com/smarttoolfactory/home/util/ViewBindings.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ import com.smarttoolfactory.home.R
2121
@BindingAdapter("app:items")
2222
fun RecyclerView.setItems(items: List<Post>?) {
2323

24-
items?.let {
25-
(adapter as ListAdapter<Post, *>)?.submitList(items)
24+
try {
25+
items?.let {
26+
(adapter as? ListAdapter<Post, *>)?.submitList(items)
27+
}
28+
} catch (e: Exception) {
29+
e.printStackTrace()
30+
println("ViewBindings exception: ${e.message}")
2631
}
2732
}
2833

libraries/core/src/main/java/com/smarttoolfactory/core/ui/adapter/BaseListAdapter.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.smarttoolfactory.core.ui.adapter
22

3-
import android.util.Log
43
import android.view.LayoutInflater
54
import android.view.ViewGroup
65
import androidx.annotation.LayoutRes
@@ -53,6 +52,7 @@ abstract class BaseListAdapter<ItemType>(
5352
position: Int,
5453
payloads: MutableList<Any>
5554
) {
55+
super.onBindViewHolder(holder, position, payloads)
5656

5757
val item: ItemType? = currentList.getOrNull(position)
5858

@@ -63,10 +63,7 @@ abstract class BaseListAdapter<ItemType>(
6363
}
6464
}
6565

66-
override fun onBindViewHolder(holder: BaseItemViewHolder, position: Int) {
67-
println("🔥🔥")
68-
Log.d(BaseListAdapter::class.toString(), "onBindViewHolder")
69-
}
66+
override fun onBindViewHolder(holder: BaseItemViewHolder, position: Int) = Unit
7067

7168
/**
7269
* Called when a ViewHolder is created. ViewHolder is either created first time or

libraries/core/src/main/java/com/smarttoolfactory/core/ui/fragment/BaseDataBindingFragment.kt

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class BaseDataBindingFragment<ViewBinding : ViewDataBinding> : Fragment
3333

3434
private var _dataBinding: ViewBinding? = null
3535

36-
lateinit var dataBinding: ViewBinding
36+
val dataBinding: ViewBinding get() = _dataBinding!!
3737

3838
/**
3939
* This method gets the layout id from the derived fragment to bind to that layout via data-binding
@@ -53,14 +53,14 @@ abstract class BaseDataBindingFragment<ViewBinding : ViewDataBinding> : Fragment
5353
savedInstanceState: Bundle?
5454
): View? {
5555

56+
println("🤣 ${this.javaClass.simpleName} #${this.hashCode()} onCreateView()")
57+
5658
// Each fragment can have it's separate toolbar menu
5759
setHasOptionsMenu(true)
5860

5961
_dataBinding =
6062
DataBindingUtil.inflate(inflater, getLayoutRes(), container, false)
6163

62-
dataBinding = _dataBinding!!
63-
6464
/**
6565
* 🔥🔥 Using viewLifecycleOwner instead of this(fragment) makes sure that
6666
* when this fragment is retrieved from back stack another observer is not added
@@ -77,19 +77,32 @@ abstract class BaseDataBindingFragment<ViewBinding : ViewDataBinding> : Fragment
7777
dimensions.y = rootView.height
7878
}
7979

80-
bindViews()
81-
8280
return rootView
8381
}
8482

83+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
84+
super.onViewCreated(view, savedInstanceState)
85+
bindViews()
86+
}
87+
8588
override fun onDestroyView() {
86-
_dataBinding = null
8789
super.onDestroyView()
90+
_dataBinding = null
91+
println("🥵 ${this.javaClass.simpleName} #${this.hashCode()} onDestroyView()")
8892
}
8993

9094
/**
91-
* Called from [Fragment.onCreateView] to implement bound ui items and set properties
95+
* Called from [Fragment.onViewCreated] to implement bound ui items and set properties
9296
*/
93-
open fun bindViews() {
97+
open fun bindViews() = Unit
98+
99+
override fun onCreate(savedInstanceState: Bundle?) {
100+
super.onCreate(savedInstanceState)
101+
println("😀 ${this.javaClass.simpleName} #${this.hashCode()} onCreate()")
102+
}
103+
104+
override fun onDestroy() {
105+
super.onDestroy()
106+
println("🥶 ${this.javaClass.simpleName} #${this.hashCode()} onDestroy()")
94107
}
95108
}

libraries/core/src/main/java/com/smarttoolfactory/core/ui/fragment/navhost/BaseDynamicNavHostFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.os.Bundle
44
import androidx.annotation.NavigationRes
55
import androidx.fragment.app.activityViewModels
66
import androidx.navigation.dynamicfeatures.fragment.DynamicNavHostFragment
7-
import androidx.navigation.fragment.NavHostFragment
87
import com.smarttoolfactory.core.error.NavigationException
98
import com.smarttoolfactory.core.util.Event
109
import com.smarttoolfactory.core.viewmodel.NavControllerViewModel
@@ -14,7 +13,7 @@ import com.smarttoolfactory.core.viewmodel.NavControllerViewModel
1413
* uses [BaseDynamicNavHostFragment.createDynamicNavHostFragment] function with navigation graph
1514
* parameter
1615
*/
17-
class BaseDynamicNavHostFragment : NavHostFragment() {
16+
class BaseDynamicNavHostFragment : DynamicNavHostFragment() {
1817

1918
private val navControllerViewModel by activityViewModels<NavControllerViewModel>()
2019

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.junit.Test
2020
import org.junit.runner.RunWith
2121

2222
@RunWith(AndroidJUnit4::class)
23-
class PostDaoCoroutinesCoroutinesFlowTest {
23+
class PostDaoCoroutinesTest {
2424

2525
companion object {
2626
val postEntityList =
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.junit.Before
1515
import org.junit.Rule
1616
import org.junit.Test
1717

18-
class PostDaoCoroutinesRxJavaTest {
18+
class PostDaoRxJavaTest {
1919

2020
companion object {
2121
val postEntityList =
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.junit.runners.Suite
66
// Runs all unit tests with JUnit4.
77
@RunWith(Suite::class)
88
@Suite.SuiteClasses(
9-
PostDaoCoroutinesCoroutinesFlowTest::class,
10-
PostDaoCoroutinesRxJavaTest::class
9+
PostDaoCoroutinesTest::class,
10+
PostDaoRxJavaTest::class
1111
)
12-
class PostDaoCoroutinesTestSuite
12+
class PostDaoTestSuite

libraries/data/src/main/java/com/smarttoolfactory/data/db/PostDaoRxJava3.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import androidx.room.Delete
55
import androidx.room.Insert
66
import androidx.room.OnConflictStrategy
77
import androidx.room.Query
8-
import androidx.room.Update
98
import com.smarttoolfactory.data.model.PostEntity
109
import io.reactivex.rxjava3.core.Completable
1110
import io.reactivex.rxjava3.core.Maybe
@@ -68,10 +67,4 @@ interface PostDaoRxJava3 {
6867
// */
6968
// @Query("SELECT * FROM post ORDER BY displayCount DESC")
7069
// suspend fun getDisplayedMostPosts(): List<PostEntity>
71-
72-
/**
73-
* Update a post's favorite or display count status.
74-
*/
75-
@Update
76-
fun updatePostFavoriteOrSelectStatus(postEntity: PostEntity)
7770
}

libraries/data/src/main/java/com/smarttoolfactory/data/model/PostEntity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ data class PostEntity(
2828
*
2929
* * Status of the [PostEntity] with [PostEntity.id] or [PostStatus.postId] belong to current user
3030
* logged in with [PostStatus.userAccountId] or -1 if any user hasn't logged in
31+
*
32+
* * 🔥 Raw STATEMENT: "CREATE TABLE IF NOT EXISTS `post_status`
33+
* (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
34+
* `userAccountId` INTEGER NOT NULL,
35+
* `postId` INTEGER NOT NULL,
36+
* `displayCount` INTEGER NOT NULL,
37+
* `isFavorite` INTEGER NOT NULL,
38+
* FOREIGN KEY(`postId`) REFERENCES `post`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )"
39+
*
3140
*/
3241
@Entity(
3342
tableName = "post_status",

libraries/domain/src/main/java/com/smarttoolfactory/domain/di/DomainModule.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

libraries/domain/src/main/java/com/smarttoolfactory/domain/di/DomainModuleDependencies.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.

libraries/domain/src/test/java/com/smarttoolfactory/domain/usecase/GetPostListUseCaseFlowTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class GetPostListUseCaseFlowTest {
5050
@RegisterExtension
5151
val testCoroutineExtension = TestCoroutineExtension()
5252

53-
val testCoroutineScope = testCoroutineExtension.testCoroutineScope
54-
5553
/*
5654
Mock Post data
5755
*/

0 commit comments

Comments
 (0)