From d22ffbec3f993826c568aa2ae9fe0df6f0933acb Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 24 Jan 2022 20:45:53 -0800 Subject: [PATCH] handle byod download links Download the thing and offer to open it on success. --- .../org/eehouse/android/xw4/DlgDelegate.java | 1 + .../android/xw4/GamesListDelegate.java | 30 +++++++++++++++++-- .../android/xw4/UpdateCheckReceiver.java | 15 ++++++++-- .../app/src/main/res/values/strings.xml | 9 ++++++ xwords4/common/knownplyr.c | 2 +- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java index 63b59aafd..7016bf1df 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java @@ -57,6 +57,7 @@ public class DlgDelegate { APPLY_CONFIG, LAUNCH_THEME_CONFIG, SEND_LOGS, + OPEN_BYOD_DICT, // BoardDelegate UNDO_LAST_ACTION, diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 171fd98d6..97c74cbd1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -1581,6 +1581,10 @@ public class GamesListDelegate extends ListDelegateBase Utils.emailLogFile( m_activity, logLoc ); break; + case OPEN_BYOD_DICT: + DictBrowseDelegate.launch( getDelegator(), (String)params[0] ); + break; + default: handled = super.onPosButton( action, params ); } @@ -2429,8 +2433,30 @@ public class GamesListDelegate extends ListDelegateBase private boolean postWordlistURL( Intent intent ) { Uri data = intent.getData(); - boolean result = null != data - && UpdateCheckReceiver.postedForDictDownload( m_activity, data ); + boolean result = null != 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; } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/UpdateCheckReceiver.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/UpdateCheckReceiver.java index 54653a44c..4588a61f5 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/UpdateCheckReceiver.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/UpdateCheckReceiver.java @@ -32,6 +32,7 @@ import android.os.AsyncTask; import android.os.SystemClock; import java.io.File; +import java.util.List; import javax.net.ssl.HttpsURLConnection; import org.json.JSONArray; import org.json.JSONObject; @@ -430,15 +431,23 @@ public class UpdateCheckReceiver extends BroadcastReceiver { 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" ); 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 ); + Uri dictUri = Uri.parse( durl ); + List 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 ); return isDownloadURI; diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 3bc8bb97c..d9441f610 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2712,4 +2712,13 @@ Settingsā€¦ + + Download of %1$s succeeded. Open it now if you like. + + Download of %1$s failed. + + + Open + diff --git a/xwords4/common/knownplyr.c b/xwords4/common/knownplyr.c index 607cee717..89dc92ac1 100644 --- a/xwords4/common/knownplyr.c +++ b/xwords4/common/knownplyr.c @@ -197,7 +197,7 @@ addPlayer( XW_DUtilCtxt* XP_UNUSED_DBG(dutil), KPState* state, const XP_UCHAR* n makeUniqueName( state, name, tmpName, VSIZE(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) ); newPlayer->name = copyString( dutil->mpool, name ); newPlayer->addr = *addr;