<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.vase4kin.teamcityapp.artifact.view;

import android.app.Activity;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.github.vase4kin.teamcityapp.R;
import com.github.vase4kin.teamcityapp.artifact.api.File;
import com.github.vase4kin.teamcityapp.artifact.data.ArtifactDataModel;
import com.github.vase4kin.teamcityapp.base.list.view.BaseListViewImpl;
import com.github.vase4kin.teamcityapp.bottomsheet_dialog.BottomSheetDialog;
import com.github.vase4kin.teamcityapp.bottomsheet_dialog.menu_items.MenuItemsFactory;

/**
 * Impl of {@link ArtifactView}
 */
public class ArtifactViewImpl extends BaseListViewImpl<ArtifactDataModel, ArtifactAdapter> implements ArtifactView {

    private static final String TAG_BOTTOM_SHEET = "Tag bottom sheet";

    private MaterialDialog mProgressDialog;
    private OnArtifactPresenterListener mListener;

    public ArtifactViewImpl(View mView,
                            Activity activity,
                            @StringRes int emptyMessage,
                            ArtifactAdapter adapter) {
        super(mView, activity, emptyMessage, adapter);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setOnArtifactPresenterListener(OnArtifactPresenterListener listener) {
        this.mListener = listener;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void initViews(@NonNull ViewListener listener) {
        super.initViews(listener);
        mProgressDialog = new MaterialDialog.Builder(mActivity)
                .title(R.string.download_artifact_dialog_title)
                .content(R.string.progress_dialog_content)
                .progress(true, 0)
                .widgetColor(Color.GRAY)
                .autoDismiss(false)
                .negativeText(R.string.text_cancel_button)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        mListener.unSubscribe();
                        mProgressDialog.dismiss();
                    }
                })
                .build();
        mProgressDialog.setCanceledOnTouchOutside(false);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showData(ArtifactDataModel dataModel) {
        mAdapter.setDataModel(dataModel);
        mAdapter.setOnClickListener(mListener);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.getAdapter().notifyDataSetChanged();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showProgressDialog() {
        mProgressDialog.show();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void dismissProgressDialog() {
        mProgressDialog.dismiss();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showFullBottomSheet(File artifactFile) {
        BottomSheetDialog bottomSheetDialog = BottomSheetDialog.createBottomSheetDialog(
                artifactFile.getName(),
                new String[]{artifactFile.getContent().getHref(), artifactFile.getChildren().getHref()},
                MenuItemsFactory.TYPE_ARTIFACT_FULL);
        bottomSheetDialog.show(((AppCompatActivity) mActivity).getSupportFragmentManager(), TAG_BOTTOM_SHEET);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showFolderBottomSheet(File artifactFile) {
        BottomSheetDialog bottomSheetDialog = BottomSheetDialog.createBottomSheetDialog(
                artifactFile.getName(), artifactFile.getContent().getHref(), MenuItemsFactory.TYPE_ARTIFACT_FOLDER);
        bottomSheetDialog.show(((AppCompatActivity) mActivity).getSupportFragmentManager(), TAG_BOTTOM_SHEET);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showBrowserBottomSheet(File artifactFile) {
        BottomSheetDialog bottomSheetDialog = BottomSheetDialog.createBottomSheetDialog(<commit_msg>Fix crash caused by long pressing on artifact folder<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.vase4kin.teamcityapp.artifact.view;

import android.app.Activity;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.github.vase4kin.teamcityapp.R;
import com.github.vase4kin.teamcityapp.artifact.api.File;
import com.github.vase4kin.teamcityapp.artifact.data.ArtifactDataModel;
import com.github.vase4kin.teamcityapp.base.list.view.BaseListViewImpl;
import com.github.vase4kin.teamcityapp.bottomsheet_dialog.BottomSheetDialog;
import com.github.vase4kin.teamcityapp.bottomsheet_dialog.menu_items.MenuItemsFactory;

/**
 * Impl of {@link ArtifactView}
 */
public class ArtifactViewImpl extends BaseListViewImpl<ArtifactDataModel, ArtifactAdapter> implements ArtifactView {

    private static final String TAG_BOTTOM_SHEET = "Tag bottom sheet";

    private MaterialDialog mProgressDialog;
    private OnArtifactPresenterListener mListener;

    public ArtifactViewImpl(View mView,
                            Activity activity,
                            @StringRes int emptyMessage,
                            ArtifactAdapter adapter) {
        super(mView, activity, emptyMessage, adapter);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setOnArtifactPresenterListener(OnArtifactPresenterListener listener) {
        this.mListener = listener;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void initViews(@NonNull ViewListener listener) {
        super.initViews(listener);
        mProgressDialog = new MaterialDialog.Builder(mActivity)
                .title(R.string.download_artifact_dialog_title)
                .content(R.string.progress_dialog_content)
                .progress(true, 0)
                .widgetColor(Color.GRAY)
                .autoDismiss(false)
                .negativeText(R.string.text_cancel_button)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        mListener.unSubscribe();
                        mProgressDialog.dismiss();
                    }
                })
                .build();
        mProgressDialog.setCanceledOnTouchOutside(false);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showData(ArtifactDataModel dataModel) {
        mAdapter.setDataModel(dataModel);
        mAdapter.setOnClickListener(mListener);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.getAdapter().notifyDataSetChanged();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showProgressDialog() {
        mProgressDialog.show();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void dismissProgressDialog() {
        mProgressDialog.dismiss();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showFullBottomSheet(File artifactFile) {
        BottomSheetDialog bottomSheetDialog = BottomSheetDialog.createBottomSheetDialog(
                artifactFile.getName(),
                new String[]{artifactFile.getContent().getHref(), artifactFile.getChildren().getHref()},
                MenuItemsFactory.TYPE_ARTIFACT_FULL);
        bottomSheetDialog.show(((AppCompatActivity) mActivity).getSupportFragmentManager(), TAG_BOTTOM_SHEET);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showFolderBottomSheet(File artifactFile) {
        BottomSheetDialog bottomSheetDialog = BottomSheetDialog.createBottomSheetDialog(
                artifactFile.getName(), artifactFile.getChildren().getHref(), MenuItemsFactory.TYPE_ARTIFACT_FOLDER);
        bottomSheetDialog.show(((AppCompatActivity) mActivity).getSupportFragmentManager(), TAG_BOTTOM_SHEET);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void showBrowserBottomSheet(File artifactFile) {
        BottomSheetDialog bottomSheetDialog = BottomSheetDialog.createBottomSheetDialog(
{'fraction_non_alphanumeric': 0.08964515459638929, 'fraction_numerical': 0.0035277028429134675, 'mean_word_length': 2.844834463502194, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4944245', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2513, 'n_words': 511}