Skip to content

Commit 91c51da

Browse files
author
tans.tan
committed
[feat] Add v2.5.2, fix recycler view data item equals error.
1 parent dde3276 commit 91c51da

File tree

5 files changed

+54
-27
lines changed

5 files changed

+54
-27
lines changed

app/src/main/java/com/tans/tfiletransporter/file/FileLeaf.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ import androidx.annotation.Keep
44

55
@Keep
66
sealed class FileLeaf(
7-
val name: String,
8-
val path: String,
9-
val lastModified: Long
107
) {
8+
abstract val name: String
9+
abstract val path: String
10+
abstract val lastModified: Long
1111
@Keep
12-
class CommonFileLeaf(name: String, path: String, val size: Long, lastModified: Long) : FileLeaf(name, path, lastModified)
12+
data class CommonFileLeaf(
13+
override val name: String,
14+
override val path: String,
15+
override val lastModified: Long,
16+
val size: Long) : FileLeaf()
1317

1418
@Keep
15-
class DirectoryFileLeaf(name: String, path: String, val childrenCount: Long, lastModified: Long) : FileLeaf(name, path, lastModified)
19+
data class DirectoryFileLeaf(
20+
override val name: String,
21+
override val path: String,
22+
override val lastModified: Long,
23+
val childrenCount: Long) : FileLeaf()
1624
}

app/src/main/java/com/tans/tfiletransporter/ui/FileTreeUI.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,14 @@ class FileTreeUI(
4848
) : CoroutineScope by coroutineScope, CoroutineState<FileTreeUI.Companion.FileTreeState> {
4949

5050
private val dirDataSource: DataSourceImpl<FileLeaf.DirectoryFileLeaf> by lazy {
51-
DataSourceImpl(
52-
areDataItemsTheSameParam = { d1, d2 -> d1.path == d2.path },
53-
areDataItemsContentTheSameParam = { d1, d2 -> d1.path == d2.path }
54-
)
51+
DataSourceImpl()
5552
}
5653

5754
private val fileDataSource: DataSourceImpl<Pair<FileLeaf.CommonFileLeaf, Boolean>> by lazy {
5855
DataSourceImpl(
59-
areDataItemsTheSameParam = { d1, d2 -> d1.first.path == d2.first.path },
60-
areDataItemsContentTheSameParam = {d1, d2 -> d1.first.path == d2.first.path && d1.second == d2.second},
61-
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first.path == d2.first.path && d1.second != d2.second) Unit else null }
56+
areDataItemsTheSameParam = { d1, d2 -> d1.first == d2.first },
57+
areDataItemsContentTheSameParam = {d1, d2 -> d1 == d2},
58+
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first == d2.first && d1.second != d2.second) Unit else null }
6259
)
6360
}
6461

app/src/main/java/com/tans/tfiletransporter/ui/filetransport/BaseMediaFragment.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ abstract class BaseMediaFragment(
8282
it to s.selectedImages.contains(it)
8383
}
8484
},
85-
areDataItemsTheSameParam = { d1, d2 -> d1.first.uri == d2.first.uri},
86-
areDataItemsContentTheSameParam = { d1, d2 -> d1.first.uri == d2.first.uri && d1.second == d2.second },
87-
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first.uri == d2.first.uri && d1.second != d2.second) Unit else null }
85+
areDataItemsTheSameParam = { d1, d2 -> d1.first == d2.first},
86+
areDataItemsContentTheSameParam = { d1, d2 -> d1 == d2 },
87+
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first == d2.first && d1.second != d2.second) Unit else null }
8888
),
8989
dataBinder = DataBinderImpl<Pair<MediaStoreImage, Boolean>> { data, view, _ ->
9090
val itemViewBinding = ImageItemLayoutBinding.bind(view)
@@ -121,9 +121,9 @@ abstract class BaseMediaFragment(
121121
it to s.selectedAudios.contains(it)
122122
}
123123
},
124-
areDataItemsTheSameParam = { d1, d2 -> d1.first.uri == d2.first.uri},
125-
areDataItemsContentTheSameParam = { d1, d2 -> d1.first.uri == d2.first.uri && d1.second == d2.second },
126-
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first.uri == d2.first.uri && d1.second != d2.second) Unit else null }
124+
areDataItemsTheSameParam = { d1, d2 -> d1.first == d2.first},
125+
areDataItemsContentTheSameParam = { d1, d2 -> d1 == d2 },
126+
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first == d2.first && d1.second != d2.second) Unit else null }
127127
),
128128
dataBinder = DataBinderImpl<Pair<MediaStoreAudio, Boolean>> { data, view, _ ->
129129
val itemViewBinding = VideoAudioItemLayoutBinding.bind(view)
@@ -160,9 +160,9 @@ abstract class BaseMediaFragment(
160160
it to s.selectedVideos.contains(it)
161161
}
162162
},
163-
areDataItemsTheSameParam = { d1, d2 -> d1.first.uri == d2.first.uri},
164-
areDataItemsContentTheSameParam = { d1, d2 -> d1.first.uri == d2.first.uri && d1.second == d2.second },
165-
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first.uri == d2.first.uri && d1.second != d2.second) Unit else null }
163+
areDataItemsTheSameParam = { d1, d2 -> d1.first == d2.first},
164+
areDataItemsContentTheSameParam = { d1, d2 -> d1 == d2 },
165+
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first == d2.first && d1.second != d2.second) Unit else null }
166166
),
167167
dataBinder = DataBinderImpl<Pair<MediaStoreVideo, Boolean>> { data, view, _ ->
168168
val itemViewBinding = VideoAudioItemLayoutBinding.bind(view)

app/src/main/java/com/tans/tfiletransporter/ui/filetransport/MyAppsFragment.kt

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class MyAppsFragment : BaseCoroutineStateFragment<MyAppsFragment.Companion.MyApp
6767
it to state.selected.contains(it)
6868
}
6969
},
70-
areDataItemsTheSameParam = { d1, d2 -> d1.first.packageName == d2.first.packageName },
71-
areDataItemsContentTheSameParam = { d1, d2 -> d1.first.packageName == d2.first.packageName && d1.second == d2.second },
72-
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first.packageName == d2.first.packageName && d1.second != d2.second) Unit else null }
70+
areDataItemsTheSameParam = { d1, d2 -> d1.first == d2.first },
71+
areDataItemsContentTheSameParam = { d1, d2 -> d1 == d2 },
72+
getDataItemsChangePayloadParam = { d1, d2 -> if (d1.first == d2.first && d1.second != d2.second) Unit else null }
7373
),
7474
dataBinder = DataBinderImpl<Pair<AppInfo, Boolean>> { data, view, _ ->
7575
val itemViewBinding = AppItemLayoutBinding.bind(view)
@@ -189,7 +189,29 @@ class MyAppsFragment : BaseCoroutineStateFragment<MyAppsFragment.Companion.MyApp
189189
val packageName: String,
190190
val appSize: Long,
191191
val icon: Drawable
192-
)
192+
) {
193+
override fun equals(other: Any?): Boolean {
194+
if (this === other) return true
195+
if (javaClass != other?.javaClass) return false
196+
197+
other as AppInfo
198+
199+
if (name != other.name) return false
200+
if (sourceDir != other.sourceDir) return false
201+
if (packageName != other.packageName) return false
202+
if (appSize != other.appSize) return false
203+
204+
return true
205+
}
206+
207+
override fun hashCode(): Int {
208+
var result = name.hashCode()
209+
result = 31 * result + sourceDir.hashCode()
210+
result = 31 * result + packageName.hashCode()
211+
result = 31 * result + appSize.hashCode()
212+
return result
213+
}
214+
}
193215

194216
data class MyAppsState(
195217
val apps: List<AppInfo> = emptyList(),

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ ANDROID_COMPILE_SDK=34
2727
ANDROID_MIN_SDK=26
2828
ANDROID_TARGET_SDK=34
2929

30-
VERSION_NAME=2.5.1
31-
VERSION_CODE=24041601
30+
VERSION_NAME=2.5.2
31+
VERSION_CODE=24041602

0 commit comments

Comments
 (0)