Git Product home page Git Product logo

royal-android's Introduction

#Royal Android This project created to help developer to have better experience in using Realm-Java

###Dependencies

dependencies {
   compile 'com.thefinestartist:royal:0.82.1.0'
}

###Royal

public class App extends Application {

   @Override
   public void onCreate() {
      super.onCreate();
      Royal.joinWith(this);
      Royal.addDatabase(new DefaultDatabase());
   }
}

###Royal Database

public class DefaultDatabase extends RoyalDatabase {

    @Override
    public String getFileName() {
        return super.getFileName();
    }

    @Override
    public boolean forCache() {
        return super.forCache();
    }

    @Override
    public byte[] getEncryptionKey() {
        return super.getEncryptionKey();
    }

    @Override
    public boolean shouldDeleteIfMigrationNeeded() {
        return super.shouldDeleteIfMigrationNeeded();
    }

    @Override
    public List<Object> getModules() {
        return super.getModules();
    }

    @Override
    public int getVersion() {
        return super.getVersion();
    }

    @Override
    public long execute(Realm realm, long version) {
        return super.execute(realm, version);
    }
}
RealmConfiguration configuration = Royal.getConfigurationOf(SecondaryDatabase.class);

###RoyalTransaction

// RealmList, RealmResults, RealmObject, List<? extends RealmObject>
RoyalTransaction.create(Class<? extends RoyalDatabase> clazz, Object... objects);
RoyalTransaction.create(RealmConfiguration configuration, Object... objects);
RoyalTransaction.create(Realm realm, Object... objects);

RoyalTransaction.save(Class<? extends RoyalDatabase> clazz, Object... objects);
RoyalTransaction.save(RealmConfiguration configuration, Object... objects);
RoyalTransaction.save(Realm realm, Object... objects);

RoyalTransaction.delete(Class<? extends RoyalDatabase> clazz, Object... objects);
RoyalTransaction.delete(RealmConfiguration configuration, Object... objects);
RoyalTransaction.delete(Realm realm, Object... objects);
User user = new User();
user.setName("Leonardo Taehwan Kim");
user.setEmail("[email protected]");
user.setUsername("TheFinestArtist");

RoyalTransaction.save(realm, user);
User user1 = new User();
user1.setName("Leonardo Taehwan Kim");
user1.setEmail("[email protected]");
user1.setUsername("TheFinestArtist");

User user2 = new User();
user2.setName("Leonardo Taehwan Kim");
user2.setEmail("[email protected]");
user2.setUsername("TheFinestArtist");

RoyalTransaction.save(realm, user1, user2);

###RoyalExport

RoyalExport.toEmail(Class<? extends RoyalDatabase>... clazzes);
RoyalExport.toEmail(String email, Class<? extends RoyalDatabase>... clazzes);
RoyalExport.toEmail(String email, Intent intent, Class<? extends RoyalDatabase>... clazzes);

RoyalExport.toEmail(RealmConfiguration... configurations);
RoyalExport.toEmail(String email, RealmConfiguration... configurations);
RoyalExport.toEmail(String email, Intent intent, RealmConfiguration... configurations);

RoyalExport.toEmail(Realm... realms);
RoyalExport.toEmail(String email, Realm... realms);
RoyalExport.toEmail(String email, Intent intent, Realm... realms);

RoyalExport.toEmailAsRawFile();
RoyalExport.toEmailAsRawFile(String email);
RoyalExport.toEmailAsRawFile(String email, Intent intent);

RoyalExport.toExternalStorage(Class<? extends RoyalDatabase>... clazzes)
RoyalExport.toExternalStorage(RealmConfiguration... configurations);
RoyalExport.toExternalStorage(Realm... realms);
RoyalExport.toExternalStorageAsRawFile();

###Rson

Gson gson = Rson.getGson();

Rson.toJsonString(RealmObject object);
Rson.toJsonString(RealmObject object, int depth);

###RealmBaseAdapter for RecyclerView

License

The MIT License (MIT)

Copyright (c) 2015 TheFinestArtist

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

royal-android's People

Stargazers

Patryk Durka avatar Piyush Malaviya avatar Stefan Popa avatar Haneef Ansari avatar jeremy avatar pirati02 avatar kimziv avatar Theik Chan avatar Nikitin Sergey avatar Nagesh Kulkarni avatar cfirmo33 avatar Albert Tavares de Almeida avatar  avatar Eric Bachhuber avatar 代码GG陆晓明 avatar Yossi Elkrief avatar crazyflysheep avatar Roger Patiño avatar Ali avatar  avatar Igor Morais avatar Gerson Alexander Pardo Gamez avatar Michael LAGUERRE avatar f-t-i-o-i avatar Hery avatar Bart Kołodziejczyk avatar Minwoo Park avatar 0xEwoks avatar Max Trense avatar Mike Scamell avatar Hendry Syamsudin avatar  avatar chuross avatar Hue Kim avatar Andy Barber avatar ralphilius avatar Taehoon Moon avatar Younes Saadat avatar Michael Basil avatar Amine Laadhari avatar Chen Mulong avatar Ryan Yoo avatar  avatar Brian Munkholm avatar Pranav Lathigara avatar Andrii Matkivskyi avatar trietbui85 avatar TK avatar Vit Veres avatar Pedro Paulo Amorim avatar Hwa Young, Lee avatar Vladislav Bauer avatar Leonardo Kim avatar

Watchers

James Cloos avatar Nhut Phan avatar Leonardo Kim avatar  avatar

royal-android's Issues

Speed Test

https://gist.github.com/cmelchior/ddac8efd018123a1e53a

// GSON can parse the data.
//
// Deserialization:
// Note there is a bug in GSON 2.3.1 that can cause it to StackOverflow when working with RealmObjects.
// To work around this, use the ExclusionStrategy below or downgrade to 1.7.1
// See more here: https://code.google.com/p/google-gson/issues/detail?id=440
//
// Serialization:
// <Type>RealmProxy objects are created by the Realm annotation processor. They are used to control
// access to the actual data instead of storing them in fields and it is therefore them we need to register a
// TypeAdapter for.
Gson gson = new GsonBuilder()
        .setExclusionStrategies(new ExclusionStrategy() {
            @Override
            public boolean shouldSkipField(FieldAttributes f) {
                return f.getDeclaringClass().equals(RealmObject.class);
            }

            @Override
            public boolean shouldSkipClass(Class<?> clazz) {
                return false;
            }
        })
        .registerTypeAdapter(Class.forName("io.realm.PersonRealmProxy"), new PersonSerializer())
        .registerTypeAdapter(Class.forName("io.realm.DogRealmProxy"), new DogSerializer())
        .create();

// Serialize a Realm object to a JSON string
String json = gson.toJson(realm.where(Person.class).findFirst());
package io.realm.example;

import io.realm.RealmObject;

public class Dog extends RealmObject {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

package io.realm.examples;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;

import io.realm.examples.realmgridview.Dog;

public class DogSerializer implements JsonSerializer<Dog> {

    @Override
    public JsonElement serialize(Dog src, Type typeOfSrc, JsonSerializationContext context) {
        final JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("name", src.getName());
        return jsonObject;
    }
}
package io.realm.example;

import io.realm.RealmList;
import io.realm.RealmObject;

public class Person extends RealmObject {

    private String name;
    private int age;
    private Dog favoriteDog;
    private RealmList<Dog> dogs;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Dog getFavoriteDog() {
        return favoriteDog;
    }

    public void setFavoriteDog(Dog favoriteDog) {
        this.favoriteDog = favoriteDog;
    }

    public RealmList<Dog> getDogs() {
        return dogs;
    }

    public void setDogs(RealmList<Dog> dogs) {
        this.dogs = dogs;
    }
}

package io.realm.example;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;

public class PersonSerializer implements JsonSerializer<Person> {

    @Override
    public JsonElement serialize(Person src, Type typeOfSrc, JsonSerializationContext context) {
        final JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("name", src.getName());
        jsonObject.addProperty("age", src.getAge());
        jsonObject.add("favoriteDog", context.serialize(src.getFavoriteDog()));
        jsonObject.add("dogs", context.serialize(src.getDogs()));
        return jsonObject;
    }
}

README.md

Royal

  • RoyalBrowser
  • RoyalTransaction
  • RoyalExport => Decrept
  • RoyalDatabase
  • For-Loop Backward
  • Realm Encryption => use xml or hardcode or code sign
  • Extended RealmList
RoyalBrowser.browse("default", "");

Application

public class BaseApplication extends Application {

   @Override
   public void onCreate() {
      super.onCreate();
      Royal.initialize(this);
   }
}

Database

Default Database

Royal.getDefaultDatabase();
Royal.getDatabase(DefaultDatabase.class);

Custom Database

  1. Helps you open a Realm once and close Realm once automatically (Forget about opening and closing)
  2. Save all realm instance for each thread and reuse it (Forget about thread)
// RoyalDatabase are abstract class
public class SecondaryDatabase extends RoyalDatabase {

   @Override
   public String getFileName() {
      return "secondary"; // Royal always uses .realm as file extension
   }

   // Cached database will only use memory (not using file system)
   // Cached database will automatically deleted or garbage collected whenever Application is removed from memory
   @Override
   public boolean forCache() {
      return false;
   }

   @Override
   public byte[] getEncryptionKey() {
      return null; // null for no encryption
   }
}

getDatabase

Royal.getDatabase(SecondaryDatabase.class);

Test Case for RealmExport

Test Case for each method for 3~5 configuration

RealmConfiguration config = new RealmConfiguration.Builder(context)
  .name("myrealm.realm")
  .encryptionKey(getKey())
  .schemaVersion(42)      
  .setModules(new MySchemaModule())
  .migration(new MyMigration())    
  .build();
    public static void toEmail(@NonNull Context context, RealmConfiguration... configurations)
    public static void toEmail(@NonNull Context context, String email, RealmConfiguration... configurations)
    public static void toEmail(@NonNull Context context, String email, Intent intent, RealmConfiguration... configurations)

    public static void toEmail(@NonNull Context context, Realm... realms) 
    public static void toEmail(@NonNull Context context, String email, Realm... realms)
    public static void toEmail(@NonNull Context context, String email, Intent intent, Realm... realms)

    public static void toEmailAsRawFile(@NonNull Context context)
    public static void toEmailAsRawFile(@NonNull Context context, String email)
    public static void toEmailAsRawFile(@NonNull Context context, String email, Intent intent)

    public static void toExternalStorage(RealmConfiguration... configurations)
    public static void toExternalStorage(Realm... realms)
    public static void toExternalStorageAsRawFile(@NonNull Context context)

Split the library & dependency

  1. Core
  2. RoyalExport (Require WRITE_EXTERNAL_STORAGE permission & most likely to use for debug build type)
  3. RoyalBrowser (Browser will use other libraries for custom view and widget & most likely to use for debug build type)
    compile 'com.android.support:support-annotations:22.+'
    compile 'com.android.support:appcompat-v7:22.+'
    compile 'com.android.support:recyclerview-v7:22.+'
    compile 'com.orhanobut:logger:1.+'
    compile 'com.google.code.gson:gson:2.3.+'
    compile 'io.realm:realm-android:0.81.1'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.