This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Class connecting the Realm lifecycle to that of LiveData objects. | |
* Realm will remain open for as long as any LiveData objects are being observed. | |
*/ | |
abstract class LiveRealmData<T: RealmModel>(val config: RealmConfiguration) : LiveData<RealmResults<T>>() { | |
private val listener = RealmChangeListener<RealmResults<T>> { results -> value = results } | |
private lateinit var realm: Realm | |
private var results: RealmResults<T>? = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2017 Realm Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04-03 15:44:04.233 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 0, is_fresh 0 | |
04-03 15:44:04.237 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 0, is_fresh 0 | |
04-03 15:44:04.276 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 8844, is_fresh 0 | |
04-03 15:44:04.279 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 9187, is_fresh 0 | |
04-03 15:44:04.289 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,upload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Realm loadAssetFileOnMigration() { | |
// TODO Don't re-create this every time | |
RealmConfiguration config = new RealmConfiguration.Builder() | |
.schemaVersion(2) // Bumping the schema because new app | |
.build(); | |
Realm realm; | |
try { | |
realm = Realm.getInstance(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -w | |
# | |
# This script will analyze a Github repo and try to rank all open issues with regard to popularity. | |
# WARNING: This script will run quite a few HTTP requests against Github to do this analysis. At least 1 pr. issue. | |
# The current limit on Github is 5000 requests pr. hour: https://developer.github.com/v3/rate_limit/ | |
# | |
# Usage: ./ruby github-issue-rankings.rb <github_user/repo> <github_api_access_token> | |
# Example: ruby github_issue_rankings.rb realm/realm-java $GITHUB_ISSUE_RANKINGS_ACCESS_TOKEN | |
# | |
# The algorithm for ranking issues are the following: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2016 Realm Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a background thread | |
RealmThread t = new RealmThread(realmConfig, new RealmRunnable() { | |
@Override | |
public void run(Realm realm) { | |
do { | |
// Do some work once, and every time the Realm changes | |
} while (realm.waitForChange()) | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Specific class for a RealmList<Bar> field | |
public class BarListParcelConverter extends RealmListParcelConverter<Bar> { | |
@Override | |
public void itemToParcel(Bar input, Parcel parcel) { | |
parcel.writeParcelable(Parcels.wrap(input), 0); | |
} | |
@Override | |
public Bar itemFromParcel(Parcel parcel) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make a custom Gson instance, with a custom TypeAdapter for each wrapper object. | |
// In this instance we only have RealmList<RealmInt> as a a wrapper for RealmList<Integer> | |
Type token = new TypeToken<RealmList<RealmInt>>(){}.getType(); | |
Gson gson = new GsonBuilder() | |
.setExclusionStrategies(new ExclusionStrategy() { | |
@Override | |
public boolean shouldSkipField(FieldAttributes f) { | |
return f.getDeclaringClass().equals(RealmObject.class); | |
} |