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

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lizhaotailang committed Mar 26, 2017
1 parent a302937 commit 64f445c
Show file tree
Hide file tree
Showing 48 changed files with 754 additions and 96 deletions.
12 changes: 6 additions & 6 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ dependencies {
})
wearApp project(':wear')
// Google Mobile Service
compile 'com.google.android.gms:play-services:10.2.1'
// Support libraries
// ReactiveX series
// Retrofit series
// Zxing
// Material data time picker
// CircleImageView
compile 'com.google.android.gms:play-services:10.2.1'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.android.support:design:25.3.0'
compile 'com.android.support:cardview-v7:25.3.0'
compile 'com.android.support:preference-v14:25.3.0'
// ReactiveX series
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Retrofit series
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
// Zxing
compile 'com.google.zxing:core:3.3.0'
// Material data time picker
compile 'com.wdullaer:materialdatetimepicker:3.1.3'
// CircleImageView
compile 'de.hdodenhof:circleimageview:2.1.0'
testCompile 'junit:junit:4.12'
}
23 changes: 8 additions & 15 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".ui.onboarding.OnboardingActivity"
android:theme="@style/AppTheme.Onboarding"
android:noHistory="true">

android:noHistory="true"
android:theme="@style/AppTheme.Onboarding">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -30,33 +28,29 @@
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />

</activity>

<activity
android:name=".mvp.packages.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name=".mvp.addpackage.AddPackageActivity"
android:label="@string/activity_add_package"
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name=".mvp.packagedetails.PackageDetailsActivity"
android:label="@string/activity_package_details"
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name=".ui.PrefsActivity"
android:name=".mvp.companydetails.CompanyDetailActivity"
android:label="@string/activity_company_details"
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name=".mvp.search.SearchActivity"
android:label="@string/activity_search"
android:name=".ui.PrefsActivity"
android:theme="@style/AppTheme.NoActionBar" />

<activity android:name=".mvp.search.SearchActivity"
android:theme="@style/AppTheme.NoActionBar"
android:label="@string/activity_search"/>
<activity
android:name=".zxing.CaptureActivity"
android:label="@string/activity_scan_code"
Expand All @@ -69,7 +63,6 @@
</activity>

<service android:name=".service.ReminderService" />

<service
android:name=".appwidget.AppWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />
Expand Down
19 changes: 19 additions & 0 deletions mobile/src/main/assets/license.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ <h2>Notices for Additional Libraries</h2>
limitations under the License.
</pre>

<ul>
<li>CircleImageView</li>
</ul>
<pre>
Copyright 2014 - 2017 Henning Dodenhof

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.
</pre>

<ul>
<li>MaterialDateTimePicker</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public int getCount() {
@Override
public RemoteViews getViewAt(int position) {
RemoteViews remoteViews = new RemoteViews(
context.getPackageName(), R.layout.package_item_for_widget);
context.getPackageName(), R.layout.item_package_for_widget);

Realm rlm = Realm.getInstance(new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.marktony.espresso.data;

import java.util.List;

/**
* Created by lizhaotailang on 2017/3/27.
*/

public class PackageAndCompanyPairs {

private List<Package> packages;
private List<Company> companies;

public PackageAndCompanyPairs(List<Package> packages, List<Company> companies) {
this.packages = packages;
this.companies = companies;
}

public List<Package> getPackages() {
return packages;
}

public void setPackages(List<Package> packages) {
this.packages = packages;
}

public List<Company> getCompanies() {
return companies;
}

public void setCompanies(List<Company> companies) {
this.companies = companies;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public interface CompaniesDataSource {

void initData();

Observable<List<Company>> searchCompanies(@NonNull String keyWords);

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public void initData() {
localDataSource.initData();
}

@Override
public Observable<List<Company>> searchCompanies(@NonNull String keyWords) {
return localDataSource.searchCompanies(keyWords);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ public interface PackagesDataSource {

void updatePackageName(@NonNull String packageId, @NonNull String name);

Observable<List<Package>> searchPackages(@NonNull String keyWords);

}
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ public void updatePackageName(@NonNull String packageId, @NonNull String name) {
packagesLocalDataSource.updatePackageName(packageId, name);
}

@Override
public Observable<List<Package>> searchPackages(@NonNull String keyWords) {
// Do nothing but just let local data source handle it.
return packagesLocalDataSource.searchPackages(keyWords);
}

/**
* Get a package with package number.
* @param packNumber The package id(number). See more @{@link Package#number}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.marktony.espresso.data.source.CompaniesDataSource;
import io.github.marktony.espresso.realm.RealmHelper;
import io.reactivex.Observable;
import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.Sort;
Expand Down Expand Up @@ -139,7 +140,7 @@ public void initData() {
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'万象物流','id':'wanxiangwuliu','tel':'400-820-8088','website':'http://www.ewinshine.com','alphabet':'wanxiangwuliu','avatar':'#00BCD4'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'宏品物流','id':'hongpinwuliu','tel':'400-612-1456','website':'http://www.hpexpress.com.cn','alphabet':'hongpinwuliu','avatar':'#00BCD4'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'GLS','id':'gls','tel':'877-914-5465','website':'http://www.gls-group.net','alphabet':'gls','avatar':'#00BCD4'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'上大物流','id':'shangda','tel':'400-021-9122','website':'http://www.sundapost.net','alphabet':'zhongtiekuaiyun','avatar':'#00BCD4'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'上大物流','id':'shangda','tel':'400-021-9122','website':'http://www.sundapost.net','alphabet':'shangdawuliu','avatar':'#00BCD4'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'中铁快运','id':'zhongtiewuliu','tel':'95572','website':'http://www.cre.cn','alphabet':'zhongtiekuaiyun','avatar':'#00BCD4'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'原飞航','id':'yuanfeihangwuliu','tel':'0769-87001100','website':'http://www.yfhex.com','alphabet':'yuanfeihang','avatar':'#00BCD4'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'海外环球','id':'haiwaihuanqiu','tel':'010-59790107','website':'http://www.haiwaihuanqiu.com/','alphabet':'haiwaihuanqiu','avatar':'#00BCD4'}");
Expand Down Expand Up @@ -703,11 +704,29 @@ public void initData() {
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'BCWELT','id':'bcwelt','tel':'','website':'','alphabet':'bcwelt','avatar':'#FFC107'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'欧亚专线','id':'euasia','tel':'','website':'','alphabet':'ouyazhuanxian','avatar':'#FFC107'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'远成快运','id':'ycgky','tel':'','website':'','alphabet':'yuanchengkuaiyun','avatar':'#FFC107'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'凡客配送(作废)','id':'vancl','tel':'400-600-6888','website':'http://www.vancl.com/','alphabet':'fankepeisong(zuofei)','avatar':'#FFC107'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'运通中港快递(作废)','id':'ytkd','tel':'','website':'','alphabet':'yuntongzhonggangkuaidi(zuofei)','avatar':'#FFC107'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'凡客订单','id':'vancl','tel':'400-600-6888','website':'http://www.vancl.com/','alphabet':'fankepeisong(zuofei)','avatar':'#FFC107'}");
rlm.createOrUpdateObjectFromJson(Company.class, "{'name':'运通中港','id':'ytkd','tel':'','website':'','alphabet':'yuntongzhonggangkuaidi(zuofei)','avatar':'#FFC107'}");
rlm.commitTransaction();
rlm.close();

}

@Override
public Observable<List<Company>> searchCompanies(@NonNull String keyWords) {
Realm rlm = Realm.getInstance(new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.name(RealmHelper.DATABASE_NAME)
.build());
List<Company> results = rlm.copyFromRealm(
rlm.where(Company.class)
.like("name","*" + keyWords + "*", Case.INSENSITIVE)
/*.contains("tel", "*" + keyWords + "*")
.contains("website", "*" + keyWords + "*")
.contains("alphabet", "*" + keyWords + "*")*/
.findAll());
return Observable.fromIterable(results)
.toList()
.toObservable();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.marktony.espresso.data.source.PackagesDataSource;
import io.github.marktony.espresso.realm.RealmHelper;
import io.reactivex.Observable;
import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmResults;
Expand Down Expand Up @@ -213,4 +214,24 @@ public void updatePackageName(@NonNull String packageId, @NonNull String name) {
rlm.close();
}

@Override
public Observable<List<Package>> searchPackages(@NonNull String keyWords) {
Realm rlm = newRealmInstance();
return Observable.fromIterable(rlm.copyFromRealm(
rlm.where(Package.class)
.like("companyChineseName", "*" + keyWords + "*", Case.INSENSITIVE)
/*.or().contains("company", "*" + keyWords + "*")
.or().contains("number", "*" + keyWords + "*")*/
.findAll()))
.toList()
.toObservable();
}

private Realm newRealmInstance() {
return Realm.getInstance(new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.name(RealmHelper.DATABASE_NAME)
.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,11 @@ public void updatePackageName(@NonNull String packageId, @NonNull String name) {
// of refreshing the packages from all available data source
}

@Override
public Observable<List<Package>> searchPackages(@NonNull String keyWords) {
// Not required because the {@link PackagesRepository} handles the logic
// of refreshing the packages from all available data source
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AddPackageActivity extends AppCompatActivity {
private AddPackageFragment fragment;

public static final int REQUEST_ADD_PACKAGE = 1;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public CompaniesAdapter(@NonNull Context context, @NonNull List<Company> list) {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_NORMAL) {
return new NormalViewHolder(inflater.inflate(R.layout.company_item, parent, false), listener);
return new NormalViewHolder(inflater.inflate(R.layout.item_company, parent, false), listener);
}
return new WithHeaderViewHolder(inflater.inflate(R.layout.company_item_with_header, parent, false), listener);
return new WithHeaderViewHolder(inflater.inflate(R.layout.item_company_with_header, parent, false), listener);
}

@Override
Expand Down Expand Up @@ -152,7 +152,7 @@ public WithHeaderViewHolder(View itemView, OnRecyclerViewItemClickListener liste
textViewAvatar = (AppCompatTextView) itemView.findViewById(R.id.textViewAvatar);
textViewCompanyName = (AppCompatTextView) itemView.findViewById(R.id.textViewCompanyName);
textViewCompanyTel = (AppCompatTextView) itemView.findViewById(R.id.textViewCompanyTel);
stickyHeaderText = (AppCompatTextView) itemView.findViewById(R.id.stickyHeaderText);
stickyHeaderText = (AppCompatTextView) itemView.findViewById(R.id.headerText);

this.listener = listener;
itemView.setOnClickListener(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.marktony.espresso.mvp.companies;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -19,6 +21,7 @@
import io.github.marktony.espresso.R;
import io.github.marktony.espresso.data.Company;
import io.github.marktony.espresso.interfaze.OnRecyclerViewItemClickListener;
import io.github.marktony.espresso.mvp.companydetails.CompanyDetailActivity;

/**
* Created by lizhaotailang on 2017/2/10.
Expand Down Expand Up @@ -101,13 +104,15 @@ public void showGetCompaniesError() {
}

@Override
public void showCompanies(List<Company> list) {
public void showCompanies(final List<Company> list) {
if (adapter == null) {
adapter = new CompaniesAdapter(getContext(), list);
adapter.setOnRecyclerViewItemClickListener(new OnRecyclerViewItemClickListener() {
@Override
public void OnItemClick(View v, int position) {

Intent intent = new Intent(getContext(), CompanyDetailActivity.class);
intent.putExtra(CompanyDetailActivity.COMPANY_ID, list.get(position).getId());
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());
}
});
recyclerView.setAdapter(adapter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.marktony.espresso.mvp.companies;

import android.support.annotation.NonNull;
import android.util.Log;

import java.util.List;

Expand All @@ -19,8 +18,6 @@

public class CompaniesPresenter implements CompaniesContract.Presenter {

private static final String TAG = CompaniesPresenter.class.getSimpleName();

@NonNull
private CompaniesContract.View view;

Expand Down
Loading

0 comments on commit 64f445c

Please sign in to comment.