Bump dependencies. Move ReactiveNetwork to app module.

This commit is contained in:
inorichi
2016-02-26 15:56:56 +01:00
parent 50b97fa28f
commit b95d0e2848
12 changed files with 8 additions and 163 deletions

View File

@ -100,16 +100,14 @@ apt {
dependencies {
final SUPPORT_LIBRARY_VERSION = '23.1.1'
final DAGGER_VERSION = '2.0.2'
final EVENTBUS_VERSION = '3.0.0'
final OKHTTP_VERSION = '3.1.2'
final OKHTTP_VERSION = '3.2.0'
final RETROFIT_VERSION = '2.0.0-beta4'
final STORIO_VERSION = '1.8.0'
final ICEPICK_VERSION = '3.1.0'
final ICEPICK_VERSION = '3.2.0'
final MOCKITO_VERSION = '1.10.19'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(":SubsamplingScaleImageView")
compile project(":ReactiveNetwork")
compile "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
@ -135,17 +133,17 @@ dependencies {
compile 'info.android15.nucleus:nucleus:2.0.5'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton.timber:timber:4.1.0'
compile 'com.jakewharton.timber:timber:4.1.1'
compile 'ch.acra:acra:4.8.2'
compile "frankiesardo:icepick:$ICEPICK_VERSION"
provided "frankiesardo:icepick-processor:$ICEPICK_VERSION"
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
compile 'eu.davidea:flexible-adapter:4.2.0'
compile 'com.nononsenseapps:filepicker:2.5.1'
compile 'com.nononsenseapps:filepicker:2.5.2'
compile 'com.github.amulyakhare:TextDrawable:558677e'
compile "org.greenrobot:eventbus:$EVENTBUS_VERSION"
apt "org.greenrobot:eventbus-annotation-processor:$EVENTBUS_VERSION"
compile "org.greenrobot:eventbus:3.0.0"
apt "org.greenrobot:eventbus-annotation-processor:3.0.1"
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"

View File

@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

View File

@ -0,0 +1,84 @@
/*
* Copyright (C) 2015 Piotr Wittchen
*
* 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
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.pwittchen.reactivenetwork.library;
import rx.functions.Func1;
public enum ConnectivityStatus {
UNKNOWN("unknown"),
WIFI_CONNECTED("connected to WiFi"),
WIFI_CONNECTED_HAS_INTERNET("connected to WiFi (Internet available)"),
WIFI_CONNECTED_HAS_NO_INTERNET("connected to WiFi (Internet not available)"),
MOBILE_CONNECTED("connected to mobile network"),
OFFLINE("offline");
public final String description;
ConnectivityStatus(final String description) {
this.description = description;
}
/**
* Creates a function, which checks
* if single connectivity status or many statuses
* are equal to current status. It can be used inside filter(...)
* method from RxJava
*
* @param statuses many connectivity statuses or single status
* @return Func1<ConnectivityStatus, Boolean> from RxJava
*/
public static Func1<ConnectivityStatus, Boolean> isEqualTo(final ConnectivityStatus... statuses) {
return new Func1<ConnectivityStatus, Boolean>() {
@Override public Boolean call(ConnectivityStatus connectivityStatus) {
boolean statuesAreEqual = false;
for (ConnectivityStatus singleStatus : statuses) {
statuesAreEqual = singleStatus == connectivityStatus;
}
return statuesAreEqual;
}
};
}
/**
* Creates a function, which checks
* if single connectivity status or many statuses
* are not equal to current status. It can be used inside filter(...)
* method from RxJava
*
* @param statuses many connectivity statuses or single status
* @return Func1<ConnectivityStatus, Boolean> from RxJava
*/
public static Func1<ConnectivityStatus, Boolean> isNotEqualTo(
final ConnectivityStatus... statuses) {
return new Func1<ConnectivityStatus, Boolean>() {
@Override public Boolean call(ConnectivityStatus connectivityStatus) {
boolean statuesAreNotEqual = false;
for (ConnectivityStatus singleStatus : statuses) {
statuesAreNotEqual = singleStatus != connectivityStatus;
}
return statuesAreNotEqual;
}
};
}
@Override public String toString() {
return "ConnectivityStatus{" + "description='" + description + '\'' + '}';
}
}

View File

@ -0,0 +1,142 @@
/*
* Copyright (C) 2015 Piotr Wittchen
*
* 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
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.pwittchen.reactivenetwork.library;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Looper;
import rx.Observable;
import rx.Scheduler;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.subscriptions.Subscriptions;
/**
* ReactiveNetwork is an Android library
* listening network connection state and change of the WiFi signal strength
* with RxJava Observables. It can be easily used with RxAndroid.
*/
public class ReactiveNetwork {
private boolean checkInternet = false;
private ConnectivityStatus status = ConnectivityStatus.UNKNOWN;
/**
* Enables Internet connection check.
* When it's called WIFI_CONNECTED_HAS_INTERNET and WIFI_CONNECTED_HAS_NO_INTERNET statuses
* can be emitted by observeConnectivity(context) method. When it isn't called
* only WIFI_CONNECTED can by emitted by observeConnectivity(context) method.
*
* @return ReactiveNetwork object
*/
public ReactiveNetwork enableInternetCheck() {
checkInternet = true;
return this;
}
/**
* Observes ConnectivityStatus,
* which can be WIFI_CONNECTED, MOBILE_CONNECTED or OFFLINE
*
* @param context Context of the activity or an application
* @return RxJava Observable with ConnectivityStatus
*/
public Observable<ConnectivityStatus> observeConnectivity(final Context context) {
final IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
return Observable.create(new Observable.OnSubscribe<ConnectivityStatus>() {
@Override public void call(final Subscriber<? super ConnectivityStatus> subscriber) {
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
final ConnectivityStatus newStatus = getConnectivityStatus(context, checkInternet);
// we need to perform check below,
// because after going off-line, onReceive() is called twice
if (newStatus != status) {
status = newStatus;
subscriber.onNext(newStatus);
}
}
};
context.registerReceiver(receiver, filter);
subscriber.add(unsubscribeInUiThread(new Action0() {
@Override public void call() {
context.unregisterReceiver(receiver);
}
}));
}
}).defaultIfEmpty(ConnectivityStatus.OFFLINE);
}
public ConnectivityStatus getConnectivityStatus(final Context context,
final boolean checkInternet) {
final String service = Context.CONNECTIVITY_SERVICE;
final ConnectivityManager manager = (ConnectivityManager) context.getSystemService(service);
final NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo == null) {
return ConnectivityStatus.OFFLINE;
}
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
if (checkInternet) {
return getWifiInternetStatus(networkInfo);
} else {
return ConnectivityStatus.WIFI_CONNECTED;
}
} else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
return ConnectivityStatus.MOBILE_CONNECTED;
}
return ConnectivityStatus.OFFLINE;
}
private ConnectivityStatus getWifiInternetStatus(final NetworkInfo networkInfo) {
if (networkInfo.isConnected()) {
return ConnectivityStatus.WIFI_CONNECTED_HAS_INTERNET;
} else {
return ConnectivityStatus.WIFI_CONNECTED_HAS_NO_INTERNET;
}
}
private Subscription unsubscribeInUiThread(final Action0 unsubscribe) {
return Subscriptions.create(new Action0() {
@Override public void call() {
if (Looper.getMainLooper() == Looper.myLooper()) {
unsubscribe.call();
} else {
final Scheduler.Worker inner = AndroidSchedulers.mainThread().createWorker();
inner.schedule(new Action0() {
@Override public void call() {
unsubscribe.call();
inner.unsubscribe();
}
});
}
}
});
}
}