check if the latest assets have been moved to the sdcard (compare with versionCode)
authorXeli
Sat, 04 Feb 2012 23:06:22 +0100
changeset 6623 6bf169f1e97c
parent 6622 01889d5bc79b
child 6624 e049b5bb0ad1
check if the latest assets have been moved to the sdcard (compare with versionCode)
project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java	Sat Feb 04 16:22:46 2012 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/MainActivity.java	Sat Feb 04 23:06:22 2012 +0100
@@ -26,6 +26,8 @@
 import android.app.ProgressDialog;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.v4.app.FragmentActivity;
@@ -54,7 +56,13 @@
 		if(cacheDir == null){
 			showDialog(0);
 		}else{
-			boolean assetsCopied = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("assetscopied", false);
+			int versionCode = 0;
+			try {
+				versionCode = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
+			} catch (NameNotFoundException e) {
+
+			}
+			boolean assetsCopied = PreferenceManager.getDefaultSharedPreferences(this).getInt("latestAssets", 0) >= versionCode;
 
 			if(!assetsCopied){
 				DownloadAssets assetsAsyncTask = new DownloadAssets(this);
@@ -79,7 +87,11 @@
 
 	public void onAssetsDownloaded(boolean result){
 		if(result){
-			PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("assetscopied", true).commit();
+			try {
+				int versionCode = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionCode;
+				PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("latestAssets", versionCode).commit();
+			} catch (NameNotFoundException e) {}
+			
 		}else{
 			Toast.makeText(this, R.string.download_failed, Toast.LENGTH_LONG);
 		}