Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
InstiApp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
RAHUL SHARMA
InstiApp
Commits
bd840c83
Commit
bd840c83
authored
Sep 30, 2018
by
Varun Patil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PATCH android_version with fcm_id
parent
0adab2b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
21 deletions
+29
-21
app/src/main/java/app/insti/activity/MainActivity.java
app/src/main/java/app/insti/activity/MainActivity.java
+24
-20
app/src/main/java/app/insti/api/model/UserFCMPatchRequest.java
...rc/main/java/app/insti/api/model/UserFCMPatchRequest.java
+5
-1
No files found.
app/src/main/java/app/insti/activity/MainActivity.java
View file @
bd840c83
...
@@ -34,6 +34,7 @@ import android.widget.Toast;
...
@@ -34,6 +34,7 @@ import android.widget.Toast;
import
com.google.android.gms.tasks.OnSuccessListener
;
import
com.google.android.gms.tasks.OnSuccessListener
;
import
com.google.firebase.iid.FirebaseInstanceId
;
import
com.google.firebase.iid.FirebaseInstanceId
;
import
com.google.firebase.iid.InstanceIdResult
;
import
com.google.firebase.iid.InstanceIdResult
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonObject
;
import
com.squareup.picasso.Picasso
;
import
com.squareup.picasso.Picasso
;
...
@@ -189,31 +190,34 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -189,31 +190,34 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
});
});
}
}
private
void
checkLatestVersion
()
{
/** Get version code we are currently on */
private
int
getCurrentVersion
()
{
try
{
try
{
PackageInfo
pInfo
=
this
.
getPackageManager
().
getPackageInfo
(
getPackageName
(),
0
);
PackageInfo
pInfo
=
this
.
getPackageManager
().
getPackageInfo
(
getPackageName
(),
0
);
final
int
versionCode
=
pInfo
.
versionCode
;
return
pInfo
.
versionCode
;
RetrofitInterface
retrofitInterface
=
getRetrofitInterface
();
retrofitInterface
.
getLatestVersion
().
enqueue
(
new
Callback
<
JsonObject
>()
{
@Override
public
void
onResponse
(
Call
<
JsonObject
>
call
,
Response
<
JsonObject
>
response
)
{
if
(
response
.
isSuccessful
())
{
if
(
response
.
body
().
get
(
"version"
).
getAsInt
()
>
versionCode
)
{
showUpdateSnackBar
(
response
.
body
().
get
(
"message"
).
getAsString
());
}
}
}
@Override
public
void
onFailure
(
Call
<
JsonObject
>
call
,
Throwable
t
)
{
}
});
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{
return
0
;
}
}
}
}
/** Check for updates in andro.json */
private
void
checkLatestVersion
()
{
final
int
versionCode
=
getCurrentVersion
();
if
(
versionCode
==
0
)
{
return
;
}
RetrofitInterface
retrofitInterface
=
getRetrofitInterface
();
retrofitInterface
.
getLatestVersion
().
enqueue
(
new
EmptyCallback
<
JsonObject
>()
{
@Override
public
void
onResponse
(
Call
<
JsonObject
>
call
,
Response
<
JsonObject
>
response
)
{
if
(
response
.
isSuccessful
())
{
final
JsonElement
currentVersion
=
response
.
body
().
get
(
"version"
);
if
(
currentVersion
!=
null
&&
currentVersion
.
getAsInt
()
>
versionCode
)
{
showUpdateSnackBar
(
response
.
body
().
get
(
"message"
).
getAsString
());
}
}
}
});
}
private
void
showUpdateSnackBar
(
String
message
)
{
private
void
showUpdateSnackBar
(
String
message
)
{
View
parentLayout
=
findViewById
(
android
.
R
.
id
.
content
);
View
parentLayout
=
findViewById
(
android
.
R
.
id
.
content
);
Snackbar
.
make
(
parentLayout
,
message
,
Snackbar
.
LENGTH_LONG
).
setAction
(
"UPDATE"
,
new
View
.
OnClickListener
()
{
Snackbar
.
make
(
parentLayout
,
message
,
Snackbar
.
LENGTH_LONG
).
setAction
(
"UPDATE"
,
new
View
.
OnClickListener
()
{
...
@@ -404,7 +408,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
...
@@ -404,7 +408,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
final
String
fcmId
=
instanceIdResult
.
getToken
();
final
String
fcmId
=
instanceIdResult
.
getToken
();
RetrofitInterface
retrofitInterface
=
getRetrofitInterface
();
RetrofitInterface
retrofitInterface
=
getRetrofitInterface
();
retrofitInterface
.
patchUserMe
(
getSessionIDHeader
(),
new
UserFCMPatchRequest
(
fcmId
)).
enqueue
(
new
Callback
<
User
>()
{
retrofitInterface
.
patchUserMe
(
getSessionIDHeader
(),
new
UserFCMPatchRequest
(
fcmId
,
getCurrentVersion
()
)).
enqueue
(
new
Callback
<
User
>()
{
@Override
@Override
public
void
onResponse
(
Call
<
User
>
call
,
Response
<
User
>
response
)
{
public
void
onResponse
(
Call
<
User
>
call
,
Response
<
User
>
response
)
{
if
(
response
.
isSuccessful
())
{
if
(
response
.
isSuccessful
())
{
...
...
app/src/main/java/app/insti/api/model/UserFCMPatchRequest.java
View file @
bd840c83
...
@@ -6,7 +6,11 @@ public class UserFCMPatchRequest {
...
@@ -6,7 +6,11 @@ public class UserFCMPatchRequest {
@SerializedName
(
"fcm_id"
)
@SerializedName
(
"fcm_id"
)
private
String
userFCMId
;
private
String
userFCMId
;
public
UserFCMPatchRequest
(
String
userFCMId
)
{
@SerializedName
(
"android_version"
)
private
int
userAndroidVersion
;
public
UserFCMPatchRequest
(
String
userFCMId
,
int
userAndroidVersion
)
{
this
.
userFCMId
=
userFCMId
;
this
.
userFCMId
=
userFCMId
;
this
.
userAndroidVersion
=
userAndroidVersion
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment