小编Spi*_*dey的帖子

Android postDelayed 与 Coroutines 延迟

我看到这个例子,我想知道是否有任何客观原因使用 Coroutinesdelay而不是 Android Handler 来实现这个postDelayed

如果链接失效,示例代码如下:

val watcher = object :TextWatcher{
    private var searchFor = ""

    override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
        val searchText = s.toString().trim()
        if (searchText == searchFor)
            return

        searchFor = searchText

        launch {       
            delay(300)  //debounce timeOut
            if (searchText != searchFor)
                return@launch

            // do our magic here
        }
    }

    override fun afterTextChanged(s: Editable?) = Unit
    override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-handler kotlin-coroutines

15
推荐指数
1
解决办法
1万
查看次数

Android Studio中的Robojuice/Butterknife @InjectView自动格式化问题

我在整个项目中采用了@InjectView主题,并且在解决这些声明时遇到了一个小问题.在我输入初始代码后,它在这样的一行中看起来很棒.

@InjectView(R.id.tv_report_summary_name)TextView tvReportSummaryName;

但是,如果我执行自动格式(Ctrl + Shift + F),Android Studio会自动将其替换为两行,因此它看起来像:

@InjectView(R.id.tv_report_summary_name)
TextView tvReportSummaryName;

有没有办法避免这种情况或修改格式化选项以使其不发生?任何帮助是极大的赞赏.

android android-studio butterknife

12
推荐指数
1
解决办法
1325
查看次数

如何在多个小部件上确定提供程序的范围,而不将提供程序放在颤振中的根小部件上

我正在开发一个简单的演示,用户登录,查看项目列表,单击项目,然后查看其详细信息。这是 3 个屏幕,但我们假设有两个流程,其中一个处理登录,另一个处理项目。

我正在使用包管理我的状态provider。我LoginRepository在我的根小部件上放置了一个提供程序,因为到处都需要该状态。这很好用。

现在我需要一个ItemRepository应该在ItemListScreen和 上可用的ItemDetailScreen。为了实现该范围,我决定创建一个名为 的共同祖先小部件ItemScreens。这是我放置提供程序和嵌套 Navigator.

我使用导航器来导航屏幕,Navigator.of(context)以确保使用了关闭的祖先导航器。我使用获取我的提供程序Provider.of<ItemRepository>(context)来确保使用关闭祖先状态。

这显然不起作用,因为我得到了Could not find the correct provider. 我知道来自同级路由的提供程序不能被另一个同级路由访问,但在这里我嵌套导航器,我希望将其ItemRepository放置在ItemScreens其中然后处理子路由,以便这两个路由可以从父路由获取提供程序?

旁注:
Flutter文档明确指出应提升提供程序以实现正确的范围界定。但我从未见过将提供程序提升为非根小部件的示例。如果我们所能做的就是将提供程序放入根小部件中,那么应该明确说明这一点。

编辑:在多个小部件上重新创建提供程序是一种替代方案,但这并不是真正的范围,它只是伪值传递。

编辑:将所有提供程序放在根小部件上MultiProvider并不是一个好主意,因为它创建了全局状态反模式。除非需要,即用户正在访问该流程/屏幕,否则不应创建某些状态。

flutter flutter-navigation flutter-provider

11
推荐指数
1
解决办法
1562
查看次数

Downloading data directly into a temporary file with python youtube_dl

I'm using python embedded youtube_dl and I'd like to download video content directly into a temporary file. I attempted to create a NamedTemporaryFile and have youtube_dl write into it, but I always get a prompt that the file was already downloaded (the temporary file has that name and it thinks the download already happened).

I also attempted to have youtube_dl stream downloaded data to stdout and redirect stdout to the temporary file but I can't get the python embedded version …

youtube-dl python-3.6

5
推荐指数
1
解决办法
3861
查看次数