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 27, 2017
1 parent 7815734 commit 7b029e0
Show file tree
Hide file tree
Showing 34 changed files with 397 additions and 146 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Espresso Android App
![icon](https://github.com/TonnyL/Espresso/blob/master/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher.png)

Espresso is an express delivery tracking app designed with Material Design style, built on MVP(Model-View-Presenter) architecture with RxJava2, Retrofit2 and Realm database.
Espresso is an express delivery tracking app designed with Material Design style, built on MVP(Model-View-Presenter) architecture with RxJava2, Retrofit2, Realm database and ZXing.

The source code in this repository reflects the app which supports mobile devices running Android 5.0+.

Expand All @@ -18,9 +18,9 @@ With this app, you can:
+ Send feedback on using experience from your devices.

### Screenshots
![screenshot0](http://upload-images.jianshu.io/upload_images/2440049-649b96f3b8858cce.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![screenshot0](https://github.com/TonnyL/Espresso/blob/master/art/screenshot0.png)

![screenshot1](http://upload-images.jianshu.io/upload_images/2440049-d3c50d9e5ca6f0a4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![screenshot1](https://github.com/TonnyL/Espresso/blob/master/art/screenshot1.png)

### How to Work with the Source
I hope the source code for this app is useful for you as a reference or starting point for creating your own app. Here is some instructions to help you better build and run the code in Android Studio.
Expand Down Expand Up @@ -48,9 +48,9 @@ This project is still in progress. Here are the some features that I will finish
- [x] Launcher app widgets.
- [x] App Shortcuts on devices that running Android 7.1+.
- [x] Material design app onboarding pages.
- [ ] Chrome Custom Tabs.
- [x] Chrome Custom Tabs.
- [x] Alphabet indexing for companies list.
- [ ] Search packages and companies.
- [x] Search packages and companies.
- [ ] Day and night mode.
- [x] Service to build notifications.
- [x] Settings and about page.
Expand Down
Binary file added art/screenshot0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,26 @@ dependencies {
})
wearApp project(':wear')
// Google Mobile Service
// Support libraries
// ReactiveX series
// Retrofit series
// Zxing
// Material data time picker
// CircleImageView
compile 'com.google.android.gms:play-services:10.2.1'
// Support libraries
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'
compile 'com.android.support:customtabs: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 date time picker
compile 'com.wdullaer:materialdatetimepicker:3.1.3'
// CircleImageView
compile 'de.hdodenhof:circleimageview:2.1.0'
testCompile 'junit:junit:4.12'
}
8 changes: 8 additions & 0 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
package="io.github.marktony.espresso">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />

<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />

<application
android:name=".app.App"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github.marktony.espresso.app;

import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatDelegate;

import io.github.marktony.espresso.util.SettingsUtil;
import io.realm.Realm;

/**
Expand All @@ -16,6 +17,12 @@ public class App extends Application {
public void onCreate() {
super.onCreate();
Realm.init(this);

/*if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(SettingsUtil.KEY_NIGHT_MODE, false)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}*/
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.marktony.espresso.customtabs;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.customtabs.CustomTabsIntent;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;

import io.github.marktony.espresso.R;
import io.github.marktony.espresso.util.SettingsUtil;

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

public class CustomTabsHelper {

public static void openUrl(Context context, String url) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

if (sharedPreferences.getBoolean(SettingsUtil.KEY_CUSTOM_TABS, true)) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
builder.build().launchUrl(context, Uri.parse(url));
} else {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)));
} catch (ActivityNotFoundException e) {
Toast.makeText(context, R.string.error_no_browser, Toast.LENGTH_SHORT).show();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,13 @@ public Observable<List<Company>> searchCompanies(@NonNull String keyWords) {
List<Company> results = rlm.copyFromRealm(
rlm.where(Company.class)
.like("name","*" + keyWords + "*", Case.INSENSITIVE)
/*.contains("tel", "*" + keyWords + "*")
.contains("website", "*" + keyWords + "*")
.contains("alphabet", "*" + keyWords + "*")*/
.findAll());
.or()
.like("tel", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("website", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("alphabet", "*" + keyWords + "*", Case.INSENSITIVE)
.findAllSorted("alphabet", Sort.ASCENDING));
return Observable.fromIterable(results)
.toList()
.toObservable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,13 @@ 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().contains("company", "*" + keyWords + "*")
.or().contains("number", "*" + keyWords + "*")*/
.or()
.like("company", "*" + keyWords + "*", Case.INSENSITIVE)
.or()
.like("number", "*" + keyWords + "*", Case.INSENSITIVE)
.findAll()))
.toList()
.toObservable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ interface View extends BaseView<Presenter> {

void showErrorMsg();



}

interface Presenter extends BasePresenter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
package io.github.marktony.espresso.mvp.companydetails;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Typeface;
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.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.Toolbar;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import io.github.marktony.espresso.R;
import io.github.marktony.espresso.customtabs.CustomTabsHelper;

/**
* Created by lizhaotailang on 2017/2/10.
Expand All @@ -27,10 +37,12 @@ public class CompanyDetailFragment extends Fragment
private AppCompatTextView textViewCompanyName;
private AppCompatTextView textViewTel;
private AppCompatTextView textViewWebsite;
private View layoutTel, layoutWebsite;

private CompanyDetailContract.Presenter presenter;

private String tel;
private String website;

public CompanyDetailFragment() {}

public static CompanyDetailFragment newInstance() {
Expand All @@ -52,29 +64,32 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

share();
}
});

layoutTel.setOnClickListener(new View.OnClickListener() {
textViewTel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String tel = textViewTel.getText().toString();
if (!tel.isEmpty()) {
if (tel != null && !tel.isEmpty()) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + tel));
getActivity().startActivity(intent);
}
}
});

layoutWebsite.setOnClickListener(new View.OnClickListener() {
textViewWebsite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (website != null) {
CustomTabsHelper.openUrl(getContext(), website);
}
}
});

setHasOptionsMenu(true);

return view;
}

Expand All @@ -90,6 +105,14 @@ public void onPause() {
presenter.unsubscribe();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
getActivity().onBackPressed();
}
return true;
}

@Override
public void initViews(View view) {

Expand All @@ -101,8 +124,6 @@ public void initViews(View view) {
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
Expand All @@ -112,22 +133,51 @@ public void setPresenter(@NonNull CompanyDetailContract.Presenter presenter) {

@Override
public void setCompanyName(String name) {
textViewCompanyName.setText(name);
String companyName = getString(R.string.company_name) + "\n" + name;
Spannable spannable = new SpannableStringBuilder(companyName);
spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, companyName.length() - name.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new StyleSpan(Typeface.NORMAL), companyName.length() - name.length(), companyName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textViewCompanyName.setText(spannable);
}

@Override
public void setCompanyTel(String tel) {
textViewTel.setText(tel);
this.tel = tel;
String companyTel = getString(R.string.phone_number) + "\n" + tel;
Spannable spannable = new SpannableStringBuilder(companyTel);
spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, companyTel.length() - tel.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new URLSpan(tel), companyTel.length() - tel.length(), companyTel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textViewTel.setText(spannable);
}

@Override
public void setCompanyWebsite(String website) {
textViewWebsite.setText(website);
this.website = website;
String ws = getString(R.string.official_website) + "\n" + website;
Spannable spannable = new SpannableStringBuilder(ws);
spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, ws.length() - website.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannable.setSpan(new URLSpan(website), ws.length() - website.length(), ws.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textViewWebsite.setText(spannable);
}

@Override
public void showErrorMsg() {
Snackbar.make(fab, R.string.something_wrong, Snackbar.LENGTH_SHORT).show();
}

public void share() {
String content = textViewCompanyName.getText().toString()
+ "\n"
+ textViewTel.getText().toString()
+ "\n"
+ textViewWebsite.getText().toString();
try {
Intent intent = new Intent().setAction(Intent.ACTION_SEND).setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, content);
startActivity(Intent.createChooser(intent, getString(R.string.share)));
} catch (ActivityNotFoundException e) {
Snackbar.make(fab, R.string.something_wrong, Snackbar.LENGTH_SHORT).show();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.marktony.espresso.mvp.packagedetails;

import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
Expand All @@ -18,6 +19,7 @@
import io.github.marktony.espresso.component.Timeline;
import io.github.marktony.espresso.data.Package;
import io.github.marktony.espresso.data.PackageStatus;
import io.github.marktony.espresso.mvp.companydetails.CompanyDetailActivity;
import io.realm.RealmList;

/**
Expand All @@ -43,7 +45,7 @@ public class PackageDetailsAdapter extends RecyclerView.Adapter<RecyclerView.Vie
public static final int TYPE_FINISH = 0x03;
public static final int TYPE_SINGLE = 0x04;

public PackageDetailsAdapter(@NonNull Context context, Package p) {
public PackageDetailsAdapter(@NonNull Context context, @NonNull Package p) {
this.context = context;
inflater = LayoutInflater.from(context);
this.aPackage = p;
Expand Down Expand Up @@ -186,6 +188,17 @@ public HeaderViewHolder(View itemView) {
textViewCompany = (AppCompatTextView) itemView.findViewById(R.id.textViewCompany);
textViewNumber = (AppCompatTextView) itemView.findViewById(R.id.textViewPackageNumber);
textViewName = (AppCompatTextView) itemView.findViewById(R.id.textViewName);

textViewCompany.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (aPackage.getCompany() != null) {
Intent intent = new Intent(context, CompanyDetailActivity.class);
intent.putExtra(CompanyDetailActivity.COMPANY_ID, aPackage.getCompany());
context.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation((PackageDetailsActivity)context).toBundle());
}
}
});
}

}
Expand Down
Loading

0 comments on commit 7b029e0

Please sign in to comment.