<commit_before>package com.pr0gramm.app.ui.fragments;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.pr0gramm.app.AndroidUtility;
import com.pr0gramm.app.R;
import com.pr0gramm.app.services.InboxService;
import com.pr0gramm.app.ui.EmptyAdapter;
import com.pr0gramm.app.ui.InboxType;
import com.pr0gramm.app.ui.MainActivity;
import com.pr0gramm.app.ui.MessageActionListener;
import com.pr0gramm.app.ui.dialogs.NewCommentDialogFragment;
import com.pr0gramm.app.ui.dialogs.WritePrivateMessageDialog;
import com.squareup.picasso.Picasso;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

import javax.inject.Inject;

import roboguice.fragment.RoboFragment;
import roboguice.inject.InjectView;
import rx.Observable;

import static com.pr0gramm.app.ui.dialogs.ErrorDialogFragment.defaultOnError;
import static rx.android.observables.AndroidObservable.bindFragment;

/**
 */
public abstract class InboxFragment<T> extends RoboFragment {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    protected static final String ARG_INBOX_TYPE = "InboxFragment.inboxType";

    @Inject
    private InboxService inboxService;

    @Inject
    private Picasso picasso;

    @InjectView(R.id.messages)
    private RecyclerView messagesView;

    @InjectView(android.R.id.empty)
    private View viewNothingHere;

    @InjectView(R.id.busy_indicator)
    private View viewBusyIndicator;

    @InjectView(R.id.refresh)
    private SwipeRefreshLayout swipeRefreshLayout;

    private Observable<List<T>> messages;

    boolean overrideLazyLoading;

    public InboxFragment() {
        setRetainInstance(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_inbox, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        messagesView.setItemAnimator(null);
        messagesView.setLayoutManager(new LinearLayoutManager(getActivity()));

        swipeRefreshLayout.setOnRefreshListener(this::reloadInboxContent);
        swipeRefreshLayout.setColorSchemeResources(R.color.primary);

        if (messages != null || !isLazyLoading()) {
            loadInboxContent();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        AndroidUtility.uninjectViews(this);
    }

    private void reloadInboxContent() {
        messages = null;

        if (hasView()) {
            messagesView.setAdapter(new EmptyAdapter());
        }

        loadInboxContent();
    }

    private boolean isLazyLoading() {
        return !overrideLazyLoading;// && getInboxType() == InboxType.UNREAD;
    }

    private void hideNothingHereIndicator() {
        if (hasView()) {
            viewNothingHere.setVisibility(View.GONE);
        }
    }

    private void showNothingHereIndicator() {
        if (hasView()) {
            viewNothingHere.setVisibility(View.VISIBLE);
            viewNothingHere.setAlpha(0);
            viewNothingHere.animate().alpha(1).start();
        }
    }

    private void showBusyIndicator() {
        if (hasView()) {
            viewBusyIndicator.setVisibility(View.VISIBLE);
        }
    }

    private void hideBusyIndicator() {
        if (hasView()) {
            viewBusyIndicator.setVisibility(View.GONE);
            swipeRefreshLayout.setRefreshing(false);
        }
    }

    private void loadInboxContent() {
        hideNothingHereIndicator();

        // initialize the message observable
        if (messages == null) {<commit_msg>Removed the busy indicator after the first loading<commit_after>package com.pr0gramm.app.ui.fragments;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import com.pr0gramm.app.AndroidUtility;
import com.pr0gramm.app.R;
import com.pr0gramm.app.services.InboxService;
import com.pr0gramm.app.ui.EmptyAdapter;
import com.pr0gramm.app.ui.InboxType;
import com.pr0gramm.app.ui.MainActivity;
import com.pr0gramm.app.ui.MessageActionListener;
import com.pr0gramm.app.ui.dialogs.NewCommentDialogFragment;
import com.pr0gramm.app.ui.dialogs.WritePrivateMessageDialog;
import com.squareup.picasso.Picasso;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

import javax.inject.Inject;

import roboguice.fragment.RoboFragment;
import roboguice.inject.InjectView;
import rx.Observable;

import static com.pr0gramm.app.ui.dialogs.ErrorDialogFragment.defaultOnError;
import static rx.android.observables.AndroidObservable.bindFragment;

/**
 */
public abstract class InboxFragment<T> extends RoboFragment {
    protected final Logger logger = LoggerFactory.getLogger(getClass());

    protected static final String ARG_INBOX_TYPE = "InboxFragment.inboxType";

    @Inject
    private InboxService inboxService;

    @Inject
    private Picasso picasso;

    @InjectView(R.id.messages)
    private RecyclerView messagesView;

    @InjectView(android.R.id.empty)
    private View viewNothingHere;

    @InjectView(R.id.busy_indicator)
    private View viewBusyIndicator;

    @InjectView(R.id.refresh)
    private SwipeRefreshLayout swipeRefreshLayout;

    private Observable<List<T>> messages;

    boolean overrideLazyLoading;

    public InboxFragment() {
        setRetainInstance(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_inbox, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        messagesView.setItemAnimator(null);
        messagesView.setLayoutManager(new LinearLayoutManager(getActivity()));

        swipeRefreshLayout.setOnRefreshListener(this::reloadInboxContent);
        swipeRefreshLayout.setColorSchemeResources(R.color.primary);

        if (messages != null || !isLazyLoading()) {
            loadInboxContent();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        AndroidUtility.uninjectViews(this);
    }

    private void reloadInboxContent() {
        messages = null;

        if (hasView()) {
            messagesView.setAdapter(new EmptyAdapter());
        }

        loadInboxContent();
    }

    private boolean isLazyLoading() {
        return !overrideLazyLoading;// && getInboxType() == InboxType.UNREAD;
    }

    private void hideNothingHereIndicator() {
        if (hasView()) {
            viewNothingHere.setVisibility(View.GONE);
        }
    }

    private void showNothingHereIndicator() {
        if (hasView()) {
            viewNothingHere.setVisibility(View.VISIBLE);
            viewNothingHere.setAlpha(0);
            viewNothingHere.animate().alpha(1).start();
        }
    }

    private void showBusyIndicator() {
        if (hasView() && viewBusyIndicator != null) {
            viewBusyIndicator.setVisibility(View.VISIBLE);
        }
    }

    private void hideBusyIndicator() {
        if (hasView()) {
            if(viewBusyIndicator != null) {
                viewBusyIndicator.setVisibility(View.GONE);
                ViewParent parent = viewBusyIndicator.getParent();
                ((ViewGroup) parent).removeView(viewBusyIndicator);

                viewBusyIndicator = null;
            }

            swipeRefreshLayout.setRefreshing(false);
        }
    }

    private void loadInboxContent() {
        hideNothingHereIndicator();

        // initialize the message observable
        if (messages == null) {
{'fraction_non_alphanumeric': 0.09644729178800233, 'fraction_numerical': 0.004426324985439721, 'mean_word_length': 3.3016032064128256, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7391767', 'n_tokens_mistral': 2528, 'n_tokens_neox': 2466, 'n_words': 436}