在 jetpack compose 的新更新中,将在可触摸对象周围提供默认的填充空间,如官方文档中所述。 参考这个
请帮助如何避免这种情况并实现此“将 LocalMinimumTouchTargetEnforcement 设置为 false ”以及在哪里执行此操作?
我在我的项目中使用 HILT 设置了 DI。现在我必须集成 FCM 推送通知,因此我必须向 Firebase 消息传递服务类提供存储库实例,以便在调用新令牌时将新的 fcm 令牌更新到服务器(从服务类执行 api 调用)。我该如何做到这一点以及最佳实践是什么?
应用程序模块
@Module
@InstallIn(ApplicationComponent::class)
class ApplicationModule {
@Provides
@Singleton
fun provideServiceTokenAuthenticator(sharedPreferences: SharedPreferences,
@ApplicationContext appContext: Context,chatManager: ChatManager): ServiceTokenAuthenticator =
ServiceTokenAuthenticator(sharedPreferences, appContext,chatManager)
@Provides
@Singleton
fun provideApiService(okHttpClient: OkHttpClient): ApiService {
return Retrofit.Builder().baseUrl(BuildConfig.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create()).client(okHttpClient).build()
.create(ApiService::class.java)
}
@Provides
@Singleton
fun provideOkHttpClient(serviceTokenAuthenticator: ServiceTokenAuthenticator,sharedPreferences: SharedPreferences): OkHttpClient {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.HEADERS
loggingInterceptor.level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
return OkHttpClient.Builder().connectTimeout(2, TimeUnit.MINUTES)
.readTimeout(2, TimeUnit.MINUTES).writeTimeout(2, TimeUnit.MINUTES)
.addInterceptor(object : Interceptor {
override fun intercept(chain: Interceptor.Chain): …
Run Code Online (Sandbox Code Playgroud) 这是一个视频通话屏幕。它需要令牌和通道名称才能工作,需要将其传递给初始化调用引擎。我将它们存储在用作可变状态的数据类中。
屏幕状态数据类
@Keep
data class CallScreenState(
val callerId: Int? = null,
val recieverId: Int? = null,
val chatRoom: ChatRoom.Data? = null,
val rtcToken: AgoraTokenResponse.TokenData? = null
)
Run Code Online (Sandbox Code Playgroud)
并在视图模型初始化状态下通过以下代码:
var callScreenState by mutableStateOf(CallScreenState())
Run Code Online (Sandbox Code Playgroud)
在聊天室和令牌 api 成功响应的视图模型中,状态将使用此代码进行更新。
callScreenState = callScreenState.copy(
chatRoom = chatRoom.data,//from response
rtcToken = token.data //from response
)
Run Code Online (Sandbox Code Playgroud)
从这里开始,预计将使用 chatRoom 和 rtcToken 的新更新值重新组合屏幕。
并且在可组合中
val screenState = remember {
viewModel.callScreenState
}
Run Code Online (Sandbox Code Playgroud)
此屏幕状态用于将值传递给 init 引擎
val mEngine = remember {
initEngine(
context,
object : IRtcEngineEventHandler() {
override fun onJoinChannelSuccess(channel: String?, uid: …
Run Code Online (Sandbox Code Playgroud) android kotlin kotlin-coroutines android-jetpack-compose compose-recomposition
我正在制作一个测验应用程序。它使用水平寻呼机,每个项目中有一个问题和 4 个选项单选按钮。我在水平寻呼机中有 10 个项目。如果我到达最后一页并滑回到第一页,所做的选择就会消失并且页面会重新加载。即使内容项滚动到最后一页,如何保存内容项的状态。当使用普通视图分页器时,我们可以设置页面偏移量,这在jetpack compose中不可用。如何解决这个问题?请帮忙。我正在使用这个版本
implementation "com.google.accompanist:accompanist-pager:0.21.2-beta"
implementation "com.google.accompanist:accompanist-pager-indicators:0.21.2-beta"
Run Code Online (Sandbox Code Playgroud) android kotlin android-jetpack-compose jetpack-compose-accompanist
我想构建一个自定义用户界面,以在自定义视图中显示分数,例如带有动画的速度计。实现就像将分数传递给视图,视图中的指针将从 0 动画到传递的分数。背景会根据通过的分数而变化,如果低于 50 为红色,高于 50 为红色。任何人都可以帮助我实现这一点。我附上给出的 ui 供参考。它也可以以任何格式分享到社交媒体。
我正在尝试限制应用程序免受系统字体缩放的影响。我已经尝试了很多解决方案,但没有一个有帮助。他们中的大多数人都告诉我们使用 dp 而不是 sp 来确定文本大小,但在撰写中,如果我是正确的,我们只能使用 sp,因为它需要一个文本单元。有没有正确的方法来限制我们使用 jetpack compose 完成的应用程序中的字体缩放?请帮忙 。
我想知道 kotlin flow flatMap 与 jetpack compose 一起使用
我有一个搜索流程,每次搜索值发生变化时我都会调用 api。
var search = MutableStateFlow("")
Run Code Online (Sandbox Code Playgroud)
并调用api
var allItems = search.flatMapLatest{query->
flow{
emit(repository.getAllItems(query)
}
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但在一种情况下除外。当搜索值已经是“”空字符串,并且我尝试刷新页面时,平面图内的代码不起作用,因为搜索值已经是空字符串,要刷新,我尝试通过更改来再次点击 api 调用搜索值“”以触发写入 fla 映射内的 api 调用。那么即使搜索值相同,可以做些什么来使这个平面图工作。
android ×7
kotlin ×5
custom-ui ×1
dagger-hilt ×1
firebase ×1
font-scaling ×1