<commit_before>package com.garpr.android.dialogs

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.garpr.android.R
import com.garpr.android.data.models.FavoritePlayer
import com.garpr.android.extensions.appComponent
import com.garpr.android.extensions.requireParcelable
import com.garpr.android.managers.FavoritePlayersManager
import com.garpr.android.misc.Refreshable
import kotlinx.android.synthetic.main.dialog_add_or_remove_player_from_favorites.*
import javax.inject.Inject

class AddOrRemovePlayerFromFavoritesDialogFragment : BaseBottomSheetDialogFragment(),
        FavoritePlayersManager.OnFavoritePlayersChangeListener, Refreshable {

    @Inject
    protected lateinit var favoritePlayersManager: FavoritePlayersManager

    private val player by lazy { arguments.requireParcelable<FavoritePlayer>(KEY_PLAYER) }


    companion object {
        const val TAG = "AddOrRemovePlayerFromFavoritesDialogFragment"
        private const val KEY_PLAYER = "Player"

        fun create(player: FavoritePlayer): AddOrRemovePlayerFromFavoritesDialogFragment {
            val args = Bundle()
            args.putParcelable(KEY_PLAYER, player)

            val fragment = AddOrRemovePlayerFromFavoritesDialogFragment()
            fragment.arguments = args

            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        appComponent.inject(this)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
            savedInstanceState: Bundle?): View? {
        super.onCreateView(inflater, container, savedInstanceState)
        return inflater.inflate(R.layout.dialog_add_or_remove_player_from_favorites, container,
                false)
    }

    override fun onDestroyView() {
        super.onDestroyView()
        favoritePlayersManager.removeListener(this)
    }

    override fun onFavoritePlayersChange(favoritePlayersManager: FavoritePlayersManager) {
        if (isAlive) {
            refresh()
        }
    }

    override fun onResume() {
        super.onResume()
        refresh()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        dialogPositiveText.setOnClickListener {
            if (player in favoritePlayersManager) {
                favoritePlayersManager.removePlayer(player)
            } else {
                favoritePlayersManager.addPlayer(player, player.region)
            }

            dismissAllowingStateLoss()
        }

        dialogNegativeText.setOnClickListener {
            dismissAllowingStateLoss()
        }

        favoritePlayersManager.addListener(this)
    }

    override fun refresh() {
        if (player in favoritePlayersManager) {
            dialogMessage.text = getString(R.string.remove_x_from_favorites, player.name)
            dialogPositiveText.setEndCompoundDrawableRelativeWithIntrinsicBounds(
                    R.drawable.ic_delete_white_24dp)
        } else {
            dialogMessage.text = getString(R.string.add_x_to_favorites, player.name)
            dialogPositiveText.setEndCompoundDrawableRelativeWithIntrinsicBounds(
                    R.drawable.ic_add_circle_white_24)
        }
    }

}
<commit_msg>adding / removing a player from favorites now triggers haptic feedback<commit_after>package com.garpr.android.dialogs

import android.os.Bundle
import android.view.HapticFeedbackConstants
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.garpr.android.R
import com.garpr.android.data.models.FavoritePlayer
import com.garpr.android.extensions.appComponent
import com.garpr.android.extensions.requireParcelable
import com.garpr.android.managers.FavoritePlayersManager
import com.garpr.android.misc.Refreshable
import kotlinx.android.synthetic.main.dialog_add_or_remove_player_from_favorites.*
import javax.inject.Inject

class AddOrRemovePlayerFromFavoritesDialogFragment : BaseBottomSheetDialogFragment(),
        FavoritePlayersManager.OnFavoritePlayersChangeListener, Refreshable {

    @Inject
    protected lateinit var favoritePlayersManager: FavoritePlayersManager

    private val player by lazy { arguments.requireParcelable<FavoritePlayer>(KEY_PLAYER) }


    companion object {
        const val TAG = "AddOrRemovePlayerFromFavoritesDialogFragment"
        private const val KEY_PLAYER = "Player"

        fun create(player: FavoritePlayer): AddOrRemovePlayerFromFavoritesDialogFragment {
            val args = Bundle()
            args.putParcelable(KEY_PLAYER, player)

            val fragment = AddOrRemovePlayerFromFavoritesDialogFragment()
            fragment.arguments = args

            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        appComponent.inject(this)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
            savedInstanceState: Bundle?): View? {
        super.onCreateView(inflater, container, savedInstanceState)
        return inflater.inflate(R.layout.dialog_add_or_remove_player_from_favorites, container,
                false)
    }

    override fun onDestroyView() {
        super.onDestroyView()
        favoritePlayersManager.removeListener(this)
    }

    override fun onFavoritePlayersChange(favoritePlayersManager: FavoritePlayersManager) {
        if (isAlive) {
            refresh()
        }
    }

    override fun onResume() {
        super.onResume()
        refresh()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        dialogPositiveText.setOnClickListener {
            if (player in favoritePlayersManager) {
                favoritePlayersManager.removePlayer(player)
            } else {
                favoritePlayersManager.addPlayer(player, player.region)
            }

            it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
            dismissAllowingStateLoss()
        }

        dialogNegativeText.setOnClickListener {
            dismissAllowingStateLoss()
        }

        favoritePlayersManager.addListener(this)
    }

    override fun refresh() {
        if (player in favoritePlayersManager) {
            dialogMessage.text = getString(R.string.remove_x_from_favorites, player.name)
            dialogPositiveText.setEndCompoundDrawableRelativeWithIntrinsicBounds(
                    R.drawable.ic_delete_white_24dp)
        } else {
            dialogMessage.text = getString(R.string.add_x_to_favorites, player.name)
            dialogPositiveText.setEndCompoundDrawableRelativeWithIntrinsicBounds(
                    R.drawable.ic_add_circle_white_24)
        }
    }

}

{'fraction_non_alphanumeric': 0.0677941601618965, 'fraction_numerical': 0.0011564035848511131, 'mean_word_length': 3.0580645161290323, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6967031', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1780, 'n_words': 308}