|
8 | 8 | import android.content.DialogInterface;
|
9 | 9 | import android.content.Intent;
|
10 | 10 | import android.content.SharedPreferences;
|
| 11 | +import android.content.pm.PackageInfo; |
11 | 12 | import android.content.res.Configuration;
|
12 | 13 | import android.content.res.Resources;
|
13 | 14 | import android.net.Uri;
|
@@ -110,8 +111,8 @@ public class selector extends AppCompatActivity {
|
110 | 111 |
|
111 | 112 | mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
|
112 | 113 |
|
113 |
| - //CheckUpdate(); |
114 | 114 | TrackingAgreement(false);
|
| 115 | + checkUpdate(); |
115 | 116 | //int margin = calcDrawerLayoutMargin();
|
116 | 117 | //LinearLayout layout = findViewById(R.id.drawerHeaderLayout);
|
117 | 118 | //setMargins(layout,0,margin,0,0);
|
@@ -143,10 +144,45 @@ public void checkUpdate() {
|
143 | 144 | new Thread(new Runnable() {
|
144 | 145 | public void run() {
|
145 | 146 | try {
|
| 147 | + PackageInfo pInfo = getApplicationContext().getPackageManager().getPackageInfo(getPackageName(), 0); |
| 148 | + String version = pInfo.versionName; |
| 149 | + |
146 | 150 | Document doc = Jsoup.connect("https://raw.githubusercontent.com/TurtleForGaming/NLR_Viewer/master/VERSION.txt").get();
|
| 151 | + String gitVersion = doc.text(); |
| 152 | + |
| 153 | + if(!version.equals(gitVersion)) { |
| 154 | + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
| 155 | + @Override |
| 156 | + public void onClick(DialogInterface dialog, int which) { |
| 157 | + switch (which){ |
| 158 | + case DialogInterface.BUTTON_POSITIVE: |
| 159 | + social_openlink("https://github.com/TurtleForGaming/NLR_Viewer/releases/download/V"+gitVersion+"/nlr_viewer.v"+gitVersion+".apk"); |
| 160 | + break; |
| 161 | + |
| 162 | + case DialogInterface.BUTTON_NEGATIVE: |
| 163 | + //No button clicked |
| 164 | + break; |
| 165 | + } |
| 166 | + } |
| 167 | + }; |
| 168 | + |
| 169 | + AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(selector.this, R.style.AlertDialogCustom)); |
| 170 | + builder.setTitle(getString(R.string.action_newupdate)) |
| 171 | + .setMessage(getString(R.string.action_newversion) + ": \n" + gitVersion + "\n\n"+getString(R.string.action_actualversion)+":\n"+version) |
| 172 | + .setPositiveButton("Download", dialogClickListener) |
| 173 | + .setNegativeButton("Pass", dialogClickListener); |
| 174 | + |
| 175 | + runOnUiThread(new Runnable() { |
| 176 | + @Override |
| 177 | + public void run() { |
| 178 | + builder.show(); |
| 179 | + } |
| 180 | + }); |
| 181 | + } |
147 | 182 |
|
148 | 183 | } catch (Exception e) {
|
149 |
| - Log.e("UpdateEpisodes", e.getMessage(), e); |
| 184 | + Log.e("checkUpdate", e.getMessage(), e); |
| 185 | + Toast.makeText(getApplicationContext(),"Failed to check update", Toast.LENGTH_LONG).show(); |
150 | 186 | }
|
151 | 187 | }
|
152 | 188 | }).start();
|
@@ -2099,54 +2135,6 @@ public String CheckUrl2(String url) {
|
2099 | 2135 | */
|
2100 | 2136 | }
|
2101 | 2137 |
|
2102 |
| - /*public void CheckUpdate() { |
2103 |
| - final String CurrentRevisonURL = "http://samuel.tugler.fr/redirect/?c=3"; |
2104 |
| - new Thread(new Runnable() { |
2105 |
| - public void run() { |
2106 |
| - try { |
2107 |
| - Document doc = Jsoup.connect(CurrentRevisonURL).get(); |
2108 |
| - String a = doc.text(); |
2109 |
| - if(!a.equals(CURRENTREVISION) && !DEBUGMODE) { |
2110 |
| - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
2111 |
| - @Override |
2112 |
| - public void onClick(DialogInterface dialog, int which) { |
2113 |
| - switch (which){ |
2114 |
| - case DialogInterface.BUTTON_POSITIVE: |
2115 |
| - social_openlink("http://samuel.tugler.fr/redirect/?c=2"); |
2116 |
| - break; |
2117 |
| -
|
2118 |
| - case DialogInterface.BUTTON_NEGATIVE: |
2119 |
| - //No button clicked |
2120 |
| - break; |
2121 |
| - } |
2122 |
| - } |
2123 |
| - }; |
2124 |
| -
|
2125 |
| - AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(selector.this, R.style.AlertDialogCustom)); |
2126 |
| - builder.setTitle(getString(R.string.action_newupdate)) |
2127 |
| - .setMessage(getString(R.string.action_newversion) + ": \n" + a + "\n\n"+getString(R.string.action_actualversion)+":\n"+CURRENTREVISION) |
2128 |
| - .setPositiveButton("Download", dialogClickListener) |
2129 |
| - .setNegativeButton("Pass", dialogClickListener); |
2130 |
| -
|
2131 |
| - runOnUiThread(new Runnable() { |
2132 |
| - @Override |
2133 |
| - public void run() { |
2134 |
| - builder.show(); |
2135 |
| - } |
2136 |
| - }); |
2137 |
| - } else { |
2138 |
| - if(DEBUGMODE) { |
2139 |
| - Toast.makeText(getApplication(), "Woaw you're running in debug mode", Toast.LENGTH_LONG).show(); |
2140 |
| - } |
2141 |
| - } |
2142 |
| - } catch (Exception e) { |
2143 |
| - Log.e("CheckUrl", "Thread", e); |
2144 |
| - Toast.makeText(getApplication(), "Error:\n" + e.getMessage(), Toast.LENGTH_LONG).show(); |
2145 |
| - } |
2146 |
| - } |
2147 |
| - }).start(); |
2148 |
| - }*/ |
2149 |
| - |
2150 | 2138 | public void TrackingAgreement(boolean ignorePreviousChoice) {
|
2151 | 2139 | SharedPreferences sharedPreferences = getBaseContext().getSharedPreferences("app_traking", MODE_PRIVATE);
|
2152 | 2140 | int value = sharedPreferences.getInt("allowtracking",-1);
|
|
0 commit comments