mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
add handling of new wordlist-download uri
If I can't figure out how to register for .xwd files, next best idea is to encode a download in a custom url. This is one way of doing that, and works with the urls just added to BYOD. Will likely change.
This commit is contained in:
parent
7fd82b4831
commit
a175ed525f
4 changed files with 61 additions and 18 deletions
|
@ -57,6 +57,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
// URIs coming in in intents
|
||||
private static final String APK_EXTRA = "APK";
|
||||
private static final String DICTS_EXTRA = "XWDS";
|
||||
private static final String NAMES_EXTRA = "NAMES";
|
||||
|
||||
private Activity m_activity;
|
||||
private ArrayList<LinearLayout> m_views;
|
||||
|
@ -95,16 +96,18 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
implements DictUtils.DownProgListener {
|
||||
private String m_savedDict = null;
|
||||
private Uri m_uri = null;
|
||||
private String m_name;
|
||||
private boolean m_isApp = false;
|
||||
private File m_appFile = null;
|
||||
private int m_totalRead = 0;
|
||||
private LinearLayout m_listItem;
|
||||
private ProgressBar m_progressBar;
|
||||
|
||||
public DownloadFilesTask( Uri uri, LinearLayout item, boolean isApp )
|
||||
public DownloadFilesTask( Uri uri, String name, LinearLayout item, boolean isApp )
|
||||
{
|
||||
super();
|
||||
m_uri = uri;
|
||||
m_name = name;
|
||||
m_isApp = isApp;
|
||||
m_listItem = item;
|
||||
m_progressBar = (ProgressBar)item.findViewById( R.id.progress_bar );
|
||||
|
@ -152,8 +155,10 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
}
|
||||
});
|
||||
InputStream is = conn.getInputStream();
|
||||
String name = basename( m_uri.getPath() );
|
||||
String name = null == m_name
|
||||
? basename( m_uri.getPath() ) : m_name;
|
||||
if ( m_isApp ) {
|
||||
Assert.assertTrueNR( null == m_name );
|
||||
m_appFile = saveToPrivate( is, name, this );
|
||||
} else {
|
||||
m_savedDict = saveDict( is, name, this );
|
||||
|
@ -277,11 +282,13 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
Uri uri = intent.getData(); // launched from Manifest case
|
||||
if ( null == uri ) {
|
||||
String appUrl = intent.getStringExtra( APK_EXTRA );
|
||||
String[] names = null;
|
||||
boolean isApp = null != appUrl;
|
||||
if ( isApp ) {
|
||||
uris = new Uri[] { Uri.parse( appUrl ) };
|
||||
} else {
|
||||
Parcelable[] parcels = intent.getParcelableArrayExtra( DICTS_EXTRA );
|
||||
names = intent.getStringArrayExtra( NAMES_EXTRA );
|
||||
uris = new Uri[parcels.length];
|
||||
for ( int ii = 0; ii < parcels.length; ++ii ) {
|
||||
uris[ii] = (Uri)(parcels[ii]);
|
||||
|
@ -291,7 +298,8 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
m_views = new ArrayList<>();
|
||||
for ( int ii = 0; ii < uris.length; ++ii ) {
|
||||
item = (LinearLayout)inflate( R.layout.import_dict_item );
|
||||
m_dfts.add( new DownloadFilesTask( uris[ii], item, isApp ));
|
||||
String name = null == names ? null : names[ii];
|
||||
m_dfts.add( new DownloadFilesTask( uris[ii], name, item, isApp ));
|
||||
m_views.add( item );
|
||||
}
|
||||
}
|
||||
|
@ -299,7 +307,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
&& intent.getType().equals( "application/x-xwordsdict" ))
|
||||
|| uri.toString().endsWith( XWConstants.DICT_EXTN ) ) {
|
||||
item = (LinearLayout)inflate( R.layout.import_dict_item );
|
||||
dft = new DownloadFilesTask( uri, item, false );
|
||||
dft = new DownloadFilesTask( uri, null, item, false );
|
||||
uris = new Uri[] { uri };
|
||||
}
|
||||
|
||||
|
@ -468,8 +476,8 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
String name,
|
||||
DownloadFinishedListener lstnr )
|
||||
{
|
||||
Uri[] uris = new Uri[] { uri };
|
||||
String[] names = new String[] { name };
|
||||
Uri[] uris = { uri };
|
||||
String[] names = { name };
|
||||
downloadDictsInBack( context, uris, names, lstnr );
|
||||
}
|
||||
|
||||
|
@ -485,6 +493,7 @@ public class DwnldDelegate extends ListDelegateBase {
|
|||
|
||||
Intent intent = new Intent( context, DwnldActivity.class );
|
||||
intent.putExtra( DICTS_EXTRA, uris ); // uris implement Parcelable
|
||||
intent.putExtra( NAMES_EXTRA, names );
|
||||
context.startActivity( intent );
|
||||
}
|
||||
|
||||
|
|
|
@ -2416,6 +2416,14 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
return result;
|
||||
}
|
||||
|
||||
private boolean postWordlistURL( Intent intent )
|
||||
{
|
||||
Uri data = intent.getData();
|
||||
boolean result = null != data
|
||||
&& UpdateCheckReceiver.postedForDictDownload( m_activity, data );
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean startNewNetGame( NetLaunchInfo nli )
|
||||
{
|
||||
boolean handled = false;
|
||||
|
@ -2827,6 +2835,7 @@ public class GamesListDelegate extends ListDelegateBase
|
|||
Log.d( TAG, "tryStartsFromIntent(extras={%s})", DbgUtils.extrasToString( intent ) );
|
||||
boolean handled = startFirstHasDict( intent )
|
||||
|| startWithInvitee( intent )
|
||||
|| postWordlistURL( intent )
|
||||
|| startNewNetGame( intent )
|
||||
|| startHasGameID( intent )
|
||||
|| startRematch( intent )
|
||||
|
|
|
@ -362,18 +362,8 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
String url = dict.getString( k_URL );
|
||||
int index = dict.getInt( k_INDEX );
|
||||
DictUtils.DictAndLoc dal = m_dals[index];
|
||||
Intent intent =
|
||||
new Intent( m_context, DictsActivity.class );
|
||||
intent.putExtra( NEW_DICT_URL, url );
|
||||
intent.putExtra( NEW_DICT_NAME, dal.name );
|
||||
intent.putExtra( NEW_DICT_LOC, dal.loc.ordinal() );
|
||||
String body =
|
||||
LocUtils.getString( m_context,
|
||||
R.string.new_dict_avail_fmt,
|
||||
dal.name );
|
||||
Utils.postNotification( m_context, intent,
|
||||
R.string.new_dict_avail,
|
||||
body, url.hashCode() );
|
||||
postDictNotification( m_context, url,
|
||||
dal.name, dal.loc, true );
|
||||
gotOne = true;
|
||||
}
|
||||
}
|
||||
|
@ -405,4 +395,37 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void postDictNotification( Context context, String url,
|
||||
String name, DictUtils.DictLoc loc,
|
||||
boolean isUpdate )
|
||||
{
|
||||
Intent intent =
|
||||
new Intent( context, DictsActivity.class );
|
||||
intent.putExtra( NEW_DICT_URL, url );
|
||||
intent.putExtra( NEW_DICT_NAME, name );
|
||||
intent.putExtra( NEW_DICT_LOC, loc.ordinal() );
|
||||
|
||||
int strID = isUpdate ? R.string.new_dict_avail_fmt
|
||||
: R.string.dict_avail_fmt;
|
||||
String body = LocUtils.getString( context, strID, name );
|
||||
|
||||
Utils.postNotification( context, intent,
|
||||
R.string.new_dict_avail,
|
||||
body, url.hashCode() );
|
||||
}
|
||||
|
||||
static boolean postedForDictDownload( Context context, final Uri uri )
|
||||
{
|
||||
String durl = uri.getQueryParameter( "durl" );
|
||||
boolean isDownloadURI = null != durl;
|
||||
if ( isDownloadURI ) {
|
||||
String name = uri.getQueryParameter( "name" );
|
||||
Assert.assertTrueNR( null != name ); // derive from uri?
|
||||
postDictNotification( context, durl, name,
|
||||
DictUtils.DictLoc.INTERNAL, false );
|
||||
}
|
||||
// Log.d( TAG, "postDictNotification(%s) => %b", uri, isDownloadURI );
|
||||
return isDownloadURI;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1929,6 +1929,8 @@
|
|||
<string name="new_dict_avail">New wordlist available</string>
|
||||
<!-- -->
|
||||
<string name="new_dict_avail_fmt">Tap to update %1$s</string>
|
||||
<!-- A wordlist that's not necessarily a replacement is available -->
|
||||
<string name="dict_avail_fmt">Tap to download wordlist “%1$s”</string>
|
||||
<!-- -->
|
||||
<string name="new_app_avail_fmt">New version of %1$s</string>
|
||||
<!-- -->
|
||||
|
|
Loading…
Add table
Reference in a new issue