package com.tasomaniac.seriesguide.plex;

import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Intent;

import com.battlelancer.seriesguide.api.Action;
import com.battlelancer.seriesguide.api.Episode;
import com.battlelancer.seriesguide.api.SeriesGuideExtension;
import com.tasomaniac.seriesguide.plex.data.Injector;

import javax.inject.Inject;

public class PlexExtension extends SeriesGuideExtension {

    @Inject Analytics analytics;

    public PlexExtension() {
        super("PlexExtension");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Injector.obtain(getApplicationContext()).inject(this);
    }

    @Override
    protected void onRequest(int episodeIdentifier, Episode episode) {

        Intent plexSearchIntent = new Intent(Intent.ACTION_SEARCH)
                .setComponent(new ComponentName("com.plexapp.android", "com.plexapp.plex.activities.SearchActivity"))
                .putExtra(SearchManager.QUERY, episode.getTitle());

        analytics.sendScreenView("Extension");
        analytics.sendEvent("Extension", "Search Plex", episode.getTitle());

        publishAction(new Action.Builder(getString(R.string.action_extension), episodeIdentifier)
                .viewIntent(plexSearchIntent)
                .build());
    }
}

@@ -236,16 +236,63 @@
 pisode;%0A
+import com.battlelancer.seriesguide.api.Movie;%0A
 import c
@@ -814,16 +814,336 @@
 sode) %7B%0A
+        publishActionWithTitleSearch(episodeIdentifier, episode.getTitle());%0A    %7D%0A%0A    @Override%0A    protected void onRequest(int movieIdentifier, Movie movie) %7B%0A        publishActionWithTitleSearch(movieIdentifier, movie.getTitle());%0A    %7D%0A%0A    private void publishActionWithTitleSearch(int identifier, String title) %7B
 %0A       
@@ -1367,34 +1367,21 @@
 .QUERY, 
-episode.getT
+t
 itle
-()
 );%0A%0A    
@@ -1479,34 +1479,21 @@
  Plex%22, 
-episode.getT
+t
 itle
-()
 );%0A%0A    
@@ -1567,24 +1567,17 @@
 nsion), 
-episodeI
+i
 dentifie

Add movie support to plex