我花了几个小时试图解决这个问题。我几乎阅读了所有有关此问题的帖子,但仍然没有找到解决方案。
我正在尝试部署具有“https got-library”依赖项的 firebase-function,但无论我做什么,都不起作用。我不是最擅长使用 Node-js 或 TypeScript(通常是 kotlin 前端开发),所以我不知道错误想要我做什么。
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": false,
"esModuleInterop": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
],
}
Run Code Online (Sandbox Code Playgroud)
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"google",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
],
plugins: [
"@typescript-eslint", …Run Code Online (Sandbox Code Playgroud) 我怎样才能获得我PagingData<Product>持有的当前物品数量?我找到的唯一解决方案是调用,shopListAdapter.itemCount但这总是返回 0。
我想做的是:获取我的 PagingAdapter 当前显示的项目数量,将该值提交给我的 shopViewModel,然后在另一个片段(DialogFragment)中使用该值。PagingData<Product>或者:从我的视图模型内部获取项目数量
这是我目前的方法
@AndroidEntryPoint
class ShopFragment : Fragment(R.layout.fragment_shop), ShopAdapter.OnItemClickListener {
private val shopViewModel: ShopViewModel by navGraphViewModels(R.id.nav_shop) { defaultViewModelProviderFactory }
private var _shopBinding: FragmentShopBinding? = null
private val shopBinding: FragmentShopBinding get() = _shopBinding!!
@Inject lateinit var shopListAdapter: ShopAdapter
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_shopBinding = FragmentShopBinding.inflate(inflater, container, false)
return shopBinding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
collectShopList()
}
private …Run Code Online (Sandbox Code Playgroud) 我的问题是,我的应用程序突然崩溃,我不知道为什么。这种情况发生不规律,但我认为这与我的房间数据库有关。我尝试提供尽可能多的信息:
@Database(entities = [ProductCacheEntity::class], version = 1)
@TypeConverters(Converters::class)
abstract class ShoppingCartDatabase : RoomDatabase() {
abstract fun shopDao(): ShoppingCartDao
companion object {
const val DATABASE_NAME = "shop_db"
}
}
Run Code Online (Sandbox Code Playgroud)
@Dao
interface ShoppingCartDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insert(productCacheEntity: ProductCacheEntity): Long
@Transaction
suspend fun upsert(productCacheEntity: ProductCacheEntity) {
val id = insert(productCacheEntity)
if (productExists(id)) increaseQuantityById(productCacheEntity.id)
}
@Query("UPDATE products SET quantity = quantity + 1 WHERE ID = :id")
suspend fun increaseQuantityById(id: Int)
@Query("UPDATE products SET quantity = quantity - 1 …Run Code Online (Sandbox Code Playgroud) 我试图在打开键盘时隐藏布局底部的一个特定按钮,以便为用户提供更多视图。
随着androidx.core:core-ktx:1.5.0-alpha02google的发布(最终)添加了一个调用的方法insets.isVisible(WindowInsetsCompat.Type.ime()),无论键盘是打开还是点击,它都会返回一个布尔值。
我正在使用一个基类EmailFragment,我在其中设置了函数以实现上述编写的功能。我的问题是我ViewCompat.setOnApplyWindowInsetsListener(view)从未被调用过(没有吐司等)。
我也尝试ViewCompat.setOnApplyWindowInsetsListener(view)直接在使用过的 Fragments 中进行设置,但这没有任何改变。
我的最小 API 是 21,在我的 AndroidManifest.XML 中有 android:windowSoftInputMode = adjustResize
abstract class EmailFragment<out T: ViewDataBinding>(
layout: Int,
// ... some other stuff that is not necessary for the question
) : BaseFragment<T>(layout) {
// ... some other stuff that is not necesarry for the question
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
hideButton(view)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: …Run Code Online (Sandbox Code Playgroud) NestedScrollView当与 结合使用时Motionlayout,我收到上述写入错误。这里奇怪的是,只有当其中有一些项目(或,等)并且当我尝试向上移动时,才会发生此错误。NestedscrollviewConstraintlayouttextviewbuttonedittextNestedScrollView
使用 aScrollView解决了这个问题,但是滚动不起作用......
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="product"
type="com.example.app.framework.datasource.models.product.Product" />
</data>
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/shop_item_content_scene"
app:showPaths="true"
tools:context=".framework.ui.view.fragments.shop.ShopItemFragment">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/shop_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:menu="@menu/shop_item_toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/product_image"
android:layout_width="0dp"
android:layout_height="142dp"
android:layout_marginStart="72dp"
android:layout_marginTop="@dimen/standard8dpMargin"
android:layout_marginEnd="72dp"
android:adjustViewBounds="true"
android:background="@color/color_white"
android:contentDescription="@null"
android:fitsSystemWindows="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/shop_toolbar"
tools:src="@drawable/ic_example_logo" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/product_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/big16dpMargin"
android:layout_marginBottom="12dp"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:maxLines="2"
android:text="@{product.name}"
android:textAlignment="textStart"
android:textColor="@color/color_text_dark"
android:textSize="@dimen/textHeadlineNormal1"
app:layout_constraintBottom_toTopOf="@id/scrollview_shop"
app:layout_constraintEnd_toEndOf="@id/barrier"
app:layout_constraintStart_toStartOf="@id/margin_left"
app:layout_constraintTop_toBottomOf="@+id/product_image" …Run Code Online (Sandbox Code Playgroud) 我目前的问题是,LoadStateAdapter显示加载和错误状态的 my 不在 my 内居中recyclerview,它有一个 gridlayout 作为布局管理器。我在官方 android 开发者网站上没有找到任何关于此的信息,所以我在这里问:如何将我的LoadStateAdapter内部集中在我的 Recyclerview 中?
@AndroidEntryPoint
class ShopFragment : Fragment(R.layout.fragment_shop), ShopAdapter.OnItemClickListener {
private val shopViewModel: ShopViewModel by viewModels()
private val shopBinding: FragmentShopBinding by viewBinding()
@Inject lateinit var shopListAdapter: ShopAdapter
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
bindObjects()
}
private fun bindObjects() {
shopBinding.adapter = shopListAdapter.withLoadStateFooter(ShopLoadAdapter(shopListAdapter::retry))
shopListAdapter.clickHandler(this)
}
override fun onDestroyView() {
requireView().findViewById<RecyclerView>(R.id.rv_shop).adapter = null
super.onDestroyView()
}
}
Run Code Online (Sandbox Code Playgroud)
@FragmentScoped
class ShopLoadAdapter(private val retry: () …Run Code Online (Sandbox Code Playgroud) android kotlin android-recyclerview android-paging android-paging-3
目前,我正在为我的原始数据存储编写一些测试。我在这里遇到的唯一问题是我无法调用特定函数,因为这样我的测试就会失败/崩溃。我发现这非常令人困惑,因为我的所有其他功能似乎都有效,除了resetDatastore
这是我的代码:
private companion object {
private const val SHOP_FILTER_PRODUCT_DATASTORE: String = "shop_filter_product_datastore_test"
private const val SHOP_FILTER_LIST_DATASTORE: String = "shop_filter_list_datastore_test"
private const val SHOP_FILTER_BTN_DATASTORE: String = "shop_filter_btn_datastore_test"
}
private val testNonVolatileProductDataStore = context.createDataStore(
fileName = SHOP_FILTER_PRODUCT_DATASTORE,
serializer = ShopFilterProductSerializer
)
private val testNonVolatileListDataStore = context.createDataStore(
fileName = SHOP_FILTER_LIST_DATASTORE,
serializer = ShopFilterListSerializer
)
private val testNonVolatileBtnDataStore = context.createDataStore(
fileName = SHOP_FILTER_BTN_DATASTORE,
serializer = ShopFilterBtnSerializer
)
override suspend fun setValueProduct(newProduct: ShopFilterTempHolder) {
if (newProduct.id == null || newProduct.mQuery == null) …Run Code Online (Sandbox Code Playgroud) 我的问题非常简单明了:两个注释/示例有什么区别:
@Singleton
class MySingletonClass() {}
@Module
@InstallIn(FragmentComponent::class)
abstract class MyFragmentModule {
@Provides
fun provideMySingletonClass() = MySingletonClass()
}
Run Code Online (Sandbox Code Playgroud)
class MySingletonClass() {}
@Module
@InstallIn(FragmentComponent::class)
abstract class MyFragmentModule {
@Singleton
@Provides
fun provideMySingletonClass() = MySingletonClass()
}
Run Code Online (Sandbox Code Playgroud)
我知道的唯一区别是,第二个示例给出了以下错误:
error: [Dagger/IncompatiblyScopedBindings] FragmentC scoped with @dagger.hilt.android.scopes.FragmentScoped may not reference bindings with different scopes:
Run Code Online (Sandbox Code Playgroud)
这是否意味着@Singleton示例一中的注释被简单地忽略了?
使用数据存储一段时间并用它编写一些业务逻辑后,我想测试使用数据存储的类/存储库。我遇到的问题是,我该怎么做?context.createDatastore(...)我尝试使用测试上下文创建一个,但我遇到了一些错误。没有关于此的官方文档,或者至少我找不到。
这是我目前的方法:
interface ShopFilterDataStoreRepository {
val shopFilterProduct: Flow<ShopFilterProduct>
val shopFilterList: Flow<ShopFilterList>
suspend fun setValueProduct(newProduct: ShopFilterTempHolder)
suspend fun setValueList(newList: ShopFilterTempHolder)
}
Run Code Online (Sandbox Code Playgroud)
class ShopFilterDataStoreRepositoryImpl @Inject constructor(
@ApplicationContext private val context: Context,
) : ShopFilterDataStoreRepository {
private companion object {
private const val SHOP_FILTER_PRODUCT_DATASTORE: String = "shop_filter_product_datastore"
private const val SHOP_FILTER_LIST_DATASTORE: String = "shop_filter_list_datastore"
}
// this causes error because test context != applicationcontext
private val nonVolatileProductDataStore = context.createDataStore(
fileName = SHOP_FILTER_PRODUCT_DATASTORE,
serializer = ShopFilterProductSerializer
)
// this causes …Run Code Online (Sandbox Code Playgroud) 突然,我的应用程序中的导航突然无法正常工作(昨天确实有效)。
这是一个示例:当我从 导航userLoggedInFragment到 时userLoggedOutFragment,使用参数app:popUpTo="@id/userLoggedOutFragment" app:popUpToInclusive="true",然后单击后退按钮,即使我使用了 popUpTo,它仍然会将我导航回 userLoggedInFragment。然后我得到信息:
I/NavController: Ignoring popBackStack to destination com.example.app:id/userLoggedOutFragment as it was not found on the current back stack
Run Code Online (Sandbox Code Playgroud)
这是我的片段代码
@AndroidEntryPoint
class UserLoggedInFragment : Fragment() {
private var _binding: FragmentUserLoggedInBinding? = null
private val binding: FragmentUserLoggedInBinding get() = _binding!!
private val viewModel: LogoutViewModel by viewModels()
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentUserLoggedInBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, …Run Code Online (Sandbox Code Playgroud) android kotlin android-navigation android-jetpack android-architecture-navigation
android ×9
kotlin ×7
android-architecture-navigation ×1
android-room ×1
dagger ×1
dagger-2 ×1
dagger-hilt ×1
firebase ×1
import ×1
javascript ×1
mvvm ×1
node.js ×1
paging ×1