handle byod download links

Download the thing and offer to open it on success.
This commit is contained in:
Eric House 2022-01-24 20:45:53 -08:00
parent 3912a60ee9
commit d22ffbec3f
5 changed files with 51 additions and 6 deletions

View file

@ -57,6 +57,7 @@ public class DlgDelegate {
APPLY_CONFIG, APPLY_CONFIG,
LAUNCH_THEME_CONFIG, LAUNCH_THEME_CONFIG,
SEND_LOGS, SEND_LOGS,
OPEN_BYOD_DICT,
// BoardDelegate // BoardDelegate
UNDO_LAST_ACTION, UNDO_LAST_ACTION,

View file

@ -1581,6 +1581,10 @@ public class GamesListDelegate extends ListDelegateBase
Utils.emailLogFile( m_activity, logLoc ); Utils.emailLogFile( m_activity, logLoc );
break; break;
case OPEN_BYOD_DICT:
DictBrowseDelegate.launch( getDelegator(), (String)params[0] );
break;
default: default:
handled = super.onPosButton( action, params ); handled = super.onPosButton( action, params );
} }
@ -2429,8 +2433,30 @@ public class GamesListDelegate extends ListDelegateBase
private boolean postWordlistURL( Intent intent ) private boolean postWordlistURL( Intent intent )
{ {
Uri data = intent.getData(); Uri data = intent.getData();
boolean result = null != data boolean result = null != data;
&& UpdateCheckReceiver.postedForDictDownload( m_activity, data ); if ( result ) {
// dfl: In case it's a BYOD download
DwnldDelegate.DownloadFinishedListener dfl =
new DwnldDelegate.DownloadFinishedListener() {
@Override
public void downloadFinished( String ignore,
String name,
boolean success ) {
int resid = success ? R.string.byod_success
: R.string.byod_failure;
DlgDelegate.Builder builder =
makeOkOnlyBuilder( getString( resid, name ) );
if ( success ) {
builder.setActionPair( Action.OPEN_BYOD_DICT,
R.string.button_open_dict )
.setParams( name );
}
builder.show();
}
};
result = UpdateCheckReceiver.postedForDictDownload( m_activity,
data, dfl );
}
return result; return result;
} }

View file

@ -32,6 +32,7 @@ import android.os.AsyncTask;
import android.os.SystemClock; import android.os.SystemClock;
import java.io.File; import java.io.File;
import java.util.List;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -430,15 +431,23 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
body, url.hashCode() ); body, url.hashCode() );
} }
static boolean postedForDictDownload( Context context, final Uri uri ) static boolean postedForDictDownload( Context context, final Uri uri,
DwnldDelegate.DownloadFinishedListener dfl )
{ {
String durl = uri.getQueryParameter( "durl" ); String durl = uri.getQueryParameter( "durl" );
boolean isDownloadURI = null != durl; boolean isDownloadURI = null != durl;
if ( isDownloadURI ) { if ( isDownloadURI ) {
String name = uri.getQueryParameter( "name" ); String name = uri.getQueryParameter( "name" );
Assert.assertTrueNR( null != name ); // derive from uri? Assert.assertTrueNR( null != name ); // derive from uri?
postDictNotification( context, durl, name, Uri dictUri = Uri.parse( durl );
DictUtils.DictLoc.INTERNAL, false ); List<String> segs = dictUri.getPathSegments();
if ( "byod".equals( segs.get(0) ) ) {
DwnldDelegate
.downloadDictInBack( context, dictUri, name, dfl );
} else {
postDictNotification( context, durl, name,
DictUtils.DictLoc.INTERNAL, false );
}
} }
// Log.d( TAG, "postDictNotification(%s) => %b", uri, isDownloadURI ); // Log.d( TAG, "postDictNotification(%s) => %b", uri, isDownloadURI );
return isDownloadURI; return isDownloadURI;

View file

@ -2712,4 +2712,13 @@
<!-- Button referenced in text above. Should match! --> <!-- Button referenced in text above. Should match! -->
<string name="button_settings">Settings…</string> <string name="button_settings">Settings…</string>
<!-- String shown when download of BYOD wordlist succeeds. There's
also an "Open" button shown in this case -->
<string name="byod_success">Download of %1$s succeeded. Open it now if you like.</string>
<!-- Shown when download fails -->
<string name="byod_failure">Download of %1$s failed.</string>
<!-- String shown when download of BYOD wordlist fails -->
<!-- Button giving option of opening just-downloaded wordlist -->
<string name="button_open_dict">Open</string>
</resources> </resources>

View file

@ -197,7 +197,7 @@ addPlayer( XW_DUtilCtxt* XP_UNUSED_DBG(dutil), KPState* state, const XP_UCHAR* n
makeUniqueName( state, name, tmpName, VSIZE(tmpName) ); makeUniqueName( state, name, tmpName, VSIZE(tmpName) );
name = tmpName; name = tmpName;
} }
XP_LOGFF( "adding new player %s!", name ); /* XP_LOGFF( "adding new player %s!", name ); */
KnownPlayer* newPlayer = XP_CALLOC( dutil->mpool, sizeof(*newPlayer) ); KnownPlayer* newPlayer = XP_CALLOC( dutil->mpool, sizeof(*newPlayer) );
newPlayer->name = copyString( dutil->mpool, name ); newPlayer->name = copyString( dutil->mpool, name );
newPlayer->addr = *addr; newPlayer->addr = *addr;