Skip to content

Commit

Permalink
Merge pull request #112 from flipkart-incubator/submodules
Browse files Browse the repository at this point in the history
Breaking into Submodules
  • Loading branch information
thekirankumar authored Nov 29, 2016
2 parents 80d0ce4 + 51623f2 commit 304fb6d
Show file tree
Hide file tree
Showing 93 changed files with 1,236 additions and 557 deletions.
34 changes: 14 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,26 @@

apply plugin: 'com.android.application'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile project(':batching')
compile project(':batching-core')
compile project(':batching-gson')
}

android {
compileSdkVersion 24
buildToolsVersion '24.0.0'
compileSdkVersion 25
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "com.flipkart.batchdemo"
minSdkVersion 14
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}

lintOptions {
Expand All @@ -49,17 +56,4 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile project(':batching')
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/flipkart/batchdemo/CustomTagData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

package com.flipkart.batchdemo;

import com.flipkart.batching.data.Tag;
import com.flipkart.batching.data.TagData;
import com.flipkart.batching.core.data.Tag;
import com.flipkart.batching.core.data.TagData;
import com.google.gson.annotations.SerializedName;

import org.json.JSONObject;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/flipkart/batchdemo/EventTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.flipkart.batchdemo;

import com.flipkart.batching.data.Tag;
import com.flipkart.batching.core.data.Tag;
import com.google.gson.annotations.SerializedName;

public class EventTag extends Tag {
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/java/com/flipkart/batchdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@
import android.view.View;
import android.webkit.ValueCallback;

import com.flipkart.batching.Batch;
import com.flipkart.batching.TagBatchManager;
import com.flipkart.batching.data.Tag;
import com.flipkart.batching.data.TagData;
import com.flipkart.batching.listener.NetworkPersistedBatchReadyListener;
import com.flipkart.batching.listener.PersistedBatchCallback;
import com.flipkart.batching.listener.TrimmedBatchCallback;
import com.flipkart.batching.persistence.GsonSerializationStrategy;
import com.flipkart.batching.persistence.SerializationStrategy;
import com.flipkart.batching.persistence.TapePersistenceStrategy;
import com.flipkart.batching.strategy.SizeBatchingStrategy;
import com.flipkart.batching.strategy.TagBatchingStrategy;
import com.flipkart.batching.core.Batch;
import com.flipkart.batching.core.SerializationStrategy;
import com.flipkart.batching.core.batch.TagBatch;
import com.flipkart.batching.core.data.Tag;
import com.flipkart.batching.core.data.TagData;
import com.flipkart.batching.gson.GsonSerializationStrategy;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -133,14 +133,14 @@ public void onTrimmed(int oldSize, int newSize) {
}
});

debugListener.setListener(new PersistedBatchCallback<TagBatchingStrategy.TagBatch<TagData>>() {
debugListener.setListener(new PersistedBatchCallback<TagBatch<TagData>>() {
@Override
public void onPersistFailure(TagBatchingStrategy.TagBatch<TagData> batch, Exception e) {
public void onPersistFailure(TagBatch<TagData> batch, Exception e) {

}

@Override
public void onPersistSuccess(TagBatchingStrategy.TagBatch<TagData> batch) {
public void onPersistSuccess(TagBatch<TagData> batch) {
// SystemClock.sleep(2000);
debugListener.finish(batch);
Log.e("Debug", "Finish Called");
Expand All @@ -165,14 +165,14 @@ public void onTrimmed(int oldSize, int newSize) {
}
});

dgListener.setListener(new PersistedBatchCallback<TagBatchingStrategy.TagBatch<TagData>>() {
dgListener.setListener(new PersistedBatchCallback<TagBatch<TagData>>() {
@Override
public void onPersistFailure(TagBatchingStrategy.TagBatch<TagData> batch, Exception e) {
public void onPersistFailure(TagBatch<TagData> batch, Exception e) {

}

@Override
public void onPersistSuccess(TagBatchingStrategy.TagBatch<TagData> batch) {
public void onPersistSuccess(TagBatch<TagData> batch) {
//SystemClock.sleep(2000);
dgListener.finish(batch);
Log.e("Dg", "Finish Called");
Expand Down
1 change: 1 addition & 0 deletions batching-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions batching-core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apply plugin: 'com.android.library'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}

android {
compileSdkVersion 24
buildToolsVersion '24'

defaultConfig {
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
17 changes: 17 additions & 0 deletions batching-core/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 /Users/anirudh.r/Library/Android/sdk/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 *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.flipkart.batching.core;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.flipkart.batching.core.test", appContext.getPackageName());
}
}
9 changes: 9 additions & 0 deletions batching-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flipkart.batching.core">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
* THE SOFTWARE.
*/

package com.flipkart.batching;
package com.flipkart.batching.core;

import java.util.Collection;

public interface Batch<T extends Data> {
Collection<T> getDataCollection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
* THE SOFTWARE.
*/

package com.flipkart.batching;

import com.google.gson.annotations.SerializedName;
package com.flipkart.batching.core;

import java.util.Collection;

Expand All @@ -34,7 +32,6 @@

public class BatchImpl<T extends Data> implements Batch<T> {

@SerializedName("dataCollection")
private DataCollection<T> dataCollection;

public BatchImpl(Collection<T> dataCollection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
* THE SOFTWARE.
*/

package com.flipkart.batching;
package com.flipkart.batching.core;

import com.flipkart.batching.data.Tag;
import com.google.gson.annotations.SerializedName;

import com.flipkart.batching.core.data.Tag;

import java.io.Serializable;

Expand All @@ -40,7 +40,6 @@
*/

public abstract class Data implements Serializable {
@SerializedName("eventId")
private long eventId;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Flipkart Internet Pvt. Ltd.
*
* 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.
*/

package com.flipkart.batching.core;

import java.util.Collection;

/**
* DataCollection class
*/

public class DataCollection<T extends Data> {
public Collection<T> dataCollection;

public DataCollection(Collection<T> dataCollection) {
this.dataCollection = dataCollection;
}

@Override
public boolean equals(Object o) {
if (o instanceof DataCollection) {
return dataCollection.equals(((DataCollection) o).dataCollection);
}
return super.equals(o);
}

@Override
public int hashCode() {
return dataCollection == null ? 0 : dataCollection.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@
* THE SOFTWARE.
*/

package com.flipkart.batching.persistence;
package com.flipkart.batching.core;

import com.flipkart.batching.Batch;
import com.flipkart.batching.Data;
import com.flipkart.batching.exception.DeserializeException;
import com.flipkart.batching.exception.SerializeException;
import com.flipkart.batching.core.exception.DeserializeException;
import com.flipkart.batching.core.exception.SerializeException;

import java.util.Collection;

/**
* This is an interface for serialization strategy. An implementation of this class
* must override all it's methods.
*
* @see GsonSerializationStrategy
*/
public interface SerializationStrategy<E extends Data, T extends Batch> {

Expand Down Expand Up @@ -79,4 +75,4 @@ public interface SerializationStrategy<E extends Data, T extends Batch> {
Collection<E> deserializeCollection(byte[] data) throws DeserializeException;

T deserializeBatch(byte[] data) throws DeserializeException;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.flipkart.batching.core.batch;


import com.flipkart.batching.core.BatchImpl;
import com.flipkart.batching.core.Data;

import java.util.Collection;

public class SizeBatch<T extends Data> extends BatchImpl<T> {
private int maxBatchSize;

public SizeBatch(Collection dataCollection, int maxBatchSize) {
super(dataCollection);
this.maxBatchSize = maxBatchSize;
}

public int getMaxBatchSize() {
return maxBatchSize;
}

@Override
public boolean equals(Object o) {
if (o instanceof SizeBatch) {
return ((SizeBatch) o).getMaxBatchSize() == maxBatchSize && super.equals(o);
}
return super.equals(o);
}

@Override
public int hashCode() {
return 31 * super.hashCode() + maxBatchSize;
}
}
Loading

0 comments on commit 304fb6d

Please sign in to comment.