Search in sources :

Example 1 with Action

use of com.battlelancer.seriesguide.api.Action in project SeriesGuide by UweTrottmann.

the class ExtensionSubscriberService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    // despite guarantees from IntentService, it may get passed a null intent, so check for it
    if (intent == null || intent.getAction() == null) {
        return;
    }
    String intentAction = intent.getAction();
    if (ACTION_PUBLISH_ACTION.equals(intentAction)) {
        // an extension published a new action
        String token = intent.getStringExtra(EXTRA_TOKEN);
        // extract the action
        Action action = null;
        if (intent.hasExtra(EXTRA_ACTION)) {
            Bundle bundle = intent.getBundleExtra(EXTRA_ACTION);
            if (bundle != null) {
                action = Action.fromBundle(bundle);
            }
        }
        // extensions may send movie actions as of API 1.3.0
        // older extensions only support episode actions
        int type = ACTION_TYPE_EPISODE;
        if (intent.hasExtra(EXTRA_ACTION_TYPE)) {
            type = intent.getIntExtra(EXTRA_ACTION_TYPE, ACTION_TYPE_EPISODE);
        }
        ExtensionManager.getInstance(this).handlePublishedAction(token, action, type);
    }
}
Also used : Action(com.battlelancer.seriesguide.api.Action) Bundle(android.os.Bundle)

Example 2 with Action

use of com.battlelancer.seriesguide.api.Action in project SeriesGuide by UweTrottmann.

the class EpisodeActionsLoader method loadInBackground.

@Override
public List<Action> loadInBackground() {
    List<Action> actions = ExtensionManager.getInstance(getContext()).getLatestEpisodeActions(episodeTvdbId);
    // no actions available yet, request extensions to publish them
    if (actions == null || actions.size() == 0) {
        actions = new ArrayList<>();
        query = getContext().getContentResolver().query(Episodes.buildEpisodeWithShowUri(episodeTvdbId), Query.PROJECTION, null, null, null);
        if (query == null) {
            return actions;
        }
        Episode episode = null;
        if (query.moveToFirst()) {
            episode = new Episode.Builder().tvdbId(episodeTvdbId).title(query.getString(Query.TITLE)).number(query.getInt(Query.NUMBER)).numberAbsolute(query.getInt(Query.NUMBER_ABSOLUTE)).season(query.getInt(Query.SEASON)).imdbId(query.getString(Query.IMDB_ID)).showTvdbId(query.getInt(Query.SHOW_TVDB_ID)).showTitle(query.getString(Query.SHOW_TITLE)).showImdbId(query.getString(Query.SHOW_IMDB_ID)).showFirstReleaseDate(query.getString(Query.SHOW_FIRST_RELEASE)).build();
        }
        // clean up query first
        query.close();
        query = null;
        if (episode != null) {
            ExtensionManager.getInstance(getContext()).requestEpisodeActions(episode);
        }
    }
    return actions;
}
Also used : Episode(com.battlelancer.seriesguide.api.Episode) Action(com.battlelancer.seriesguide.api.Action)

Example 3 with Action

use of com.battlelancer.seriesguide.api.Action in project SeriesGuide by UweTrottmann.

the class ActionsHelper method populateActions.

/**
     * Replaces all child views of the given {@link android.view.ViewGroup} with a {@link
     * android.widget.Button} per action plus one linking to {@link com.battlelancer.seriesguide.extensions.ExtensionsConfigurationActivity}.
     * Sets up {@link android.view.View.OnClickListener} if {@link com.battlelancer.seriesguide.api.Action#getViewIntent()}
     * of an  {@link com.battlelancer.seriesguide.api.Action} is not null.
     */
public static void populateActions(@NonNull LayoutInflater layoutInflater, @NonNull Resources.Theme theme, @Nullable ViewGroup actionsContainer, @Nullable List<Action> data, @NonNull final String logCategory) {
    if (actionsContainer == null) {
        // nothing we can do, view is already gone
        Timber.d("populateActions: action view container gone, aborting");
        return;
    }
    actionsContainer.removeAllViews();
    // re-use drawable for all buttons
    int vectorResId = Utils.resolveAttributeToResourceId(theme, R.attr.drawableExtension);
    VectorDrawableCompat drawable = VectorDrawableCompat.create(actionsContainer.getResources(), vectorResId, theme);
    // add a view per action
    if (data != null) {
        for (Action action : data) {
            Button actionView = (Button) layoutInflater.inflate(R.layout.item_action, actionsContainer, false);
            actionView.setText(action.getTitle());
            Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(actionView, drawable, null, null, null);
            CheatSheet.setup(actionView, action.getTitle());
            final Intent viewIntent = action.getViewIntent();
            if (viewIntent != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
                } else {
                    //noinspection deprecation
                    viewIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                }
                actionView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Utils.tryStartActivity(v.getContext(), viewIntent, true);
                    }
                });
            }
            actionsContainer.addView(actionView);
        }
    }
    // link to extensions configuration
    TextView configureView = (TextView) layoutInflater.inflate(R.layout.item_action_add, actionsContainer, false);
    configureView.setText(R.string.action_extensions_configure);
    configureView.setOnClickListener(new View.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(v.getContext(), ExtensionsConfigurationActivity.class);
            if (AndroidUtils.isJellyBeanOrHigher()) {
                v.getContext().startActivity(intent, ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle());
            } else {
                v.getContext().startActivity(intent);
            }
            Utils.trackAction(v.getContext(), logCategory, "Manage extensions");
        }
    });
    actionsContainer.addView(configureView);
}
Also used : Action(com.battlelancer.seriesguide.api.Action) Button(android.widget.Button) Intent(android.content.Intent) TextView(android.widget.TextView) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) TextView(android.widget.TextView) View(android.view.View) TargetApi(android.annotation.TargetApi)

Example 4 with Action

use of com.battlelancer.seriesguide.api.Action in project SeriesGuide by UweTrottmann.

the class ExtensionManager method handlePublishedAction.

public void handlePublishedAction(String token, Action action, int type) {
    if (TextUtils.isEmpty(token) || action == null) {
        // whoops, no token or action received
        Timber.d("handlePublishedAction: token or action empty");
        return;
    }
    if (type != ACTION_TYPE_EPISODE && type != ACTION_TYPE_MOVIE) {
        Timber.d("handlePublishedAction: unknown type of entity");
        return;
    }
    synchronized (this) {
        if (!tokens.containsKey(token)) {
            // we are not subscribed, ignore
            Timber.d("handlePublishedAction: token invalid, ignoring incoming action");
            return;
        }
        // check if action entity identifier is for an entity we requested actions for
        Map<ComponentName, Action> actionMap;
        if (type == ACTION_TYPE_EPISODE) {
            // episode
            actionMap = sEpisodeActionsCache.get(action.getEntityIdentifier());
        } else {
            // movie
            actionMap = sMovieActionsCache.get(action.getEntityIdentifier());
        }
        if (actionMap == null) {
            // did not request actions for this episode, or is already out of cache (too late!)
            Timber.d("handlePublishedAction: ignoring actions for %s, not requested", action.getEntityIdentifier());
            return;
        }
        // store action for this entity
        ComponentName extension = tokens.get(token);
        actionMap.put(extension, action);
    }
    // notify that actions were updated
    if (type == ACTION_TYPE_EPISODE) {
        EventBus.getDefault().post(new EpisodeActionReceivedEvent(action.getEntityIdentifier()));
    } else {
        EventBus.getDefault().post(new MovieActionReceivedEvent(action.getEntityIdentifier()));
    }
}
Also used : Action(com.battlelancer.seriesguide.api.Action) ComponentName(android.content.ComponentName)

Aggregations

Action (com.battlelancer.seriesguide.api.Action)4 TargetApi (android.annotation.TargetApi)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 VectorDrawableCompat (android.support.graphics.drawable.VectorDrawableCompat)1 View (android.view.View)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 Episode (com.battlelancer.seriesguide.api.Episode)1