Skip to content

Commit

Permalink
force update added|server change
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuwan-Harshakumara-Piyarathna committed Sep 10, 2021
1 parent f70c00f commit d24ed5c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.cipher.pera.quizme"
minSdkVersion 19
targetSdkVersion 30
versionCode 2
versionName "2.0"
versionCode 4
versionName "2.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Binary file added app/release/app-release.aab
Binary file not shown.
61 changes: 60 additions & 1 deletion app/src/main/java/com/example/quizme/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.icu.text.DateTimePatternGenerator;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
Expand All @@ -22,6 +27,7 @@
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.example.quizme.utility.NetworkChangeListener;
import com.fangxu.allangleexpandablebutton.AllAngleExpandableButton;
Expand Down Expand Up @@ -294,7 +300,60 @@ public void onCollapse() {
}

private void checkForUpdates() {

Log.e("VERSION CODE",String.valueOf(BuildConfig.VERSION_CODE));
Log.e("VERSION NAME",String.valueOf(BuildConfig.VERSION_NAME));

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
String baseURL =pref.getString("baseURL",null);
String url = baseURL + "/all/version/find";

JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
String newerVersion = response.getString("version");
Log.e("BACKEND VERSION",newerVersion);
String currentVersion = String.valueOf(BuildConfig.VERSION_NAME);
if(newerVersion.compareTo(currentVersion) > 0){
android.view.ContextThemeWrapper ctw = new android.view.ContextThemeWrapper(MainActivity.this,R.style.Theme_AlertDialog);
final android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(ctw);
alertDialogBuilder.setTitle("Update Quiz Me");
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setIcon(R.drawable.playstore1);
alertDialogBuilder.setMessage("Quiz Me recommends that you update to the latest version for a seamless & enhanced performance of the app.");
alertDialogBuilder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
try{
Log.e("UPDATE TRYCATCH","try");
startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id="+getPackageName())));
}
catch (ActivityNotFoundException e){
Log.e("UPDATE TRYCATCH","catch");
startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://play.google.com/store/apps/details?id="+getPackageName())));
}
}
});
alertDialogBuilder.show();

}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});

// Add the request to the RequestQueue.
queue.add(request);

}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/quizme/SplashActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void onFinish() {

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
editor.putString("baseURL", "http://quizmebackendv2-env.eba-7pycjpu4.us-east-1.elasticbeanstalk.com");
editor.putString("baseURL", "https://quizmeonline.herokuapp.com");
editor.commit();


Expand Down
Binary file added app/src/main/res/drawable/icons_google_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/playstore1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,18 @@
<item name="android:windowCloseOnTouchOutside">true</item>

</style>

<style name="AlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="cornerRadius">40dp</item>
</style>

<style name="Theme.AlertDialog" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:background">@android:color/transparent</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:windowTitleStyle">@style/Theme.AlertDialog.Title</item>
</style>

<style name="Theme.AlertDialog.Title" parent="@android:style/TextAppearance.DialogWindowTitle">
<item name="android:textColor">#fff</item>
</style>
</resources>

0 comments on commit d24ed5c

Please sign in to comment.