Skip to content

Instantly share code, notes, and snippets.

@cesclong
cesclong / LiveEventBus.java
Created May 7, 2023 15:39
LiveEventBus.java
package com.pplive.archcomponent.jetpack.livedata;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.Observer;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import java.util.HashMap;
@cesclong
cesclong / LiveEvent.kt
Created May 7, 2023 15:39
LiveEvent LiveData
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@cesclong
cesclong / UserMgr.kt
Last active May 12, 2023 01:44
ConcurrentHashMap日常使用的例子
/**
* 当有很多用户同时登入和登出时,
* onUserSignIn() 和 onUserSignOut() 就会有很多线程同时调用
*/
class UserMgr private constructor() {
private val userMap: ConcurrentHashMap<String, User> = ConcurrentHashMap<String, User>()
companion object {
private val instance by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { UserMgr() }
@cesclong
cesclong / PreDelegate.kt
Created January 6, 2022 07:42
使用委托类实现简化SharedPreference的使用
class PreDelegate<T>(
private val name: String,
private val default: T,
private val isCommit: Boolean = false,
private val prefs: SharedPreferences
) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T {
return getPref(name, default) ?: default
}
@cesclong
cesclong / LiveDataBus.java
Created June 25, 2021 11:48
防止数据倒灌Livedata
public class LiveDataBus {
private static LiveDataBus liveDataBus;
//应用中所有数据持有类的集合
private Map<String,MyMutableLiveData<Object>> map;
private LiveDataBus(){
map=new HashMap<>();
@cesclong
cesclong / HowToUseActivity.kt
Last active June 23, 2021 07:18
响应生命周期的ViewHolder和Adapter
import android.os.Bundle
import android.util.Log
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import app.keima.android.recyclerviewsandbox.databinding.ActivityMainBinding
@cesclong
cesclong / FixCrashWithDialogFragment
Created April 5, 2021 08:01
Fix `DialogFragment` crash questions ... 修复DialogFragment崩溃崩溃的
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
/**
* Fix `DialogFragment` crash questions ... <br /><br />
*
@cesclong
cesclong / BaseRecyclerView.java
Created March 30, 2021 14:59
响应生命周期Lifecycle的自定义RecyclerView
public class BaseRecyclerView extends RecyclerView implements LifecycleObserver {
public BaseRecyclerView(@NonNull Context context) {
super(context);
init(context);
}
public BaseRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.longzhu.utils.android;
import android.text.TextUtils;
import android.util.Log;
@cesclong
cesclong / dwn.desktop
Created March 21, 2021 06:38
dwm在/usr/share/xsessions/dwm.desktop
[Desktop Entry]
Name=dwm
Comment=Suckless Window Manager
Exec=/usr/local/bin/dwm
TryExec=/usr/local/bin/dwm
Icon=/home/cesc/dwm/dwm.png
Type=Application