Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit a5d1fb6

Browse files
committed
Add: App version checking logic
1 parent 33a3e44 commit a5d1fb6

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

app/src/main/java/io/github/tavisco/rvglassistant/fragments/MainFragment.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import butterknife.OnClick;
4242
import io.github.tavisco.rvglassistant.R;
4343
import io.github.tavisco.rvglassistant.objects.adapters.IOPackageViewItem;
44+
import io.github.tavisco.rvglassistant.objects.enums.UpdateStatus;
4445
import io.github.tavisco.rvglassistant.others.Constants;
4546
import permissions.dispatcher.NeedsPermission;
4647
import permissions.dispatcher.OnPermissionDenied;
@@ -74,6 +75,8 @@ public class MainFragment extends Fragment {
7475
TextView tvAppInstalledVersion;
7576
@BindView(R.id.tv_main_app_lastVersion)
7677
TextView tvAppLastVersion;
78+
@BindView(R.id.card_main_appUpdateVersions)
79+
CardView cardAppUpdateVersions;
7780

7881

7982
// =-=-=-= Recycler =-=-=-=
@@ -83,7 +86,8 @@ public class MainFragment extends Fragment {
8386

8487

8588
// =-=-=-= Items/Variables =-=-=-=
86-
boolean updateAvaiable = false;
89+
boolean gameUpdateAvaiable = false;
90+
UpdateStatus appUpdateStatus = UpdateStatus.NOT_INSTALLED;
8791

8892

8993
public MainFragment() {
@@ -143,8 +147,39 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
143147
}
144148

145149
private void checkForAppUpdates() {
150+
// TODO: Click on this card opens github page, and a dialog to alert the update
151+
146152
tvAppInstalledVersion.setText(String.format(getString(R.string.main_installed_version),
147153
BuildConfig.VERSION_NAME));
154+
155+
Context ctx = this.getContext();
156+
157+
if (ctx != null) {
158+
// Instantiate the RequestQueue.
159+
RequestQueue queue = Volley.newRequestQueue(this.getContext());
160+
161+
// Request a string response from the rvioRequest URL.
162+
StringRequest stringRequest = new StringRequest(Request.Method.GET, Constants.APP_LAST_VERSION_LINK,
163+
response -> {
164+
if (!response.isEmpty()){
165+
String appLastVersion = response.substring(0, 8);
166+
tvAppLastVersion.setText(String.format(getString(R.string.main_app_last_version), appLastVersion));
167+
168+
if (appLastVersion.equals(BuildConfig.VERSION_NAME)){
169+
appUpdateStatus = UpdateStatus.UPDATED;
170+
} else {
171+
appUpdateStatus = UpdateStatus.UPDATE_AVAIABLE;
172+
cardAppUpdateVersions.setCardBackgroundColor(ctx.getResources().getColor(R.color.newVersionRed));
173+
}
174+
}
175+
}, error -> Log.d(Constants.TAG, error.getLocalizedMessage()));
176+
177+
// Add the request to the RequestQueue.
178+
queue.add(stringRequest);
179+
}
180+
181+
182+
148183
}
149184

150185
@Override
@@ -303,15 +338,15 @@ public void compareWithLocalVersion(String localVersion, String lastVersion){
303338
cardUpdate.setCardBackgroundColor(getResources().getColor(R.color.newVersionRed));
304339
tvUpdateStatus.setText(String.format(getString(R.string.main_update_avaiable), lastVersion));
305340
imgUpdateStatus.setImageDrawable(getResources().getDrawable(R.drawable.ic_cloud_download));
306-
updateAvaiable = true;
341+
gameUpdateAvaiable = true;
307342
}
308343
}
309344
}
310345
}
311346

312347
@OnClick(R.id.card_main_updateStatus)
313348
public void clickCardUpdate(){
314-
if (updateAvaiable){
349+
if (gameUpdateAvaiable){
315350
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.RVGL_ANDROID_APK_LINK));
316351
startActivity(browserIntent);
317352
} else {

app/src/main/java/io/github/tavisco/rvglassistant/others/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Constants {
2323
public static final String RVIO_AVAIABLE_PACKAGES_LINK = "http://distribute.re-volt.io/packages.txt";
2424
public static final String RVIO_ASSETS_LINK = "https://distribute.re-volt.io/assets/";
2525
public static final String RVIO_DOWNLOAD_PACKS_LINK = "https://distribute.re-volt.io/packs/";
26+
public static final String APP_LAST_VERSION_LINK = "https://raw.githubusercontent.com/Tavisco/RVGL-Assistant_Android/master/last_version.txt";
2627

2728
//Files
2829
public static final String RVGL_CURRENT_VERSION_TXT = "rvgl_version.txt";

app/src/main/res/layout/fragment_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
</android.support.v7.widget.CardView>
111111

112112
<android.support.v7.widget.CardView
113+
android:id="@+id/card_main_appUpdateVersions"
113114
android:layout_width="0dp"
114115
android:layout_height="match_parent"
115116
android:layout_weight="4">

0 commit comments

Comments
 (0)