Panagiotis Triantafyllou

login + profile

...@@ -3,13 +3,19 @@ package warp.ly.android_sdk.activities; ...@@ -3,13 +3,19 @@ package warp.ly.android_sdk.activities;
3 import android.content.Intent; 3 import android.content.Intent;
4 import android.os.Bundle; 4 import android.os.Bundle;
5 5
6 +import org.json.JSONObject;
7 +
6 import java.util.Timer; 8 import java.util.Timer;
7 import java.util.TimerTask; 9 import java.util.TimerTask;
8 10
9 import ly.warp.sdk.Warply; 11 import ly.warp.sdk.Warply;
12 +import ly.warp.sdk.io.callbacks.CallbackReceiver;
10 import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver; 13 import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver;
11 import ly.warp.sdk.io.callbacks.WarplyReadyCallback; 14 import ly.warp.sdk.io.callbacks.WarplyReadyCallback;
15 +import ly.warp.sdk.io.request.WarplyConsumerRequest;
16 +import ly.warp.sdk.io.request.WarplyLoginRequest;
12 import ly.warp.sdk.utils.WarplyInitializer; 17 import ly.warp.sdk.utils.WarplyInitializer;
18 +import ly.warp.sdk.utils.managers.WarplyManager;
13 import warp.ly.android_sdk.R; 19 import warp.ly.android_sdk.R;
14 20
15 public class SplashActivity extends BaseActivity { 21 public class SplashActivity extends BaseActivity {
...@@ -24,7 +30,11 @@ public class SplashActivity extends BaseActivity { ...@@ -24,7 +30,11 @@ public class SplashActivity extends BaseActivity {
24 mWarplyInitializer = Warply.getInitializer(this, new WarplyReadyCallback() { 30 mWarplyInitializer = Warply.getInitializer(this, new WarplyReadyCallback() {
25 @Override 31 @Override
26 public void onWarplyReady() { 32 public void onWarplyReady() {
27 - startNextActivity(); 33 + WarplyManager.login(new WarplyLoginRequest()
34 + .setId("6981234567")
35 + .setPassword("123456"),
36 + mLoginReceiver
37 + );
28 } 38 }
29 39
30 @Override 40 @Override
...@@ -58,7 +68,7 @@ public class SplashActivity extends BaseActivity { ...@@ -58,7 +68,7 @@ public class SplashActivity extends BaseActivity {
58 68
59 private void startNextActivity() { 69 private void startNextActivity() {
60 if (!isFinishing()) { 70 if (!isFinishing()) {
61 - long MIN_SPLASH_TIME = 2000; 71 + long MIN_SPLASH_TIME = 1000;
62 new Timer().schedule(new TimerTask() { 72 new Timer().schedule(new TimerTask() {
63 73
64 @Override 74 @Override
...@@ -75,4 +85,18 @@ public class SplashActivity extends BaseActivity { ...@@ -75,4 +85,18 @@ public class SplashActivity extends BaseActivity {
75 }, MIN_SPLASH_TIME); 85 }, MIN_SPLASH_TIME);
76 } 86 }
77 } 87 }
88 +
89 + private final CallbackReceiver<JSONObject> mLoginReceiver = new CallbackReceiver<JSONObject>() {
90 + @Override
91 + public void onSuccess(JSONObject result) {
92 + if (result != null && result.optInt("status") == 1) {
93 + startNextActivity();
94 + }
95 + }
96 +
97 + @Override
98 + public void onFailure(int errorCode) {
99 + startNextActivity();
100 + }
101 + };
78 } 102 }
......
...@@ -2,6 +2,8 @@ package ly.warp.sdk.fragments; ...@@ -2,6 +2,8 @@ package ly.warp.sdk.fragments;
2 2
3 import android.content.Intent; 3 import android.content.Intent;
4 import android.os.Bundle; 4 import android.os.Bundle;
5 +import android.os.Handler;
6 +import android.os.Looper;
5 import android.view.LayoutInflater; 7 import android.view.LayoutInflater;
6 import android.view.View; 8 import android.view.View;
7 import android.view.ViewGroup; 9 import android.view.ViewGroup;
...@@ -20,6 +22,11 @@ import org.json.JSONException; ...@@ -20,6 +22,11 @@ import org.json.JSONException;
20 import ly.warp.sdk.R; 22 import ly.warp.sdk.R;
21 import ly.warp.sdk.activities.BillPaymentActivity; 23 import ly.warp.sdk.activities.BillPaymentActivity;
22 import ly.warp.sdk.activities.CouponInfoActivity; 24 import ly.warp.sdk.activities.CouponInfoActivity;
25 +import ly.warp.sdk.io.callbacks.CallbackReceiver;
26 +import ly.warp.sdk.io.models.Consumer;
27 +import ly.warp.sdk.io.request.WarplyConsumerRequest;
28 +import ly.warp.sdk.io.request.WarplyLoginRequest;
29 +import ly.warp.sdk.utils.managers.WarplyManager;
23 import ly.warp.sdk.views.adapters.HomeCampaignAdapter; 30 import ly.warp.sdk.views.adapters.HomeCampaignAdapter;
24 import ly.warp.sdk.views.adapters.HomeCouponAdapter; 31 import ly.warp.sdk.views.adapters.HomeCouponAdapter;
25 import ly.warp.sdk.activities.WarpViewActivity; 32 import ly.warp.sdk.activities.WarpViewActivity;
...@@ -35,6 +42,19 @@ public class HomeFragment extends Fragment implements View.OnClickListener { ...@@ -35,6 +42,19 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
35 private HomeCouponAdapter mAdapterCoupons; 42 private HomeCouponAdapter mAdapterCoupons;
36 private HomeCampaignAdapter mAdapterCampaigns; 43 private HomeCampaignAdapter mAdapterCampaigns;
37 private LinearLayout mLlBillPayment; 44 private LinearLayout mLlBillPayment;
45 + private TextView mTvUsername;
46 + public static Consumer mConsumer;
47 +
48 + @Override
49 + public void onCreate(Bundle savedInstanceState) {
50 + super.onCreate(savedInstanceState);
51 +
52 + new Thread(() -> {
53 + if (!Thread.currentThread().isInterrupted()) {
54 + WarplyManager.getConsumer(new WarplyConsumerRequest(), mConsumerReceiver);
55 + }
56 + }).start();
57 + }
38 58
39 @Override 59 @Override
40 public View onCreateView( 60 public View onCreateView(
...@@ -68,6 +88,8 @@ public class HomeFragment extends Fragment implements View.OnClickListener { ...@@ -68,6 +88,8 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
68 mLlBillPayment = view.findViewById(R.id.ll_bill_payment); 88 mLlBillPayment = view.findViewById(R.id.ll_bill_payment);
69 mLlBillPayment.setOnClickListener(this); 89 mLlBillPayment.setOnClickListener(this);
70 90
91 + mTvUsername = view.findViewById(R.id.welcome_user_txt);
92 +
71 /********* TEST CAMPAIGNS DATA **********/ 93 /********* TEST CAMPAIGNS DATA **********/
72 CampaignList clistCampaigns = new CampaignList(); 94 CampaignList clistCampaigns = new CampaignList();
73 try { 95 try {
...@@ -134,4 +156,20 @@ public class HomeFragment extends Fragment implements View.OnClickListener { ...@@ -134,4 +156,20 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
134 HomeFragment homeFragment = new HomeFragment(); 156 HomeFragment homeFragment = new HomeFragment();
135 return homeFragment; 157 return homeFragment;
136 } 158 }
159 +
160 + private final CallbackReceiver<Consumer> mConsumerReceiver = new CallbackReceiver<Consumer>() {
161 + @Override
162 + public void onSuccess(Consumer result) {
163 + mConsumer = result;
164 + new Handler(Looper.getMainLooper()).post(() -> {
165 + mTvUsername.setText(String.format(getResources().getString(R.string.welcome_user),
166 + mConsumer.getFirstName() + " " + mConsumer.getLastName()));
167 + });
168 + }
169 +
170 + @Override
171 + public void onFailure(int errorCode) {
172 + Thread.currentThread().interrupt();
173 + }
174 + };
137 } 175 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
46 android:layout_marginBottom="8dp" 46 android:layout_marginBottom="8dp"
47 android:maxLines="1" 47 android:maxLines="1"
48 android:scrollHorizontally="true" 48 android:scrollHorizontally="true"
49 - android:text="@string/welcome_user" 49 + tools:text="@string/welcome_user"
50 android:textColor="#415564" /> 50 android:textColor="#415564" />
51 51
52 <ImageView 52 <ImageView
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
6 <string name="rate_dialog_negative">No, Thanks</string> 6 <string name="rate_dialog_negative">No, Thanks</string>
7 7
8 <string name="cos_profile_tab">Profile</string> 8 <string name="cos_profile_tab">Profile</string>
9 - <string name="welcome_user">Γεία σου Γιώργος !</string> 9 + <string name="welcome_user">Γεία σου %1$s !</string>
10 <string name="cos_profile_name">Γιώργος</string> 10 <string name="cos_profile_name">Γιώργος</string>
11 <string name="cos_profile_type">Traveller</string> 11 <string name="cos_profile_type">Traveller</string>
12 <string name="header_add">Προσθήκη</string> 12 <string name="header_add">Προσθήκη</string>
......