4141import butterknife .OnClick ;
4242import io .github .tavisco .rvglassistant .R ;
4343import io .github .tavisco .rvglassistant .objects .adapters .IOPackageViewItem ;
44+ import io .github .tavisco .rvglassistant .objects .enums .UpdateStatus ;
4445import io .github .tavisco .rvglassistant .others .Constants ;
4546import permissions .dispatcher .NeedsPermission ;
4647import 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 {
0 commit comments