Skip to content

Commit 9368665

Browse files
committed
update gradle, Observable source emits error when there is no data found in the repository
1 parent 8e30ebb commit 9368665

File tree

9 files changed

+50
-16
lines changed

9 files changed

+50
-16
lines changed

.idea/gradle.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/anax/preference/MainActivity.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import android.view.View;
99
import android.widget.ProgressBar;
1010

11-
1211
import com.anax.preference.Model.Country;
1312
import com.anax.preference.Preference.CountryPreferenceRepo;
1413
import com.anax.preference.Remote.ApiInterface;
1514

1615
import java.util.ArrayList;
16+
import java.util.Collections;
1717
import java.util.List;
1818

1919
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -67,7 +67,12 @@ protected void onCreate(Bundle savedInstanceState) {
6767
public void getCountriesCodeWithRx() {
6868
progressBar.setVisibility(View.VISIBLE);
6969

70-
countryPreferenceRepo.getListObservable()
70+
countryPreferenceRepo.getListObservable().onErrorReturn(new Function<Throwable, List<Country>>() {
71+
@Override
72+
public List<Country> apply(Throwable throwable) throws Exception {
73+
return Collections.emptyList();
74+
}
75+
})
7176
.mergeWith(ApiInterface.Creator.newApiService().getCountryCodeObservable()
7277
.map(new Function<List<Country>, List<Country>>() {
7378
@Override
@@ -90,7 +95,8 @@ public void onNext(List<Country> countriesList) {
9095

9196
@Override
9297
public void onError(Throwable e) {
93-
98+
Log.d(LOG, "onError");
99+
Log.d(LOG, e.getMessage());
94100
}
95101

96102
@Override

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.2.3'
9+
classpath 'com.android.tools.build:gradle:2.3.0'
1010
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 28 10:00:20 PST 2015
1+
#Fri Mar 10 13:43:22 EET 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

preferencerhythm/src/main/java/com/anax/preferencerhythm/PreferenceRepoImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.content.Context;
44

5+
import com.anax.preferencerhythm.exception.SharedPrefDataNotFoundException;
6+
57
import java.util.List;
68

79
import io.reactivex.Observable;
@@ -49,7 +51,7 @@ public final List<T> getList() {
4951
@Override
5052
public final Observable<List<T>> getListObservable() {
5153
if (preferences.getList(listKey, clazz) == null)
52-
return Observable.empty();
54+
return Observable.error(new SharedPrefDataNotFoundException());
5355
return Observable.just(preferences.getList(listKey, clazz));
5456
}
5557

@@ -66,7 +68,7 @@ public final T getObject() {
6668
@Override
6769
public final Observable<T> getObjectObservable() {
6870
if (preferences.getSingleObject(objectKey, clazz) == null)
69-
return Observable.empty();
71+
return Observable.error(new SharedPrefDataNotFoundException());
7072

7173
return Observable.just(preferences.getSingleObject(objectKey, clazz));
7274
}

preferencerhythm/src/main/java/com/anax/preferencerhythm/Preferences.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @since 27/01/2017
1313
*/
1414
class Preferences {
15-
private final String KEY_CHEKER = "TEST_ENCRYPTION_KEY";
15+
private final String KEY_CHECKER = "TEST_ENCRYPTION_KEY";
1616

1717
private SharedPreferences mPref;
1818
private Serializer serializer;
@@ -119,19 +119,19 @@ <T> List<T> getList(String name, Class<T> clazz) {
119119
}
120120
}
121121

122-
public boolean isEmpty() {
122+
boolean isEmpty() {
123123
return mPref.getAll().size() == 0;
124124
}
125125

126126
private void saveEncryptionKeyTester() {
127-
saveSingleObject(KEY_CHEKER, KEY_CHEKER);
127+
saveSingleObject(KEY_CHECKER, KEY_CHECKER);
128128
}
129129

130130
private String getEncryptionKeyTester() {
131-
return getSingleObject(KEY_CHEKER, String.class);
131+
return getSingleObject(KEY_CHECKER, String.class);
132132
}
133133

134134
private boolean isEncryptionKeyChanged() {
135-
return !getEncryptionKeyTester().equals(KEY_CHEKER);
135+
return !getEncryptionKeyTester().equals(KEY_CHECKER);
136136
}
137137
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.anax.preferencerhythm.exception;
2+
3+
/**
4+
* Created by Anas AlaaEldin on 3/10/2017.
5+
*/
6+
7+
public class SharedPrefDataNotFoundException extends Exception {
8+
9+
public SharedPrefDataNotFoundException() {
10+
}
11+
12+
public SharedPrefDataNotFoundException(String message) {
13+
super(message);
14+
}
15+
16+
public SharedPrefDataNotFoundException(String message, Throwable cause) {
17+
super(message, cause);
18+
}
19+
20+
public SharedPrefDataNotFoundException(Throwable cause) {
21+
super(cause);
22+
}
23+
}

0 commit comments

Comments
 (0)