Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
InvestCustomer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Giang Tran
InvestCustomer
Commits
f12dda9c
Commit
f12dda9c
authored
May 05, 2021
by
Nguyễn Thị Thúy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update version
parent
0c3d0ca1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
220 additions
and
15 deletions
+220
-15
KeyStore
android/app/KeyStore
+0
-0
build.gradle
android/app/build.gradle
+12
-4
InAppUpdateModule.java
...d/app/src/main/java/com/dcv/invest/InAppUpdateModule.java
+158
-0
InAppUpdatePackage.java
.../app/src/main/java/com/dcv/invest/InAppUpdatePackage.java
+29
-0
MainApplication.java
...oid/app/src/main/java/com/dcv/invest/MainApplication.java
+1
-0
RootView.js
src/RootView.js
+0
-1
index.js
src/Screens/VersionChecker/index.js
+17
-10
InAppUpdate.js
src/helper/InAppUpdate.js
+3
-0
No files found.
android/app/KeyStore
0 → 100644
View file @
f12dda9c
File added
android/app/build.gradle
View file @
f12dda9c
...
...
@@ -132,8 +132,8 @@ android {
applicationId
"com.dcv.invest"
minSdkVersion
rootProject
.
ext
.
minSdkVersion
targetSdkVersion
rootProject
.
ext
.
targetSdkVersion
versionCode
3
versionName
"1.
3
"
versionCode
2
versionName
"1.
2
"
vectorDrawables
.
useSupportLibrary
=
true
}
splits
{
...
...
@@ -151,6 +151,12 @@ android {
keyAlias
'androiddebugkey'
keyPassword
'android'
}
release
{
storeFile
file
(
'KeyStore'
)
storePassword
'dcvinvest'
keyAlias
'dcvinvest'
keyPassword
'dcvinvest'
}
}
buildTypes
{
debug
{
...
...
@@ -159,8 +165,9 @@ android {
release
{
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig
signingConfigs
.
debug
signingConfig
signingConfigs
.
release
minifyEnabled
enableProguardInReleaseBuilds
debuggable
true
proguardFiles
getDefaultProguardFile
(
"proguard-android.txt"
),
"proguard-rules.pro"
}
}
...
...
@@ -222,7 +229,8 @@ implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
implementation
jscFlavor
}
implementation
'com.google.firebase:firebase-analytics:17.2.2'
implementation
'com.google.android.play:core:1.7.3'
implementation
'com.google.android.material:material:1.0.0'
}
// Run this once to be able to run the application with BUCK
...
...
android/app/src/main/java/com/dcv/invest/InAppUpdateModule.java
0 → 100644
View file @
f12dda9c
package
com
.
dcv
.
invest
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.content.IntentSender
;
import
android.graphics.Color
;
import
androidx.annotation.NonNull
;
import
com.facebook.react.bridge.ActivityEventListener
;
import
com.facebook.react.bridge.BaseActivityEventListener
;
import
com.facebook.react.bridge.LifecycleEventListener
;
import
com.facebook.react.bridge.ReactApplicationContext
;
import
com.facebook.react.bridge.ReactContextBaseJavaModule
;
import
com.facebook.react.bridge.ReactMethod
;
import
com.google.android.material.snackbar.Snackbar
;
import
com.google.android.play.core.appupdate.AppUpdateInfo
;
import
com.google.android.play.core.appupdate.AppUpdateManager
;
import
com.google.android.play.core.appupdate.AppUpdateManagerFactory
;
import
com.google.android.play.core.install.InstallState
;
import
com.google.android.play.core.install.InstallStateUpdatedListener
;
import
com.google.android.play.core.install.model.AppUpdateType
;
import
com.google.android.play.core.install.model.InstallStatus
;
import
com.google.android.play.core.install.model.UpdateAvailability
;
import
com.google.android.play.core.tasks.Task
;
import
java.util.Objects
;
import
static
android
.
app
.
Activity
.
RESULT_OK
;
public
class
InAppUpdateModule
extends
ReactContextBaseJavaModule
implements
InstallStateUpdatedListener
,
LifecycleEventListener
{
private
AppUpdateManager
appUpdateManager
;
private
static
ReactApplicationContext
reactContext
;
private
static
final
int
STALE_DAYS
=
5
;
private
static
final
int
MY_REQUEST_CODE
=
0
;
private
final
ActivityEventListener
mActivityEventListener
=
new
BaseActivityEventListener
()
{
@Override
public
void
onActivityResult
(
Activity
activity
,
int
requestCode
,
int
resultCode
,
Intent
intent
)
{
if
(
requestCode
==
MY_REQUEST_CODE
)
{
if
(
resultCode
!=
RESULT_OK
)
{
System
.
out
.
println
(
"Update flow failed! Result code: "
+
resultCode
);
// If the update is cancelled or fails,
// you can request to start the update again.
}
}
}
};
InAppUpdateModule
(
ReactApplicationContext
context
)
{
super
(
context
);
reactContext
=
context
;
reactContext
.
addActivityEventListener
(
mActivityEventListener
);
reactContext
.
addLifecycleEventListener
(
this
);
}
@NonNull
@Override
public
String
getName
()
{
return
"InAppUpdate"
;
}
@ReactMethod
public
void
checkUpdate
()
throws
Exception
{
appUpdateManager
=
AppUpdateManagerFactory
.
create
(
reactContext
);
appUpdateManager
.
registerListener
(
this
);
Task
<
AppUpdateInfo
>
appUpdateInfoTask
=
appUpdateManager
.
getAppUpdateInfo
();
if
(
appUpdateInfoTask
.
getException
()
!=
null
)
throw
appUpdateInfoTask
.
getException
();
appUpdateInfoTask
.
addOnSuccessListener
(
appUpdateInfo
->
{
if
(
appUpdateInfo
.
updateAvailability
()
==
UpdateAvailability
.
UPDATE_AVAILABLE
&&
appUpdateInfo
.
clientVersionStalenessDays
()
!=
null
&&
appUpdateInfo
.
clientVersionStalenessDays
()
>
STALE_DAYS
&&
appUpdateInfo
.
isUpdateTypeAllowed
(
AppUpdateType
.
IMMEDIATE
))
{
try
{
appUpdateManager
.
startUpdateFlowForResult
(
appUpdateInfo
,
AppUpdateType
.
IMMEDIATE
,
reactContext
.
getCurrentActivity
(),
MY_REQUEST_CODE
);
}
catch
(
IntentSender
.
SendIntentException
e
)
{
e
.
printStackTrace
();
}
}
else
{
if
(
appUpdateInfo
.
updateAvailability
()
==
UpdateAvailability
.
UPDATE_AVAILABLE
&&
appUpdateInfo
.
isUpdateTypeAllowed
(
AppUpdateType
.
FLEXIBLE
))
{
try
{
appUpdateManager
.
startUpdateFlowForResult
(
appUpdateInfo
,
AppUpdateType
.
FLEXIBLE
,
reactContext
.
getCurrentActivity
(),
MY_REQUEST_CODE
);
}
catch
(
IntentSender
.
SendIntentException
e
)
{
e
.
printStackTrace
();
}
}
}
});
}
@Override
public
void
onStateUpdate
(
InstallState
state
)
{
if
(
state
.
installStatus
()
==
InstallStatus
.
DOWNLOADED
)
{
popupSnackbarForCompleteUpdate
();
}
}
private
void
popupSnackbarForCompleteUpdate
()
{
Snackbar
snackbar
=
Snackbar
.
make
(
Objects
.
requireNonNull
(
reactContext
.
getCurrentActivity
()).
findViewById
(
android
.
R
.
id
.
content
).
getRootView
(),
"An update has just been downloaded."
,
Snackbar
.
LENGTH_INDEFINITE
);
snackbar
.
setAction
(
"RESTART"
,
view
->
appUpdateManager
.
completeUpdate
());
snackbar
.
setActionTextColor
(
Color
.
GREEN
);
snackbar
.
show
();
}
@Override
public
void
onHostResume
()
{
if
(
appUpdateManager
!=
null
)
{
appUpdateManager
.
getAppUpdateInfo
()
.
addOnSuccessListener
(
appUpdateInfo
->
{
if
(
appUpdateInfo
.
installStatus
()
==
InstallStatus
.
DOWNLOADED
)
{
popupSnackbarForCompleteUpdate
();
}
if
(
appUpdateInfo
.
updateAvailability
()
==
UpdateAvailability
.
DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS
)
{
try
{
appUpdateManager
.
startUpdateFlowForResult
(
appUpdateInfo
,
AppUpdateType
.
IMMEDIATE
,
reactContext
.
getCurrentActivity
(),
MY_REQUEST_CODE
);
}
catch
(
IntentSender
.
SendIntentException
e
)
{
e
.
printStackTrace
();
}
}
});
}
}
@Override
public
void
onHostPause
()
{
}
@Override
public
void
onHostDestroy
()
{
if
(
appUpdateManager
!=
null
)
{
appUpdateManager
.
unregisterListener
(
this
);
}
}
}
android/app/src/main/java/com/dcv/invest/InAppUpdatePackage.java
0 → 100644
View file @
f12dda9c
package
com
.
dcv
.
invest
;
import
androidx.annotation.NonNull
;
import
com.facebook.react.ReactPackage
;
import
com.facebook.react.bridge.NativeModule
;
import
com.facebook.react.bridge.ReactApplicationContext
;
import
com.facebook.react.uimanager.ViewManager
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
public
class
InAppUpdatePackage
implements
ReactPackage
{
@NonNull
@Override
public
List
<
NativeModule
>
createNativeModules
(
@NonNull
ReactApplicationContext
reactContext
)
{
List
<
NativeModule
>
modules
=
new
ArrayList
<>();
modules
.
add
(
new
InAppUpdateModule
(
reactContext
));
return
modules
;
}
@NonNull
@Override
public
List
<
ViewManager
>
createViewManagers
(
@NonNull
ReactApplicationContext
reactContext
)
{
return
Collections
.
emptyList
();
}
}
android/app/src/main/java/com/dcv/invest/MainApplication.java
View file @
f12dda9c
...
...
@@ -29,6 +29,7 @@ public class MainApplication extends Application implements ReactApplication {
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
// packages.add(new RNBootSplashPackage());
packages
.
add
(
new
InAppUpdatePackage
());
return
packages
;
}
...
...
src/RootView.js
View file @
f12dda9c
...
...
@@ -15,7 +15,6 @@ enableScreens();
const
RootView
=
(
props
)
=>
{
useEffect
(()
=>
{
checkVersion
();
},
[]);
const
checkVersion
=
(
props
)
=>
{
...
...
src/Screens/VersionChecker/index.js
View file @
f12dda9c
...
...
@@ -14,6 +14,7 @@ import {getFontXD, getHeight, getWidth, HEIGHTXD, WIDTHXD} from '../../Config/Fu
import
I18n
from
'../../helper/i18/i18n'
;
import
DeviceInfo
from
'react-native-device-info'
;
import
{
getNewestVersionInfo
}
from
'../../apis/Functions/users'
;
import
InAppUpdate
from
'../../helper/InAppUpdate'
;
const
VersionChecker
=
(
props
)
=>
{
const
[
visible
,
setVisible
]
=
useState
(
false
);
...
...
@@ -29,11 +30,11 @@ const VersionChecker = (props) => {
platform
:
Platform
.
OS
,
});
if
((
res
.
data
.
code
=
200
&&
res
.
data
.
data
))
{
console
.
log
(
res
)
if
(
res
.
data
.
data
[
0
].
version_name
!==
verCurrent
||
res
.
data
.
data
[
0
].
build
.
toString
()
!==
DeviceInfo
.
getBuildNumber
)
{
setVersion
(
res
.
data
.
data
[
0
].
version_name
)
setVisible
(
true
)
setIsForceUpdate
(
res
.
data
.
data
[
0
].
is_require_update
==
0
?
false
:
true
)
console
.
log
(
res
)
;
if
(
res
.
data
.
data
[
0
].
version_name
!==
verCurrent
||
res
.
data
.
data
[
0
].
build
.
toString
()
!==
DeviceInfo
.
getBuildNumber
)
{
setVersion
(
res
.
data
.
data
[
0
].
version_name
)
;
setVisible
(
true
)
;
setIsForceUpdate
(
res
.
data
.
data
[
0
].
is_require_update
==
0
?
false
:
true
)
;
}
}
};
...
...
@@ -54,7 +55,12 @@ const VersionChecker = (props) => {
if
(
Platform
.
OS
===
'ios'
)
{
Linking
.
openURL
(
'itms-apps://itunes.apple.com/us/app/dcv-invest/id1556621903?l=id'
);
}
else
{
Linking
.
openURL
(
'https://play.google.com/store/apps/details?id=com.dcv.invest'
);
try
{
InAppUpdate
.
checkUpdate
()
}
catch
(
e
)
{
console
.
log
(
e
)
}
// Linking.openURL('https://play.google.com/store/apps/details?id=com.dcv.invest');
}
}
catch
(
error
)
{
}
...
...
@@ -97,7 +103,8 @@ const VersionChecker = (props) => {
<
View
pointerEvents
=
"box-none"
style
=
{
styles
.
containerStyle
}
>
<
View
style
=
{
styles
.
imageUpgradeContainer
}
zIndex
=
{
100
}
>
<
Image
style
=
{[
styles
.
imageUpgradeStyle
,
{
tintColor
:
R
.
colors
.
main
}]}
/
>
source
=
{
R
.
images
.
iconUpgrade
}
style
=
{[
styles
.
imageUpgradeStyle
,
{
tintColor
:
R
.
colors
.
main
}]}
/
>
<
/View
>
<
View
style
=
{
styles
.
contentContainerStyle
}
>
...
...
@@ -112,7 +119,7 @@ const VersionChecker = (props) => {
{
_renderDivider
()}
{
isForceUpdate
?
<
TouchableOpacity
onPress
=
{()
=>
onUpdatePressed
()}
style
=
{
styles
.
notNowContainerStyle
}
>
<
TouchableOpacity
onPress
=
{()
=>
onUpdatePressed
()}
style
=
{
styles
.
notNowContainerStyle
}
>
<
Text
style
=
{[
styles
.
textNotNowStyle
,
{
color
:
R
.
colors
.
main
}]}
>
{
I18n
.
t
(
'Update'
)}
<
/Text
>
<
/TouchableOpacity
>
...
...
@@ -121,13 +128,13 @@ const VersionChecker = (props) => {
flexDirection
:
'row'
,
marginHorizontal
:
WIDTHXD
(
100
),
}]}
>
<
TouchableOpacity
onPress
=
{()
=>
cancelUpdate
()}
<
TouchableOpacity
onPress
=
{()
=>
cancelUpdate
()}
style
=
{[
styles
.
btnButton
,
{
paddingRight
:
WIDTHXD
(
90
)}]}
>
<
Text
style
=
{[
styles
.
textNotNowStyle
,
{
color
:
R
.
colors
.
color777
}]}
>
{
I18n
.
t
(
'Cancel'
)}
<
/Text
>
<
/TouchableOpacity
>
<
View
style
=
{
styles
.
dividerStyleVertical
}
><
/View
>
<
TouchableOpacity
onPress
=
{()
=>
onUpdatePressed
()}
<
TouchableOpacity
onPress
=
{()
=>
onUpdatePressed
()}
style
=
{[
styles
.
btnButton
,
{
paddingLeft
:
WIDTHXD
(
90
)}]}
>
<
Text
style
=
{[
styles
.
textNotNowStyle
,
{
color
:
R
.
colors
.
main
}]}
>
{
I18n
.
t
(
'Update'
)}
<
/Text
>
...
...
src/helper/InAppUpdate.js
0 → 100644
View file @
f12dda9c
import
{
NativeModules
}
from
'react-native'
module
.
exports
=
NativeModules
.
InAppUpdate
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