Skip to content

Instantly share code, notes, and snippets.

@CodeK1988
CodeK1988 / IllegalArgumentException: Cannot add the same observer with different lifecycles
Created April 1, 2020 01:24
IllegalArgumentException: Cannot add the same observer with different lifecycles
场景:dialogfragment(tabLayout+viewpager) + 两个Afragment
解决方案一:
class SafeMutableLiveData<T> : MutableLiveData<T>() {
private var weakLifecycleOwner: WeakReference<LifecycleOwner>? = null
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {
weakLifecycleOwner?.get()?.let {
removeObservers(it)
@CodeK1988
CodeK1988 / dialogfragment使用记录
Last active February 8, 2020 12:19
dialogfragment使用记录
dialogfragment使用记录
https://gist.github.com/yizuochengchi/2ad1e5e0127a3d42dd7c569da132c292
@CodeK1988
CodeK1988 / material 相关控件使用记录
Last active December 2, 2019 08:25
material 相关控件使用记录
1.MaterialButton
常规使用
android:insetTop="0dp"
android:insetBottom="0dp"
android:textAppearance="?android:attr/textAppearance"
selector enable false
app:backgroundTint="@color/login_selector_button"
@CodeK1988
CodeK1988 / Received status code 400 from server: Bad Request
Last active November 25, 2019 08:30
Received status code 400 from server: Bad Request
换了家公司 新公司用的是windows系统 入职第一天搭建环境
1.安装jdk1.8发现orale需要注册账号才可以下载 fuck!之前印象中好像没有
无奈从论坛下载
2.新建项目报错 Received status code 400 from server: Bad Request
懵逼了半天 解决办法 删除.gradle目录下 gradle.properties 最后4行设置的代理
感谢 https://www.jianshu.com/p/e0ba79c83183
window坑真多啊
@CodeK1988
CodeK1988 / Gson UserGuide
Created October 28, 2019 02:58
Gson使用技巧
1.正常使用大家都知道 fromJson等
2.将json字符串中某个字段转换成实体类代码如下
if (data.has("pop")) {
val jsonElement = Gson().fromJson<JsonElement>(json, JsonElement::class.java)
val pop = jsonElement.asJsonObject.getAsJsonObject("data").getAsJsonObject("pop")
val bean = Gson().fromJson<Bean>(pop, Bean::class.java)
}
@CodeK1988
CodeK1988 / Remove ViewPager2 Overscroll animatoin
Last active October 28, 2019 09:18
Remove ViewPager2 Overscroll animatoin
thanks
1.https://stackoverflow.com/questions/56878906/remove-viewpager2-overscroll-animatoin
viewPager2.apply {
orientation = ViewPager2.ORIENTATION_HORIZONTAL
(getChildAt(0) as RecyclerView).overScrollMode = RecyclerView.OVER_SCROLL_NEVER
}
android:overScrollMode="never" is not working
@CodeK1988
CodeK1988 / TabLayout custom change tabTextSize
Last active February 18, 2021 06:28
TabLayout custom change tabTextSize
1.tabTextAppearance
<style name="YourTextAppearance" parent="TextAppearance.AppCompat.Button">
<item name="android:textSize">20sp</item>
...
</style>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
@CodeK1988
CodeK1988 / ExoPlayer notes
Last active September 17, 2019 04:56
ExoPlayer notes
/**
* 播放raw下的本地文件
*/
fun initPlayer(context: Context, rawRes: Int): SimpleExoPlayer {
val dataSpec = DataSpec(RawResourceDataSource.buildRawResourceUri(rawRes))
val dataSource = RawResourceDataSource(context)
dataSource.open(dataSpec)
val bandwidthMeter = DefaultBandwidthMeter()
val extractorsFactory = DefaultExtractorsFactory()
@CodeK1988
CodeK1988 / App Startup Time
Created September 12, 2019 06:51
应用启动优化记录
早上做地铁 在应用商店打开app 看到oppo应用商店的安全评测分平均分 92
其中启动60 启动时间4s且有白屏
应用启动这块一直想优化 但一直没顾得上
查文档:
https://developer.android.com/topic/performance/vitals/launch-time
理论认知:
应用的启动方式
冷启动:当启动应用时,后台没有该应用的进程,这时系统会首先会创建一个新的进程分配给该应用,这种启动方式就是冷启动。
旧项目中使用Volley
移植入Okhttp Retrofit 如何同步cookie
1.之前的思路:
Volley 底层替换
class OkHttpStack(
private val okHttpClient: OkHttpClient
) : BaseHttpStack() {