
package com.battlelancer.seriesguide.ui;

import com.actionbarsherlock.app.ActionBar;
import com.battlelancer.seriesguide.R;
import com.battlelancer.seriesguide.items.Series;
import com.battlelancer.seriesguide.util.DBUtils;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

public class OverviewActivity extends BaseActivity {

    private Fragment mFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.overview);

        final ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle(getString(R.string.description_overview));
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);

        if (savedInstanceState == null) {
            mFragment = new OverviewFragment();
            mFragment.setArguments(getIntent().getExtras());

            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
            ft.replace(R.id.fragment_overview, mFragment).commit();
        }
    }

    @Override
    public boolean onSearchRequested() {
        // refine search with the show's title
        int showId = getIntent().getExtras().getInt(OverviewFragment.InitBundle.SHOW_TVDBID);
        if (showId == 0) {
            return false;
        }

        final Series show = DBUtils.getShow(this, String.valueOf(showId));
        final String showTitle = show.getSeriesName();

        Bundle args = new Bundle();
        args.putString(SearchFragment.InitBundle.SHOW_TITLE, showTitle);
        startSearch(null, false, args, false);
        return true;
    }
}

@@ -223,33 +223,275 @@
 ls;%0A
-%0Aimport android.os.Bundle
+import com.battlelancer.seriesguide.util.TaskManager;%0Aimport com.battlelancer.seriesguide.util.UpdateTask;%0Aimport com.battlelancer.seriesguide.util.Utils;%0A%0Aimport android.content.SharedPreferences;%0Aimport android.os.Bundle;%0Aimport android.preference.PreferenceManager
 ;%0Aim
@@ -1458,16 +1458,1361 @@
        %7D
+%0A%0A        // try to update this show%0A        onUpdate();%0A    %7D%0A%0A    private void onUpdate() %7B%0A        final int showId = getIntent().getIntExtra(OverviewFragment.InitBundle.SHOW_TVDBID, -1);%0A%0A        // only update this show if no global update is running%0A        if (showId != -1 && !TaskManager.getInstance(this).isUpdateTaskRunning(false)) %7B%0A%0A            // look if we are online%0A            if (Utils.isNetworkConnected(this)) %7B%0A                final SharedPreferences prefs = PreferenceManager%0A                        .getDefaultSharedPreferences(getApplicationContext());%0A%0A                // check if auto-update is enabled%0A                final boolean isAutoUpdateEnabled = prefs.getBoolean(%0A                        SeriesGuidePreferences.KEY_AUTOUPDATE, true);%0A                if (isAutoUpdateEnabled) %7B%0A%0A                    // check if wifi is required and available%0A                    final boolean isWifiOnly = prefs.getBoolean(%0A                            SeriesGuidePreferences.KEY_AUTOUPDATEWLANONLY, true);%0A                    if (!isWifiOnly %7C%7C Utils.isWifiConnected(this)) %7B%0A%0A                        UpdateTask updateTask = new UpdateTask(String.valueOf(showId), this);%0A                        TaskManager.getInstance(this).tryUpdateTask(updateTask, false, -1);%0A                    %7D%0A                %7D%0A            %7D%0A%0A        %7D
 %0A    %7D%0A%0A

Update shows if their overview screen is used