Permalink
Browse files

added NotificationProvider

  • Loading branch information...
avalax committed Feb 18, 2018
1 parent c3fafc9 commit d2cb855051d0bf04fe5394066076161026d31a6a
Showing with 340 additions and 39 deletions.
  1. BIN doc/prototype.epgz
  2. BIN doc/prototype/support.png
  3. +11 −1 proguard.cfg
  4. +9 −8 src/androidTest/java/de/avalax/fitbuddy/FitbuddyAcceptanceTest.java
  5. +11 −3 src/androidTest/java/de/avalax/fitbuddy/runner/ApplicationRunner.java
  6. +16 −0 src/androidTest/java/de/avalax/fitbuddy/runner/BillingRunner.java
  7. +0 −1 src/androidTest/java/de/avalax/fitbuddy/runner/FitbuddyActivityTestRule.java
  8. +29 −0 src/androidTest/java/de/avalax/fitbuddy/runner/FitbuddyTestModule.java
  9. +5 −2 src/androidTest/java/de/avalax/fitbuddy/runner/TestFitbuddyApplication.java
  10. +1 −0 src/main/AndroidManifest.xml
  11. +2 −0 src/main/java/de/avalax/fitbuddy/application/billing/BillingProvider.java
  12. +5 −0 src/main/java/de/avalax/fitbuddy/application/billing/NotificationProvider.java
  13. +20 −1 src/main/java/de/avalax/fitbuddy/port/adapter/service/billing/GooglePlayBillingProvider.java
  14. +46 −0 src/main/java/de/avalax/fitbuddy/port/adapter/service/billing/HttpNotificationProvider.java
  15. +15 −11 src/main/java/de/avalax/fitbuddy/presentation/FitbuddyModule.java
  16. +21 −9 src/main/java/de/avalax/fitbuddy/presentation/MainActivity.java
  17. +58 −0 src/main/java/de/avalax/fitbuddy/presentation/dialog/SupportDialogFragment.java
  18. +32 −0 src/main/res/layout/fragment_support.xml
  19. +3 −1 src/main/res/values/strings.xml
  20. +29 −2 src/test/java/de/avalax/fitbuddy/port/adapter/service/billing/GooglePlayBillingProviderTest.java
  21. +27 −0 src/test/java/de/avalax/fitbuddy/port/adapter/service/billing/HttpNotificationProviderTest.java
BIN +24 Bytes (100%) doc/prototype.epgz
Binary file not shown.
BIN -71 Bytes (100%) doc/prototype/support.png
Binary file not shown.
@@ -76,4 +76,14 @@
# Dagger
-dontwarn dagger.internal.codegen.**
-dontwarn javax.annotation.**
-keep public class de.avalax.fitbuddy.presentation.** { *; }
-keep public class de.avalax.fitbuddy.presentation.** { *; }
# Retrofit2
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
@@ -16,6 +16,7 @@
import de.avalax.fitbuddy.domain.model.workout.Workout;
import de.avalax.fitbuddy.presentation.MainActivity;
import de.avalax.fitbuddy.runner.ApplicationRunner;
import de.avalax.fitbuddy.runner.BillingRunner;
import de.avalax.fitbuddy.runner.FitbuddyActivityTestRule;
import de.avalax.fitbuddy.runner.PersistenceRunner;
@@ -29,6 +30,7 @@
private ApplicationRunner application;
private PersistenceRunner persistence;
private BillingRunner billing;
@Rule
public FitbuddyActivityTestRule activityRule = new FitbuddyActivityTestRule(MainActivity.class);
@@ -37,6 +39,7 @@
public void setUp() throws Exception {
application = new ApplicationRunner();
persistence = new PersistenceRunner(activityRule);
billing = new BillingRunner(activityRule);
}
@Test
@@ -419,22 +422,20 @@ public void paidApp_shouldNotShowAds() throws Exception {
}
@Test
public void reclaimPaidStatus_shouldNotShowAds() throws Exception {
public void supportFitbuddy_shouldSetSharedPropertyAndNotify() throws Exception {
BasicSetBuilder set = aSet().withWeight(42).withMaxReps(12);
BasicExerciseBuilder exercise = anExercise().withName("an exercise").withSet(set);
BasicWorkoutBuilder workout = aWorkout().withName("a workout").withExercise(exercise);
Workout persistedWorkout = persistence.addWorkout(workout);
persistence.finishWorkout(persistedWorkout);
activityRule.launchActivity(null);
application.doPayment();
application.showSupportDiablog();
application.hasShownSupportDialog();
application.showsSuccessfulPaymentMessage();
application.notDisplayAdMob();
application.navigateToSummary();
application.notDisplayAdMob();
application.navigateToStart();
application.notDisplayAdMob();
application.support();
application.showsPaymentMessage();
billing.hasNotificationSend();
}
@After
@@ -406,12 +406,20 @@ public void showsFinishedExerciseDetail(int position, String name, String sets)
.check(matches(itemAtPosition(position, withText(sets), R.id.item_subtitle)));
}
public void doPayment() {
public void showSupportDiablog() {
onView(withId(R.id.toolbar_support)).perform(click());
}
public void showsSuccessfulPaymentMessage() {
onView(withText(R.string.message_app_purchased)).inRoot(isToast()).check(matches(isDisplayed()));
public void showsPaymentMessage() {
onView(withText(R.string.message_payment_available_soon)).inRoot(isToast()).check(matches(isDisplayed()));
}
public void hasShownSupportDialog() {
onView(withText(R.string.dialog_support)).check(matches(isDisplayed()));
}
public void support() {
onView(withId(R.id.button_support)).perform(click());
}
private static ViewAction setNumberPicker(final int value) {
@@ -0,0 +1,16 @@
package de.avalax.fitbuddy.runner;
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
public class BillingRunner {
private FitbuddyActivityTestRule activityRule;
public BillingRunner(FitbuddyActivityTestRule activityRule) {
this.activityRule = activityRule;
}
public void hasNotificationSend() {
assertThat(activityRule.billingProvider.hasNotificationSend(), equalTo(true));
}
}
@@ -4,7 +4,6 @@
import javax.inject.Inject;
import de.avalax.fitbuddy.application.ad_mod.AdMobProvider;
import de.avalax.fitbuddy.application.billing.BillingProvider;
import de.avalax.fitbuddy.application.edit.workout.EditWorkoutService;
import de.avalax.fitbuddy.application.summary.FinishedWorkoutService;
@@ -0,0 +1,29 @@
package de.avalax.fitbuddy.runner;
import android.content.Context;
import android.content.SharedPreferences;
import de.avalax.fitbuddy.application.billing.BillingProvider;
import de.avalax.fitbuddy.port.adapter.service.billing.GooglePlayBillingProvider;
import de.avalax.fitbuddy.presentation.FitbuddyModule;
public class FitbuddyTestModule extends FitbuddyModule {
private Context context;
public FitbuddyTestModule(Context context) {
super(context);
this.context = context;
}
@Override
public BillingProvider provideBillingProvider() {
return new GooglePlayBillingProvider(context, notificationProvider) {
@Override
public void sendNotification() {
SharedPreferences preferences = context.getSharedPreferences("fitbuddy", Context.MODE_PRIVATE);
preferences.edit().putBoolean("notification_send", true).apply();
}
};
}
}
@@ -1,17 +1,20 @@
package de.avalax.fitbuddy.runner;
import android.content.Context;
import javax.inject.Singleton;
import dagger.Component;
import dagger.Module;
import de.avalax.fitbuddy.presentation.DaggerFitbuddyApplication_ApplicationComponent;
import de.avalax.fitbuddy.presentation.FitbuddyApplication;
import de.avalax.fitbuddy.presentation.FitbuddyModule;
public class TestFitbuddyApplication extends FitbuddyApplication {
@Override
protected ApplicationComponent createComponent() {
return DaggerTestFitbuddyApplication_TestComponent.builder()
.fitbuddyModule(new FitbuddyModule(this)).build();
return DaggerTestFitbuddyApplication_TestComponent.builder().fitbuddyModule(new FitbuddyTestModule(this)).build();
}
@Singleton
@@ -3,6 +3,7 @@
package="de.avalax.fitbuddy"
android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
@@ -3,4 +3,6 @@
public interface BillingProvider {
boolean isPaid();
void purchase();
int sendNotification();
boolean hasNotificationSend();
}
@@ -0,0 +1,5 @@
package de.avalax.fitbuddy.application.billing;
public interface NotificationProvider {
int sendNotification();
}
@@ -3,13 +3,18 @@
import android.content.Context;
import android.content.SharedPreferences;
import java.net.HttpURLConnection;
import de.avalax.fitbuddy.application.billing.BillingProvider;
import de.avalax.fitbuddy.application.billing.NotificationProvider;
public class GooglePlayBillingProvider implements BillingProvider {
private SharedPreferences preferences;
private final NotificationProvider notificationProvider;
public GooglePlayBillingProvider(Context context) {
public GooglePlayBillingProvider(Context context, NotificationProvider notificationProvider) {
preferences = context.getSharedPreferences("fitbuddy", Context.MODE_PRIVATE);
this.notificationProvider = notificationProvider;
}
@Override
@@ -21,4 +26,18 @@ public boolean isPaid() {
public void purchase() {
preferences.edit().putBoolean("paid", true).apply();
}
@Override
public int sendNotification() {
int statusCode = notificationProvider.sendNotification();
if (statusCode == HttpURLConnection.HTTP_CREATED) {
preferences.edit().putBoolean("notification_send", true).apply();
}
return statusCode;
}
@Override
public boolean hasNotificationSend() {
return preferences.getBoolean("notification_send", false);
}
}
@@ -0,0 +1,46 @@
package de.avalax.fitbuddy.port.adapter.service.billing;
import android.util.Base64;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import de.avalax.fitbuddy.application.billing.NotificationProvider;
public class HttpNotificationProvider implements NotificationProvider {
private String appName;
public HttpNotificationProvider(String appName) {
this.appName = appName;
}
@Override
public int sendNotification() {
try {
URL url = new URL("http://silex.avalax.de/insights");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(15000);
connection.setConnectTimeout(15000);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Authorization", "Basic " + getAuth());
try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
String params = "name=" + appName;
wr.write(params.getBytes());
}
return connection.getResponseCode();
} catch (IOException e) {
return HttpURLConnection.HTTP_UNAVAILABLE;
}
}
private String getAuth() {
String userPassword = appName + ":" + appName;
return Base64.encodeToString(userPassword.getBytes(), Base64.NO_WRAP);
}
}
@@ -12,6 +12,7 @@
import de.avalax.fitbuddy.R;
import de.avalax.fitbuddy.application.ad_mod.AdMobProvider;
import de.avalax.fitbuddy.application.billing.BillingProvider;
import de.avalax.fitbuddy.application.billing.NotificationProvider;
import de.avalax.fitbuddy.application.edit.workout.EditWorkoutService;
import de.avalax.fitbuddy.application.summary.FinishedWorkoutService;
import de.avalax.fitbuddy.application.workout.WorkoutService;
@@ -31,6 +32,7 @@
import de.avalax.fitbuddy.port.adapter.persistence.SQLiteWorkoutRepository;
import de.avalax.fitbuddy.port.adapter.service.ad_mob.GmsAdMobProvider;
import de.avalax.fitbuddy.port.adapter.service.billing.GooglePlayBillingProvider;
import de.avalax.fitbuddy.port.adapter.service.billing.HttpNotificationProvider;
import de.avalax.fitbuddy.presentation.edit.exercise.EditExerciseViewHelper;
import de.avalax.fitbuddy.presentation.edit.workout.EditWorkoutViewHelper;
import de.avalax.fitbuddy.presentation.helper.ExerciseViewHelper;
@@ -43,6 +45,7 @@
private final Context context;
private final WorkoutRepository workoutRepository;
private final FinishedWorkoutRepository finishedWorkoutRepository;
private final NotificationProvider notificationProvider;
public FitbuddyModule(Context context) {
this.context = context;
@@ -58,69 +61,70 @@ public FitbuddyModule(Context context) {
= new SQLiteFinishedExerciseRepository(sqLiteOpenHelper, finishedSetRepository);
finishedWorkoutRepository = new SQLiteFinishedWorkoutRepository(
sqLiteOpenHelper, finishedExerciseRepository);
notificationProvider = new HttpNotificationProvider("fitbuddy");
}
@Provides
@Singleton
WorkoutService provideWorkoutService() {
public WorkoutService provideWorkoutService() {
return new WorkoutService(
workoutSession,
finishedWorkoutRepository);
}
@Provides
@Singleton
FinishedWorkoutService provideFinishedWorkoutService() {
public FinishedWorkoutService provideFinishedWorkoutService() {
return new FinishedWorkoutService(finishedWorkoutRepository);
}
@Provides
@Singleton
ExerciseViewHelper provideExerciseViewHelper() {
public ExerciseViewHelper provideExerciseViewHelper() {
Locale locale = context.getResources().getConfiguration().locale;
return new ExerciseViewHelper(context, locale);
}
@Provides
@Singleton
EditWorkoutService provideManageWorkout() {
public EditWorkoutService provideManageWorkout() {
return new EditWorkoutService(
workoutRepository);
}
@Provides
@Singleton
EditWorkoutViewHelper provideEditWorkoutViewHelper(EditExerciseViewHelper editExerciseViewHelper) {
public EditWorkoutViewHelper provideEditWorkoutViewHelper(EditExerciseViewHelper editExerciseViewHelper) {
return new EditWorkoutViewHelper(context, editExerciseViewHelper);
}
@Provides
@Singleton
FinishedWorkoutViewHelper provideFinishedWorkoutViewHelper() {
public FinishedWorkoutViewHelper provideFinishedWorkoutViewHelper() {
return new FinishedWorkoutViewHelper(context, finishedWorkoutRepository);
}
@Provides
@Singleton
FinishedExerciseViewHelper provideFinishedExerciseViewHelper() {
public FinishedExerciseViewHelper provideFinishedExerciseViewHelper() {
return new FinishedExerciseViewHelper();
}
@Provides
@Singleton
EditExerciseViewHelper provideEditExerciseViewHelper() {
public EditExerciseViewHelper provideEditExerciseViewHelper() {
return new EditExerciseViewHelper(context);
}
@Provides
@Singleton
BillingProvider provideBillingProvider() {
return new GooglePlayBillingProvider(context);
public BillingProvider provideBillingProvider() {
return new GooglePlayBillingProvider(context, notificationProvider);
}
@Provides
@Singleton
AdMobProvider provideAdMobProvider(BillingProvider billingProvider) {
public AdMobProvider provideAdMobProvider(BillingProvider billingProvider) {
return new GmsAdMobProvider(billingProvider);
}
Oops, something went wrong.

0 comments on commit d2cb855

Please sign in to comment.