<commit_before>/*
 * Copyright 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.mkjensen.dml.ondemand;

import static com.github.mkjensen.dml.ondemand.OnDemandListeners.createOnItemViewClickedListener;
import static com.github.mkjensen.dml.ondemand.OnDemandListeners.createOnItemViewSelectedListener;
import static com.github.mkjensen.dml.ondemand.OnDemandListeners.createOnSearchClickedListener;

import android.os.Bundle;
import android.support.v17.leanback.app.BrowseSupportFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.util.Log;

import com.github.mkjensen.dml.backend.loader.CategoriesLoader;
import com.github.mkjensen.dml.model.Category;
import com.github.mkjensen.dml.presenter.VideoPresenter;
import com.github.mkjensen.dml.util.LoadingHelper;

import java.util.List;

/**
 * Browse screen for on-demand videos.
 */
public final class BrowseFragment extends BrowseSupportFragment
    implements LoaderManager.LoaderCallbacks<List<Category>> {

  private static final String TAG = "BrowseFragment";

  private ArrayObjectAdapter rows;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    LoadingHelper.showLoading(this);
    initUi();
    initListeners();
    initLoader();
  }

  private void initUi() {
    rows = new ArrayObjectAdapter(new ListRowPresenter());
    setAdapter(rows);
    enableRowScaling(false);
  }

  private void initListeners() {
    FragmentActivity activity = getActivity();
    setOnItemViewClickedListener(createOnItemViewClickedListener(activity));
    setOnItemViewSelectedListener(createOnItemViewSelectedListener(activity));
    setOnSearchClickedListener(createOnSearchClickedListener(activity));
  }

  private void initLoader() {
    getLoaderManager().initLoader(0, null, this);
  }

  @Override
  public Loader<List<Category>> onCreateLoader(int id, Bundle args) {
    Log.d(TAG, "onCreateLoader");
    return new CategoriesLoader(getActivity());
  }

  @Override
  public void onLoadFinished(Loader<List<Category>> loader, List<Category> data) {
    Log.d(TAG, "onLoadFinished");
    LoadingHelper.hideLoading(this);
    rows.clear();
    if (data == null) {<commit_msg>Add app title<commit_after>/*
 * Copyright 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.mkjensen.dml.ondemand;

import static com.github.mkjensen.dml.ondemand.OnDemandListeners.createOnItemViewClickedListener;
import static com.github.mkjensen.dml.ondemand.OnDemandListeners.createOnItemViewSelectedListener;
import static com.github.mkjensen.dml.ondemand.OnDemandListeners.createOnSearchClickedListener;

import android.os.Bundle;
import android.support.v17.leanback.app.BrowseSupportFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.HeaderItem;
import android.support.v17.leanback.widget.ListRow;
import android.support.v17.leanback.widget.ListRowPresenter;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.util.Log;

import com.github.mkjensen.dml.R;
import com.github.mkjensen.dml.backend.loader.CategoriesLoader;
import com.github.mkjensen.dml.model.Category;
import com.github.mkjensen.dml.presenter.VideoPresenter;
import com.github.mkjensen.dml.util.LoadingHelper;

import java.util.List;

/**
 * Browse screen for on-demand videos.
 */
public final class BrowseFragment extends BrowseSupportFragment
    implements LoaderManager.LoaderCallbacks<List<Category>> {

  private static final String TAG = "BrowseFragment";

  private ArrayObjectAdapter rows;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    LoadingHelper.showLoading(this);
    initUi();
    initListeners();
    initLoader();
  }

  private void initUi() {
    rows = new ArrayObjectAdapter(new ListRowPresenter());
    setAdapter(rows);
    setTitle(getString(R.string.app_name));
    enableRowScaling(false);
  }

  private void initListeners() {
    FragmentActivity activity = getActivity();
    setOnItemViewClickedListener(createOnItemViewClickedListener(activity));
    setOnItemViewSelectedListener(createOnItemViewSelectedListener(activity));
    setOnSearchClickedListener(createOnSearchClickedListener(activity));
  }

  private void initLoader() {
    getLoaderManager().initLoader(0, null, this);
  }

  @Override
  public Loader<List<Category>> onCreateLoader(int id, Bundle args) {
    Log.d(TAG, "onCreateLoader");
    return new CategoriesLoader(getActivity());
  }

  @Override
  public void onLoadFinished(Loader<List<Category>> loader, List<Category> data) {
    Log.d(TAG, "onLoadFinished");
    LoadingHelper.hideLoading(this);
    rows.clear();
    if (data == null) {
{'fraction_non_alphanumeric': 0.09878516624040921, 'fraction_numerical': 0.007033248081841432, 'mean_word_length': 5.1223091976516635, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6615815', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1826, 'n_words': 419}