From 57795eaec14ec8180bb1f477ade2a91bc8e0a785 Mon Sep 17 00:00:00 2001 From: Sajal Narang Date: Fri, 26 May 2017 15:29:13 +0530 Subject: [PATCH 1/5] Shorten share URLs --- app/build.gradle | 2 + .../android/api/FirebaseDynamicLinksHub.java | 20 ++++++ .../api/FirebaseDynamicLinksHubFactory.java | 34 ++++++++++ .../model/FirebaseDynamicLinksResponse.java | 31 ++++++++++ .../java/org/gdg/frisbee/android/app/App.java | 10 +++ .../onboarding/AppInviteLinkGenerator.java | 62 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 7 files changed, 148 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java create mode 100644 app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHubFactory.java create mode 100644 app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksResponse.java diff --git a/app/build.gradle b/app/build.gradle index e43ba9469..c94678219 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -66,6 +66,7 @@ android { buildConfigField "String", "IP_SIMPLE_API_ACCESS_KEY", "\"$local_properties.ip_simple_api_access_key\"" buildConfigField "String", "ANDROID_SIMPLE_API_ACCESS_KEY", "\"$local_properties.android_simple_api_access_key\"" + buildConfigField "String", "FIREBASE_WEB_API_KEY", "\"$local_properties.firebase_web_api_key\"" resValue "string", "android_simple_api_access_key", local_properties.android_simple_api_access_key ?: "" resValue "string", "authority", "org.gdg.frisbee.android.provider" } @@ -78,6 +79,7 @@ android { buildConfigField "String", "IP_SIMPLE_API_ACCESS_KEY", "\"$local_properties.ip_simple_api_access_key_debug\"" buildConfigField "String", "ANDROID_SIMPLE_API_ACCESS_KEY", "\"$local_properties.android_simple_api_access_key_debug\"" + buildConfigField "String", "FIREBASE_WEB_API_KEY", "\"$local_properties.firebase_web_api_key_debug\"" resValue "string", "android_simple_api_access_key", local_properties.android_simple_api_access_key_debug ?: "" resValue "string", "authority", "org.gdg.frisbee.android.debug.provider" } diff --git a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java new file mode 100644 index 000000000..02b7b4249 --- /dev/null +++ b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java @@ -0,0 +1,20 @@ +package org.gdg.frisbee.android.api; + +import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksResponse; + +import retrofit2.Call; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.POST; +import retrofit2.http.Query; + +/** + * Created by unstablebrainiac on 26/5/17. + */ + +public interface FirebaseDynamicLinksHub { + + @FormUrlEncoded + @POST("/v1/shortLinks") + Call getShortenedUrl(@Query("key") String api_key, @Field("longDynamicLink") String long_dynamic_url); +} diff --git a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHubFactory.java b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHubFactory.java new file mode 100644 index 000000000..92efc7994 --- /dev/null +++ b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHubFactory.java @@ -0,0 +1,34 @@ +package org.gdg.frisbee.android.api; + +import com.google.gson.FieldNamingPolicy; + +import org.gdg.frisbee.android.utils.Utils; + +import okhttp3.OkHttpClient; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +/** + * Created by unstablebrainiac on 26/5/17. + */ + +public final class FirebaseDynamicLinksHubFactory { + private static final String BASE_URL = "https://firebasedynamiclinks.googleapis.com"; + + private FirebaseDynamicLinksHubFactory() { + } + + private static Retrofit provideRestAdapter(OkHttpClient okHttpClient) { + return new Retrofit.Builder() + .baseUrl(BASE_URL) + .client(okHttpClient) + .addConverterFactory( + GsonConverterFactory.create(Utils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)) + ) + .build(); + } + + public static FirebaseDynamicLinksHub provideFirebaseDynamicLinksApi(OkHttpClient okHttpClient) { + return provideRestAdapter(okHttpClient).create(FirebaseDynamicLinksHub.class); + } +} diff --git a/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksResponse.java b/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksResponse.java new file mode 100644 index 000000000..7fe4b28d3 --- /dev/null +++ b/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksResponse.java @@ -0,0 +1,31 @@ +package org.gdg.frisbee.android.api.model; + +/** + * Created by unstablebrainiac on 26/5/17. + */ + +public class FirebaseDynamicLinksResponse { + private String shortLink; + private String previewLink; + + public FirebaseDynamicLinksResponse(String shortLink, String previewLink) { + this.shortLink = shortLink; + this.previewLink = previewLink; + } + + public String getShortLink() { + return shortLink; + } + + public void setShortLink(String shortLink) { + this.shortLink = shortLink; + } + + public String getPreviewLink() { + return previewLink; + } + + public void setPreviewLink(String previewLink) { + this.previewLink = previewLink; + } +} diff --git a/app/src/main/java/org/gdg/frisbee/android/app/App.java b/app/src/main/java/org/gdg/frisbee/android/app/App.java index 5d868ba22..82f876708 100644 --- a/app/src/main/java/org/gdg/frisbee/android/app/App.java +++ b/app/src/main/java/org/gdg/frisbee/android/app/App.java @@ -34,6 +34,8 @@ import org.gdg.frisbee.android.BuildConfig; import org.gdg.frisbee.android.R; +import org.gdg.frisbee.android.api.FirebaseDynamicLinksHub; +import org.gdg.frisbee.android.api.FirebaseDynamicLinksHubFactory; import org.gdg.frisbee.android.api.GdeDirectory; import org.gdg.frisbee.android.api.GdeDirectoryFactory; import org.gdg.frisbee.android.api.GdgXHub; @@ -78,6 +80,7 @@ public class App extends BaseApp implements LocationListener { private OrganizerChecker mOrganizerChecker; private List mTaggedEventSeriesList; private RefWatcher refWatcher; + private FirebaseDynamicLinksHub firebaseDynamicLinksHub; public static App from(Context context) { return (App) context.getApplicationContext(); @@ -296,6 +299,13 @@ public PlusApi getPlusApi() { return plusApi; } + public FirebaseDynamicLinksHub getFirebaseDynamicLinksHub() { + if (firebaseDynamicLinksHub == null) { + firebaseDynamicLinksHub = FirebaseDynamicLinksHubFactory.provideFirebaseDynamicLinksApi(okHttpClient); + } + return firebaseDynamicLinksHub; + } + public RefWatcher getRefWatcher() { return refWatcher; } diff --git a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java index 3680927ee..b47b3a7cc 100644 --- a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java +++ b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java @@ -1,9 +1,14 @@ package org.gdg.frisbee.android.onboarding; +import android.app.ProgressDialog; import android.support.v4.app.ShareCompat; import org.gdg.frisbee.android.BuildConfig; import org.gdg.frisbee.android.R; +import org.gdg.frisbee.android.api.Callback; +import org.gdg.frisbee.android.api.FirebaseDynamicLinksHub; +import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksResponse; +import org.gdg.frisbee.android.app.App; import org.gdg.frisbee.android.common.GdgActivity; import org.gdg.frisbee.android.utils.PlusUtils; @@ -16,31 +21,40 @@ public class AppInviteLinkGenerator { private final String dynamicLinkDomain; private final String deepLinkBaseUrl; + private GdgActivity activity; + private ProgressDialog shareProgressDialog; static String extractSender(HttpUrl httpUrl) { return httpUrl.queryParameter(SENDER); } - public static AppInviteLinkGenerator create() { - return new AppInviteLinkGenerator("https://fmec6.app.goo.gl/", "https://gdg.events/"); + public static AppInviteLinkGenerator create(GdgActivity activity) { + return new AppInviteLinkGenerator("https://fmec6.app.goo.gl/", "https://gdg.events/", activity); } - private AppInviteLinkGenerator(String dynamicLinkDomain, String deepLinkBaseUrl) { + private AppInviteLinkGenerator(String dynamicLinkDomain, String deepLinkBaseUrl, GdgActivity activity) { this.dynamicLinkDomain = dynamicLinkDomain; this.deepLinkBaseUrl = deepLinkBaseUrl; + this.activity = activity; } public static void shareAppInviteLink(GdgActivity activity) { - AppInviteLinkGenerator linkGenerator = create(); + AppInviteLinkGenerator linkGenerator = create(activity); String gplusId = PlusUtils.getCurrentPlusId(activity); - HttpUrl appInviteLink = gplusId != null - ? linkGenerator.createAppInviteLink(gplusId) - : NON_SIGNED_IN_INVITE_URL; - ShareCompat.IntentBuilder.from(activity) - .setChooserTitle(R.string.invite_friends) - .setText(activity.getString(R.string.invitation_message, appInviteLink)) - .setType("text/plain") - .startChooser(); + HttpUrl appInviteLink; + if (gplusId != null) { + appInviteLink = linkGenerator.createAppInviteLink(gplusId); + linkGenerator.shareShortAppInviteLink(appInviteLink.toString()); + linkGenerator.shareProgressDialog = new ProgressDialog(activity); + linkGenerator.shareProgressDialog.setIndeterminate(true); + linkGenerator.shareProgressDialog.setCancelable(true); + linkGenerator.shareProgressDialog.setMessage(activity.getString(R.string.generating_url)); + linkGenerator.shareProgressDialog.show(); + } else { + appInviteLink = NON_SIGNED_IN_INVITE_URL; + linkGenerator.createChooser(appInviteLink); + } + activity.sendAnalyticsEvent("AppInvite", "Shared", gplusId != null ? "Signed In" : "Non Signed In"); @@ -63,4 +77,28 @@ private String createDeepLink(String gplusId) { .toString(); } + private void shareShortAppInviteLink(String longUrl) { + FirebaseDynamicLinksHub firebaseDynamicLinksHub = App.from(activity).getFirebaseDynamicLinksHub(); + firebaseDynamicLinksHub.getShortenedUrl(BuildConfig.FIREBASE_WEB_API_KEY, longUrl).enqueue(new Callback() { + @Override + public void onSuccess(FirebaseDynamicLinksResponse response) { + createChooser(HttpUrl.parse(response.getShortLink())); + shareProgressDialog.dismiss(); + } + + @Override + public void onError() { + createChooser(NON_SIGNED_IN_INVITE_URL); + shareProgressDialog.dismiss(); + } + }); + } + + private void createChooser(HttpUrl appInviteLink) { + ShareCompat.IntentBuilder.from(activity) + .setChooserTitle(R.string.invite_friends) + .setText(activity.getString(R.string.invitation_message, appInviteLink)) + .setType("text/plain") + .startChooser(); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b9a3b289d..5c839d014 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -174,4 +174,5 @@ Yey! You\'re invited by\n%s a friend Login/Register + Generating URL From 7e608d2af8e75c239f5af25d5f81094f05678ff7 Mon Sep 17 00:00:00 2001 From: Sajal Narang Date: Fri, 26 May 2017 16:48:03 +0530 Subject: [PATCH 2/5] Add SHORT param --- .../org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java | 4 +++- .../frisbee/android/onboarding/AppInviteLinkGenerator.java | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java index 02b7b4249..5e5e717ca 100644 --- a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java +++ b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java @@ -2,7 +2,9 @@ import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksResponse; +import okhttp3.RequestBody; import retrofit2.Call; +import retrofit2.http.Body; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.POST; @@ -16,5 +18,5 @@ public interface FirebaseDynamicLinksHub { @FormUrlEncoded @POST("/v1/shortLinks") - Call getShortenedUrl(@Query("key") String api_key, @Field("longDynamicLink") String long_dynamic_url); + Call getShortenedUrl(@Query("key") String api_key, @Body RequestBody body); } diff --git a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java index b47b3a7cc..eea9db803 100644 --- a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java +++ b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java @@ -13,6 +13,7 @@ import org.gdg.frisbee.android.utils.PlusUtils; import okhttp3.HttpUrl; +import okhttp3.RequestBody; public class AppInviteLinkGenerator { @@ -79,7 +80,9 @@ private String createDeepLink(String gplusId) { private void shareShortAppInviteLink(String longUrl) { FirebaseDynamicLinksHub firebaseDynamicLinksHub = App.from(activity).getFirebaseDynamicLinksHub(); - firebaseDynamicLinksHub.getShortenedUrl(BuildConfig.FIREBASE_WEB_API_KEY, longUrl).enqueue(new Callback() { + String requestString = "{\"longDynamicLink\": \"" + longUrl + "\",\"suffix\": {\"option\": \"SHORT\"}}"; + RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), requestString); + firebaseDynamicLinksHub.getShortenedUrl(BuildConfig.FIREBASE_WEB_API_KEY, body).enqueue(new Callback() { @Override public void onSuccess(FirebaseDynamicLinksResponse response) { createChooser(HttpUrl.parse(response.getShortLink())); From a5276fb50faf893fc17138a5d19dcd9631b98d10 Mon Sep 17 00:00:00 2001 From: Sajal Narang Date: Mon, 29 May 2017 05:32:48 +0530 Subject: [PATCH 3/5] Align code with project conventions --- app/build.gradle | 2 -- ...inksHub.java => FirebaseDynamicLinks.java} | 11 +++----- ....java => FirebaseDynamicLinksFactory.java} | 12 +++------ .../model/FirebaseDynamicLinksRequest.java | 11 ++++++++ .../model/FirebaseDynamicLinksResponse.java | 16 ++---------- .../gdg/frisbee/android/api/model/Suffix.java | 5 ++++ .../java/org/gdg/frisbee/android/app/App.java | 14 +++++----- .../onboarding/AppInviteLinkGenerator.java | 26 +++++++++++-------- 8 files changed, 47 insertions(+), 50 deletions(-) rename app/src/main/java/org/gdg/frisbee/android/api/{FirebaseDynamicLinksHub.java => FirebaseDynamicLinks.java} (55%) rename app/src/main/java/org/gdg/frisbee/android/api/{FirebaseDynamicLinksHubFactory.java => FirebaseDynamicLinksFactory.java} (73%) create mode 100644 app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksRequest.java create mode 100644 app/src/main/java/org/gdg/frisbee/android/api/model/Suffix.java diff --git a/app/build.gradle b/app/build.gradle index c94678219..e43ba9469 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -66,7 +66,6 @@ android { buildConfigField "String", "IP_SIMPLE_API_ACCESS_KEY", "\"$local_properties.ip_simple_api_access_key\"" buildConfigField "String", "ANDROID_SIMPLE_API_ACCESS_KEY", "\"$local_properties.android_simple_api_access_key\"" - buildConfigField "String", "FIREBASE_WEB_API_KEY", "\"$local_properties.firebase_web_api_key\"" resValue "string", "android_simple_api_access_key", local_properties.android_simple_api_access_key ?: "" resValue "string", "authority", "org.gdg.frisbee.android.provider" } @@ -79,7 +78,6 @@ android { buildConfigField "String", "IP_SIMPLE_API_ACCESS_KEY", "\"$local_properties.ip_simple_api_access_key_debug\"" buildConfigField "String", "ANDROID_SIMPLE_API_ACCESS_KEY", "\"$local_properties.android_simple_api_access_key_debug\"" - buildConfigField "String", "FIREBASE_WEB_API_KEY", "\"$local_properties.firebase_web_api_key_debug\"" resValue "string", "android_simple_api_access_key", local_properties.android_simple_api_access_key_debug ?: "" resValue "string", "authority", "org.gdg.frisbee.android.debug.provider" } diff --git a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinks.java similarity index 55% rename from app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java rename to app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinks.java index 5e5e717ca..6e3b182fa 100644 --- a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHub.java +++ b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinks.java @@ -1,22 +1,17 @@ package org.gdg.frisbee.android.api; +import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksRequest; import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksResponse; import okhttp3.RequestBody; import retrofit2.Call; import retrofit2.http.Body; -import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.POST; import retrofit2.http.Query; -/** - * Created by unstablebrainiac on 26/5/17. - */ +public interface FirebaseDynamicLinks { -public interface FirebaseDynamicLinksHub { - - @FormUrlEncoded @POST("/v1/shortLinks") - Call getShortenedUrl(@Query("key") String api_key, @Body RequestBody body); + Call shortenUrl(@Query("key") String apiKey, @Body FirebaseDynamicLinksRequest firebaseDynamicLinksRequest); } diff --git a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHubFactory.java b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksFactory.java similarity index 73% rename from app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHubFactory.java rename to app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksFactory.java index 92efc7994..cd2eabd66 100644 --- a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksHubFactory.java +++ b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinksFactory.java @@ -8,14 +8,10 @@ import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; -/** - * Created by unstablebrainiac on 26/5/17. - */ - -public final class FirebaseDynamicLinksHubFactory { +public final class FirebaseDynamicLinksFactory { private static final String BASE_URL = "https://firebasedynamiclinks.googleapis.com"; - private FirebaseDynamicLinksHubFactory() { + private FirebaseDynamicLinksFactory() { } private static Retrofit provideRestAdapter(OkHttpClient okHttpClient) { @@ -28,7 +24,7 @@ private static Retrofit provideRestAdapter(OkHttpClient okHttpClient) { .build(); } - public static FirebaseDynamicLinksHub provideFirebaseDynamicLinksApi(OkHttpClient okHttpClient) { - return provideRestAdapter(okHttpClient).create(FirebaseDynamicLinksHub.class); + public static FirebaseDynamicLinks provideFirebaseDynamicLinksApi(OkHttpClient okHttpClient) { + return provideRestAdapter(okHttpClient).create(FirebaseDynamicLinks.class); } } diff --git a/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksRequest.java b/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksRequest.java new file mode 100644 index 000000000..92f1153ee --- /dev/null +++ b/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksRequest.java @@ -0,0 +1,11 @@ +package org.gdg.frisbee.android.api.model; + +public class FirebaseDynamicLinksRequest { + private String longDynamicLink; + private Suffix suffix; + + public FirebaseDynamicLinksRequest(String longDynamicLink, Suffix suffix) { + this.longDynamicLink = longDynamicLink; + this.suffix = suffix; + } +} diff --git a/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksResponse.java b/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksResponse.java index 7fe4b28d3..f6438fed8 100644 --- a/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksResponse.java +++ b/app/src/main/java/org/gdg/frisbee/android/api/model/FirebaseDynamicLinksResponse.java @@ -1,12 +1,8 @@ package org.gdg.frisbee.android.api.model; -/** - * Created by unstablebrainiac on 26/5/17. - */ - public class FirebaseDynamicLinksResponse { - private String shortLink; - private String previewLink; + private final String shortLink; + private final String previewLink; public FirebaseDynamicLinksResponse(String shortLink, String previewLink) { this.shortLink = shortLink; @@ -17,15 +13,7 @@ public String getShortLink() { return shortLink; } - public void setShortLink(String shortLink) { - this.shortLink = shortLink; - } - public String getPreviewLink() { return previewLink; } - - public void setPreviewLink(String previewLink) { - this.previewLink = previewLink; - } } diff --git a/app/src/main/java/org/gdg/frisbee/android/api/model/Suffix.java b/app/src/main/java/org/gdg/frisbee/android/api/model/Suffix.java new file mode 100644 index 000000000..4fc23b46c --- /dev/null +++ b/app/src/main/java/org/gdg/frisbee/android/api/model/Suffix.java @@ -0,0 +1,5 @@ +package org.gdg.frisbee.android.api.model; + +public class Suffix { + private final String option = "SHORT"; +} diff --git a/app/src/main/java/org/gdg/frisbee/android/app/App.java b/app/src/main/java/org/gdg/frisbee/android/app/App.java index 82f876708..aa48a21de 100644 --- a/app/src/main/java/org/gdg/frisbee/android/app/App.java +++ b/app/src/main/java/org/gdg/frisbee/android/app/App.java @@ -34,8 +34,8 @@ import org.gdg.frisbee.android.BuildConfig; import org.gdg.frisbee.android.R; -import org.gdg.frisbee.android.api.FirebaseDynamicLinksHub; -import org.gdg.frisbee.android.api.FirebaseDynamicLinksHubFactory; +import org.gdg.frisbee.android.api.FirebaseDynamicLinks; +import org.gdg.frisbee.android.api.FirebaseDynamicLinksFactory; import org.gdg.frisbee.android.api.GdeDirectory; import org.gdg.frisbee.android.api.GdeDirectoryFactory; import org.gdg.frisbee.android.api.GdgXHub; @@ -80,7 +80,7 @@ public class App extends BaseApp implements LocationListener { private OrganizerChecker mOrganizerChecker; private List mTaggedEventSeriesList; private RefWatcher refWatcher; - private FirebaseDynamicLinksHub firebaseDynamicLinksHub; + private FirebaseDynamicLinks firebaseDynamicLinks; public static App from(Context context) { return (App) context.getApplicationContext(); @@ -299,11 +299,11 @@ public PlusApi getPlusApi() { return plusApi; } - public FirebaseDynamicLinksHub getFirebaseDynamicLinksHub() { - if (firebaseDynamicLinksHub == null) { - firebaseDynamicLinksHub = FirebaseDynamicLinksHubFactory.provideFirebaseDynamicLinksApi(okHttpClient); + public FirebaseDynamicLinks getFirebaseDynamicLinks() { + if (firebaseDynamicLinks == null) { + firebaseDynamicLinks = FirebaseDynamicLinksFactory.provideFirebaseDynamicLinksApi(okHttpClient); } - return firebaseDynamicLinksHub; + return firebaseDynamicLinks; } public RefWatcher getRefWatcher() { diff --git a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java index eea9db803..8d5c88700 100644 --- a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java +++ b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java @@ -6,14 +6,15 @@ import org.gdg.frisbee.android.BuildConfig; import org.gdg.frisbee.android.R; import org.gdg.frisbee.android.api.Callback; -import org.gdg.frisbee.android.api.FirebaseDynamicLinksHub; +import org.gdg.frisbee.android.api.FirebaseDynamicLinks; +import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksRequest; import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksResponse; +import org.gdg.frisbee.android.api.model.Suffix; import org.gdg.frisbee.android.app.App; import org.gdg.frisbee.android.common.GdgActivity; import org.gdg.frisbee.android.utils.PlusUtils; import okhttp3.HttpUrl; -import okhttp3.RequestBody; public class AppInviteLinkGenerator { @@ -46,11 +47,7 @@ public static void shareAppInviteLink(GdgActivity activity) { if (gplusId != null) { appInviteLink = linkGenerator.createAppInviteLink(gplusId); linkGenerator.shareShortAppInviteLink(appInviteLink.toString()); - linkGenerator.shareProgressDialog = new ProgressDialog(activity); - linkGenerator.shareProgressDialog.setIndeterminate(true); - linkGenerator.shareProgressDialog.setCancelable(true); - linkGenerator.shareProgressDialog.setMessage(activity.getString(R.string.generating_url)); - linkGenerator.shareProgressDialog.show(); + linkGenerator.showProgressDialog(activity); } else { appInviteLink = NON_SIGNED_IN_INVITE_URL; linkGenerator.createChooser(appInviteLink); @@ -79,10 +76,9 @@ private String createDeepLink(String gplusId) { } private void shareShortAppInviteLink(String longUrl) { - FirebaseDynamicLinksHub firebaseDynamicLinksHub = App.from(activity).getFirebaseDynamicLinksHub(); - String requestString = "{\"longDynamicLink\": \"" + longUrl + "\",\"suffix\": {\"option\": \"SHORT\"}}"; - RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), requestString); - firebaseDynamicLinksHub.getShortenedUrl(BuildConfig.FIREBASE_WEB_API_KEY, body).enqueue(new Callback() { + FirebaseDynamicLinks firebaseDynamicLinks = App.from(activity).getFirebaseDynamicLinks(); + FirebaseDynamicLinksRequest firebaseDynamicLinksRequest = new FirebaseDynamicLinksRequest(longUrl, new Suffix()); + firebaseDynamicLinks.shortenUrl(BuildConfig.IP_SIMPLE_API_ACCESS_KEY, firebaseDynamicLinksRequest).enqueue(new Callback() { @Override public void onSuccess(FirebaseDynamicLinksResponse response) { createChooser(HttpUrl.parse(response.getShortLink())); @@ -97,6 +93,14 @@ public void onError() { }); } + private void showProgressDialog(GdgActivity activity) { + shareProgressDialog = new ProgressDialog(activity); + shareProgressDialog.setIndeterminate(true); + shareProgressDialog.setCancelable(true); + shareProgressDialog.setMessage(activity.getString(R.string.generating_url)); + shareProgressDialog.show(); + } + private void createChooser(HttpUrl appInviteLink) { ShareCompat.IntentBuilder.from(activity) .setChooserTitle(R.string.invite_friends) From 5137f049877a8d877c6844d3b5f85de9b73ddd20 Mon Sep 17 00:00:00 2001 From: Sajal Date: Sat, 24 Nov 2018 13:39:44 +0530 Subject: [PATCH 4/5] Make style changes to align with repository conventions --- .../org/gdg/frisbee/android/api/FirebaseDynamicLinks.java | 5 ++--- .../frisbee/android/onboarding/AppInviteLinkGenerator.java | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinks.java b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinks.java index 6e3b182fa..9e5486493 100644 --- a/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinks.java +++ b/app/src/main/java/org/gdg/frisbee/android/api/FirebaseDynamicLinks.java @@ -3,15 +3,14 @@ import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksRequest; import org.gdg.frisbee.android.api.model.FirebaseDynamicLinksResponse; -import okhttp3.RequestBody; import retrofit2.Call; import retrofit2.http.Body; -import retrofit2.http.FormUrlEncoded; import retrofit2.http.POST; import retrofit2.http.Query; public interface FirebaseDynamicLinks { @POST("/v1/shortLinks") - Call shortenUrl(@Query("key") String apiKey, @Body FirebaseDynamicLinksRequest firebaseDynamicLinksRequest); + Call shortenUrl(@Query("key") String apiKey, + @Body FirebaseDynamicLinksRequest firebaseDynamicLinksRequest); } diff --git a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java index 8d5c88700..84409e733 100644 --- a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java +++ b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java @@ -77,8 +77,10 @@ private String createDeepLink(String gplusId) { private void shareShortAppInviteLink(String longUrl) { FirebaseDynamicLinks firebaseDynamicLinks = App.from(activity).getFirebaseDynamicLinks(); - FirebaseDynamicLinksRequest firebaseDynamicLinksRequest = new FirebaseDynamicLinksRequest(longUrl, new Suffix()); - firebaseDynamicLinks.shortenUrl(BuildConfig.IP_SIMPLE_API_ACCESS_KEY, firebaseDynamicLinksRequest).enqueue(new Callback() { + FirebaseDynamicLinksRequest firebaseDynamicLinksRequest = + new FirebaseDynamicLinksRequest(longUrl, new Suffix()); + firebaseDynamicLinks.shortenUrl(BuildConfig.IP_SIMPLE_API_ACCESS_KEY, firebaseDynamicLinksRequest) + .enqueue(new Callback() { @Override public void onSuccess(FirebaseDynamicLinksResponse response) { createChooser(HttpUrl.parse(response.getShortLink())); From 68ef1b43924e4f9902138c533c2b69fa0900693e Mon Sep 17 00:00:00 2001 From: Sajal Date: Sat, 24 Nov 2018 13:48:45 +0530 Subject: [PATCH 5/5] Fix indentation issues --- .../onboarding/AppInviteLinkGenerator.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java index 84409e733..4466bd346 100644 --- a/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java +++ b/app/src/main/java/org/gdg/frisbee/android/onboarding/AppInviteLinkGenerator.java @@ -26,6 +26,12 @@ public class AppInviteLinkGenerator { private GdgActivity activity; private ProgressDialog shareProgressDialog; + private AppInviteLinkGenerator(String dynamicLinkDomain, String deepLinkBaseUrl, GdgActivity activity) { + this.dynamicLinkDomain = dynamicLinkDomain; + this.deepLinkBaseUrl = deepLinkBaseUrl; + this.activity = activity; + } + static String extractSender(HttpUrl httpUrl) { return httpUrl.queryParameter(SENDER); } @@ -34,12 +40,6 @@ public static AppInviteLinkGenerator create(GdgActivity activity) { return new AppInviteLinkGenerator("https://fmec6.app.goo.gl/", "https://gdg.events/", activity); } - private AppInviteLinkGenerator(String dynamicLinkDomain, String deepLinkBaseUrl, GdgActivity activity) { - this.dynamicLinkDomain = dynamicLinkDomain; - this.deepLinkBaseUrl = deepLinkBaseUrl; - this.activity = activity; - } - public static void shareAppInviteLink(GdgActivity activity) { AppInviteLinkGenerator linkGenerator = create(activity); String gplusId = PlusUtils.getCurrentPlusId(activity); @@ -81,18 +81,18 @@ private void shareShortAppInviteLink(String longUrl) { new FirebaseDynamicLinksRequest(longUrl, new Suffix()); firebaseDynamicLinks.shortenUrl(BuildConfig.IP_SIMPLE_API_ACCESS_KEY, firebaseDynamicLinksRequest) .enqueue(new Callback() { - @Override - public void onSuccess(FirebaseDynamicLinksResponse response) { - createChooser(HttpUrl.parse(response.getShortLink())); - shareProgressDialog.dismiss(); - } - - @Override - public void onError() { - createChooser(NON_SIGNED_IN_INVITE_URL); - shareProgressDialog.dismiss(); - } - }); + @Override + public void onSuccess(FirebaseDynamicLinksResponse response) { + createChooser(HttpUrl.parse(response.getShortLink())); + shareProgressDialog.dismiss(); + } + + @Override + public void onError() { + createChooser(NON_SIGNED_IN_INVITE_URL); + shareProgressDialog.dismiss(); + } + }); } private void showProgressDialog(GdgActivity activity) {