Panagiotis Triantafyllou

feedback fixes

......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4.6rc72'
PUBLISH_VERSION = '4.5.4.6rc73'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -86,6 +86,10 @@ public class ActiveGiftsActivity extends Activity implements View.OnClickListene
mAdapterMergedActiveGifts.getPositionClicks()
.doOnNext(dataItem -> {
if (dataItem.getDataType() == 1) {
if (!WarplyManagerHelper.noInternetDialog(ActiveGiftsActivity.this, true)) {
WarplyManagerHelper.noInternetDialog(ActiveGiftsActivity.this);
return;
}
startActivity(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())));
} else if (dataItem.getDataType() == 2) {
Intent intent = new Intent(ActiveGiftsActivity.this, CouponInfoActivity.class);
......
......@@ -262,6 +262,10 @@ public class GiftsForYouActivity extends AppCompatActivity implements View.OnCli
}
}
} else {
if (!WarplyManagerHelper.noInternetDialog(this, true)) {
WarplyManagerHelper.noInternetDialog(this);
return;
}
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("Loyalty").concat(":").concat(dataItem.getCampaign().getSessionUUID()));
startActivityForResult(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())), 1004);
}
......@@ -297,6 +301,10 @@ public class GiftsForYouActivity extends AppCompatActivity implements View.OnCli
}
}
} else {
if (!WarplyManagerHelper.noInternetDialog(this, true)) {
WarplyManagerHelper.noInternetDialog(this);
return;
}
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("Loyalty").concat(":").concat(dataItem.getCampaign().getSessionUUID()));
startActivityForResult(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())), 1004);
}
......@@ -334,17 +342,29 @@ public class GiftsForYouActivity extends AppCompatActivity implements View.OnCli
if (extraFields.has("ccms_offer") && extraFields.optString("ccms_offer").equals("true")) {
for (LoyaltyContextualOfferModel ccms : WarplyManagerHelper.getCCMSLoyaltyCampaigns()) {
if (ccms.getLoyaltyCampaignId().equals(dataItem.getCampaign().getSessionUUID())) {
if (!WarplyManagerHelper.noInternetDialog(this, true)) {
WarplyManagerHelper.noInternetDialog(this);
return;
}
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("Contextual").concat(":").concat(ccms.getSessionId()));
startActivityForResult(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCcmsUrl(dataItem.getCampaign(), ccms)), 1004);
break;
}
}
} else {
if (!WarplyManagerHelper.noInternetDialog(this, true)) {
WarplyManagerHelper.noInternetDialog(this);
return;
}
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("Loyalty").concat(":").concat(dataItem.getCampaign().getSessionUUID()));
startActivityForResult(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())), 1004);
}
}
} catch (Exception exception) {
if (!WarplyManagerHelper.noInternetDialog(this, true)) {
WarplyManagerHelper.noInternetDialog(this);
return;
}
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("Loyalty").concat(":").concat(dataItem.getCampaign().getSessionUUID()));
startActivityForResult(WarpViewActivity.createIntentFromURL(this, WarplyManagerHelper.constructCampaignUrl(dataItem.getCampaign())), 1004);
}
......
......@@ -5,7 +5,6 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
......@@ -41,9 +40,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import io.github.inflationx.calligraphy3.CalligraphyTypefaceSpan;
......@@ -237,6 +233,10 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener, Vie
return;
}
if (view.getId() == R.id.ll_user_questionnaire || view.getId() == R.id.ll_user_badge) {
if (!WarplyManagerHelper.noInternetDialog(this, true)) {
WarplyManagerHelper.noInternetDialog(this);
return;
}
if (!mQuestionnairePressed) {
mQuestionnairePressed = true;
WarplyAnalyticsManager.logTrackersEvent(this, "click", ("LoyaltyWalletScreen")
......@@ -577,6 +577,11 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener, Vie
} else {
String badgeValue = String.format("%.02f", 0.0f);
mTvMarketValue.setText(String.format(getString(R.string.cos_value), badgeValue));
SpannableStringBuilder sBuilderThird = new SpannableStringBuilder();
sBuilderThird.append(String.format(getString(R.string.cos_supermarket_win), badgeValue));
CalligraphyTypefaceSpan typefaceBoldSpanThird = new CalligraphyTypefaceSpan(TypefaceUtils.load(getAssets(), "fonts/PeridotPE-Bold.ttf"));
sBuilderThird.setSpan(typefaceBoldSpanThird, 15, 16 + badgeValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTvMarketAll.setText(sBuilderThird, TextView.BufferType.SPANNABLE);
}
// Sum Expandable Banner
......
......@@ -6,6 +6,10 @@ import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
......@@ -23,11 +27,17 @@ import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.List;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver;
import ly.warp.sdk.utils.constants.WarpConstants;
......@@ -396,6 +406,57 @@ public class WarplyDeviceInfoCollector {
}
}
public static boolean isOnline() {
try {
int timeoutMs = 1500;
Socket sock = new Socket();
SocketAddress sockaddr = new InetSocketAddress("8.8.8.8", 53);
sock.connect(sockaddr, timeoutMs);
sock.close();
return true;
} catch (IOException e) {
return false;
}
}
public static Single<Boolean> hasInternetConnection() {
return Single.fromCallable(() -> {
try {
// Connect to Google DNS to check for connection
int timeoutMs = 1500;
Socket socket = new Socket();
InetSocketAddress socketAddress = new InetSocketAddress("8.8.8.8", 53);
socket.connect(socketAddress, timeoutMs);
socket.close();
return true;
} catch (IOException e) {
return false;
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Network nw = connectivityManager.getActiveNetwork();
if (nw == null) return false;
NetworkCapabilities actNw = connectivityManager.getNetworkCapabilities(nw);
return actNw != null &&
(actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) ||
actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) ||
actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI_AWARE)) /*&&
(actNw.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) &&
actNw.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED))*/;
} else {
NetworkInfo nwInfo = connectivityManager.getActiveNetworkInfo();
return nwInfo != null && nwInfo.isConnected();
}
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
......
......@@ -25,6 +25,7 @@
package ly.warp.sdk.utils;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
......@@ -122,8 +123,9 @@ public class WarplyManagerHelper {
private static ArrayList<ActiveDFYCouponModel> mDfyCoupons = new ArrayList();
private static ArrayList<LoyaltyGiftsForYouPackage> mSeasonalList = new ArrayList<>();
private static ArrayList<LoyaltyContextualOfferModel> mCCMSList = new ArrayList<>();
private static AlertDialog mAlertDialogSharing, mAlertDialogAcceptSharing, mAlertDialogRejectSharing,
mAlertDialogReturnSharing, mAlertDialogErrorSharing, mAlertDialogErrorUsedSharing, mAlertDialogErrorExpiredSharing;
private static AlertDialog mAlertDialogSharing, mAlertDialogAcceptSharing,
mAlertDialogRejectSharing, mAlertDialogReturnSharing, mAlertDialogErrorSharing,
mAlertDialogErrorUsedSharing, mAlertDialogErrorExpiredSharing, mAlertDialogNoInternet;
private static LoyaltyBadgeModel mLoyaltyBadge = new LoyaltyBadgeModel();
private static float mDealsSum = 0.0f;
private static MerchantList mMerchantList = new MerchantList();
......@@ -456,6 +458,37 @@ public class WarplyManagerHelper {
}
/**
* No Internet Connection Dialog
*/
public static void noInternetDialog(Activity context) {
if (!context.isFinishing()) {
mAlertDialogNoInternet = new AlertDialog.Builder(context)
.setTitle(R.string.cos_dlg_no_internet_title)
.setMessage(R.string.cos_dlg_no_internet_subtitle)
.setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> {
dialogPositive.dismiss();
})
.show();
}
}
public static boolean noInternetDialog(Context context, boolean check) {
final boolean[] hasInternetConnection = {true};
if (WarplyDeviceInfoCollector.isNetworkAvailable(context)) {
WarplyDeviceInfoCollector.hasInternetConnection()
.subscribe((hasInternet) -> {
if (!hasInternet) {
hasInternetConnection[0] = false;
}
});
} else {
hasInternetConnection[0] = false;
}
return hasInternetConnection[0];
}
/**
* Open CCMS campaign
*/
public static String constructCcmsUrl(Campaign item, LoyaltyContextualOfferModel ccmsItem) {
......@@ -755,6 +788,10 @@ public class WarplyManagerHelper {
e.printStackTrace();
}
if (!WarplyManagerHelper.noInternetDialog(context, true)) {
WarplyManagerHelper.noInternetDialog((Activity) context);
return;
}
WarpUtils.setWebviewParams(Warply.getWarplyContext(), params);
WarplyAnalyticsManager.logTrackersEvent(context, "click", ("Contextual").concat(":").concat(item.getSessionId()));
context.startActivity(WarpViewActivity.createIntentFromURL(context, url));
......@@ -823,6 +860,10 @@ public class WarplyManagerHelper {
}
}
} else {
if (!WarplyManagerHelper.noInternetDialog(context, true)) {
WarplyManagerHelper.noInternetDialog((Activity) context);
return;
}
WarplyAnalyticsManager.logTrackersEvent(context, "click", ("Loyalty").concat(":").concat(item.getSessionUUID()));
context.startActivity(WarpViewActivity.createIntentFromURL(context, WarplyManagerHelper.constructCampaignUrl(item)));
}
......@@ -858,6 +899,10 @@ public class WarplyManagerHelper {
}
}
} else {
if (!WarplyManagerHelper.noInternetDialog(context, true)) {
WarplyManagerHelper.noInternetDialog((Activity) context);
return;
}
WarplyAnalyticsManager.logTrackersEvent(context, "click", ("Loyalty").concat(":").concat(item.getSessionUUID()));
context.startActivity(WarpViewActivity.createIntentFromURL(context, WarplyManagerHelper.constructCampaignUrl(item)));
}
......@@ -869,6 +914,10 @@ public class WarplyManagerHelper {
return;
}
if (!WarplyManagerHelper.noInternetDialog(context, true)) {
WarplyManagerHelper.noInternetDialog((Activity) context);
return;
}
WarplyAnalyticsManager.logTrackersEvent(context, "click", ("Loyalty").concat(":").concat(item.getSessionUUID()));
context.startActivity(WarpViewActivity.createIntentFromURL(context, WarplyManagerHelper.constructCampaignUrl(item)));
}
......
......@@ -3134,22 +3134,24 @@ public class WarplyManager {
@Override
public void onFailure(int errorCode) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_read_campaign_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
if (errorCode == 301 || errorCode == 302 || errorCode == 307 || errorCode == 308) {
LoyaltySDKDynatraceEventModel dynatraceEvent = new LoyaltySDKDynatraceEventModel();
dynatraceEvent.setEventName("custom_success_read_campaign_loyalty");
EventBus.getDefault().post(new WarplyEventBusManager(dynatraceEvent));
getCampaigns(new WarplyGetCampaignsRequest().setLanguage("en"), new CallbackReceiver<ArrayList<Campaign>>() {
@Override
public void onSuccess(ArrayList<Campaign> result) {
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
WorkManager.getInstance(Warply.getWarplyContext()).enqueue(mywork);
}
getCampaigns(new WarplyGetCampaignsRequest().setLanguage("en"), new CallbackReceiver<ArrayList<Campaign>>() {
@Override
public void onSuccess(ArrayList<Campaign> result) {
OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
WorkManager.getInstance(Warply.getWarplyContext()).enqueue(mywork);
}
@Override
public void onFailure(int errorCode) {
@Override
public void onFailure(int errorCode) {
}
});
}
});
}
}
}, null);
}
......
......@@ -179,6 +179,8 @@
<string name="cos_telematics">Telematics Demo</string>
<string name="cos_dlg_start_trip">Start Trip</string>
<string name="cos_dlg_stop_trip">Stop Trip</string>
<string name="cos_dlg_no_internet_title">Δεν υπάρχει σύνδεση</string>
<string name="cos_dlg_no_internet_subtitle">Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.</string>
<string-array name="coupons_array">
<item>Κουπόνια</item>
......