Skip to content
This repository has been archived by the owner on May 28, 2020. It is now read-only.

Commit

Permalink
add travis
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhaotailang committed Apr 26, 2017
1 parent b57942f commit f2a598c
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .idea/modules.xml

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

18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: android

android:
components:
- tools
- platform-tools
- build-tools-25.0.2
- android-25
- extra-android-m2repository
- extra-google-google_play_services

jdk:
- oraclejdk8

notifications:
email: false

script: ./gradlew assemble check
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright(c) 2017 lizhaotailang
*
* 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 io.github.marktony.espresso.data.source;

import android.support.annotation.NonNull;
Expand Down Expand Up @@ -52,4 +68,4 @@ public Observable<List<Company>> searchCompanies(@NonNull String keyWords) {
return localDataSource.searchCompanies(keyWords);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright(c) 2017 lizhaotailang
*
* 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 io.github.marktony.espresso.data.source;

import android.support.annotation.NonNull;
Expand Down Expand Up @@ -40,8 +56,6 @@ public class PackagesRepository implements PackagesDataSource {

private Map<String, Package> cachedPackages;

private Package cachePackage = null;

// Prevent direct instantiation
private PackagesRepository(@NonNull PackagesDataSource packagesRemoteDataSource,
@NonNull PackagesDataSource packagesLocalDataSource) {
Expand Down Expand Up @@ -158,7 +172,6 @@ public void savePackage(@NonNull Package pack) {
*/
@Override
public void deletePackage(@NonNull String packageId) {
cachePackage = getPackageWithNumber(packageId);
packagesLocalDataSource.deletePackage(packageId);
cachedPackages.remove(packageId);
}
Expand Down Expand Up @@ -316,4 +329,4 @@ public void accept(Package aPackage) throws Exception {
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
import android.support.annotation.Nullable;

import java.util.List;
import java.util.concurrent.Callable;

import io.github.marktony.espresso.data.Company;
import io.github.marktony.espresso.data.source.CompaniesDataSource;
import io.github.marktony.espresso.realm.RealmHelper;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;
import io.realm.Case;
import io.realm.Realm;
import io.realm.Sort;
Expand Down Expand Up @@ -55,31 +52,18 @@ public static CompaniesLocalDataSource getInstance() {

@Override
public Observable<List<Company>> getCompanies() {
return Observable.fromCallable(new Callable<List<Company>>() {
@Override
public List<Company> call() throws Exception {
Realm rlm = RealmHelper.newRealmInstance();
List<Company> companyList = rlm.copyFromRealm(rlm.where(Company.class)
.findAllSorted("alphabet", Sort.ASCENDING));
rlm.close();
return companyList;
}
});
Realm rlm = RealmHelper.newRealmInstance();
return Observable
.fromIterable(rlm.copyFromRealm(rlm.where(Company.class).findAllSorted("alphabet", Sort.ASCENDING)))
.toList()
.toObservable();
}

@Override
public Observable<Company> getCompany(@NonNull final String companyId) {
return Observable.fromCallable(new Callable<Company>() {
@Override
public Company call() throws Exception {
Realm rlm = RealmHelper.newRealmInstance();
Company company = rlm.copyFromRealm(rlm.where(Company.class)
.equalTo("id", companyId)
.findFirst());
rlm.close();
return company;
}
});
public Observable<Company> getCompany(@NonNull String companyId) {
Realm rlm = RealmHelper.newRealmInstance();
return Observable
.just(rlm.copyFromRealm(rlm.where(Company.class).equalTo("id", companyId).findFirst()));
}

@Override
Expand Down Expand Up @@ -734,28 +718,21 @@ public void initData() {
}

@Override
public Observable<List<Company>> searchCompanies(@NonNull final String keyWords) {

return Observable.fromCallable(new Callable<List<Company>>() {
@Override
public List<Company> call() throws Exception {
Realm rlm = RealmHelper.newRealmInstance();
List<Company> companies = rlm.copyFromRealm(rlm.where(Company.class)
.like(
"name",
"*" + keyWords + "*",
Case.INSENSITIVE)
public Observable<List<Company>> searchCompanies(@NonNull String keyWords) {
Realm rlm = RealmHelper.newRealmInstance();
List<Company> results = rlm.copyFromRealm(
rlm.where(Company.class)
.like("name","*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("tel", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("website", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("alphabet", "*" + keyWords + "*", Case.INSENSITIVE)
.findAllSorted("alphabet", Sort.ASCENDING));
rlm.close();
return companies;
}
});
return Observable.fromIterable(results)
.toList()
.toObservable();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.support.annotation.Nullable;

import java.util.List;
import java.util.concurrent.Callable;

import io.github.marktony.espresso.data.Package;
import io.github.marktony.espresso.data.source.PackagesDataSource;
Expand Down Expand Up @@ -65,16 +64,10 @@ public static void destroyInstance() {
*/
@Override
public Observable<List<Package>> getPackages() {
return Observable.fromCallable(new Callable<List<Package>>() {
@Override
public List<Package> call() throws Exception {
Realm rlm = RealmHelper.newRealmInstance();
List<Package> packageList = rlm.copyFromRealm(rlm.where(Package.class)
.findAllSorted("timestamp", Sort.DESCENDING));
rlm.close();
return packageList;
}
});
Realm rlm = RealmHelper.newRealmInstance();

return Observable.just(rlm.copyFromRealm(rlm.where(Package.class)
.findAllSorted("timestamp", Sort.DESCENDING)));
}

/**
Expand All @@ -85,18 +78,11 @@ public List<Package> call() throws Exception {
* @return The observable package from database.
*/
@Override
public Observable<Package> getPackage(@NonNull final String packNumber) {
return Observable.fromCallable(new Callable<Package>() {
@Override
public Package call() throws Exception {
Realm rlm = RealmHelper.newRealmInstance();
Package aPackage = rlm.copyFromRealm(rlm.where(Package.class)
.equalTo("number", packNumber)
.findFirst());
rlm.close();
return aPackage;
}
});
public Observable<Package> getPackage(@NonNull String packNumber) {
Realm rlm = RealmHelper.newRealmInstance();
return Observable.just(rlm.copyFromRealm(rlm.where(Package.class)
.equalTo("number", packNumber)
.findFirst()));
}

/**
Expand Down Expand Up @@ -201,7 +187,6 @@ public boolean isPackageExist(@NonNull String packageId) {
RealmResults<Package> results = rlm.where(Package.class)
.equalTo("number", packageId)
.findAll();
rlm.close();
return (results != null) && (!results.isEmpty());
}

Expand All @@ -221,32 +206,20 @@ public void updatePackageName(@NonNull String packageId, @NonNull String name) {
}

@Override
public Observable<List<Package>> searchPackages(@NonNull
final String keyWords) {

return Observable.fromCallable(new Callable<List<Package>>() {
@Override
public List<Package> call() throws Exception {
Realm rlm = RealmHelper.newRealmInstance();
List<Package> packages = rlm.copyFromRealm(rlm.where(Package.class)
.like(
"name",
"*" + keyWords + "*",
Case.INSENSITIVE)
public Observable<List<Package>> searchPackages(@NonNull String keyWords) {
Realm rlm = RealmHelper.newRealmInstance();
return Observable.fromIterable(rlm.copyFromRealm(
rlm.where(Package.class)
.like("name", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("companyChineseName", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like(
"company",
"*" + keyWords + "*",
Case.INSENSITIVE)
.like("company", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("number", "*" + keyWords + "*", Case.INSENSITIVE)
.findAll());
rlm.close();
return packages;
}
});
.findAll()))
.toList()
.toObservable();
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright(c) 2017 lizhaotailang
*
* 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 io.github.marktony.espresso.data.source.remote;

import android.support.annotation.NonNull;
Expand All @@ -7,7 +23,6 @@

import io.github.marktony.espresso.data.Package;
import io.github.marktony.espresso.data.source.PackagesDataSource;
import io.github.marktony.espresso.realm.RealmHelper;
import io.github.marktony.espresso.retrofit.RetrofitClient;
import io.github.marktony.espresso.retrofit.RetrofitService;
import io.reactivex.Observable;
Expand All @@ -19,6 +34,8 @@
import io.realm.Realm;
import io.realm.RealmConfiguration;

import static io.github.marktony.espresso.realm.RealmHelper.DATABASE_NAME;

/**
* Created by lizhaotailang on 2017/3/7.
* Implementation of the data source that adds a latency simulating network.
Expand Down Expand Up @@ -81,7 +98,10 @@ public void deletePackage(@NonNull String packageId) {
public Observable<List<Package>> refreshPackages() {
// It is necessary to build a new realm instance
// in a different thread.
Realm realm = RealmHelper.newRealmInstance();
Realm realm = Realm.getInstance(new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.name(DATABASE_NAME)
.build());

return Observable.fromIterable(realm.copyFromRealm(realm.where(Package.class).findAll()))
.subscribeOn(Schedulers.io())
Expand All @@ -105,7 +125,10 @@ public ObservableSource<Package> apply(Package aPackage) throws Exception {
public Observable<Package> refreshPackage(@NonNull String packageId) {
// It is necessary to build a new realm instance
// in a different thread.
Realm realm = RealmHelper.newRealmInstance();
Realm realm = Realm.getInstance(new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.name(DATABASE_NAME)
.build());
// Set a copy rather than use the raw data.
final Package p = realm.copyFromRealm(realm.where(Package.class)
.equalTo("number", packageId)
Expand All @@ -131,7 +154,10 @@ public void accept(Package aPackage) throws Exception {
if (aPackage != null && aPackage.getData() != null) {
// It is necessary to build a new realm instance
// in a different thread.
Realm rlm = RealmHelper.newRealmInstance();
Realm rlm = Realm.getInstance(new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.name(DATABASE_NAME)
.build());

// Only when the origin data is null or the origin
// data's size is less than the latest data's size
Expand Down
Loading

0 comments on commit f2a598c

Please sign in to comment.