added update mechanism to iitcm

This commit is contained in:
Philipp Schaefer
2013-11-08 21:42:59 +01:00
parent 210a306042
commit c82803d236
3 changed files with 140 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package com.cradle.iitc_mobile;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.content.Context;
import android.content.DialogInterface;
@@ -15,6 +16,7 @@ import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -28,6 +30,7 @@ import android.widget.SearchView;
import android.widget.Toast;
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
import com.cradle.iitc_mobile.async.DownloadIitcUpdate;
import java.io.File;
import java.io.IOException;
@@ -38,6 +41,7 @@ import java.util.Stack;
public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeListener, LocationListener {
private static final int REQUEST_LOGIN = 1;
public static final int REQUEST_UPDATE_FINISHED = 2;
private IITC_WebView mIitcWebView;
private final String mIntelUrl = "https://www.ingress.com/intel";
@@ -53,6 +57,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
private SharedPreferences mSharedPrefs;
private IITC_NavigationHelper mNavigationHelper;
private IITC_MapSettings mMapSettings;
private ProgressDialog mProgressDialog;
// Used for custom back stack handling
private final Stack<Pane> mBackStack = new Stack<IITC_NavigationHelper.Pane>();
@@ -106,6 +111,13 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
// Clear the back stack
mBackStack.clear();
// init update progress dialog
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Downloading IITCm update...");
mProgressDialog.setIndeterminate(true);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(true);
handleIntent(getIntent(), true);
}
@@ -570,6 +582,10 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
// authentication activity has returned. mLogin will continue authentication
mLogin.onActivityResult(resultCode, data);
break;
case REQUEST_UPDATE_FINISHED:
// clean up update apk
File file = new File(Environment.getExternalStorageDirectory().toString() + "/iitc_update.apk");
if (file != null) file.delete();
default:
super.onActivityResult(requestCode, resultCode, data);
@@ -626,6 +642,17 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
}
}
public void updateIitc(String url) {
final DownloadIitcUpdate updateTask = new DownloadIitcUpdate(this);
updateTask.execute(url);
mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
updateTask.cancel(true);
}
});
}
/**
* @see getNavigationHelper()
* @deprecated ActionBar related stuff should be handled by IITC_NavigationHelper
@@ -643,4 +670,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
public IITC_MapSettings getMapSettings() {
return mMapSettings;
}
public ProgressDialog getProgressDialog() {
return mProgressDialog;
}
}