Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  Do not cache /me responses
  Login: Do not resend error report for HTTPException
  fix default database migration
  fix crash on rotate in settings fragment
  use google oss licenses plugin
  update google-play services plugin and addons
  code cleanup
  billingmanager: prevent NPE
  login: log all error
  • Loading branch information
shalzz committed May 4, 2018
2 parents cc98d91 + 19b0ebe commit b27e95e
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 233 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ apply plugin: 'com.android.application'
apply plugin: 'com.squareup.sqldelight'
apply plugin: 'com.github.triplet.play'
apply plugin: 'com.bugsnag.android.gradle'
apply plugin: 'com.google.gms.oss.licenses.plugin'

bugsnag {
apiKey '600a00bfd5bd72e5df7f288f74df8f9b'
Expand Down Expand Up @@ -139,7 +140,10 @@ android {
final AUTO_VALUE_GSON_VERSION = '0.7.0'
final AUTO_VALUE_PARCEL_VERSION = '0.2.5'

implementation 'com.google.firebase:firebase-core:15.0.0'
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.google.firebase:firebase-analytics:15.0.2'

implementation 'com.google.android.gms:play-services-oss-licenses:15.0.1'

implementation "com.android.support:support-compat:$SUPPORT_LIBRARY_VERSION"
implementation "com.android.support:support-core-utils:$SUPPORT_LIBRARY_VERSION"
Expand Down Expand Up @@ -196,7 +200,6 @@ android {
implementation 'com.malinskiy:materialicons:1.0.2'
implementation 'com.github.amlcurran.showcaseview:library:5.4.0'
implementation 'com.github.afollestad.material-dialogs:core:0.8.5.5'
implementation 'de.psdev.licensesdialog:licensesdialog:1.8.0'

//noinspection GradleDynamicVersion
implementation 'com.bugsnag:bugsnag-android:4.+'
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,11 @@
</intent-filter>
</activity>

<activity android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/OSSLicenseTheme"/>

<activity android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:theme="@style/OSSLicenseTheme"/>

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,17 @@ public void queryPurchases() {
if (areSubscriptionsSupported()) {
PurchasesResult subscriptionResult
= mBillingClient.queryPurchases(SkuType.SUBS);
Timber.i("Querying purchases and subscriptions elapsed time: %s ms",
(System.currentTimeMillis() - time));
Timber.i( "Querying subscriptions result code: %d res: %d"
, subscriptionResult.getResponseCode()
, subscriptionResult.getPurchasesList().size());

if (subscriptionResult.getResponseCode() == BillingResponse.OK) {
if (subscriptionResult!= null && subscriptionResult.getResponseCode()
== BillingResponse.OK) {
purchasesResult.getPurchasesList().addAll(
subscriptionResult.getPurchasesList());

Timber.i("Querying purchases and subscriptions elapsed time: %s ms",
(System.currentTimeMillis() - time));
Timber.i( "Querying subscriptions result code: %d res: %d"
, subscriptionResult.getResponseCode()
, subscriptionResult.getPurchasesList().size());
} else {
Timber.e( "Got an error response trying to query subscription purchases");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ public void onCreate(SupportSQLiteDatabase db) {
@Override
public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
switch (oldVersion) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
default:

// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + Subject.TABLE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import timber.log.Timber;

public class CacheControlInterceptor implements Interceptor {
private Context mContext;
Expand All @@ -26,27 +27,34 @@ public CacheControlInterceptor(@ApplicationContext Context context) {

@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Request request = chain.request();
if (NetworkUtil.isNetworkConnected(mContext)) {
Response originalResponse = chain.proceed(chain.request());
int maxAge = 60; // read from cache for 1 minute
return originalResponse.newBuilder()
.header("Cache-Control", "public, max-age=" + maxAge)
.build();

} else {
Request request = chain.request();
// only for the 'verify' api route
if (request.url().encodedPath().equals("/api/v1/verify")) {
CacheControl cacheControl = new CacheControl.Builder()
.onlyIfCached()
.maxStale(7, TimeUnit.DAYS)
// Do not cache the '/me' api route
if (request.url().encodedPath().equals("/api/v1/me")) {
Response originalResponse = chain.proceed(request);
return originalResponse.newBuilder()
.header("Cache-Control", "public, max-age=0")
.build();

request = request.newBuilder()
.cacheControl(cacheControl)
}
else {
Timber.d("Caching: %s",request.url().encodedPath());
Response originalResponse = chain.proceed(request);
int maxAge = 60; // read from cache for 1 minute
return originalResponse.newBuilder()
.header("Cache-Control", "public, max-age=" + maxAge)
.build();
}
return chain.proceed(request);
// only for the 'verify' api route
} else if (request.url().encodedPath().equals("/api/v1/verify")) {
CacheControl cacheControl = new CacheControl.Builder()
.onlyIfCached()
.maxStale(7, TimeUnit.DAYS)
.build();

request = request.newBuilder()
.cacheControl(cacheControl)
.build();
}
return chain.proceed(request);
}
}
10 changes: 5 additions & 5 deletions app/src/main/java/com/shalzz/attendance/sync/Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public Bundle addAccount(
String s,
String s2,
String[] strings,
Bundle bundle) throws NetworkErrorException {
Bundle bundle) {
return null;
}
// Ignore attempts to confirm credentials
@Override
public Bundle confirmCredentials(
AccountAuthenticatorResponse r,
Account account,
Bundle bundle) throws NetworkErrorException {
Bundle bundle) {
return null;
}
// Getting an authentication token is not supported
Expand All @@ -65,7 +65,7 @@ public Bundle getAuthToken(
AccountAuthenticatorResponse r,
Account account,
String s,
Bundle bundle) throws NetworkErrorException {
Bundle bundle) {
throw new UnsupportedOperationException();
}
// Getting a label for the auth token is not supported
Expand All @@ -78,14 +78,14 @@ public String getAuthTokenLabel(String s) {
public Bundle updateCredentials(
AccountAuthenticatorResponse r,
Account account,
String s, Bundle bundle) throws NetworkErrorException {
String s, Bundle bundle) {
throw new UnsupportedOperationException();
}
// Checking features for the account is not supported
@Override
public Bundle hasFeatures(
AccountAuthenticatorResponse r,
Account account, String[] strings) throws NetworkErrorException {
Account account, String[] strings) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,18 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
private void inflateChildView(final View view) {
final GenericViewHolder views = (GenericViewHolder) view.getTag();

ViewStub stub = (ViewStub) view.findViewById(R.id.subject_details_stub);
ViewStub stub = view.findViewById(R.id.subject_details_stub);
if (stub != null) {
views.childView = (RelativeLayout) stub.inflate();
}
else
views.childView = (RelativeLayout) views.itemView.findViewById(R.id.subTree);
views.childView = views.itemView.findViewById(R.id.subTree);

// child view
View childView = views.childView;
views.tvAbsent = (TextView) childView.findViewById(R.id.tvAbsent);
views.tvReach = (TextView) childView.findViewById(R.id.tvReach);
views.ivAlert = (ImageView) childView.findViewById(R.id.imageView1);
views.tvAbsent = childView.findViewById(R.id.tvAbsent);
views.tvReach = childView.findViewById(R.id.tvReach);
views.ivAlert = childView.findViewById(R.id.imageView1);

bindChildView(views,views.position);
}
Expand Down Expand Up @@ -476,9 +476,9 @@ private void prepareHeaderFooter(HeaderFooterViewHolder vh, View view){

/** --------footer-------- */
view.setVisibility(View.VISIBLE);
TextView tvPercent = (TextView) view.findViewById(R.id.tvTotalPercent);
TextView tvClasses = (TextView) view.findViewById(R.id.tvClass);
ProgressBar pbPercent = (ProgressBar) view.findViewById(R.id.pbTotalPercent);
TextView tvPercent = view.findViewById(R.id.tvTotalPercent);
TextView tvClasses = view.findViewById(R.id.tvClass);
ProgressBar pbPercent = view.findViewById(R.id.pbTotalPercent);
tvPercent.setText(mResources.getString(R.string.atten_list_percentage,
mFooter.getPercentage()));
tvClasses.setText(mResources.getString(R.string.atten_list_attended_upon_held,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ public void onNext(User user) {

@Override
public void onError(Throwable e) {
RetrofitException error = (RetrofitException) e;
if (error.getKind() == RetrofitException.Kind.UNEXPECTED) {
getMvpView().showError(error.getMessage());
Timber.e(e);
}
else {
getMvpView().showError(error.getMessage());
if (isViewAttached()) {
RetrofitException error = (RetrofitException) e;
if (error.getKind() == RetrofitException.Kind.HTTP) {
getMvpView().showError(error.getMessage());
} else {
getMvpView().showError(error.getMessage());
Timber.e(e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Set the list's click listener
mNavigationView.setNavigationItemSelectedListener(new NavigationItemSelectedListener());

initDrawer();
init(savedInstanceState);
}

Expand All @@ -196,13 +197,6 @@ protected void onResume() {
}
}

@Override
protected void onStart() {
super.onStart();

initDrawer();
}

/**
* Initialise a fragment
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
package com.shalzz.attendance.ui.settings;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceScreen;

import com.bugsnag.android.Bugsnag;
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.shalzz.attendance.BuildConfig;
import com.shalzz.attendance.R;
Expand All @@ -35,8 +37,6 @@
import javax.inject.Inject;
import javax.inject.Named;

import de.psdev.licensesdialog.LicensesDialog;

public class AboutSettingsFragment extends PreferenceFragmentCompat {

private MainActivity mainActivity;
Expand All @@ -50,12 +50,16 @@ public class AboutSettingsFragment extends PreferenceFragmentCompat {

@Override
public void onCreatePreferences(Bundle bundle, String s) {
((MainActivity) getActivity()).activityComponent().inject(this);
Bugsnag.setContext("About");
addPreferencesFromResource(R.xml.pref_about);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
mainActivity = ((MainActivity) getActivity());
mainActivity.activityComponent().inject(this);
mainActivity.setDrawerAsUp(true);

addPreferencesFromResource(R.xml.pref_about);
super.onActivityCreated(savedInstanceState);
}

@Override
Expand Down Expand Up @@ -84,34 +88,9 @@ public void onResume() {
return true;
});

// Preference pref = prefScreen.getPreference(index++);
// pref.setOnPreferenceClickListener(preference -> {
// final String name = getString(R.string.app_name);
// final String url = getString(R.string.app_url);
// final String copyright = getString(R.string.copyright_year) + " "
// + getString(R.string.app_copyright);
// final License license = new GnuGeneralPublicLicense20();
// final Notice notice = new Notice(name, url, copyright, license);
// new LicensesDialog.Builder(mContext)
// .setNotices(notice)
// .setShowFullLicenseText(true)
// .build()
// .show();
//
// mTracker.send(new HitBuilders.EventBuilder()
// .setCategory("Click")
// .setAction("License")
// .build());
// return true;
// });

Preference noticePref = prefScreen.getPreference(index++);
noticePref.setOnPreferenceClickListener(preference -> {
new LicensesDialog.Builder(mContext)
.setNotices(R.raw.notices)
.setIncludeOwnLicense(true)
.build()
.show();
startActivity(new Intent(mContext, OssLicensesMenuActivity.class));

Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, getString(R.string.pref_key_info_notices));
Expand Down
Loading

0 comments on commit b27e95e

Please sign in to comment.