我正在利用新的Paging库从其他API加载分页数据,但是我无法理解如何在Room中缓存后继续加载新数据.目前,我有一个PagedListAdapter,它通过使用边界回调来加载来自API的项目,然后存储在本地数据库(Room)中,这些数据通过可流动的方式发送到UI.
来自BoundaryCallback的onZeroItemsLoaded和onItemAtEndLoaded调用都按预期运行,但仅适用于初始加载.一旦数据被检索一次并存储在缓存(Room)中,我将永远不会从网络服务获得新数据 - 缓存中已有数据,并且不会触发边界回调.
如何使用分页库将项目标记为陈旧,以便每次应用程序打开时我的数据都是新鲜的?
ItemCallback.kt:
class ItemBoundaryCallback : PagedList.BoundaryCallback<Item>() {
override fun onZeroItemsLoaded() {
itemsFromNetwork(0)
}
override fun onItemAtEndLoaded(itemAtEnd: Item) {
itemsFromNetwork(itemAtEnd.rank)
}
}
Run Code Online (Sandbox Code Playgroud)
ItemRepository.kt:
fun items(): Flowable<PagedList<Item>> {
return RxPagedListBuilder(database.itemDao().items(), pageSize)
.setBoundaryCallback(boundaryCallback)
.buildFlowable(BackpressureStrategy.LATEST)
}
Run Code Online (Sandbox Code Playgroud)
ItemDao.kt
@Query("SELECT * FROM item ORDER BY rank ASC")
fun items(): DataSource.Factory<Int, Item>
Run Code Online (Sandbox Code Playgroud)
ItemAdapter.kt
class ItemAdapter() : PagedListAdapter<Item, ItemViewHolder>(diffCallback) {
companion object {
private val diffCallback = object : DiffUtil.ItemCallback<Item>() {
override fun areItemsTheSame(old: Item, new: Item): Boolean = old.id == new.id
override fun …Run Code Online (Sandbox Code Playgroud) 我正在尝试将用Swift编写的外部库添加到Objective-C项目中.图书馆在这里:
https://github.com/Ramotion/animated-tab-bar
我按照他们的指示添加RAMAnimatedTabBarController到我的项目,然后修改我的`Tab Bar控制器,Tab Bar项目以利用故事板中的自定义类.
它与日志中的未知类消息一起崩溃,因此即使自定义类上的自动完成工作,它显然无法查看/编译项目文件:
2015-05-01 14:59:26.309 <project>[xxxx:xxxxx] Unknown class RAMAnimatedTabBarItem in Interface Builder file.
2015-05-01 14:59:26.350 <project>[xxxx:xxxxx] Unknown class RAMAnimatedTabBarController in Interface Builder file.
2015-05-01 14:59:26.353 <project>[xxxx:xxxxx] Unknown class RAMBounceAnimation in Interface Builder file.
Run Code Online (Sandbox Code Playgroud)
我已经阅读了很多关于包含swift头文件的内容,以便在你的项目中使用objc和swift进行交换,但是他们提到了导入到你的ViewController类中(因为TabBar和NavController只在故事板中我没有) .
如何从同一个故事板访问Objective-C和Swift类?
对故事板来说还是很新的,我觉得我在这里错过了一个关键的部分.救命!
在iOS 9之前,我们的IPA大小约为6MB.通过Xcode 7归档和导出我们的IPA后,我们的IPA增加到大约17MB.经过进一步调查,我们发现在导出设置中启用"Bitcode"选项是导致大文件大小跳转的原因.
我的问题是:如果我们启用此选项,我们的IPA大小是否会在商店中达到17MB?或者Apple是否对捆绑做了一些事情,使其大小与以前大致相同(6MB).
目前关于Bitcode的信息并不多,我希望在提交给商店之前得到通知.6MB和17MB就足够了.
使用 Gradle 在终端中运行仪器或单元测试相对简单。让我们以这个示例类为例:
class MyClass {
@Test
fun mySimpleTest() {
// Test logic here
}
}
Run Code Online (Sandbox Code Playgroud)
要在终端中运行这个单一单元测试方法(忽略我可以使用通配符等的事实):
./gradlew a:b:c:test --tests 'com.sample.package.MyClass.mySimpleTest'
Run Code Online (Sandbox Code Playgroud)
但是如果您有一个利用反引号的 Kotlin 方法怎么办?
class MyClass {
@Test
fun `my simple test`() {
// Test logic here
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试用下划线替换空格,完全删除空格,带或不带反引号等,但没有取得任何成功。
所以我的问题是:当方法名称使用反引号时,如何在终端中运行单个测试方法?
过去 2 天我一直在尝试对为什么我的 RecyclerView 在滚动时如此缓慢地进行分类,并将其缩小到我用于行的 ConstraintLayout。在 android 上使用 GPU 分析器显示绿色/蓝绿色条一直到屏幕顶部,表明严重卡顿。很明显有什么地方不对劲。
这是我的观察者的样子:
class MyViewHolder(
override val containerView: View) : RecyclerView.ViewHolder(containerView), LayoutContainer {
fun bindTo(item: Item?, clickListener: (Item?) -> Unit) {
text_item_name.text = item?.name
Glide.with(containerView.context).load(item?.url).into(image_item)
containerView.setOnClickListener { clickListener(item) }
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我的布局的样子。尽可能简单:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:paddingBottom="@dimen/padding"
android:paddingEnd="@dimen/padding_2x"
android:paddingStart="@dimen/padding_2x"
android:paddingTop="@dimen/padding">
<ImageView
android:id="@+id/image_item"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="@dimen/margin_2x"
android:layout_marginStart="@dimen/margin_2x"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_coin_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin_2x"
android:layout_marginStart="@dimen/margin_2x"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/image_item"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:我的布局有什么问题导致了卡顿?我是否使用了不正确的 LayoutManager?约束是否会导致透支?
如果我将布局 XML …
android android-viewholder android-recyclerview android-constraintlayout
我的架构如下:
Dao 方法返回Flow<T>:
@Query("SELECT * FROM table WHERE id = :id")
fun itemById(id: Int): Flow<Item>
Run Code Online (Sandbox Code Playgroud)存储库层从数据库返回项目,但也从网络回填:
(* 这里需要帮助——这没有按预期工作**)
fun items(): Flow<Item> = flow {
// Immediately emit values from DB
emitAll(itemDao.itemById(1))
// Backfill DB via network request without blocking coroutine
itemApi.makeRequest()
.also { insert(it) }
}
Run Code Online (Sandbox Code Playgroud)ViewModel 层采用流程,应用任何转换,并使用 .asLiveData() 将其转换为 LiveData:
fun observeItem(): LiveData<Item> = itemRepository.getItemFlow()
.map { // apply transformation to view model }
.asLiveData()
Run Code Online (Sandbox Code Playgroud)Fragment 观察 LiveData 发射并更新 UI:
viewModel.item().observeNotNull(viewLifecycleOwner) {
renderUI(it)
}
Run Code Online (Sandbox Code Playgroud)我遇到的问题是在步骤 2 中。我似乎无法找到一种方法来构建逻辑,以便我可以立即从 …
android ×3
ios ×2
kotlin ×2
xcode ×2
android-room ×1
bitcode ×1
gradle ×1
objective-c ×1
paging ×1
storyboard ×1
swift ×1
unit-testing ×1
xcode7 ×1