Skip to content

Commit

Permalink
Added fetch2core to share common modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyofrancis committed Jun 6, 2018
1 parent 95e5d3d commit 59ab986
Show file tree
Hide file tree
Showing 72 changed files with 499 additions and 297 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions fetch2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ dependencies {
kapt "android.arch.persistence.room:compiler:$room_version"
api "android.arch.persistence.room:runtime:$room_version"

api project(':fetch2core')

testImplementation "junit:junit:$junit_version"
androidTestImplementation "com.android.support.test:runner:$test_runner_version"
androidTestImplementation "com.android.support.test.espresso:espresso-core:$espresso_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.tonyodev.fetch2.database.migration.Migration;
import com.tonyodev.fetch2.util.FetchDatabaseExtensions;
import com.tonyodev.fetch2.util.FetchTypeConverterExtensions;
import com.tonyodev.fetch2core.FetchLogger;

import org.junit.After;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import com.tonyodev.fetch2.provider.NetworkInfoProvider;
import com.tonyodev.fetch2.util.FetchDefaults;
import com.tonyodev.fetch2.util.FetchTypeConverterExtensions;
import com.tonyodev.fetch2.util.FetchUtils;
import com.tonyodev.fetch2core.Downloader;
import com.tonyodev.fetch2core.FetchCoreDefaults;
import com.tonyodev.fetch2core.FetchCoreUtils;
import com.tonyodev.fetch2core.FetchLogger;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -49,14 +52,14 @@ public void useAppContext() throws Exception {
FetchLogger fetchLogger = new FetchLogger(true, namespace);
databaseManager = new DatabaseManagerImpl(appContext, namespace, fetchLogger, migrations);
final Downloader client = FetchDefaults.getDefaultDownloader();
final long progessInterval = FetchDefaults.DEFAULT_PROGRESS_REPORTING_INTERVAL_IN_MILLISECONDS;
final long progessInterval = FetchCoreDefaults.DEFAULT_PROGRESS_REPORTING_INTERVAL_IN_MILLISECONDS;
final int concurrentLimit = FetchDefaults.DEFAULT_CONCURRENT_LIMIT;
final int bufferSize = FetchDefaults.DEFAULT_DOWNLOAD_BUFFER_SIZE_BYTES;
final NetworkInfoProvider networkInfoProvider = new NetworkInfoProvider(appContext);
final boolean retryOnNetworkGain = false;
final Handler uiHandler = new Handler(Looper.getMainLooper());
final DownloadInfoUpdater downloadInfoUpdater = new DownloadInfoUpdater(databaseManager);
final String tempDir = FetchUtils.getFileTempDir(appContext);
final String tempDir = FetchCoreUtils.getFileTempDir(appContext);
final DownloadManagerCoordinator downloadManagerCoordinator = new DownloadManagerCoordinator(namespace);
final ListenerCoordinator listenerCoordinator = new ListenerCoordinator(namespace);
downloadManager = new DownloadManagerImpl(client, concurrentLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
import com.tonyodev.fetch2.downloader.DownloadManager;
import com.tonyodev.fetch2.downloader.DownloadManagerImpl;
import com.tonyodev.fetch2.fetch.DownloadManagerCoordinator;
import com.tonyodev.fetch2.fetch.HandlerWrapper;
import com.tonyodev.fetch2core.Downloader;
import com.tonyodev.fetch2core.FetchCoreDefaults;
import com.tonyodev.fetch2core.FetchCoreUtils;
import com.tonyodev.fetch2core.FetchLogger;
import com.tonyodev.fetch2core.HandlerWrapper;
import com.tonyodev.fetch2.fetch.ListenerCoordinator;
import com.tonyodev.fetch2.helper.DownloadInfoUpdater;
import com.tonyodev.fetch2.helper.PriorityListProcessor;
import com.tonyodev.fetch2.helper.PriorityListProcessorImpl;
import com.tonyodev.fetch2.provider.DownloadProvider;
import com.tonyodev.fetch2.provider.NetworkInfoProvider;
import com.tonyodev.fetch2.util.FetchDefaults;
import com.tonyodev.fetch2.util.FetchUtils;

import org.junit.After;
import org.junit.Before;
Expand All @@ -47,14 +50,14 @@ public void useAppContext() throws Exception {
final Migration[] migrations = DownloadDatabase.getMigrations();
final DatabaseManager databaseManager = new DatabaseManagerImpl(appContext, namespace, fetchLogger, migrations);
final Downloader client = FetchDefaults.getDefaultDownloader();
final long progessInterval = FetchDefaults.DEFAULT_PROGRESS_REPORTING_INTERVAL_IN_MILLISECONDS;
final long progessInterval = FetchCoreDefaults.DEFAULT_PROGRESS_REPORTING_INTERVAL_IN_MILLISECONDS;
final int concurrentLimit = FetchDefaults.DEFAULT_CONCURRENT_LIMIT;
final int bufferSize = FetchDefaults.DEFAULT_DOWNLOAD_BUFFER_SIZE_BYTES;
final NetworkInfoProvider networkInfoProvider = new NetworkInfoProvider(appContext);
final boolean retryOnNetworkGain = false;
final Handler uiHandler = new Handler(Looper.getMainLooper());
final DownloadInfoUpdater downloadInfoUpdater = new DownloadInfoUpdater(databaseManager);
final String tempDir = FetchUtils.getFileTempDir(appContext);
final String tempDir = FetchCoreUtils.getFileTempDir(appContext);
final DownloadManagerCoordinator downloadManagerCoordinator = new DownloadManagerCoordinator(namespace);
final ListenerCoordinator listenerCoordinator = new ListenerCoordinator(namespace);
final DownloadManager downloadManager = new DownloadManagerImpl(client, concurrentLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.tonyodev.fetch2.database.migration.Migration;
import com.tonyodev.fetch2.provider.DownloadProvider;
import com.tonyodev.fetch2.util.FetchTypeConverterExtensions;
import com.tonyodev.fetch2core.FetchLogger;

import org.junit.After;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import com.tonyodev.fetch2core.FetchLogger;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
import com.tonyodev.fetch2.fetch.DownloadManagerCoordinator;
import com.tonyodev.fetch2.fetch.FetchHandler;
import com.tonyodev.fetch2.fetch.FetchHandlerImpl;
import com.tonyodev.fetch2.fetch.HandlerWrapper;
import com.tonyodev.fetch2core.Downloader;
import com.tonyodev.fetch2core.FetchCoreDefaults;
import com.tonyodev.fetch2core.FetchCoreUtils;
import com.tonyodev.fetch2core.FetchLogger;
import com.tonyodev.fetch2core.HandlerWrapper;
import com.tonyodev.fetch2.fetch.ListenerCoordinator;
import com.tonyodev.fetch2.helper.DownloadInfoUpdater;
import com.tonyodev.fetch2.helper.PriorityListProcessor;
Expand All @@ -26,7 +30,6 @@
import com.tonyodev.fetch2.provider.NetworkInfoProvider;
import com.tonyodev.fetch2.util.FetchDefaults;
import com.tonyodev.fetch2.util.FetchTypeConverterExtensions;
import com.tonyodev.fetch2.util.FetchUtils;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -62,14 +65,14 @@ public void useAppContext() throws Exception {
databaseManager = new DatabaseManagerImpl(appContext, namespace, fetchLogger, migrations);
final HandlerWrapper handlerWrapper = new HandlerWrapper(namespace);
final Downloader client = FetchDefaults.getDefaultDownloader();
final long progessInterval = FetchDefaults.DEFAULT_PROGRESS_REPORTING_INTERVAL_IN_MILLISECONDS;
final long progessInterval = FetchCoreDefaults.DEFAULT_PROGRESS_REPORTING_INTERVAL_IN_MILLISECONDS;
final int concurrentLimit = FetchDefaults.DEFAULT_CONCURRENT_LIMIT;
final int bufferSize = FetchDefaults.DEFAULT_DOWNLOAD_BUFFER_SIZE_BYTES;
final NetworkInfoProvider networkInfoProvider = new NetworkInfoProvider(appContext);
final boolean retryOnNetworkGain = false;
final Handler uiHandler = new Handler(Looper.getMainLooper());
final DownloadInfoUpdater downloadInfoUpdater = new DownloadInfoUpdater(databaseManager);
final String tempDir = FetchUtils.getFileTempDir(appContext);
final String tempDir = FetchCoreUtils.getFileTempDir(appContext);
final DownloadManagerCoordinator downloadManagerCoordinator = new DownloadManagerCoordinator(namespace);
final ListenerCoordinator listenerCoordinator = new ListenerCoordinator(namespace);
final DownloadManager downloadManager = new DownloadManagerImpl(client, concurrentLimit,
Expand Down
4 changes: 3 additions & 1 deletion fetch2/src/main/java/com/tonyodev/fetch2/Fetch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import com.tonyodev.fetch2.exception.FetchException
import com.tonyodev.fetch2.fetch.FetchImpl
import com.tonyodev.fetch2.fetch.FetchModulesBuilder
import com.tonyodev.fetch2.util.DEFAULT_INSTANCE_NAMESPACE
import com.tonyodev.fetch2.util.GLOBAL_FETCH_CONFIGURATION_NOT_SET
import com.tonyodev.fetch2core.GLOBAL_FETCH_CONFIGURATION_NOT_SET
import com.tonyodev.fetch2.util.createConfigWithNewNamespace
import com.tonyodev.fetch2core.Func
import com.tonyodev.fetch2core.Func2


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tonyodev.fetch2
import android.content.Context
import com.tonyodev.fetch2.exception.FetchException
import com.tonyodev.fetch2.util.*
import com.tonyodev.fetch2core.*

/**
* Class used to hold the configuration settings for a Fetch instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.tonyodev.fetch2

import com.tonyodev.fetch2.util.*
import com.tonyodev.fetch2core.*
import java.io.IOException
import java.net.SocketTimeoutException

Expand Down
2 changes: 2 additions & 0 deletions fetch2/src/main/java/com/tonyodev/fetch2/FetchExtentions.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tonyodev.fetch2

import com.tonyodev.fetch2.exception.FetchException
import com.tonyodev.fetch2core.Func
import com.tonyodev.fetch2core.Func2


/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.tonyodev.fetch2

import com.tonyodev.fetch2.util.InterruptMonitor
import com.tonyodev.fetch2.util.getFileMd5String
import com.tonyodev.fetch2core.Downloader
import com.tonyodev.fetch2core.InterruptMonitor
import com.tonyodev.fetch2core.getFileMd5String
import java.io.InputStream
import java.io.OutputStream
import java.net.HttpURLConnection
Expand All @@ -12,7 +13,7 @@ import kotlin.collections.HashMap
/**
* The default Downloader used by Fetch for downloading requests.
* This downloader uses a HttpUrlConnection to perform http requests
* @see {@link com.tonyodev.fetch2.Downloader}
* @see {@link com.tonyodev.fetch2core.Downloader}
* */
open class HttpUrlConnectionDownloader @JvmOverloads constructor(
/**
Expand Down
2 changes: 1 addition & 1 deletion fetch2/src/main/java/com/tonyodev/fetch2/Request.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tonyodev.fetch2

import com.tonyodev.fetch2.util.getUniqueId
import com.tonyodev.fetch2core.getUniqueId

/**
* Use this class to create a request that is used by Fetch to enqueue a download and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.tonyodev.fetch2.database
import android.arch.persistence.room.TypeConverter
import com.tonyodev.fetch2.*
import com.tonyodev.fetch2.util.EMPTY_JSON_OBJECT_STRING
import com.tonyodev.fetch2.NetworkType
import com.tonyodev.fetch2.Priority
import com.tonyodev.fetch2.Status
import org.json.JSONObject

class Converter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tonyodev.fetch2.database

import com.tonyodev.fetch2.Logger
import com.tonyodev.fetch2core.Logger
import com.tonyodev.fetch2.Status
import java.io.Closeable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.arch.persistence.db.SupportSQLiteDatabase
import android.arch.persistence.room.Room
import android.content.Context
import android.database.sqlite.SQLiteException
import com.tonyodev.fetch2.Logger
import com.tonyodev.fetch2core.Logger
import com.tonyodev.fetch2.Status
import com.tonyodev.fetch2.database.migration.Migration
import com.tonyodev.fetch2.exception.FetchException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import android.arch.persistence.room.Index
import android.arch.persistence.room.PrimaryKey
import com.tonyodev.fetch2.*
import com.tonyodev.fetch2.util.*
import com.tonyodev.fetch2.NetworkType
import com.tonyodev.fetch2.Priority
import com.tonyodev.fetch2.Status
import com.tonyodev.fetch2core.calculateProgress


@Entity(tableName = DownloadDatabase.TABLE_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import com.tonyodev.fetch2.helper.FileDownloaderDelegate
import com.tonyodev.fetch2.fetch.ListenerCoordinator
import com.tonyodev.fetch2.provider.NetworkInfoProvider
import com.tonyodev.fetch2.util.getRequestForDownload
import com.tonyodev.fetch2.util.isFetchFileServerUrl
import com.tonyodev.fetch2.util.toDownloadInfo
import com.tonyodev.fetch2core.Downloader
import com.tonyodev.fetch2core.FileServerDownloader
import com.tonyodev.fetch2core.Logger
import com.tonyodev.fetch2core.isFetchFileServerUrl
import java.util.concurrent.Executors

class DownloadManagerImpl(private val httpDownloader: Downloader,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.tonyodev.fetch2.downloader

import com.tonyodev.fetch2.Download
import com.tonyodev.fetch2.Downloader
import com.tonyodev.fetch2core.Downloader
import com.tonyodev.fetch2.Error
import com.tonyodev.fetch2.Logger
import com.tonyodev.fetch2core.Logger
import com.tonyodev.fetch2.exception.FetchException
import com.tonyodev.fetch2.getErrorFromThrowable
import com.tonyodev.fetch2.provider.NetworkInfoProvider
import com.tonyodev.fetch2.util.*
import com.tonyodev.fetch2core.*
import java.io.*
import java.net.HttpURLConnection
import java.util.concurrent.ExecutorService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.tonyodev.fetch2.*
import com.tonyodev.fetch2.exception.FetchException
import com.tonyodev.fetch2.provider.NetworkInfoProvider
import com.tonyodev.fetch2.util.*
import com.tonyodev.fetch2core.*
import java.io.*
import java.net.HttpURLConnection
import kotlin.math.ceil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.tonyodev.fetch2.database.DownloadInfo
import com.tonyodev.fetch2.downloader.DownloadManager
import com.tonyodev.fetch2.helper.PriorityListProcessor
import com.tonyodev.fetch2.util.*
import com.tonyodev.fetch2core.*
import java.io.File
import java.util.*

Expand Down
4 changes: 4 additions & 0 deletions fetch2/src/main/java/com/tonyodev/fetch2/fetch/FetchImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import com.tonyodev.fetch2.*
import com.tonyodev.fetch2.exception.FetchException
import com.tonyodev.fetch2.getErrorFromMessage
import com.tonyodev.fetch2.fetch.FetchModulesBuilder.Modules
import com.tonyodev.fetch2core.Func
import com.tonyodev.fetch2core.Func2
import com.tonyodev.fetch2core.HandlerWrapper
import com.tonyodev.fetch2core.Logger

open class FetchImpl constructor(override val namespace: String,
protected val handlerWrapper: HandlerWrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import com.tonyodev.fetch2.helper.PriorityListProcessor
import com.tonyodev.fetch2.helper.PriorityListProcessorImpl
import com.tonyodev.fetch2.provider.DownloadProvider
import com.tonyodev.fetch2.provider.NetworkInfoProvider
import com.tonyodev.fetch2.util.getFileTempDir
import com.tonyodev.fetch2core.HandlerWrapper
import com.tonyodev.fetch2core.getFileTempDir

object FetchModulesBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.tonyodev.fetch2.*
import com.tonyodev.fetch2.database.DownloadInfo
import com.tonyodev.fetch2.downloader.FileDownloader
import com.tonyodev.fetch2.util.defaultNoError
import com.tonyodev.fetch2.Status
import com.tonyodev.fetch2core.Logger


class FileDownloaderDelegate(private val downloadInfoUpdater: DownloadInfoUpdater,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.tonyodev.fetch2.helper

import com.tonyodev.fetch2.*
import com.tonyodev.fetch2.downloader.DownloadManager
import com.tonyodev.fetch2.fetch.HandlerWrapper
import com.tonyodev.fetch2core.HandlerWrapper
import com.tonyodev.fetch2.provider.DownloadProvider
import com.tonyodev.fetch2.provider.NetworkInfoProvider
import com.tonyodev.fetch2.util.PRIORITY_QUEUE_INTERVAL_IN_MILLISECONDS
import com.tonyodev.fetch2.util.isFetchFileServerUrl
import com.tonyodev.fetch2.NetworkType
import com.tonyodev.fetch2core.Logger
import com.tonyodev.fetch2core.isFetchFileServerUrl

class PriorityListProcessorImpl constructor(private val handlerWrapper: HandlerWrapper,
private val downloadProvider: DownloadProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.tonyodev.fetch2.provider

import android.content.Context
import com.tonyodev.fetch2.NetworkType
import com.tonyodev.fetch2.util.isNetworkAvailable
import com.tonyodev.fetch2.util.isOnWiFi
import com.tonyodev.fetch2core.isNetworkAvailable
import com.tonyodev.fetch2core.isOnWiFi


class NetworkInfoProvider constructor(private val context: Context) {
Expand Down
8 changes: 4 additions & 4 deletions fetch2/src/main/java/com/tonyodev/fetch2/util/Defaults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
package com.tonyodev.fetch2.util

import com.tonyodev.fetch2.*
import com.tonyodev.fetch2.NetworkType
import com.tonyodev.fetch2.Priority
import com.tonyodev.fetch2.Status
import com.tonyodev.fetch2core.*


const val DEFAULT_TAG = "fetch2"
const val DEFAULT_GROUP_ID = 0
const val DEFAULT_UNIQUE_IDENTIFIER = 0L
const val DEFAULT_PROGRESS_REPORTING_INTERVAL_IN_MILLISECONDS = 2_000L
const val DEFAULT_DOWNLOAD_SPEED_REPORTING_INTERVAL_IN_MILLISECONDS = 1_000L
const val DEFAULT_CONCURRENT_LIMIT = 1
const val EMPTY_JSON_OBJECT_STRING = "{}"
const val DEFAULT_LOGGING_ENABLED = true
const val PRIORITY_QUEUE_INTERVAL_IN_MILLISECONDS = 500L
const val DEFAULT_DOWNLOAD_BUFFER_SIZE_BYTES = 8192
const val DEFAULT_AUTO_START = true
Expand Down
Loading

0 comments on commit 59ab986

Please sign in to comment.