<commit_before># RxAppFocus

[![Release](https://jitpack.io/v/com.gramboid/RxAppFocus.svg)](https://jitpack.io/#com.gramboid/RxAppFocus)

A tiny library for Android/RxJava to tell you when your app becomes visible or hidden.

Why would you want to do that?

Maybe you want to trigger a sync with a cloud service when your app is resumed.
Maybe you want to stop receiving location updates when your app goes into the background.

RxAppFocus is most useful in a non-Activity context: application startup, receiving broadcasts, responding to asynchronous task completion, etc. (After all, in an Activity, the lifecycle methods already tell you what you need to know.)

## Usage

See the [rxappfocus-sample](https://github.com/gramboid/RxAppFocus/tree/master/rxappfocus-sample) module for a working example.

### Visibility update stream

In your `Application.onCreate()`:
```kotlin
val focusProvider = AppFocusProvider(this)
focusProvider.getAppFocus().subscribe { visible: Boolean -> /* ... */ }
```

### Quick visibility check

```kotlin
if (focusProvider.isVisible) { /* ... */ }
```

### Visible activity
<commit_msg>Add CI status<commit_after># RxAppFocus

[![Release](https://jitpack.io/v/com.gramboid/RxAppFocus.svg)](https://jitpack.io/#com.gramboid/RxAppFocus)
[![CircleCI](https://circleci.com/gh/gramboid/RxAppFocus.svg?style=shield)](https://circleci.com/gh/gramboid/RxAppFocus)

A tiny library for Android/RxJava to tell you when your app becomes visible or hidden.

Why would you want to do that?

Maybe you want to trigger a sync with a cloud service when your app is resumed.
Maybe you want to stop receiving location updates when your app goes into the background.

RxAppFocus is most useful in a non-Activity context: application startup, receiving broadcasts, responding to asynchronous task completion, etc. (After all, in an Activity, the lifecycle methods already tell you what you need to know.)

## Usage

See the [rxappfocus-sample](https://github.com/gramboid/RxAppFocus/tree/master/rxappfocus-sample) module for a working example.

### Visibility update stream

In your `Application.onCreate()`:
```kotlin
val focusProvider = AppFocusProvider(this)
focusProvider.getAppFocus().subscribe { visible: Boolean -> /* ... */ }
```

### Quick visibility check

```kotlin
if (focusProvider.isVisible) { /* ... */ }
```

### Visible activity

{'fraction_non_alphanumeric': 0.11455239711497667, 'fraction_numerical': 0.0, 'mean_word_length': 4.737226277372263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6449415', 'n_tokens_mistral': 695, 'n_tokens_neox': 663, 'n_words': 243}