Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Nix committed Jul 1, 2014
2 parents 4dff816 + 9d80023 commit 0e25b42
Show file tree
Hide file tree
Showing 137 changed files with 2,935 additions and 1,943 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
*.iml
build/
.gradle
wrapper
local.properties
/wrapper
File renamed without changes.
39 changes: 39 additions & 0 deletions AndroidLibrary/build.gradle
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')
}
17 changes: 17 additions & 0 deletions AndroidLibrary/proguard-rules.pro
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 *;
#}
10 changes: 10 additions & 0 deletions AndroidLibrary/src/main/AndroidManifest.xml
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>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.bailedout.prevail.android.example.service;
package ninja.ugly.prevail.executor;


import android.os.Handler;
Expand Down
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);
}
}
3 changes: 3 additions & 0 deletions AndroidLibrary/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Prevail</string>
</resources>

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0e25b42

Please sign in to comment.