Panagiotis Triantafyllou

login + profile

......@@ -3,13 +3,19 @@ package warp.ly.android_sdk.activities;
import android.content.Intent;
import android.os.Bundle;
import org.json.JSONObject;
import java.util.Timer;
import java.util.TimerTask;
import ly.warp.sdk.Warply;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver;
import ly.warp.sdk.io.callbacks.WarplyReadyCallback;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyLoginRequest;
import ly.warp.sdk.utils.WarplyInitializer;
import ly.warp.sdk.utils.managers.WarplyManager;
import warp.ly.android_sdk.R;
public class SplashActivity extends BaseActivity {
......@@ -24,7 +30,11 @@ public class SplashActivity extends BaseActivity {
mWarplyInitializer = Warply.getInitializer(this, new WarplyReadyCallback() {
@Override
public void onWarplyReady() {
startNextActivity();
WarplyManager.login(new WarplyLoginRequest()
.setId("6981234567")
.setPassword("123456"),
mLoginReceiver
);
}
@Override
......@@ -58,7 +68,7 @@ public class SplashActivity extends BaseActivity {
private void startNextActivity() {
if (!isFinishing()) {
long MIN_SPLASH_TIME = 2000;
long MIN_SPLASH_TIME = 1000;
new Timer().schedule(new TimerTask() {
@Override
......@@ -75,4 +85,18 @@ public class SplashActivity extends BaseActivity {
}, MIN_SPLASH_TIME);
}
}
private final CallbackReceiver<JSONObject> mLoginReceiver = new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
if (result != null && result.optInt("status") == 1) {
startNextActivity();
}
}
@Override
public void onFailure(int errorCode) {
startNextActivity();
}
};
}
......
......@@ -2,6 +2,8 @@ package ly.warp.sdk.fragments;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -20,6 +22,11 @@ import org.json.JSONException;
import ly.warp.sdk.R;
import ly.warp.sdk.activities.BillPaymentActivity;
import ly.warp.sdk.activities.CouponInfoActivity;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.Consumer;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyLoginRequest;
import ly.warp.sdk.utils.managers.WarplyManager;
import ly.warp.sdk.views.adapters.HomeCampaignAdapter;
import ly.warp.sdk.views.adapters.HomeCouponAdapter;
import ly.warp.sdk.activities.WarpViewActivity;
......@@ -35,6 +42,19 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
private HomeCouponAdapter mAdapterCoupons;
private HomeCampaignAdapter mAdapterCampaigns;
private LinearLayout mLlBillPayment;
private TextView mTvUsername;
public static Consumer mConsumer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread(() -> {
if (!Thread.currentThread().isInterrupted()) {
WarplyManager.getConsumer(new WarplyConsumerRequest(), mConsumerReceiver);
}
}).start();
}
@Override
public View onCreateView(
......@@ -68,6 +88,8 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
mLlBillPayment = view.findViewById(R.id.ll_bill_payment);
mLlBillPayment.setOnClickListener(this);
mTvUsername = view.findViewById(R.id.welcome_user_txt);
/********* TEST CAMPAIGNS DATA **********/
CampaignList clistCampaigns = new CampaignList();
try {
......@@ -134,4 +156,20 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
HomeFragment homeFragment = new HomeFragment();
return homeFragment;
}
private final CallbackReceiver<Consumer> mConsumerReceiver = new CallbackReceiver<Consumer>() {
@Override
public void onSuccess(Consumer result) {
mConsumer = result;
new Handler(Looper.getMainLooper()).post(() -> {
mTvUsername.setText(String.format(getResources().getString(R.string.welcome_user),
mConsumer.getFirstName() + " " + mConsumer.getLastName()));
});
}
@Override
public void onFailure(int errorCode) {
Thread.currentThread().interrupt();
}
};
}
\ No newline at end of file
......
......@@ -46,7 +46,7 @@
android:layout_marginBottom="8dp"
android:maxLines="1"
android:scrollHorizontally="true"
android:text="@string/welcome_user"
tools:text="@string/welcome_user"
android:textColor="#415564" />
<ImageView
......
......@@ -6,7 +6,7 @@
<string name="rate_dialog_negative">No, Thanks</string>
<string name="cos_profile_tab">Profile</string>
<string name="welcome_user">Γεία σου Γιώργος !</string>
<string name="welcome_user">Γεία σου %1$s !</string>
<string name="cos_profile_name">Γιώργος</string>
<string name="cos_profile_type">Traveller</string>
<string name="header_add">Προσθήκη</string>
......