-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
137 changed files
with
2,935 additions
and
1,943 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
*.iml | ||
build/ | ||
.gradle | ||
wrapper | ||
local.properties | ||
/wrapper |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:0.12.+' | ||
} | ||
} | ||
apply plugin: 'android-library' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
android { | ||
compileSdkVersion 19 | ||
buildToolsVersion '19.1.0' | ||
defaultConfig { | ||
applicationId 'ninja.ugly.prevail' | ||
minSdkVersion 17 | ||
targetSdkVersion 19 | ||
versionCode 1 | ||
versionName '1.0' | ||
} | ||
buildTypes { | ||
release { | ||
runProguard false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
productFlavors { | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
compile 'com.android.support:appcompat-v7:19.+' | ||
compile project(':Library') | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /opt/android-sdk-linux-x86_64/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ninja.ugly.prevail"> | ||
|
||
<application android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:icon="@drawable/ic_launcher"> | ||
|
||
</application> | ||
|
||
</manifest> |
2 changes: 1 addition & 1 deletion
2
...d/example/service/MainThreadExecutor.java → .../prevail/executor/MainThreadExecutor.java
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
165 changes: 165 additions & 0 deletions
165
AndroidLibrary/src/main/java/ninja/ugly/prevail/loader/ChunkLoader.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package ninja.ugly.prevail.loader; | ||
|
||
import android.content.AsyncTaskLoader; | ||
import android.content.Context; | ||
import android.os.CancellationSignal; | ||
import android.os.OperationCanceledException; | ||
import android.util.Log; | ||
import com.google.common.base.Optional; | ||
import ninja.ugly.prevail.chunk.QueryResult; | ||
import ninja.ugly.prevail.datamodel.DataModel; | ||
|
||
import java.io.FileDescriptor; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public abstract class ChunkLoader<K, V> extends AsyncTaskLoader<QueryResult<V>> { | ||
|
||
private static final String TAG = ChunkLoader.class.getSimpleName(); | ||
|
||
private final Optional<String> mSegment; | ||
|
||
K mKey; | ||
QueryResult<V> mResults; | ||
private DataModel mDataModel; | ||
private CancellationSignal mCancellationSignal; | ||
|
||
public ChunkLoader(Context context, DataModel dataModel, String segment, K key) { | ||
super(context); | ||
mDataModel = dataModel; | ||
mKey = key; | ||
mSegment = segment == null ? Optional.<String>absent() : Optional.of(segment); | ||
} | ||
|
||
public ChunkLoader(final Context context, final DataModel dataModel, final K key) { | ||
this(context, dataModel, null, key); | ||
} | ||
|
||
@Override | ||
public QueryResult<V> loadInBackground() { | ||
|
||
synchronized (this) { | ||
if (isLoadInBackgroundCanceled()) { | ||
throw new OperationCanceledException(); | ||
} | ||
mCancellationSignal = new CancellationSignal(); | ||
} | ||
|
||
List<QueryResult<Object>> queryResults = null; | ||
|
||
try { | ||
if (mSegment.isPresent()) { | ||
queryResults = mDataModel.query(mSegment.get(), mKey).get(); | ||
} else { | ||
queryResults = mDataModel.query(mKey).get(); | ||
} | ||
} catch (InterruptedException e) { | ||
Log.e(TAG, "Exception querying " + mKey, e); | ||
} catch (ExecutionException e) { | ||
Log.e(TAG, "Exception querying " + mKey, e); | ||
} finally { | ||
synchronized (this) { | ||
mCancellationSignal = null; | ||
} | ||
} | ||
|
||
return (QueryResult<V>) queryResults.get(0); | ||
} | ||
|
||
@Override | ||
public void deliverResult(QueryResult<V> results) { | ||
if (isReset()) { | ||
// An async query came in while the loader is stopped | ||
close(mResults); | ||
return; | ||
} | ||
QueryResult<V> oldResults = mResults; | ||
mResults = results; | ||
|
||
if (isStarted()) { | ||
super.deliverResult(results); | ||
} | ||
|
||
if (oldResults != results) { | ||
close(oldResults); | ||
} | ||
} | ||
|
||
/** | ||
* Starts an asynchronous load of the contacts list data. When the result is ready the callbacks | ||
* will be called on the UI thread. If a previous load has been completed and is still valid | ||
* the result may be passed to the callbacks immediately. | ||
* <p/> | ||
* Must be called from the UI thread | ||
*/ | ||
@Override | ||
protected void onStartLoading() { | ||
if (mResults != null) { | ||
deliverResult(mResults); | ||
} | ||
if (takeContentChanged() || mResults == null) { | ||
forceLoad(); | ||
} | ||
} | ||
|
||
/** | ||
* Must be called from the UI thread | ||
*/ | ||
@Override | ||
protected void onStopLoading() { | ||
// Attempt to cancel the current load task if possible. | ||
cancelLoad(); | ||
} | ||
|
||
@Override | ||
public void onCanceled(QueryResult<V> result) { | ||
close(result); | ||
} | ||
|
||
private void close(final QueryResult<V> result) { | ||
if (result != null && !result.isClosed()) { | ||
try { | ||
result.close(); | ||
} catch (IOException e) { | ||
Log.d(TAG, "Exception closing old results", e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onReset() { | ||
super.onReset(); | ||
|
||
// Ensure the loader is stopped | ||
onStopLoading(); | ||
|
||
close(mResults); | ||
mResults = null; | ||
} | ||
|
||
@Override | ||
public void cancelLoadInBackground() { | ||
super.cancelLoadInBackground(); | ||
synchronized (this) { | ||
if (mCancellationSignal != null) { | ||
mCancellationSignal.cancel(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { | ||
super.dump(prefix, fd, writer, args); | ||
writer.print(prefix); | ||
writer.print("mKey="); | ||
writer.println(mKey); | ||
writer.print(prefix); | ||
writer.print("mSegment="); | ||
writer.println(mSegment); | ||
writer.print(prefix); | ||
writer.print("mResults="); | ||
writer.println(mResults); | ||
} | ||
} |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">Prevail</string> | ||
</resources> |
13 changes: 0 additions & 13 deletions
13
...java/org/bailedout/prevail/android/example/event/database/DatabaseDeleteEventFactory.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...java/org/bailedout/prevail/android/example/event/database/DatabaseInsertEventFactory.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
.../java/org/bailedout/prevail/android/example/event/database/DatabaseQueryEventFactory.java
This file was deleted.
Oops, something went wrong.
82 changes: 0 additions & 82 deletions
82
...App/src/main/java/org/bailedout/prevail/android/example/model/database/DatabaseChunk.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.