mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-06 20:45:54 +01:00
start on checking for updates/latest version: a menu item that
triggers new code that sends an HTTP POST to a python script on the server that returns whether the current version is correct.
This commit is contained in:
parent
9128c2d60c
commit
3ef81f248b
5 changed files with 90 additions and 6 deletions
|
@ -1,6 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/gamel_menu_checkupdates"
|
||||
android:title="@string/gamel_menu_checkupdates"
|
||||
/>
|
||||
<item android:id="@+id/gamel_menu_newgame"
|
||||
android:title="@string/button_new_game"
|
||||
android:icon="@android:drawable/ic_menu_add"
|
||||
|
@ -31,7 +34,6 @@
|
|||
android:title="@string/gamel_menu_checkmoves"
|
||||
android:icon="@drawable/stat_notify_sync"
|
||||
/>
|
||||
|
||||
<!-- Debug only menuitems -->
|
||||
<item android:id="@+id/gamel_menu_storedb"
|
||||
android:title="@string/gamel_menu_storedb"
|
||||
|
|
|
@ -1996,4 +1996,6 @@
|
|||
enable play via SMS, go to Settings->Network game settings.)
|
||||
</string>
|
||||
|
||||
<string name="gamel_menu_checkupdates">Check for updates</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -577,6 +577,10 @@ public class GamesList extends XWListActivity
|
|||
SYNC_MENU_ACTION );
|
||||
break;
|
||||
|
||||
case R.id.gamel_menu_checkupdates:
|
||||
NetUtils.checkVersions( this );
|
||||
break;
|
||||
|
||||
case R.id.gamel_menu_prefs:
|
||||
intent = new Intent( this, PrefsActivity.class );
|
||||
startActivity( intent );
|
||||
|
|
|
@ -25,15 +25,27 @@ import java.net.InetAddress;
|
|||
import java.net.Socket;
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||
|
||||
|
@ -270,4 +282,41 @@ public class NetUtils {
|
|||
}
|
||||
} // sendToRelay
|
||||
|
||||
|
||||
public static void checkVersions( Context context )
|
||||
{
|
||||
PackageManager pm = context.getPackageManager();
|
||||
String packageName = context.getPackageName();
|
||||
try {
|
||||
int versionCode = pm.getPackageInfo( packageName, 0 ).versionCode;
|
||||
|
||||
// Create a new HttpClient and Post Header
|
||||
HttpPost post =
|
||||
new HttpPost("http://www.eehouse.org/xw4/info.py/curVersion");
|
||||
|
||||
// Add your data
|
||||
List<NameValuePair> nvp = new ArrayList<NameValuePair>();
|
||||
nvp.add(new BasicNameValuePair( "name", packageName ) );
|
||||
nvp.add( new BasicNameValuePair( "version",
|
||||
String.format( "%d",
|
||||
versionCode ) ) );
|
||||
post.setEntity( new UrlEncodedFormEntity(nvp) );
|
||||
|
||||
// Execute HTTP Post Request
|
||||
HttpClient httpclient = new DefaultHttpClient();
|
||||
HttpResponse response = httpclient.execute(post);
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
String result = EntityUtils.toString( entity );
|
||||
DbgUtils.logf( "checkVersions: received: \"%s\"", result );
|
||||
}
|
||||
} catch ( PackageManager.NameNotFoundException nnfe ) {
|
||||
DbgUtils.logf( "checkVersions: %s", nnfe.toString() );
|
||||
} catch (ClientProtocolException cpe) {
|
||||
DbgUtils.logf( "checkVersions: %s", cpe.toString() );
|
||||
} catch (java.io.IOException ioe) {
|
||||
DbgUtils.logf( "checkVersions: %s", ioe.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
27
xwords4/android/scripts/info.py
Executable file
27
xwords4/android/scripts/info.py
Executable file
|
@ -0,0 +1,27 @@
|
|||
# Script meant to be installed on eehouse.org that will hard-code the
|
||||
# latest version of a bunch of stuff and reply with empty string if
|
||||
# the client's version is up-to-date or with the newer version if it's
|
||||
# not. May include md5 sums in liu of versions for .xwd files.
|
||||
|
||||
import logging
|
||||
|
||||
s_versions = { 'org.eehouse.android.xw4' : '42'
|
||||
,'org.eehouse.android.xw4sms' : '41'
|
||||
}
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG
|
||||
,format='%(asctime)s [[%(levelname)s]] %(message)s'
|
||||
,datefmt='%d %b %y %H:%M'
|
||||
,filename='/tmp/info.py.log'
|
||||
,filemode='a')
|
||||
|
||||
def curVersion( req, name, version ):
|
||||
global s_versions
|
||||
if name in s_versions:
|
||||
if s_versions[name] == version:
|
||||
logging.debug(name + " is up-to-date")
|
||||
return ""
|
||||
else:
|
||||
return s_versions[name]
|
||||
else:
|
||||
logging.debug( 'Error: bad name ' + name )
|
Loading…
Add table
Reference in a new issue