• Stars
    star
    176
  • Rank 210,062 (Top 5 %)
  • Language
    Java
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reactive extension for NoSQL data storage on Android

RxPaper

Build Status

RxPaper is a RxJava wrapper for the cool paper library, a fast NoSQL data storage for Android that lets you save/restore Java objects by using efficient Kryo serialization and handling data structure changes automatically.

For the RxJava 2 version please go to RxPaper2 made by Pakoito.

Paper icon

What's new for the new PaperDB 2.0 (starting on 0.5.0+ version)

  • Update internal Kryo serializer to 4.0. The data format is changed, but Paper supports backward data compatibility automatically;
  • Now 58% less methods count : 4037;
  • Depends on data structure you may experience faster reading but slower writing.

Add dependency

repositories {
    jcenter()
    maven { url "https://jitpack.io" }
 }
dependencies {
    compile 'com.cesarferreira.rxpaper:rxpaper:0.5.0'
}

Install

Init the library in your Application class

public class SampleApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        RxPaper.init(this);
    }
}

Save

Save data object. Your custom classes must have no-arg constructor. Paper creates separate data file for each key.

RxPaper.book()
        .write(key, value)
        .subscribe(success -> /* all good */ );

I'm serious: Your custom classes must have no-arg constructor.

Read

Read data objects. Paper instantiates exactly the classes which has been used in saved data. The limited backward and forward compatibility is supported. See Handle data class changes.

Use default values if object doesn't exist in the storage.

RxPaper.book()
        .read(key, defaultPersonValue)
        .subscribe(person -> /* all good */ );

Delete

Delete data for one key.

RxPaper.book()
       .delete(key)
       .subscribe();

Completely destroys Paper storage.

RxPaper.book()
       .destroy()
       .subscribe();

Exists

Check if a key is persisted

RxPaper.book()
       .exists(key)
       .subscribe(success -> /* all good */);

Get all keys

Returns all keys for objects in the book.

RxPaper.book()
       .getAllKeys()
       .subscribe(allKeys -> /* all good */);

Use custom book

You can create custom Book book separate storage using

RxPaper.book("custom-book")...;

Any changes in one book doesn't affect to others books.

Important information

Don't forget to specify which threads you want to use before subscribing to any data manipulation, or else it'll run on the UI thread.

...
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(...

Handle data structure changes

Class fields which has been removed will be ignored on restore and new fields will have their default values. For example, if you have following data class saved in Paper storage:

class Person {
    public String firstName; // Cesar
    public String middleName; // Costa
}

And then you realized you need to change the class like:

class Person {
    public String firstName; // Cesar
    // public String middleName; removed field, who cares about middle names
    public String lastName; // New field
}

Then on restore the middleName field will be ignored and new lastName field will have its default value null.

Exclude fields

Use transient keyword for fields which you want to exclude from saving process.

public transient String tempId = "default"; // Won't be saved

Proguard config

  • Keep data classes:
-keep class my.package.data.model.** { *; }

alternatively you can implement Serializable in all your data classes and keep all of them using:

-keep class * implements java.io.Serializable { *; }
  • Keep library classes and its dependencies
-keep class io.paperdb.** { *; }
-keep class com.esotericsoftware.** { *; }
-dontwarn com.esotericsoftware.**
-keep class de.javakaffee.kryoserializers.** { *; }
-dontwarn de.javakaffee.kryoserializers.**

How it works

Paper is based on the following assumptions:

  • Saved data on mobile are relatively small;
  • Random file access on flash storage is very fast.

So each data object is saved in separate file and write/read operations write/read whole file.

The Kryo is used for object graph serialization and to provide data compatibility support.

Benchmark results

Running Benchmark on Nexus 4, in ms:

Benchmark Paper Hawk
Read/write 500 contacts 187 447
Write 500 contacts 108 221
Read 500 contacts 79 155

More Repositories

1

dryrun

☁️ Try the demo project of any Android Library
Ruby
3,822
star
2

SwiftEventBus

A publish/subscribe EventBus optimized for iOS
Swift
1,089
star
3

drone

🍰 The missing library manager for Android Developers
JavaScript
515
star
4

alfi

Android Library Finder
Ruby
502
star
5

RxPeople

Observing people... wait what?
Java
425
star
6

colorize

Access to 1000+ colors on android!
Java
410
star
7

CatKit

Android kit for cat placeholders 🐱
Java
270
star
8

AndroidQuickUtils

Android Development Utils
Java
260
star
9

purrge

🐱 Quickly purrge android apps from your phone
JavaScript
186
star
10

android-rocket-launcher

πŸš€ Launch android modules from the terminal
Kotlin
163
star
11

gradlr

πŸŒ€ Fastest auto complete for gradle tasks
JavaScript
152
star
12

MaterialComponent.Banner

Material component for Android: Banner
Kotlin
114
star
13

international

Tool to convert CSV to localization specific files (ios/android)
Ruby
102
star
14

j2j

Convert any file.json to the corresponding mapped java files
Ruby
64
star
15

faker

A kotlin extension to load images asynchronously on android
Kotlin
58
star
16

kotlin-pluralizer

β˜€οΈ Kotlin extension to pluralize and singularize strings
Kotlin
49
star
17

react-native-logcat

⚑ Colored Logcat for react-native android
Ruby
48
star
18

tempo

⌚Kotlin intuitive Date extensions.
Kotlin
39
star
19

seguro

Secure persistence using AES+CBC encryption on Android with no dependencies.
Kotlin
35
star
20

flutter-architecture-example

Easy Flutter architecture using dependency injection (DI) + BLoC + State Manager + Repository Pattern
Dart
30
star
21

jsonify

Convert any Java object to JSON for easier debugging
Java
27
star
22

git-gud

:octocat: Tool to enhance your github workflow
JavaScript
26
star
23

goplaces

πŸ’ͺ Launch apps on your phone/emulator from the terminal
JavaScript
26
star
24

monzo-cli

πŸ’³ Monzo bank command line interface client
Ruby
26
star
25

gito

⚑ git helper tool to clone/open/auto-install/edit with a one-liner
Ruby
26
star
26

interactive-git-tag

:octocat: Interactive tool that helps with your git tagging by suggesting versions
JavaScript
25
star
27

facelift

Quick github-pages generator
JavaScript
24
star
28

lasertag

Automatically map android app versions to git tags
Ruby
24
star
29

generator-android-library

Boilerplate code for creating an android library
JavaScript
23
star
30

open-on-android

Open anything on your android phone
JavaScript
21
star
31

tray-apk-install

πŸ’Ž Fastest way to install APKs
JavaScript
19
star
32

Pretender

Lorem Ipsum, but for people [android]
Java
18
star
33

clean-idea

Fastest way to cleanup your IntelliJ IDEA files
Ruby
16
star
34

android-latest

Latest android versions for developers (buildTools, TargetSdk, etc.)
HTML
14
star
35

android-unique-device-id

Generate a 64-bit hex string as an unique Android ID
Kotlin
14
star
36

awsnap

πŸ„ Generate beautiful screenshots
JavaScript
13
star
37

yap-json

πŸ‹ Lightweight colorized JSON prettifier for the terminal
JavaScript
12
star
38

node-adb-api

A node API for adb (android debug bridge)
JavaScript
11
star
39

apu

β˜• Set of useful tools for android developers
Ruby
11
star
40

PainlessPrefs

Static way to use android preferences, no hassle
Java
11
star
41

UIState

Cleanest way of representing UI state in a flutter widget.
C++
11
star
42

pod-tools

Set of Cocoapods tools (clean, reinstall, clean derived data)
Ruby
9
star
43

oh

Quickly open any app in the folder you're currently in (Open Here)
JavaScript
8
star
44

lgtv-cli

CLI to control LG TV with WebOS
JavaScript
7
star
45

drone-hive

Companion repository for https://github.com/cesarferreira/drone
JavaScript
7
star
46

robin

Run scripts for any project
JavaScript
5
star
47

UserAgentForAndroid

Easily add app context to your android API calls
Kotlin
5
star
48

readme-senpai

Pretty prints markdown in the terminal given a gituhub username/repo
JavaScript
4
star
49

timecop

Static way to count time in android
Java
4
star
50

generator-node-skeleton

A yeoman generator for node modules
JavaScript
3
star
51

generator-node-cli-skeleton

A yeoman generator for a node cli app
JavaScript
3
star
52

node-time-log

console.log() with a beautiful timestamp
JavaScript
3
star
53

fpm

WIP - Flutter Package Manager
Dart
3
star
54

clap-detector-android

Kotlin
2
star
55

myboy

CSS
2
star
56

chef-cli

Quickly convert things into other things
JavaScript
2
star
57

insta-story

Creates an instagram story like UI
Kotlin
2
star
58

foodbot

A slack bot that knows what street food is available @ Paddington Central
JavaScript
2
star
59

better-version

Kotlin
2
star
60

generator-kotlin-mvp-dagger

generator-kotlin-starterkit
Kotlin
2
star
61

mvvm-arch-components-click-handling

Sample with MVVM google architecture components click handling
Kotlin
2
star
62

kotlin-dagger2-LettersAndNumbers

Example of Android project showing integration with Kotlin and Dagger 2
Kotlin
1
star
63

android-helloworld

just a sample project
Java
1
star
64

pod_player

Dart
1
star
65

json

JavaScript
1
star
66

jetpack-navigation-component-example

Example of jetpack navigation component with conditional login case
Kotlin
1
star
67

cesarferreira.github.io

HTML
1
star
68

release-notes

WIP - Tool to get release notes based on commit messages between commits
JavaScript
1
star
69

node-read-url

Reads an URL into a string
JavaScript
1
star
70

sample-data

JavaScript
1
star
71

flutterfy-cli

Flutter CLI tool to increase development speed
Ruby
1
star
72

swearjar

Static code analysis that looks for swear words in your codebase
Python
1
star
73

cm_to_nanoacres

Useless tool that converts cm2 into nanoacres
Rust
1
star