thkouk00

Merge branch 'cosmote' of https://git.warp.ly/open-source/warply_android_sdk_mav…

…en_plugin into cosmote
package ly.warp.sdk.fragments;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
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.utils.managers.WarplyManager;
public class BaseFragment extends Fragment {
private 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 void onDestroyView() {
super.onDestroyView();
}
public static Consumer getConsumer() {
return mConsumer;
}
private final CallbackReceiver<Consumer> mConsumerReceiver = new CallbackReceiver<Consumer>() {
@Override
public void onSuccess(Consumer result) {
mConsumer = result;
Thread.currentThread().interrupt();
}
@Override
public void onFailure(int errorCode) {
Thread.currentThread().interrupt();
}
};
}
\ No newline at end of file
......@@ -2,8 +2,6 @@ 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;
......@@ -22,20 +20,15 @@ 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;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.io.models.Coupon;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.views.adapters.HomeCampaignAdapter;
import ly.warp.sdk.views.adapters.HomeCouponAdapter;
public class HomeFragment extends Fragment implements View.OnClickListener {
public class HomeFragment extends BaseFragment implements View.OnClickListener {
private RelativeLayout mOptionOne, mOptionTwo, mOptionThree;
private RecyclerView mRecyclerCampaigns, mRecyclerCoupons;
......@@ -43,18 +36,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
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(
......@@ -89,6 +70,9 @@ public class HomeFragment extends Fragment implements View.OnClickListener {
mLlBillPayment.setOnClickListener(this);
mTvUsername = view.findViewById(R.id.welcome_user_txt);
if (BaseFragment.getConsumer() != null)
mTvUsername.setText(String.format(getResources().getString(R.string.welcome_user),
BaseFragment.getConsumer().getFirstName() + " " + BaseFragment.getConsumer().getLastName()));
/********* TEST CAMPAIGNS DATA **********/
CampaignList clistCampaigns = new CampaignList();
......@@ -156,20 +140,4 @@ 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
......
......@@ -6,6 +6,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
......@@ -22,7 +23,7 @@ import ly.warp.sdk.io.models.Campaign;
import ly.warp.sdk.io.models.CampaignList;
import ly.warp.sdk.views.adapters.ProfileCampaignAdapter;
public class LoyaltyFragment extends Fragment implements View.OnClickListener {
public class LoyaltyFragment extends BaseFragment implements View.OnClickListener {
// ===========================================================
// Constants
......@@ -36,6 +37,7 @@ public class LoyaltyFragment extends Fragment implements View.OnClickListener {
private ProfileCampaignAdapter mAdapterDeals, mAdapterGifts, mAdapterMore;
private LinearLayout mLlMoreDeals, mLlMoreGifts, mLlMore;
private ConstraintLayout mClRewardsWallet;
private TextView mTvUsername;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -63,6 +65,11 @@ public class LoyaltyFragment extends Fragment implements View.OnClickListener {
mClRewardsWallet = view.findViewById(R.id.cl_rewards_wallet);
mClRewardsWallet.setOnClickListener(this);
mTvUsername = view.findViewById(R.id.tv_name);
if (BaseFragment.getConsumer() != null)
mTvUsername.setText(String.format(getResources().getString(R.string.cos_profile_name),
BaseFragment.getConsumer().getFirstName() + " " + BaseFragment.getConsumer().getLastName()));
mLlMoreDeals = view.findViewById(R.id.ll_more);
mLlMoreDeals.setOnClickListener(this);
mLlMoreGifts = view.findViewById(R.id.ll_more2);
......
......@@ -4,6 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@android:color/white">
<LinearLayout
......@@ -32,7 +33,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="6dp"
android:text="@string/cos_profile_name"
tools:text="Test Name"
android:maxLines="1"
android:textColor="@color/grey"
app:layout_constraintLeft_toRightOf="@+id/iv_profile_photo"
......
......@@ -7,7 +7,7 @@
<string name="cos_profile_tab">Profile</string>
<string name="welcome_user">Γεία σου %1$s !</string>
<string name="cos_profile_name">Γιώργος</string>
<string name="cos_profile_name">%1$s</string>
<string name="cos_profile_type">Traveller</string>
<string name="header_add">Προσθήκη</string>
<string name="cos_profile_reward">My reward wallet</string>
......