Skip to content

Instantly share code, notes, and snippets.

@leoherzog
Last active November 27, 2019 16:25
Show Gist options
  • Save leoherzog/d56029bc4003ba80c2c0b2269269626d to your computer and use it in GitHub Desktop.
Save leoherzog/d56029bc4003ba80c2c0b2269269626d to your computer and use it in GitHub Desktop.
Pseudocode for Flicki. Package name: productions.agentl.flicki

The app Muzei (https://muzei.co/) has lots of plugins (https://play.google.com/store/search?q=muzei&c=apps). I would like you to create one in Java that uses the Flickr API and Android Awareness APIs. Familiarity in Retrofit, REST APIs, and the Android Awareness API are a must. App itself will have no launcher icon and no UI, and will act as a plugin for Muzei.

When the Art Source is selected, the finished app must:

  • Attempt to get the user's location via the Fused Location API from Google Play Services
    • If the location isn't granted, pop up dialog message saying it's required and ask again (loop until granted or cancelled)
  • Start the initial refresh

When it's time for a refresh, the finished app must:

  • Get current weather condition for user's location via the NWS JSON API v3 (happy to assist with this)
  • Ask Flickr for photos for this location
    • If there are, send them to Muzei
    • If there are none, ask Flickr for photos with the same weather condition as the search string, but st a random location from the locations XML, then send to Muzei

I'd like delivered source that can compile against SDK 29, min API of 21, latest Gradle, and with as few external libraries as possible. Package name of tech.herzog.flicki. Also, I'd like it to be pretty easy to tweak the "title", "byline", and "source URL" parameters that Muzei is fed at the refresh... Different whether it's photos at the user's location or from an XML random location.

How the app works

  1. The user installs Muzei and this proposed app
  2. They launch Muzei and choose this app as their Art Source
  3. This app runs the method whenFlickiIsSetAsArtSource()
  4. The app is now scheduled to run refreshWallpaper() every X minutes Then, it searches Flickr for photos around that user matching that weather condition. It then randomized the list of photos and sends it to Muzei. If there are no photos of the weather condition around the user of the user's location, then pick a location fake-locations.xml below at random and search for photos at that location of the user's current weather condition.

More information on the Muzei API:

// This project will use RetroFit, the Android Awareness API, and the Muzei API
//
function getLocation() {
get Awareness API rough location; // https://developers.google.com/awareness/
return condition;
}
function getWeather() {
Get Awareness API weather condition; // https://developers.google.com/awareness/
return condition;
}
function getImageForLocation(location) {
getWeather();
query Flickr API for given location and weather;
return {randomized list of photos: url_l, title, more info url}; // more info url is https://www.flickr.com/photos/{UserID}/{PhotoID}/
// https://www.flickr.com/services/api/misc.urls.html
}
function refreshWallpaper() {
getLocation();
getImageForLocation(location);
if (no photos found above) {
getImageForLocation(random location from preset list)
}
sendToMuzei(); // url_l of photo, title of photo as title, byline as weather condition, viewIntent as more info url.
// javadoc at https://github.com/romannurik/muzei/releases
}
function whenFlickiIsSetAsArtSource() {
checkPermissions(); // make sure we have permissions to get location when on android 6.0+
refreshWallpaper();
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="fake_locations">
<item>41.889767,12.4926499</item> <!--Colosseum, Rome-->
<item>48.8581706,2.294695</item> <!--Tour Eiffel, Paris-->
<item>25.1970379,55.2743848</item> <!--Burj Khalifa, Dubai -->
<item>40.689784,-74.045431</item> <!--Statue of Liberty, New York-->
<item>52.5164541,13.3777558</item> <!--Brandenburg Gate, Berlin-->
<item>-33.8550533,151.2214656</item> <!--Opera House, Sydney-->
<item>27.174997,78.0421577</item> <!--Taj Mahal, India-->
<item>51.5010419,-0.12201</item> <!--West Minsterabbey, UK-->
<item>36.0596261,-112.018748</item> <!--Grand Canyon, Co-->
<item>19.8226551,-155.4724603</item> <!--Mauna Kea, HI-->
<item>55.752523,37.623087</item> <!--St Basel's Cathedral, Moscow-->
<item>-13.163141,-72.544936</item> <!--Machu Picchu, Peru-->
<item>25.1414152,55.1854908</item> <!--The Burj al Arab Hotel, Dubai-->
<item>43.7229588,10.3965809</item> <!--The Leaning Tower of Pisa, Italy-->
<item>-22.951916,-43.210487</item> <!--Christ the Redeemer, Rio-->
<item>35.3599595,138.7273769</item> <!--Mount Fuji, Japan-->
<item>43.0777681,-79.0586001</item> <!--Niagra Falls, NY-->
</string-array>
</resources>
/* API Call info: https://www.flickr.com/services/api/flickr.photos.search.html */
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://api.flickr.com/services/rest")
.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addQueryParam("group_id", "1463451%40N25");
request.addQueryParam("lat", getLocation().getLat());
request.addQueryParam("lon", getLocation().getLong());
request.addQueryParam("radius", "20");
request.addQueryParam("text", getWeather());
request.addQueryParam("extras", "url_l”);
request.addQueryParam("format", "json”);
request.addQueryParam("nojsoncallback", "1”);
request.addQueryParam("api_key", "0952e1ceeeca7a0e1b3867533ba4beff");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment