From 64f445c16ec28cc359e427c6954f11d35d2fad43 Mon Sep 17 00:00:00 2001 From: lizhaotailang Date: Mon, 27 Mar 2017 00:40:58 +0800 Subject: [PATCH] Initial commit --- mobile/build.gradle | 12 +-- mobile/src/main/AndroidManifest.xml | 23 ++--- mobile/src/main/assets/license.html | 19 ++++ .../espresso/appwidget/WidgetListFactory.java | 2 +- .../espresso/data/PackageAndCompanyPairs.java | 34 +++++++ .../data/source/CompaniesDataSource.java | 2 + .../data/source/CompaniesRepository.java | 5 + .../data/source/PackagesDataSource.java | 2 + .../data/source/PackagesRepository.java | 6 ++ .../local/CompaniesLocalDataSource.java | 25 ++++- .../source/local/PackagesLocalDataSource.java | 21 ++++ .../remote/PackagesRemoteDataSource.java | 7 ++ .../mvp/addpackage/AddPackageActivity.java | 1 + .../mvp/companies/CompaniesAdapter.java | 6 +- .../mvp/companies/CompaniesFragment.java | 9 +- .../mvp/companies/CompaniesPresenter.java | 3 - .../companydetails/CompanyDetailActivity.java | 16 ++- .../companydetails/CompanyDetailContract.java | 12 +++ .../companydetails/CompanyDetailFragment.java | 58 +++++++++-- .../CompanyDetailPresenter.java | 55 ++++++++++- .../PackageDetailsActivity.java | 7 ++ .../packagedetails/PackageDetailsAdapter.java | 2 +- .../PackageDetailsFragment.java | 2 +- .../mvp/packages/PackagesAdapter.java | 2 +- .../mvp/packages/PackagesFragment.java | 3 +- .../espresso/mvp/search/SearchActivity.java | 49 +++++++++- .../espresso/mvp/search/SearchContract.java | 28 ++++++ .../espresso/mvp/search/SearchFragment.java | 98 ++++++++++++++++++- .../espresso/mvp/search/SearchPresenter.java | 97 ++++++++++++++++++ .../mvp/search/SearchResultsAdapter.java | 34 ++++++- .../marktony/espresso/ui/PrefsActivity.java | 5 +- .../ui/onboarding/OnboardingActivity.java | 14 ++- .../main/res/drawable/ic_share_white_24dp.xml | 9 ++ .../main/res/layout/activity_onboarding.xml | 6 +- mobile/src/main/res/layout/activity_prefs.xml | 42 +++++--- mobile/src/main/res/layout/container.xml | 2 +- .../main/res/layout/fragment_add_package.xml | 2 + .../res/layout/fragment_company_details.xml | 22 ++++- ...tails.xml => fragment_package_details.xml} | 0 .../src/main/res/layout/fragment_search.xml | 65 ++++++++++++ .../{company_item.xml => item_company.xml} | 2 +- ...eader.xml => item_company_with_header.xml} | 6 +- .../{package_item.xml => item_package.xml} | 0 ...widget.xml => item_package_for_widget.xml} | 0 ...tatus_item.xml => item_package_status.xml} | 0 .../layout/item_search_result_category.xml | 13 +++ .../res/layout/item_search_result_empty.xml | 10 ++ mobile/src/main/res/values/strings.xml | 12 +++ 48 files changed, 754 insertions(+), 96 deletions(-) create mode 100644 mobile/src/main/java/io/github/marktony/espresso/data/PackageAndCompanyPairs.java create mode 100644 mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchContract.java create mode 100644 mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchPresenter.java create mode 100644 mobile/src/main/res/drawable/ic_share_white_24dp.xml rename mobile/src/main/res/layout/{fragment_details.xml => fragment_package_details.xml} (100%) create mode 100644 mobile/src/main/res/layout/fragment_search.xml rename mobile/src/main/res/layout/{company_item.xml => item_company.xml} (97%) rename mobile/src/main/res/layout/{company_item_with_header.xml => item_company_with_header.xml} (86%) rename mobile/src/main/res/layout/{package_item.xml => item_package.xml} (100%) rename mobile/src/main/res/layout/{package_item_for_widget.xml => item_package_for_widget.xml} (100%) rename mobile/src/main/res/layout/{package_status_item.xml => item_package_status.xml} (100%) create mode 100644 mobile/src/main/res/layout/item_search_result_category.xml create mode 100644 mobile/src/main/res/layout/item_search_result_empty.xml diff --git a/mobile/build.gradle b/mobile/build.gradle index 67d471d..a5bb50e 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -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' } diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index bf1ce8e..2394ea9 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -14,12 +14,10 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - - + android:noHistory="true" + android:theme="@style/AppTheme.Onboarding"> @@ -30,33 +28,29 @@ - - - - - - - + - diff --git a/mobile/src/main/assets/license.html b/mobile/src/main/assets/license.html index 5576120..0f64a85 100644 --- a/mobile/src/main/assets/license.html +++ b/mobile/src/main/assets/license.html @@ -33,6 +33,25 @@

Notices for Additional Libraries

limitations under the License. +
    +
  • CircleImageView
  • +
+
+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.
+
+
  • MaterialDateTimePicker
diff --git a/mobile/src/main/java/io/github/marktony/espresso/appwidget/WidgetListFactory.java b/mobile/src/main/java/io/github/marktony/espresso/appwidget/WidgetListFactory.java index f6837c9..b7384aa 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/appwidget/WidgetListFactory.java +++ b/mobile/src/main/java/io/github/marktony/espresso/appwidget/WidgetListFactory.java @@ -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() diff --git a/mobile/src/main/java/io/github/marktony/espresso/data/PackageAndCompanyPairs.java b/mobile/src/main/java/io/github/marktony/espresso/data/PackageAndCompanyPairs.java new file mode 100644 index 0000000..ee3b77a --- /dev/null +++ b/mobile/src/main/java/io/github/marktony/espresso/data/PackageAndCompanyPairs.java @@ -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 packages; + private List companies; + + public PackageAndCompanyPairs(List packages, List companies) { + this.packages = packages; + this.companies = companies; + } + + public List getPackages() { + return packages; + } + + public void setPackages(List packages) { + this.packages = packages; + } + + public List getCompanies() { + return companies; + } + + public void setCompanies(List companies) { + this.companies = companies; + } +} diff --git a/mobile/src/main/java/io/github/marktony/espresso/data/source/CompaniesDataSource.java b/mobile/src/main/java/io/github/marktony/espresso/data/source/CompaniesDataSource.java index 0f94aad..2fb9063 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/data/source/CompaniesDataSource.java +++ b/mobile/src/main/java/io/github/marktony/espresso/data/source/CompaniesDataSource.java @@ -21,4 +21,6 @@ public interface CompaniesDataSource { void initData(); + Observable> searchCompanies(@NonNull String keyWords); + } diff --git a/mobile/src/main/java/io/github/marktony/espresso/data/source/CompaniesRepository.java b/mobile/src/main/java/io/github/marktony/espresso/data/source/CompaniesRepository.java index 9899129..11a5809 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/data/source/CompaniesRepository.java +++ b/mobile/src/main/java/io/github/marktony/espresso/data/source/CompaniesRepository.java @@ -47,4 +47,9 @@ public void initData() { localDataSource.initData(); } + @Override + public Observable> searchCompanies(@NonNull String keyWords) { + return localDataSource.searchCompanies(keyWords); + } + } diff --git a/mobile/src/main/java/io/github/marktony/espresso/data/source/PackagesDataSource.java b/mobile/src/main/java/io/github/marktony/espresso/data/source/PackagesDataSource.java index 01c4413..2eb13e5 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/data/source/PackagesDataSource.java +++ b/mobile/src/main/java/io/github/marktony/espresso/data/source/PackagesDataSource.java @@ -35,4 +35,6 @@ public interface PackagesDataSource { void updatePackageName(@NonNull String packageId, @NonNull String name); + Observable> searchPackages(@NonNull String keyWords); + } diff --git a/mobile/src/main/java/io/github/marktony/espresso/data/source/PackagesRepository.java b/mobile/src/main/java/io/github/marktony/espresso/data/source/PackagesRepository.java index afaa918..105fb83 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/data/source/PackagesRepository.java +++ b/mobile/src/main/java/io/github/marktony/espresso/data/source/PackagesRepository.java @@ -273,6 +273,12 @@ public void updatePackageName(@NonNull String packageId, @NonNull String name) { packagesLocalDataSource.updatePackageName(packageId, name); } + @Override + public Observable> 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}. diff --git a/mobile/src/main/java/io/github/marktony/espresso/data/source/local/CompaniesLocalDataSource.java b/mobile/src/main/java/io/github/marktony/espresso/data/source/local/CompaniesLocalDataSource.java index 0221e43..d1ae16a 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/data/source/local/CompaniesLocalDataSource.java +++ b/mobile/src/main/java/io/github/marktony/espresso/data/source/local/CompaniesLocalDataSource.java @@ -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; @@ -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'}"); @@ -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> searchCompanies(@NonNull String keyWords) { + Realm rlm = Realm.getInstance(new RealmConfiguration.Builder() + .deleteRealmIfMigrationNeeded() + .name(RealmHelper.DATABASE_NAME) + .build()); + List 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(); + } + } \ No newline at end of file diff --git a/mobile/src/main/java/io/github/marktony/espresso/data/source/local/PackagesLocalDataSource.java b/mobile/src/main/java/io/github/marktony/espresso/data/source/local/PackagesLocalDataSource.java index d609359..4bf6d46 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/data/source/local/PackagesLocalDataSource.java +++ b/mobile/src/main/java/io/github/marktony/espresso/data/source/local/PackagesLocalDataSource.java @@ -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; @@ -213,4 +214,24 @@ public void updatePackageName(@NonNull String packageId, @NonNull String name) { rlm.close(); } + @Override + public Observable> 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()); + } + } diff --git a/mobile/src/main/java/io/github/marktony/espresso/data/source/remote/PackagesRemoteDataSource.java b/mobile/src/main/java/io/github/marktony/espresso/data/source/remote/PackagesRemoteDataSource.java index d9e52d4..f2be059 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/data/source/remote/PackagesRemoteDataSource.java +++ b/mobile/src/main/java/io/github/marktony/espresso/data/source/remote/PackagesRemoteDataSource.java @@ -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> searchPackages(@NonNull String keyWords) { + // Not required because the {@link PackagesRepository} handles the logic + // of refreshing the packages from all available data source + return null; + } + } \ No newline at end of file diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/addpackage/AddPackageActivity.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/addpackage/AddPackageActivity.java index bca3dac..032b745 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/addpackage/AddPackageActivity.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/addpackage/AddPackageActivity.java @@ -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); diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesAdapter.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesAdapter.java index daa0c47..a956afd 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesAdapter.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesAdapter.java @@ -49,9 +49,9 @@ public CompaniesAdapter(@NonNull Context context, @NonNull List 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 @@ -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); diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesFragment.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesFragment.java index ba98c1b..9f1b09a 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesFragment.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesFragment.java @@ -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; @@ -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. @@ -101,13 +104,15 @@ public void showGetCompaniesError() { } @Override - public void showCompanies(List list) { + public void showCompanies(final List 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); diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesPresenter.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesPresenter.java index fb3916d..6cbffd0 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesPresenter.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/companies/CompaniesPresenter.java @@ -1,7 +1,6 @@ package io.github.marktony.espresso.mvp.companies; import android.support.annotation.NonNull; -import android.util.Log; import java.util.List; @@ -19,8 +18,6 @@ public class CompaniesPresenter implements CompaniesContract.Presenter { - private static final String TAG = CompaniesPresenter.class.getSimpleName(); - @NonNull private CompaniesContract.View view; diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailActivity.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailActivity.java index 9416b16..cdb5b17 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailActivity.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailActivity.java @@ -5,8 +5,12 @@ import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; +import android.transition.Explode; +import android.view.animation.AccelerateDecelerateInterpolator; import io.github.marktony.espresso.R; +import io.github.marktony.espresso.data.source.CompaniesRepository; +import io.github.marktony.espresso.data.source.local.CompaniesLocalDataSource; /** * Created by lizhaotailang on 2017/2/10. @@ -16,6 +20,8 @@ public class CompanyDetailActivity extends AppCompatActivity { private CompanyDetailFragment fragment; + public static final String COMPANY_ID = "COMPANY_ID"; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -26,6 +32,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); } + Explode explode = new Explode(); + explode.setDuration(500); + explode.setInterpolator(new AccelerateDecelerateInterpolator()); + getWindow().setEnterTransition(explode); + if (savedInstanceState != null) { fragment = (CompanyDetailFragment) getSupportFragmentManager().getFragment(savedInstanceState, "CompanyDetailFragment"); } else { @@ -38,7 +49,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { .commit(); } - new CompanyDetailPresenter(fragment); + new CompanyDetailPresenter( + fragment, + CompaniesRepository.getInstance(CompaniesLocalDataSource.getInstance()), + getIntent().getStringExtra(COMPANY_ID)); } diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailContract.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailContract.java index 341d518..74961bc 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailContract.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailContract.java @@ -1,5 +1,7 @@ package io.github.marktony.espresso.mvp.companydetails; +import java.util.List; + import io.github.marktony.espresso.mvp.BasePresenter; import io.github.marktony.espresso.mvp.BaseView; @@ -11,6 +13,16 @@ public interface CompanyDetailContract { interface View extends BaseView { + void setCompanyName(String name); + + void setCompanyTel(String tel); + + void setCompanyWebsite(String website); + + void showErrorMsg(); + + + } interface Presenter extends BasePresenter { diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailFragment.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailFragment.java index 66e1d58..2f1c7fa 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailFragment.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailFragment.java @@ -1,17 +1,19 @@ package io.github.marktony.espresso.mvp.companydetails; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; +import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; import io.github.marktony.espresso.R; -import io.github.marktony.espresso.mvp.packagedetails.PackageDetailsActivity; /** * Created by lizhaotailang on 2017/2/10. @@ -20,7 +22,12 @@ public class CompanyDetailFragment extends Fragment implements CompanyDetailContract.View { - private LinearLayout layoutPhoneNumber, layoutWebsite; + // View references. + private FloatingActionButton fab; + private AppCompatTextView textViewCompanyName; + private AppCompatTextView textViewTel; + private AppCompatTextView textViewWebsite; + private View layoutTel, layoutWebsite; private CompanyDetailContract.Presenter presenter; @@ -42,13 +49,25 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, initViews(view); - layoutPhoneNumber.setOnClickListener(new View.OnClickListener() { + fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); + layoutTel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String tel = textViewTel.getText().toString(); + if (!tel.isEmpty()) { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse("tel:" + tel)); + getActivity().startActivity(intent); + } + } + }); + layoutWebsite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -74,13 +93,16 @@ public void onPause() { @Override public void initViews(View view) { - PackageDetailsActivity activity = (PackageDetailsActivity) getActivity(); + CompanyDetailActivity activity = (CompanyDetailActivity) getActivity(); activity.setSupportActionBar((Toolbar) view.findViewById(R.id.toolbar)); activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); - layoutWebsite = (LinearLayout) view.findViewById(R.id.layoutCompanyOfficialWebsite); - layoutPhoneNumber = (LinearLayout) view.findViewById(R.id.layoutCompanyPhoneNumber); - + fab = (FloatingActionButton) view.findViewById(R.id.fab); + textViewCompanyName = (AppCompatTextView) view.findViewById(R.id.textViewCompany); + textViewTel = (AppCompatTextView) view.findViewById(R.id.textViewCompanyPhoneNumber); + textViewWebsite = (AppCompatTextView) view.findViewById(R.id.textViewCompanyWebsite); + layoutTel = view.findViewById(R.id.layoutCompanyPhoneNumber); + layoutWebsite = view.findViewById(R.id.layoutCompanyOfficialWebsite); } @Override @@ -88,4 +110,24 @@ public void setPresenter(@NonNull CompanyDetailContract.Presenter presenter) { this.presenter = presenter; } + @Override + public void setCompanyName(String name) { + textViewCompanyName.setText(name); + } + + @Override + public void setCompanyTel(String tel) { + textViewTel.setText(tel); + } + + @Override + public void setCompanyWebsite(String website) { + textViewWebsite.setText(website); + } + + @Override + public void showErrorMsg() { + + } + } diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailPresenter.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailPresenter.java index a321af4..4efd3ca 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailPresenter.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/companydetails/CompanyDetailPresenter.java @@ -2,27 +2,78 @@ import android.support.annotation.NonNull; +import io.github.marktony.espresso.data.Company; +import io.github.marktony.espresso.data.source.CompaniesRepository; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.disposables.Disposable; +import io.reactivex.observers.DisposableObserver; +import io.reactivex.schedulers.Schedulers; + /** * Created by lizhaotailang on 2017/2/10. */ public class CompanyDetailPresenter implements CompanyDetailContract.Presenter { + @NonNull private CompanyDetailContract.View view; - public CompanyDetailPresenter(@NonNull CompanyDetailContract.View view) { + @NonNull + private CompaniesRepository companiesRepository; + + @NonNull + private String companyId; + + @NonNull + private CompositeDisposable compositeDisposable; + + public CompanyDetailPresenter(@NonNull CompanyDetailContract.View view, + @NonNull CompaniesRepository companiesRepository, + @NonNull String companyId) { this.view = view; + this.companiesRepository = companiesRepository; + this.companyId = companyId; this.view.setPresenter(this); + compositeDisposable = new CompositeDisposable(); } @Override public void subscribe() { - + fetchCompanyData(); } @Override public void unsubscribe() { + compositeDisposable.clear(); + } + + private void fetchCompanyData() { + Disposable disposable = companiesRepository + .getCompany(companyId) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableObserver() { + @Override + public void onNext(Company value) { + if (value != null) { + view.setCompanyName(value.getName()); + view.setCompanyTel(value.getTel()); + view.setCompanyWebsite(value.getWebsite()); + } + } + + @Override + public void onError(Throwable e) { + view.showErrorMsg(); + } + + @Override + public void onComplete() { + } + }); + compositeDisposable.add(disposable); } } diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsActivity.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsActivity.java index 5771944..d37530b 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsActivity.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsActivity.java @@ -5,6 +5,8 @@ import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; +import android.transition.Explode; +import android.view.animation.AccelerateDecelerateInterpolator; import io.github.marktony.espresso.R; import io.github.marktony.espresso.data.source.local.PackagesLocalDataSource; @@ -31,6 +33,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); } + Explode explode = new Explode(); + explode.setDuration(500); + explode.setInterpolator(new AccelerateDecelerateInterpolator()); + getWindow().setEnterTransition(explode); + // Restore the status. if (savedInstanceState != null) { fragment = (PackageDetailsFragment) getSupportFragmentManager().getFragment(savedInstanceState, "PackageDetailsFragment"); diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsAdapter.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsAdapter.java index 799a97e..8324b10 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsAdapter.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsAdapter.java @@ -66,7 +66,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType if (viewType == TYPE_HEADER) { return new HeaderViewHolder(inflater.inflate(R.layout.package_details_header, parent, false)); } - return new PackageStatusViewHolder(inflater.inflate(R.layout.package_status_item, parent, false)); + return new PackageStatusViewHolder(inflater.inflate(R.layout.item_package_status, parent, false)); } @Override diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsFragment.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsFragment.java index bd3d481..b8b4463 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsFragment.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/packagedetails/PackageDetailsFragment.java @@ -65,7 +65,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_details, container, false); + View view = inflater.inflate(R.layout.fragment_package_details, container, false); initViews(view); diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/packages/PackagesAdapter.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/packages/PackagesAdapter.java index 017c179..61df17b 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/packages/PackagesAdapter.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/packages/PackagesAdapter.java @@ -50,7 +50,7 @@ public PackagesAdapter(@NonNull Context context, @NonNull List list) { @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - return new PackageViewHolder(inflater.inflate(R.layout.package_item, parent, false), listener); + return new PackageViewHolder(inflater.inflate(R.layout.item_package, parent, false), listener); } @Override diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/packages/PackagesFragment.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/packages/PackagesFragment.java index 512b813..a63d18d 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/packages/PackagesFragment.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/packages/PackagesFragment.java @@ -36,6 +36,7 @@ import io.github.marktony.espresso.data.Package; import io.github.marktony.espresso.interfaze.OnRecyclerViewItemClickListener; import io.github.marktony.espresso.mvp.packagedetails.PackageDetailsActivity; +import io.github.marktony.espresso.mvp.search.SearchActivity; /** * Created by lizhaotailang on 2017/2/10. @@ -154,7 +155,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_search) { - + startActivity(new Intent(getContext(), SearchActivity.class)); } else if (id == R.id.action_mark_all_read) { presenter.markAllPacksRead(); } diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchActivity.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchActivity.java index e0a5858..5509f8f 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchActivity.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchActivity.java @@ -1,18 +1,59 @@ package io.github.marktony.espresso.mvp.search; -import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.transition.Explode; +import android.view.animation.AccelerateDecelerateInterpolator; -/** - * Created by lizhaotailang on 2017/3/18. - */ +import io.github.marktony.espresso.R; +import io.github.marktony.espresso.data.source.CompaniesRepository; +import io.github.marktony.espresso.data.source.PackagesRepository; +import io.github.marktony.espresso.data.source.local.CompaniesLocalDataSource; +import io.github.marktony.espresso.data.source.local.PackagesLocalDataSource; +import io.github.marktony.espresso.data.source.remote.PackagesRemoteDataSource; public class SearchActivity extends AppCompatActivity { + private SearchFragment fragment; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.container); + + // Set the navigation bar color + if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("navigation_bar_tint", true)) { + getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); + } + + // Set the animations. + Explode explode = new Explode(); + explode.setDuration(500); + explode.setInterpolator(new AccelerateDecelerateInterpolator()); + getWindow().setEnterTransition(explode); + + if (savedInstanceState != null) { + fragment = (SearchFragment) getSupportFragmentManager().getFragment(savedInstanceState, "SearchFragment"); + } else { + fragment = SearchFragment.newInstance(); + } + + getSupportFragmentManager().beginTransaction() + .replace(R.id.container, fragment) + .commit(); + + new SearchPresenter(fragment, + PackagesRepository.getInstance(PackagesRemoteDataSource.getInstance(), PackagesLocalDataSource.getInstance()), + CompaniesRepository.getInstance(CompaniesLocalDataSource.getInstance())); + } + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + getSupportFragmentManager().putFragment(outState, "SearchFragment", fragment); + } } diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchContract.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchContract.java new file mode 100644 index 0000000..d75adc3 --- /dev/null +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchContract.java @@ -0,0 +1,28 @@ +package io.github.marktony.espresso.mvp.search; + +import java.util.List; + +import io.github.marktony.espresso.data.Company; +import io.github.marktony.espresso.data.Package; +import io.github.marktony.espresso.mvp.BasePresenter; +import io.github.marktony.espresso.mvp.BaseView; + +/** + * Created by lizhaotailang on 2017/3/26. + */ + +public interface SearchContract { + + interface View extends BaseView { + + void showResult(List packages, List companies); + + } + + interface Presenter extends BasePresenter { + + void search(String keyWords); + + } + +} diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchFragment.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchFragment.java index 4dcc123..acf1d32 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchFragment.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchFragment.java @@ -1,17 +1,44 @@ package io.github.marktony.espresso.mvp.search; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; +import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import java.util.List; + +import io.github.marktony.espresso.R; +import io.github.marktony.espresso.data.Company; +import io.github.marktony.espresso.data.Package; +import io.github.marktony.espresso.interfaze.OnRecyclerViewItemClickListener; + /** * Created by lizhaotailang on 2017/3/18. */ -public class SearchFragment extends Fragment { +public class SearchFragment extends Fragment + implements SearchContract.View { + + private SearchView searchView; + private RecyclerView recyclerView; + + private SearchResultsAdapter adapter; + + private SearchContract.Presenter presenter; + + public SearchFragment() {} + + public static SearchFragment newInstance() { + return new SearchFragment(); + } @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -21,16 +48,79 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - return super.onCreateView(inflater, container, savedInstanceState); + View view = inflater.inflate(R.layout.fragment_search, container, false); + + initViews(view); + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + presenter.search(query); + return true; + } + + @Override + public boolean onQueryTextChange(String newText) { + presenter.search(newText); + return true; + } + }); + + setHasOptionsMenu(true); + + return view; + } + + @Override + public void onResume() { + super.onResume(); + presenter.subscribe(); } @Override public void onPause() { super.onPause(); + presenter.unsubscribe(); } @Override - public void onStop() { - super.onStop(); + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + getActivity().onBackPressed(); + } + return true; + } + + @Override + public void initViews(View view) { + SearchActivity activity = (SearchActivity) getActivity(); + activity.setSupportActionBar((Toolbar) view.findViewById(R.id.toolbar)); + activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + searchView = (SearchView) view.findViewById(R.id.searchView); + searchView.setIconified(false); + recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + } + + @Override + public void setPresenter(@NonNull SearchContract.Presenter presenter) { + this.presenter = presenter; + } + + @Override + public void showResult(List packages, List companies) { + if (adapter == null) { + adapter = new SearchResultsAdapter(getContext(), packages, companies); + adapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() { + @Override + public void OnItemClick(View v, int position) { + + } + }); + recyclerView.setAdapter(adapter); + } else { + adapter.updateData(packages, companies); + } } } diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchPresenter.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchPresenter.java new file mode 100644 index 0000000..14ad52f --- /dev/null +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchPresenter.java @@ -0,0 +1,97 @@ +package io.github.marktony.espresso.mvp.search; + +import android.support.annotation.NonNull; + +import java.util.List; + +import io.github.marktony.espresso.data.Company; +import io.github.marktony.espresso.data.Package; +import io.github.marktony.espresso.data.PackageAndCompanyPairs; +import io.github.marktony.espresso.data.source.CompaniesRepository; +import io.github.marktony.espresso.data.source.PackagesRepository; +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.disposables.Disposable; +import io.reactivex.functions.BiFunction; +import io.reactivex.observers.DisposableObserver; +import io.reactivex.schedulers.Schedulers; + +/** + * Created by lizhaotailang on 2017/3/26. + */ + +public class SearchPresenter implements SearchContract.Presenter{ + + @NonNull + private SearchContract.View view; + + @NonNull + private PackagesRepository packagesRepository; + + @NonNull + private CompaniesRepository companiesRepository; + + private CompositeDisposable compositeDisposable; + + public SearchPresenter(@NonNull SearchContract.View view, + @NonNull PackagesRepository packagesRepository, + @NonNull CompaniesRepository companiesRepository) { + this.view = view; + this.packagesRepository = packagesRepository; + this.companiesRepository = companiesRepository; + this.view.setPresenter(this); + compositeDisposable = new CompositeDisposable(); + } + + @Override + public void subscribe() { + + } + + @Override + public void unsubscribe() { + compositeDisposable.clear(); + } + + @Override + public void search(String keyWords) { + + Observable> companyObservable = companiesRepository + .searchCompanies(keyWords) + .subscribeOn(Schedulers.io()); + + Observable> packageObservable = packagesRepository + .searchPackages(keyWords) + .subscribeOn(Schedulers.io()); + + Disposable disposable = Observable + .zip(packageObservable, companyObservable, new BiFunction, List, PackageAndCompanyPairs>() { + @Override + public PackageAndCompanyPairs apply(List packages, List companies) throws Exception { + return new PackageAndCompanyPairs(packages, companies); + } + }) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableObserver() { + @Override + public void onNext(PackageAndCompanyPairs value) { + view.showResult(value.getPackages(), value.getCompanies()); + } + + @Override + public void onError(Throwable e) { + + } + + @Override + public void onComplete() { + + } + }); + + compositeDisposable.add(disposable); + + } + +} diff --git a/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchResultsAdapter.java b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchResultsAdapter.java index bd7bbfa..4cde14c 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchResultsAdapter.java +++ b/mobile/src/main/java/io/github/marktony/espresso/mvp/search/SearchResultsAdapter.java @@ -4,17 +4,19 @@ import android.graphics.Color; import android.graphics.Typeface; import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatTextView; import android.support.v7.widget.RecyclerView; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import java.util.ArrayList; import java.util.List; import de.hdodenhof.circleimageview.CircleImageView; + import io.github.marktony.espresso.R; import io.github.marktony.espresso.data.Company; import io.github.marktony.espresso.data.Package; @@ -162,7 +164,33 @@ public int getItemViewType(int position) { } public void updateData(List packages, List companies) { - + this.packages.clear(); + this.companies.clear(); + this.list.clear(); + this.packages = packages; + this.companies = companies; + this.list.add(new ItemWrapper(ItemWrapper.TYPE_CATEGORY)); + if (packages.size() > 0) { + for (int i = 0; i < packages.size(); i++) { + ItemWrapper wrapper = new ItemWrapper(ItemWrapper.TYPE_PACKAGE); + wrapper.index = i; + list.add(wrapper); + } + } else { + list.add(new ItemWrapper(ItemWrapper.TYPE_EMPTY)); + } + + this.list.add(new ItemWrapper(ItemWrapper.TYPE_CATEGORY)); + if (companies.size() > 0) { + for (int i = 0; i < companies.size(); i++) { + ItemWrapper wrapper = new ItemWrapper(ItemWrapper.TYPE_COMPANY); + wrapper.index = i; + list.add(wrapper); + } + } else { + list.add(new ItemWrapper(ItemWrapper.TYPE_EMPTY)); + } + notifyDataSetChanged(); } public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) { @@ -180,7 +208,7 @@ private class PackageHolder extends RecyclerView.ViewHolder PackageHolder(View itemView, OnRecyclerViewItemClickListener listener) { super(itemView); - avatar = (CircleImageView) itemView.findViewById(R.id.imageViewAvatar); + avatar = (CircleImageView) itemView.findViewById(R.id.circleImageView); textViewPackageName = (AppCompatTextView) itemView.findViewById(R.id.textViewPackageName); textViewStatus = (AppCompatTextView) itemView.findViewById(R.id.textViewStatus); textViewTime = (AppCompatTextView) itemView.findViewById(R.id.textViewTime); diff --git a/mobile/src/main/java/io/github/marktony/espresso/ui/PrefsActivity.java b/mobile/src/main/java/io/github/marktony/espresso/ui/PrefsActivity.java index d57b31f..b203ab1 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/ui/PrefsActivity.java +++ b/mobile/src/main/java/io/github/marktony/espresso/ui/PrefsActivity.java @@ -23,8 +23,7 @@ public class PrefsActivity extends AppCompatActivity { public static final String EXTRA_FLAG= "EXTRA_FLAG"; - public static final int FLAG_SETTINGS = 0, FLAG_ABOUT = 1, - FLAG_LICENSES = 2; + public static final int FLAG_SETTINGS = 0, FLAG_ABOUT = 1, FLAG_LICENSES = 2; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -61,7 +60,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { getSupportFragmentManager() .beginTransaction() - .replace(R.id.container_prefs,fragment) + .replace(R.id.container,fragment) .commit(); } diff --git a/mobile/src/main/java/io/github/marktony/espresso/ui/onboarding/OnboardingActivity.java b/mobile/src/main/java/io/github/marktony/espresso/ui/onboarding/OnboardingActivity.java index c28ae20..2699944 100644 --- a/mobile/src/main/java/io/github/marktony/espresso/ui/onboarding/OnboardingActivity.java +++ b/mobile/src/main/java/io/github/marktony/espresso/ui/onboarding/OnboardingActivity.java @@ -41,7 +41,12 @@ public class OnboardingActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + // Set the navigation bar color + if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("navigation_bar_tint", true)) { + getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); + } + + final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); if (sp.getBoolean(SettingsUtils.KEY_FIRST_LAUNCH, true)) { setContentView(R.layout.activity_onboarding); @@ -79,6 +84,9 @@ public void onPageScrollStateChanged(int state) { buttonFinish.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + SharedPreferences.Editor ed = sp.edit(); + ed.putBoolean(SettingsUtils.KEY_FIRST_LAUNCH, false); + ed.apply(); navigateToMainActivity(); } }); @@ -99,10 +107,6 @@ public void onClick(View v) { } }); - SharedPreferences.Editor ed = sp.edit(); - ed.putBoolean(SettingsUtils.KEY_FIRST_LAUNCH, false); - ed.apply(); - } else { navigateToMainActivity(); diff --git a/mobile/src/main/res/drawable/ic_share_white_24dp.xml b/mobile/src/main/res/drawable/ic_share_white_24dp.xml new file mode 100644 index 0000000..9040666 --- /dev/null +++ b/mobile/src/main/res/drawable/ic_share_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/mobile/src/main/res/layout/activity_onboarding.xml b/mobile/src/main/res/layout/activity_onboarding.xml index 4472471..44fe1b2 100644 --- a/mobile/src/main/res/layout/activity_onboarding.xml +++ b/mobile/src/main/res/layout/activity_onboarding.xml @@ -38,7 +38,7 @@ android:layout_height="wrap_content" android:id="@+id/imageButtonPre" style="@style/Widget.AppCompat.Button.Borderless" - android:contentDescription="Pre" + android:contentDescription="@string/onboarding_pre_button_description" android:layout_gravity="start|center" android:padding="@dimen/activity_horizontal_margin" android:src="@drawable/ic_chevron_left_white_24dp" @@ -82,7 +82,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|center" - android:text="Finish" + android:text="@string/onboarding_finish_button_description" android:textColor="@android:color/white" android:visibility="gone" /> @@ -91,7 +91,7 @@ android:layout_height="wrap_content" style="@style/Widget.AppCompat.Button.Borderless" android:id="@+id/imageButtonNext" - android:contentDescription="Next" + android:contentDescription="@string/onboarding_next_button_description" android:layout_gravity="end|center" android:padding="@dimen/activity_horizontal_margin" android:src="@drawable/ic_chevron_right_white_24dp" diff --git a/mobile/src/main/res/layout/activity_prefs.xml b/mobile/src/main/res/layout/activity_prefs.xml index 7be1b3e..d62be03 100644 --- a/mobile/src/main/res/layout/activity_prefs.xml +++ b/mobile/src/main/res/layout/activity_prefs.xml @@ -1,3 +1,4 @@ + - + + android:layout_height="match_parent"> - + android:layout_height="wrap_content" + android:id="@+id/app_bar" + android:theme="@style/AppTheme.AppBarOverlay"> - + - + + + + + + + \ No newline at end of file diff --git a/mobile/src/main/res/layout/container.xml b/mobile/src/main/res/layout/container.xml index a36cb41..cebc625 100644 --- a/mobile/src/main/res/layout/container.xml +++ b/mobile/src/main/res/layout/container.xml @@ -2,4 +2,4 @@ \ No newline at end of file + android:id="@+id/container" /> diff --git a/mobile/src/main/res/layout/fragment_add_package.xml b/mobile/src/main/res/layout/fragment_add_package.xml index 7f1fa9c..32ce314 100644 --- a/mobile/src/main/res/layout/fragment_add_package.xml +++ b/mobile/src/main/res/layout/fragment_add_package.xml @@ -6,6 +6,8 @@ android:layout_height="match_parent" android:fitsSystemWindows="true" android:id="@+id/coordinatorLayout" + android:descendantFocusability="beforeDescendants" + android:focusableInTouchMode="true" tools:context=".mvp.addpackage.AddPackageActivity"> - + android:textIsSelectable="true"/> + android:textIsSelectable="true"/> @@ -114,12 +114,24 @@ android:layout_marginBottom="4dp" android:id="@+id/textViewCompanyWebsite" android:textAppearance="@style/TextAppearance.AppCompat.Small" - android:text="http://www.sf-express.com"/> + android:textIsSelectable="true"/> - + + + \ No newline at end of file diff --git a/mobile/src/main/res/layout/fragment_details.xml b/mobile/src/main/res/layout/fragment_package_details.xml similarity index 100% rename from mobile/src/main/res/layout/fragment_details.xml rename to mobile/src/main/res/layout/fragment_package_details.xml diff --git a/mobile/src/main/res/layout/fragment_search.xml b/mobile/src/main/res/layout/fragment_search.xml new file mode 100644 index 0000000..8d64b23 --- /dev/null +++ b/mobile/src/main/res/layout/fragment_search.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mobile/src/main/res/layout/company_item.xml b/mobile/src/main/res/layout/item_company.xml similarity index 97% rename from mobile/src/main/res/layout/company_item.xml rename to mobile/src/main/res/layout/item_company.xml index 8ceabeb..6830600 100644 --- a/mobile/src/main/res/layout/company_item.xml +++ b/mobile/src/main/res/layout/item_company.xml @@ -31,7 +31,7 @@ @@ -15,13 +15,13 @@ - + \ No newline at end of file diff --git a/mobile/src/main/res/layout/package_item.xml b/mobile/src/main/res/layout/item_package.xml similarity index 100% rename from mobile/src/main/res/layout/package_item.xml rename to mobile/src/main/res/layout/item_package.xml diff --git a/mobile/src/main/res/layout/package_item_for_widget.xml b/mobile/src/main/res/layout/item_package_for_widget.xml similarity index 100% rename from mobile/src/main/res/layout/package_item_for_widget.xml rename to mobile/src/main/res/layout/item_package_for_widget.xml diff --git a/mobile/src/main/res/layout/package_status_item.xml b/mobile/src/main/res/layout/item_package_status.xml similarity index 100% rename from mobile/src/main/res/layout/package_status_item.xml rename to mobile/src/main/res/layout/item_package_status.xml diff --git a/mobile/src/main/res/layout/item_search_result_category.xml b/mobile/src/main/res/layout/item_search_result_category.xml new file mode 100644 index 0000000..707ff55 --- /dev/null +++ b/mobile/src/main/res/layout/item_search_result_category.xml @@ -0,0 +1,13 @@ + + \ No newline at end of file diff --git a/mobile/src/main/res/layout/item_search_result_empty.xml b/mobile/src/main/res/layout/item_search_result_empty.xml new file mode 100644 index 0000000..80602b8 --- /dev/null +++ b/mobile/src/main/res/layout/item_search_result_empty.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index a66b1ec..43a511d 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -148,7 +148,19 @@ All packages are delivered. + + Next + Finish + Pre + + + NO RESULT + Package or company… + PACKAGE + COMPANY + Loading… + \ No newline at end of file