Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_android_sdk_maven_plugin
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Panagiotis Triantafyllou
2024-10-25 16:10:18 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
03b45bc32868878e24437df944c4cc38b4d03e38
03b45bc3
1 parent
32bbc511
sdk optimizations
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
222 additions
and
120 deletions
app/src/main/java/warp/ly/android_sdk/activities/SplashActivity.java
warply_android_sdk/src/main/java/ly/warp/sdk/activities/BaseFragmentActivity.java
warply_android_sdk/src/main/java/ly/warp/sdk/db/WarplyDBHelper.java
warply_android_sdk/src/main/java/ly/warp/sdk/fragments/HomeFragment.java
warply_android_sdk/src/main/java/ly/warp/sdk/io/callbacks/VolleyTransformer.java
warply_android_sdk/src/main/java/ly/warp/sdk/io/volley/ApiService.java
warply_android_sdk/src/main/java/ly/warp/sdk/utils/WarpUtils.java
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyManager.java
warply_android_sdk/src/main/res/layout/fragment_home.xml
warply_android_sdk/src/main/res/values/strings.xml
app/src/main/java/warp/ly/android_sdk/activities/SplashActivity.java
View file @
03b45bc
...
...
@@ -2,25 +2,15 @@ package warp.ly.android_sdk.activities;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.widget.Toast
;
import
org.json.JSONObject
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
ly.warp.sdk.Warply
;
import
ly.warp.sdk.activities.BaseFragmentActivity
;
import
ly.warp.sdk.db.WarplyDBHelper
;
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.WarplyCosmoteUserRequest
;
import
ly.warp.sdk.io.request.WarplyLoginRequest
;
import
ly.warp.sdk.io.request.WarplyVerifyTicketRequest
;
import
ly.warp.sdk.utils.WarplyInitializer
;
import
ly.warp.sdk.utils.managers.WarplyManager
;
import
warp.ly.android_sdk.R
;
public
class
SplashActivity
extends
BaseActivity
{
...
...
@@ -35,14 +25,7 @@ public class SplashActivity extends BaseActivity {
mWarplyInitializer
=
Warply
.
getInitializer
(
this
,
new
WarplyReadyCallback
()
{
@Override
public
void
onWarplyReady
()
{
if
(!
WarplyDBHelper
.
getInstance
(
SplashActivity
.
this
).
isTableNotEmpty
(
"auth"
))
{
//6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons
//prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282, live 3000136179
WarplyManager
.
getCosmoteUser
(
"7000001053"
,
mLoginReceiver
);
// WarplyManager.verifyTicket("", "7000023699", mLoginReceiver);
}
else
{
startNextActivity
();
}
startNextActivity
();
}
@Override
...
...
@@ -93,19 +76,4 @@ 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();
Toast
.
makeText
(
SplashActivity
.
this
,
"LOGIN ERROR"
,
Toast
.
LENGTH_SHORT
).
show
();
}
};
}
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/activities/BaseFragmentActivity.java
View file @
03b45bc
...
...
@@ -19,6 +19,7 @@ import com.google.android.material.navigation.NavigationBarView;
import
java.util.ArrayList
;
import
ly.warp.sdk.R
;
import
ly.warp.sdk.db.WarplyDBHelper
;
import
ly.warp.sdk.fragments.HomeFragment
;
import
ly.warp.sdk.fragments.LoyaltyFragment
;
import
ly.warp.sdk.fragments.MyRewardsFragment
;
...
...
@@ -53,9 +54,11 @@ public class BaseFragmentActivity extends FragmentActivity implements Navigation
mBottomNavigationView
=
findViewById
(
R
.
id
.
bt_tabs
);
WarplyManager
.
getUserCouponsWithCouponsets
(
mUserCouponsReceiver
);
WarplyManager
.
getCampaigns
(
mCampaignsCallback
);
WarplyManager
.
getUnifiedCouponsDeals
(
mUnifiedCallback
);
if
(
WarplyDBHelper
.
getInstance
(
this
).
isTableNotEmpty
(
"auth"
))
{
WarplyManager
.
getUserCouponsWithCouponsets
(
mUserCouponsReceiver
);
WarplyManager
.
getCampaigns
(
mCampaignsCallback
);
WarplyManager
.
getUnifiedCouponsDeals
(
mUnifiedCallback
);
}
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
if
(!
hasNotificationPermission
())
{
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/db/WarplyDBHelper.java
View file @
03b45bc
...
...
@@ -40,7 +40,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
private
static
final
String
DB_NAME
=
"warply.db"
;
private
static
final
int
DB_VERSION
=
1
0
;
private
static
final
int
DB_VERSION
=
1
2
;
private
static
final
String
KEY_CIPHER
=
"tn#mpOl3v3Dy1pr@W"
;
//------------------------------ Fields -----------------------------//
...
...
@@ -154,6 +154,19 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
return
mDb
;
}
private
SQLiteDatabase
getReadableDb
()
{
if
(
mDb
==
null
)
mDb
=
getReadableDatabase
(
KEY_CIPHER
);
return
mDb
;
}
private
void
closeDb
()
{
if
(
mDb
!=
null
&&
mDb
.
isOpen
())
{
mDb
.
close
();
mDb
=
null
;
}
}
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
CREATE_TABLE_REQUESTS
);
...
...
@@ -215,27 +228,36 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
public
synchronized
void
clearTable
(
String
tableName
)
{
SQLiteDatabase
db
=
getDb
();
db
.
delete
(
tableName
,
null
,
null
);
closeDb
();
}
public
synchronized
void
insert
(
String
tableName
,
ContentValues
values
)
{
SQLiteDatabase
db
=
getDb
();
db
.
insert
(
tableName
,
null
,
values
);
closeDb
();
}
public
synchronized
void
update
(
String
tableName
,
ContentValues
values
)
{
SQLiteDatabase
db
=
getDb
();
db
.
update
(
tableName
,
values
,
null
,
null
);
closeDb
();
}
public
synchronized
boolean
isTableNotEmpty
(
String
tableName
)
{
Cursor
cursor
=
getDb
().
rawQuery
(
"SELECT COUNT(*) FROM "
+
tableName
,
Cursor
cursor
=
get
Readable
Db
().
rawQuery
(
"SELECT COUNT(*) FROM "
+
tableName
,
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
boolean
isNotEmpty
=
cursor
.
getInt
(
0
)
>
0
;
cursor
.
close
();
closeDb
();
return
isNotEmpty
;
}
else
}
else
{
closeDb
();
return
false
;
}
}
//------------------------------ Auth -----------------------------//
...
...
@@ -266,24 +288,30 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
@Nullable
public
synchronized
String
getAuthValue
(
String
columnName
)
{
String
columnValue
=
""
;
Cursor
cursor
=
getDb
().
query
(
TABLE_AUTH
,
new
String
[]{
columnName
},
null
,
null
,
null
,
null
,
null
);
Cursor
cursor
=
get
Readable
Db
().
query
(
TABLE_AUTH
,
new
String
[]{
columnName
},
null
,
null
,
null
,
null
,
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
cursor
.
moveToFirst
();
columnValue
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
columnName
));
cursor
.
close
();
}
closeDb
();
return
columnValue
;
}
@Nullable
public
synchronized
String
getClientValue
(
String
columnName
)
{
String
columnValue
=
""
;
Cursor
cursor
=
getDb
().
query
(
TABLE_CLIENT
,
new
String
[]{
columnName
},
null
,
null
,
null
,
null
,
null
);
Cursor
cursor
=
get
Readable
Db
().
query
(
TABLE_CLIENT
,
new
String
[]{
columnName
},
null
,
null
,
null
,
null
,
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
cursor
.
moveToFirst
();
columnValue
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
columnName
));
cursor
.
close
();
}
closeDb
();
return
columnValue
;
}
...
...
@@ -297,24 +325,21 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
//------------------------------ Api requests -----------------------------//
public
synchronized
Cursor
getAllRequests
()
{
return
getDb
().
query
(
TABLE_REQUESTS
,
return
getReadableDb
().
query
(
TABLE_REQUESTS
,
new
String
[]{
KEY_REQUESTS_ID
,
KEY_REQUESTS_MICROAPP
,
KEY_REQUESTS_ENTITY
},
null
,
null
,
null
,
null
,
KEY_REQUESTS_DATE_ADDED
+
" asc"
,
"20"
);
}
public
synchronized
Cursor
getAllPushRequests
()
{
return
getDb
().
query
(
TABLE_PUSH_REQUESTS
,
return
getReadableDb
().
query
(
TABLE_PUSH_REQUESTS
,
new
String
[]{
KEY_REQUESTS_ID
,
KEY_REQUESTS_MICROAPP
,
KEY_REQUESTS_ENTITY
},
null
,
null
,
null
,
null
,
KEY_REQUESTS_DATE_ADDED
+
" asc"
,
"20"
);
}
public
synchronized
Cursor
getAllPushAckRequests
()
{
return
getDb
().
query
(
TABLE_PUSH_ACK_REQUESTS
,
return
getReadableDb
().
query
(
TABLE_PUSH_ACK_REQUESTS
,
new
String
[]{
KEY_REQUESTS_ID
,
KEY_REQUESTS_MICROAPP
,
KEY_REQUESTS_ENTITY
},
null
,
null
,
null
,
null
,
KEY_REQUESTS_DATE_ADDED
+
" asc"
,
"20"
);
...
...
@@ -375,7 +400,6 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
public
synchronized
void
deleteRequests
(
Long
...
ids
)
{
StringBuilder
strFilter
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
ids
.
length
;
i
++)
{
if
(
i
>
0
)
{
...
...
@@ -386,10 +410,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter
.
append
(
ids
[
i
]);
}
getDb
().
delete
(
TABLE_REQUESTS
,
strFilter
.
toString
(),
null
);
closeDb
();
}
public
synchronized
void
deletePushRequests
(
Long
...
ids
)
{
StringBuilder
strFilter
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
ids
.
length
;
i
++)
{
if
(
i
>
0
)
{
...
...
@@ -400,10 +425,11 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter
.
append
(
ids
[
i
]);
}
getDb
().
delete
(
TABLE_PUSH_REQUESTS
,
strFilter
.
toString
(),
null
);
closeDb
();
}
public
synchronized
void
deletePushAckRequests
(
Long
...
ids
)
{
StringBuilder
strFilter
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
ids
.
length
;
i
++)
{
if
(
i
>
0
)
{
...
...
@@ -414,45 +440,55 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter
.
append
(
ids
[
i
]);
}
getDb
().
delete
(
TABLE_PUSH_ACK_REQUESTS
,
strFilter
.
toString
(),
null
);
closeDb
();
}
public
synchronized
boolean
isForceRequestsExist
()
{
Cursor
cursor
=
getDb
().
query
(
TABLE_REQUESTS
,
null
,
KEY_REQUESTS_FORCE
+
"=1"
,
Cursor
cursor
=
get
Readable
Db
().
query
(
TABLE_REQUESTS
,
null
,
KEY_REQUESTS_FORCE
+
"=1"
,
null
,
null
,
null
,
null
);
boolean
result
=
false
;
if
(
cursor
!=
null
)
{
result
=
cursor
.
getCount
()
>
0
;
cursor
.
close
();
}
closeDb
();
return
result
;
}
public
synchronized
boolean
isForcePushRequestsExist
()
{
Cursor
cursor
=
getDb
().
query
(
TABLE_PUSH_REQUESTS
,
null
,
KEY_REQUESTS_FORCE
+
"=1"
,
Cursor
cursor
=
get
Readable
Db
().
query
(
TABLE_PUSH_REQUESTS
,
null
,
KEY_REQUESTS_FORCE
+
"=1"
,
null
,
null
,
null
,
null
);
boolean
result
=
false
;
if
(
cursor
!=
null
)
{
result
=
cursor
.
getCount
()
>
0
;
cursor
.
close
();
}
closeDb
();
return
result
;
}
public
synchronized
boolean
isForcePushAckRequestsExist
()
{
Cursor
cursor
=
getDb
().
query
(
TABLE_PUSH_ACK_REQUESTS
,
null
,
KEY_REQUESTS_FORCE
+
"=1"
,
Cursor
cursor
=
get
Readable
Db
().
query
(
TABLE_PUSH_ACK_REQUESTS
,
null
,
KEY_REQUESTS_FORCE
+
"=1"
,
null
,
null
,
null
,
null
);
boolean
result
=
false
;
if
(
cursor
!=
null
)
{
result
=
cursor
.
getCount
()
>
0
;
cursor
.
close
();
}
closeDb
();
return
result
;
}
//------------------------------ Tags -----------------------------//
public
synchronized
void
saveTags
(
String
[]
tags
)
{
if
(
tags
!=
null
&&
tags
.
length
>
0
)
{
try
{
getDb
().
beginTransaction
();
ContentValues
values
=
new
ContentValues
();
...
...
@@ -464,11 +500,14 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
getDb
().
setTransactionSuccessful
();
}
catch
(
SQLException
e
)
{
closeDb
();
if
(
WarpConstants
.
DEBUG
)
{
e
.
printStackTrace
();
}
}
finally
{
getDb
().
endTransaction
();
closeDb
();
}
}
}
...
...
@@ -505,6 +544,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
strFilter
.
append
(
"'"
);
}
getDb
().
delete
(
TABLE_TAGS
,
strFilter
.
toString
(),
null
);
closeDb
();
}
public
synchronized
void
removeAllTags
()
{
...
...
@@ -515,7 +555,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
public
synchronized
String
[]
getTags
()
{
List
<
String
>
tags
=
null
;
Cursor
cursor
=
getDb
().
query
(
TABLE_TAGS
,
null
,
null
,
null
,
null
,
null
,
null
);
Cursor
cursor
=
get
Readable
Db
().
query
(
TABLE_TAGS
,
null
,
null
,
null
,
null
,
null
,
null
);
if
(
cursor
!=
null
)
{
tags
=
new
ArrayList
<>(
cursor
.
getCount
());
...
...
@@ -525,6 +565,9 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
}
cursor
.
close
();
}
closeDb
();
return
tags
!=
null
?
tags
.
toArray
(
new
String
[
tags
.
size
()])
:
null
;
}
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/fragments/HomeFragment.java
View file @
03b45bc
...
...
@@ -5,6 +5,7 @@ import android.os.Bundle;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.EditText
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.RelativeLayout
;
...
...
@@ -12,10 +13,7 @@ import android.widget.TextView;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.constraintlayout.widget.ConstraintLayout
;
import
androidx.fragment.app.Fragment
;
import
androidx.recyclerview.widget.LinearLayoutManager
;
import
androidx.recyclerview.widget.RecyclerView
;
import
androidx.swiperefreshlayout.widget.SwipeRefreshLayout
;
import
org.json.JSONObject
;
...
...
@@ -23,28 +21,24 @@ import org.json.JSONObject;
import
java.util.ArrayList
;
import
ly.warp.sdk.R
;
import
ly.warp.sdk.activities.ActiveCouponsActivity
;
import
ly.warp.sdk.activities.BaseFragmentActivity
;
import
ly.warp.sdk.activities.TelematicsActivity
;
import
ly.warp.sdk.activities.TelematicsHistoryActivity
;
import
ly.warp.sdk.
activities.WarpViewActivity
;
import
ly.warp.sdk.
db.WarplyDBHelper
;
import
ly.warp.sdk.io.callbacks.CallbackReceiver
;
import
ly.warp.sdk.io.models.Campaign
;
import
ly.warp.sdk.io.models.CouponList
;
import
ly.warp.sdk.io.models.UnifiedCoupon
;
import
ly.warp.sdk.io.request.WarplyGetCampaignsRequest
;
import
ly.warp.sdk.utils.WarplyManagerHelper
;
import
ly.warp.sdk.utils.managers.WarplyManager
;
import
ly.warp.sdk.views.adapters.HomeCampaignAdapter
;
public
class
HomeFragment
extends
Fragment
implements
View
.
OnClickListener
,
SwipeRefreshLayout
.
OnRefreshListener
{
private
RelativeLayout
mOptionOne
,
mOptionTwo
,
mOptionThree
,
mRlDriving
,
mRlDrivingHistory
;
private
LinearLayout
mLlBillPayment
;
private
TextView
mTvUsername
,
mTvActiveCoupons
;
private
ConstraintLayout
mClActiveCoupons
;
private
ImageView
mIvStepsActivity
;
private
RelativeLayout
mOptionOne
,
mOptionTwo
,
mOptionThree
,
mRlDriving
,
mRlDrivingHistory
,
mPbLoading
;
private
TextView
mTvUsername
;
private
SwipeRefreshLayout
mSwipeRefresh
;
private
EditText
mEtGuid
;
private
LinearLayout
mLlAuthLogin
,
mLlAuthLogout
;
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
...
...
@@ -74,17 +68,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
mOptionThreeText
.
setText
(
"1"
);
mOptionThreeImage
.
setImageResource
(
R
.
drawable
.
tv_option
);
mClActiveCoupons
=
view
.
findViewById
(
R
.
id
.
cl_coupon
);
mTvActiveCoupons
=
mClActiveCoupons
.
findViewById
(
R
.
id
.
tv_active_coupons
);
mTvActiveCoupons
.
setText
(
String
.
format
(
getResources
().
getString
(
R
.
string
.
cos_active_coupons
),
String
.
valueOf
(
WarplyManagerHelper
.
getCouponList
().
size
())));
mClActiveCoupons
.
setOnClickListener
(
this
);
mLlBillPayment
=
view
.
findViewById
(
R
.
id
.
ll_bill_payment
);
mLlBillPayment
.
setOnClickListener
(
this
);
mIvStepsActivity
=
view
.
findViewById
(
R
.
id
.
iv_settings
);
mIvStepsActivity
.
setOnClickListener
(
this
);
mTvUsername
=
view
.
findViewById
(
R
.
id
.
welcome_user_txt
);
if
(
WarplyManagerHelper
.
getConsumer
()
!=
null
)
mTvUsername
.
setText
(
String
.
format
(
getResources
().
getString
(
R
.
string
.
welcome_user
),
...
...
@@ -94,6 +77,25 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
mRlDriving
.
setOnClickListener
(
this
);
mRlDrivingHistory
=
view
.
findViewById
(
R
.
id
.
rl_driving_history
);
mRlDrivingHistory
.
setOnClickListener
(
this
);
mPbLoading
=
view
.
findViewById
(
R
.
id
.
pb_loading
);
mPbLoading
.
setOnTouchListener
((
v
,
event
)
->
true
);
mEtGuid
=
view
.
findViewById
(
R
.
id
.
et_login
);
mLlAuthLogin
=
view
.
findViewById
(
R
.
id
.
ll_auth_login
);
mLlAuthLogin
.
setOnClickListener
(
this
);
mLlAuthLogout
=
view
.
findViewById
(
R
.
id
.
ll_auth_logout
);
mLlAuthLogout
.
setOnClickListener
(
this
);
if
(!
WarplyDBHelper
.
getInstance
(
getActivity
()).
isTableNotEmpty
(
"auth"
))
{
mLlAuthLogout
.
setVisibility
(
View
.
GONE
);
mLlAuthLogin
.
setVisibility
(
View
.
VISIBLE
);
mEtGuid
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
mEtGuid
.
setVisibility
(
View
.
GONE
);
mLlAuthLogin
.
setVisibility
(
View
.
GONE
);
mLlAuthLogout
.
setVisibility
(
View
.
VISIBLE
);
}
}
@Override
...
...
@@ -111,12 +113,6 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
@Override
public
void
onClick
(
View
view
)
{
if
(
view
.
getId
()
==
R
.
id
.
cl_coupon
)
{
Intent
intent
=
new
Intent
(
getContext
(),
ActiveCouponsActivity
.
class
);
intent
.
putExtra
(
"couponlist"
,
WarplyManagerHelper
.
getCouponList
());
startActivity
(
intent
);
return
;
}
if
(
view
.
getId
()
==
R
.
id
.
rl_driving
)
{
Intent
intent
=
new
Intent
(
getContext
(),
TelematicsActivity
.
class
);
startActivity
(
intent
);
...
...
@@ -127,7 +123,15 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
startActivity
(
intent
);
return
;
}
if
(
view
.
getId
()
==
R
.
id
.
iv_settings
)
{
if
(
view
.
getId
()
==
R
.
id
.
ll_auth_login
)
{
//6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons
//prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282, live 3000136179
mPbLoading
.
setVisibility
(
View
.
VISIBLE
);
WarplyManager
.
getCosmoteUser
(
mEtGuid
.
getText
().
toString
(),
mLoginReceiver
);
return
;
}
if
(
view
.
getId
()
==
R
.
id
.
ll_auth_logout
)
{
mPbLoading
.
setVisibility
(
View
.
VISIBLE
);
WarplyManager
.
logout
(
mLogoutReceiver
);
}
}
...
...
@@ -177,12 +181,38 @@ public class HomeFragment extends Fragment implements View.OnClickListener, Swip
private
final
CallbackReceiver
<
JSONObject
>
mLogoutReceiver
=
new
CallbackReceiver
<
JSONObject
>()
{
@Override
public
void
onSuccess
(
JSONObject
result
)
{
mPbLoading
.
setVisibility
(
View
.
GONE
);
mLlAuthLogout
.
setVisibility
(
View
.
GONE
);
mLlAuthLogin
.
setVisibility
(
View
.
VISIBLE
);
mEtGuid
.
setVisibility
(
View
.
VISIBLE
);
Toast
.
makeText
(
getActivity
(),
"LOGOUT SUCCESS"
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
public
void
onFailure
(
int
errorCode
)
{
mPbLoading
.
setVisibility
(
View
.
GONE
);
Toast
.
makeText
(
getActivity
(),
"LOGOUT ERROR"
,
Toast
.
LENGTH_SHORT
).
show
();
}
};
private
final
CallbackReceiver
<
JSONObject
>
mLoginReceiver
=
new
CallbackReceiver
<
JSONObject
>()
{
@Override
public
void
onSuccess
(
JSONObject
result
)
{
mPbLoading
.
setVisibility
(
View
.
GONE
);
mLlAuthLogin
.
setVisibility
(
View
.
GONE
);
mEtGuid
.
setVisibility
(
View
.
GONE
);
mLlAuthLogout
.
setVisibility
(
View
.
VISIBLE
);
if
(
result
!=
null
&&
result
.
optInt
(
"status"
)
==
1
)
{
WarplyManager
.
getUserCouponsWithCouponsets
(
mUserCouponsReceiver
);
WarplyManager
.
getCampaigns
(
mCampaignsCallback
);
WarplyManager
.
getUnifiedCouponsDeals
(
mUnifiedCallback
);
}
}
@Override
public
void
onFailure
(
int
errorCode
)
{
mPbLoading
.
setVisibility
(
View
.
GONE
);
Toast
.
makeText
(
getActivity
(),
"LOGIN ERROR"
,
Toast
.
LENGTH_SHORT
).
show
();
}
};
}
\ No newline at end of file
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/io/callbacks/VolleyTransformer.java
View file @
03b45bc
...
...
@@ -25,7 +25,6 @@
package
ly
.
warp
.
sdk
.
io
.
callbacks
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
ly.warp.sdk.Warply
;
...
...
@@ -42,6 +41,8 @@ import ly.warp.sdk.utils.WarpUtils;
import
static
ly
.
warp
.
sdk
.
Warply
.
getWarplyContext
;
import
android.text.TextUtils
;
public
class
VolleyTransformer
implements
Listener
<
JSONObject
>,
ErrorListener
{
public
VolleyTransformer
(
CallbackReceiver
<
JSONObject
>
listener
)
{
...
...
@@ -81,30 +82,42 @@ public class VolleyTransformer implements Listener<JSONObject>, ErrorListener {
@Override
public
void
onResponse
(
JSONObject
response
)
{
if
(
response
!=
null
)
{
if
(
response
.
optJSONObject
(
"context"
)
!=
null
)
{
if
(
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
)
!=
null
)
{
WarpUtils
.
setIsWarped
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optBoolean
(
"warped"
));
// WarpUtils.setDeviceToken(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optString("device_token"));
// WarpUtils.setHasApplicationInfo(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("application_info_saved"));
WarpUtils
.
setDeviceId
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optString
(
"device_id"
));
WarpUtils
.
setIsDeviceIdSaved
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optBoolean
(
"device_id_saved"
));
// WarpUtils.setIsDeviceInfoSaved(getWarplyContext(), response.optJSONObject("context").optJSONObject("device_status").optBoolean("device_info_saved"));
if
(
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"application_info"
)
!=
null
)
{
WarpUtils
.
setAppDataObject
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"application_info"
));
WarpUtils
.
setSDKVersion
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"application_info"
).
optString
(
"sdk_version"
));
WarpUtils
.
setAppVersion
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"application_info"
).
optString
(
"app_version"
));
JSONObject
contextObj
=
response
.
optJSONObject
(
"context"
);
if
(
contextObj
!=
null
)
{
JSONObject
deviceStatusObj
=
contextObj
.
optJSONObject
(
"device_status"
);
if
(
deviceStatusObj
!=
null
)
{
WarpUtils
.
setIsWarped
(
getWarplyContext
(),
deviceStatusObj
.
optBoolean
(
"warped"
));
WarpUtils
.
setDeviceId
(
getWarplyContext
(),
deviceStatusObj
.
optString
(
"device_id"
));
WarpUtils
.
setIsDeviceIdSaved
(
getWarplyContext
(),
deviceStatusObj
.
optBoolean
(
"device_id_saved"
));
JSONObject
applicationInfoObj
=
deviceStatusObj
.
optJSONObject
(
"application_info"
);
if
(
applicationInfoObj
!=
null
)
{
WarpUtils
.
setAppDataObject
(
getWarplyContext
(),
applicationInfoObj
);
WarpUtils
.
setSDKVersion
(
getWarplyContext
(),
applicationInfoObj
.
optString
(
"sdk_version"
));
WarpUtils
.
setAppVersion
(
getWarplyContext
(),
applicationInfoObj
.
optString
(
"app_version"
));
}
if
(
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"device_info"
)
!=
null
)
{
WarpUtils
.
setDeviceInfoObject
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"device_info"
));
WarpUtils
.
setOSVersion
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"device_info"
).
optString
(
"os_version"
));
WarpUtils
.
setDeviceBrand
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"device_info"
).
optString
(
"manufacturer"
));
WarpUtils
.
setCarrierName
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"device_status"
).
optJSONObject
(
"device_info"
).
optString
(
"carrier_name"
));
JSONObject
deviceInfoObj
=
deviceStatusObj
.
optJSONObject
(
"device_info"
);
if
(
deviceInfoObj
!=
null
)
{
WarpUtils
.
setDeviceInfoObject
(
getWarplyContext
(),
deviceInfoObj
);
WarpUtils
.
setOSVersion
(
getWarplyContext
(),
deviceInfoObj
.
optString
(
"os_version"
));
WarpUtils
.
setDeviceBrand
(
getWarplyContext
(),
deviceInfoObj
.
optString
(
"manufacturer"
));
WarpUtils
.
setCarrierName
(
getWarplyContext
(),
deviceInfoObj
.
optString
(
"carrier_name"
));
}
}
if
(
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"application_data"
)
!=
null
)
{
WarpUtils
.
setIsAPPDATAENABLED
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"application_data"
).
optBoolean
(
"APPLICATION_DATA_ENABLED"
));
WarpUtils
.
setIsDEVICEINFOENABLED
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"application_data"
).
optBoolean
(
"DEVICE_INFO_ENABLED"
));
WarpUtils
.
setIsLIFECYCLEANALYTICSENABLED
(
getWarplyContext
(),
response
.
optJSONObject
(
"context"
).
optJSONObject
(
"application_data"
).
optBoolean
(
"LIFECYCLE_ANALYTICS_ENABLED"
,
true
));
JSONObject
applicationDataObj
=
contextObj
.
optJSONObject
(
"application_data"
);
if
(
applicationDataObj
!=
null
)
{
WarpUtils
.
setIsAPPDATAENABLED
(
getWarplyContext
(),
applicationDataObj
.
optBoolean
(
"APPLICATION_DATA_ENABLED"
));
WarpUtils
.
setIsDEVICEINFOENABLED
(
getWarplyContext
(),
applicationDataObj
.
optBoolean
(
"DEVICE_INFO_ENABLED"
));
WarpUtils
.
setIsLIFECYCLEANALYTICSENABLED
(
getWarplyContext
(),
applicationDataObj
.
optBoolean
(
"LIFECYCLE_ANALYTICS_ENABLED"
,
true
));
if
(
applicationDataObj
.
has
(
"AUTHENTICATION"
))
{
String
jwtAuth
=
applicationDataObj
.
optString
(
"AUTHENTICATION"
,
""
);
WarpUtils
.
setIsJWTEnabled
(
getWarplyContext
(),
!
TextUtils
.
isEmpty
(
jwtAuth
)
&&
jwtAuth
.
equals
(
"JWT"
));
}
else
{
WarpUtils
.
setIsJWTEnabled
(
getWarplyContext
(),
false
);
}
}
}
}
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/io/volley/ApiService.java
View file @
03b45bc
...
...
@@ -77,6 +77,17 @@ public interface ApiService {
@Header
(
WarpConstants
.
HEADER_SIGNATURE
)
String
signature
);
@Headers
(
"Content-Type: application/json"
)
@POST
(
"/user/v5/{appUuid}/logout"
)
Call
<
ResponseBody
>
logoutUserJwt
(
@Path
(
"appUuid"
)
String
appUuid
,
@Body
RequestBody
request
,
@Header
(
WarpConstants
.
HEADER_DATE
)
String
timeStamp
,
@Header
(
WarpConstants
.
HEADER_LOYALTY_BUNDLE_ID
)
String
bundleId
,
@Header
(
WarpConstants
.
HEADER_UNIQUE_DEVICE_ID
)
String
deviceId
,
@Header
(
WarpConstants
.
HEADER_CHANNEL
)
String
channel
,
@Header
(
WarpConstants
.
HEADER_WEB_ID
)
String
webId
,
@Header
(
WarpConstants
.
HEADER_SIGNATURE
)
String
signature
);
@Headers
(
"Content-Type: application/json"
)
@POST
(
"/oauth/{appUuid}/context"
)
Call
<
ResponseBody
>
getCouponsets
(
@Path
(
"appUuid"
)
String
appUuid
,
@Body
RequestBody
request
,
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/utils/WarpUtils.java
View file @
03b45bc
...
...
@@ -159,6 +159,8 @@ public class WarpUtils {
+
"steps"
;
private
static
final
String
PREFERENCES_KEY_STEPS_MANUALLY_STOPPED
=
PREFERENCES_PREFIX
+
"steps_manually_stopped"
;
private
static
final
String
PREFERENCES_KEY_JWT_ENABLED
=
PREFERENCES_PREFIX
+
"jwt_enabled"
;
private
static
SharedPreferences
_prefs
;
...
...
@@ -639,6 +641,17 @@ public class WarpUtils {
editor
.
apply
();
}
public
static
boolean
isJWTEnabled
(
Context
context
)
{
SharedPreferences
prefs
=
getPreferences
(
context
);
return
prefs
.
getBoolean
(
PREFERENCES_KEY_JWT_ENABLED
,
true
);
}
public
static
void
setIsJWTEnabled
(
Context
context
,
boolean
jwtEnabled
)
{
SharedPreferences
.
Editor
editor
=
getPreferences
(
context
).
edit
();
editor
.
putBoolean
(
PREFERENCES_KEY_JWT_ENABLED
,
jwtEnabled
);
editor
.
apply
();
}
public
static
JSONObject
getAppDataObject
(
Context
context
)
{
SharedPreferences
prefs
=
getPreferences
(
context
);
try
{
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyManager.java
View file @
03b45bc
...
...
@@ -595,21 +595,39 @@ public class WarplyManager {
String
webId
=
WarpUtils
.
getWebId
(
Warply
.
getWarplyContext
());
Map
<
String
,
Object
>
jsonParams
=
new
ArrayMap
<>();
jsonParams
.
put
(
"access_token"
,
WarplyDBHelper
.
getInstance
(
Warply
.
getWarplyContext
()).
getAuthValue
(
"access_token"
));
jsonParams
.
put
(
"refresh_token"
,
WarplyDBHelper
.
getInstance
(
Warply
.
getWarplyContext
()).
getAuthValue
(
"refresh_token"
));
if
(
WarpUtils
.
isJWTEnabled
(
Warply
.
getWarplyContext
()))
{
jsonParams
.
put
(
"access_token"
,
WarplyDBHelper
.
getInstance
(
Warply
.
getWarplyContext
()).
getAuthValue
(
"access_token"
));
jsonParams
.
put
(
"refresh_token"
,
WarplyDBHelper
.
getInstance
(
Warply
.
getWarplyContext
()).
getAuthValue
(
"refresh_token"
));
}
else
{
jsonParams
.
put
(
"token"
,
WarplyDBHelper
.
getInstance
(
Warply
.
getWarplyContext
()).
getAuthValue
(
"access_token"
));
jsonParams
.
put
(
"client_id"
,
WarplyDBHelper
.
getInstance
(
Warply
.
getWarplyContext
()).
getClientValue
(
"client_id"
));
jsonParams
.
put
(
"client_secret"
,
WarplyDBHelper
.
getInstance
(
Warply
.
getWarplyContext
()).
getClientValue
(
"client_secret"
));
}
RequestBody
loginRequest
=
RequestBody
.
create
(
MediaType
.
get
(
"application/json; charset=utf-8"
),
(
new
JSONObject
(
jsonParams
)).
toString
());
Call
<
ResponseBody
>
logoutCall
=
service
.
logoutUser
(
WarplyProperty
.
getAppUuid
(
Warply
.
getWarplyContext
()),
loginRequest
,
timeStamp
,
"android:"
+
Warply
.
getWarplyContext
().
getPackageName
(),
new
WarplyDeviceInfoCollector
(
Warply
.
getWarplyContext
()).
getUniqueDeviceId
(),
"mobile"
,
webId
,
WarpUtils
.
produceSignature
(
apiKey
+
timeStamp
)
);
Call
<
ResponseBody
>
logoutCall
=
WarpUtils
.
isJWTEnabled
(
Warply
.
getWarplyContext
())
?
service
.
logoutUserJwt
(
WarplyProperty
.
getAppUuid
(
Warply
.
getWarplyContext
()),
loginRequest
,
timeStamp
,
"android:"
+
Warply
.
getWarplyContext
().
getPackageName
(),
new
WarplyDeviceInfoCollector
(
Warply
.
getWarplyContext
()).
getUniqueDeviceId
(),
"mobile"
,
webId
,
WarpUtils
.
produceSignature
(
apiKey
+
timeStamp
)
)
:
service
.
logoutUser
(
WarplyProperty
.
getAppUuid
(
Warply
.
getWarplyContext
()),
loginRequest
,
timeStamp
,
"android:"
+
Warply
.
getWarplyContext
().
getPackageName
(),
new
WarplyDeviceInfoCollector
(
Warply
.
getWarplyContext
()).
getUniqueDeviceId
(),
"mobile"
,
webId
,
WarpUtils
.
produceSignature
(
apiKey
+
timeStamp
)
);
logoutCall
.
enqueue
(
new
Callback
<
ResponseBody
>()
{
@Override
...
...
warply_android_sdk/src/main/res/layout/fragment_home.xml
View file @
03b45bc
This diff is collapsed. Click to expand it.
warply_android_sdk/src/main/res/values/strings.xml
View file @
03b45bc
...
...
@@ -213,6 +213,7 @@
<string
name=
"lbl_take_photo_decline"
>
Άκυρο
</string>
<string
name=
"lbl_gps_enabled"
>
Θέλετε να ενεργοποιήσετε το GPS;
</string>
<string
name=
"cos_telematics"
>
Safe Driving
</string>
<string
name=
"cos_hint"
>
GUID
</string>
<string
name=
"cos_telematics_metrics"
>
Ανάλυση
</string>
<string
name=
"cos_dlg_start_trip"
>
Έναρξη
</string>
<string
name=
"cos_dlg_stop_trip"
>
Παύση
</string>
...
...
@@ -244,6 +245,8 @@
<string
name=
"cos_vouchers_info_title_disabled"
>
Διαθέσιμο υπόλοιπο
</string>
<string
name=
"cos_vouchers_info_title_disabled_en"
>
Available balance
</string>
<string
name=
"cos_coupons_header"
>
Κουπόνια
</string>
<string
name=
"cos_login_text"
>
Σύνδεση
</string>
<string
name=
"cos_logout_text"
>
Αποσύνδεση
</string>
<string-array
name=
"coupons_array"
>
<item>
Κουπόνια
</item>
...
...
Please
register
or
login
to post a comment