Skip to content

Instantly share code, notes, and snippets.

View jixiaoyong's full-sized avatar
👨‍💻
Focusing

JI,XIAOYONG jixiaoyong

👨‍💻
Focusing
View GitHub Profile
@jixiaoyong
jixiaoyong / README.md
Last active March 7, 2024 02:47
the difference of TickerModel.FIX_PERIOD and TickerModel.FIX_DELAY

ticker channel 定义见文档Ticker channels

TickerMode定义见文档TickerMode

假设initialDelayMillis为0,delayMillis为100,分别在0、50、100、150、250、300、350取值则(Y 有,N 无):

分类\时间ms 0 50 100 150 等待 100 250 300 350
FIX_PERIOD Y N Y N \ Y Y N
FIX_DELAY Y N Y N \ Y N Y
@jixiaoyong
jixiaoyong / TextTail.kt
Last active December 1, 2023 09:02
Jtepack compose Text:Add a “tail” to the text, if the total length exceeds the limit, add an ellipsis between the text and the tail. 给文本添加“尾巴”,如果全部长度超过限制,则在文本和尾巴之间添加省略号
/**
* Add a “tail” to the text, if the total length exceeds the limit, add an ellipsis between the text and the tail.
* 给文本添加“尾巴”,如果全部长度超过限制,则在文本和尾巴之间添加省略号
*/
@Composable
fun TextTail(
modifier: Modifier = Modifier,
text: String,
tail: String = "",
style: TextStyle = TextStyle(),
@jixiaoyong
jixiaoyong / endless_list_river_pod.dart
Created August 13, 2023 06:40
An infinite loading scrollable list built with riverpod which can work as expected
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'endless_list_river_pod.g.dart';
/// @author : jixiaoyong
/// @description :使用riverpod实现一个无限加载滚动的列表
/// An infinite loading scrollable list built with riverpod
///
@jixiaoyong
jixiaoyong / count_git_code_lins.sh
Created May 15, 2023 03:03
这个是一个对比两次commit的代码差别的行数的脚本。只是简单对比前后的变化,而不会统计两次commit之间新增又删除的情况。This is bash script to compare the number of lines of code difference between two commits. It simply compares the changes before and after, without counting the lines added and deleted between the two commits.
#!/bin/bash
###
# @Author: jixiaoyong
# @Email: jixiaoyong1995@gmail.com
# @Date: 23/05/15
# @LastEditors: jixiaoyong
# @LastEditTime: 23/05/15
# @Description:
# 这个是一个对比两次commit的代码差别的行数的脚本。
# 只是简单对比前后的变化,而不会统计两次commit之间新增又删除的情况。
@jixiaoyong
jixiaoyong / DuolingoWordBankExtractor.js
Last active March 31, 2023 13:21
为Duolingo填空题候选单词编号,以便使用数字键填空/取消填空的油猴脚本
// ==UserScript==
// @name 为Duolingo填空题候选单词编号,以便使用数字键填空/取消填空
// @namespace DuolingoWordBankExtractor
// @version 0.3
// @description 当识别出填空题候选单词之后,会为每个单词前面编号,此时只需点击对应的数字就可以选中并填空该单词,
// 再次点击该数字则取消填空。如果候选单词超过9个,则两次数字必须在1s之内输入,比如编号为11,
// 则必须在1s内点击两次1,否则会被认为输入的是编号1。
// @match http*://www.duolingo.com/*
// @match http*://www.duolingo.cn/*
// @author jixiaoyong
@jixiaoyong
jixiaoyong / AutoScrollText.kt
Created March 16, 2023 12:16
Jetpack compose写的超长自动滚动的Text
// 文字超长之后,反复向右滑动
BoxWithConstraints {
val parentMaxWidth = constraints.maxWidth
var textWidth by remember { mutableStateOf(parentMaxWidth) }
val anim by rememberInfiniteTransition().animateFloat(
initialValue = 0F,
targetValue = (parentMaxWidth - textWidth).toFloat(),
animationSpec = InfiniteRepeatableSpec(
TweenSpec(
// 根据文字长度调整滚动速度
@jixiaoyong
jixiaoyong / advanced_hero_animation.dart
Last active August 14, 2022 10:52
hero动画示例
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'dart:math' as math;
/// @author : jixiaoyong
/// @description : Hero动画的进阶使用
/// 这个示例中,First和Second页面中的正方形Hero.child内部被ClipOval和ClipRect相交部分裁剪
/// ClipRect的边长为也即Hero.child最大边长,是与直径为maxClipOvalDiameter的圆的内切正方形的边长
/// 也即:maxClipOvalDiameter / 2 * 根号2
/// 而Hero.child最小的时候,则为半径为minClipOvalDiameter/2的圆

官方demo power_image_example_kotlin_swift中,从网络加载图片时实际缓存到磁盘中的是原图,这在源图比较大(5~6Mb以上)时,可能默认250MB磁盘缓存很快耗尽导致网络图片需重新下载,从而在页面上看起来部分已经加载的图片又在重新通过网络下载。

比如将example_kotlin_swift中texture_image页面的图源换成 "https://bing.img.run/rand_uhd.php?$index",等加载到五六百张图片之后,又滑动到顶部会发现最顶部的图片缓存被清空,又重新从网络加载(当然这不是power_image的问题)。

虽然使用者一般会自己实现原生的图片加载,但还是希望官方有空的话可以修改一下demo中的Glide缓存策略,以便更好体现power_image的性能,比如改成DiskCacheStrategy.RESOURCE

        Glide.with(context).asDrawable().load(request.srcString())
            .listener(object : RequestListener<Drawable> {
                override fun onLoadFailed(
@jixiaoyong
jixiaoyong / BitmapUtils.kt
Created March 6, 2020 03:22
计算Bitmap取样率
import android.graphics.Bitmap
import android.graphics.BitmapFactory
/**
* Created by jixiaoyong1995@gmail.com
* Data: 2020/3/6.
* Description:
*/
object BitmapUtils {
@jixiaoyong
jixiaoyong / JetpackWorkManager.kt
Last active November 21, 2019 08:44
Jetpack-WorkManager
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.work.*
/**
* Created by jixiaoyong1995@gmail.com
* Data: 2019/11/21.
* Description: WorkManager使用示例
*