<commit_before>package me.kirimin.mitsumine.ui.adapter

import com.squareup.picasso.Picasso

import me.kirimin.mitsumine.R
import me.kirimin.mitsumine.model.Feed
import me.kirimin.mitsumine.network.RequestQueueSingleton
import me.kirimin.mitsumine.network.api.BookmarkCountApi
import me.kirimin.mitsumine.ui.adapter.FeedPagerAdapter.OnSlideListener
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.android.view.ViewObservable
import rx.functions.Action1
import rx.schedulers.Schedulers

import android.content.Context
import android.support.v4.view.ViewPager
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnClickListener
import android.view.View.OnLongClickListener
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView

public class FeedAdapter(context: Context, private val mListener: FeedAdapter.FeedAdapterListener, private val mUseReadLater: Boolean, private val mUseRead: Boolean) : ArrayAdapter<Feed>(context, 0), OnClickListener, OnLongClickListener {

    public trait FeedAdapterListener {
        public fun onFeedLeftSlide(view: View)

        public fun onFeedRightSlide(view: View)

        public fun onFeedClick(view: View)

        public fun onFeedLongClick(view: View)

        public fun onFeedShareClick(view: View)

        public fun onFeedShareLongClick(view: View)
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view: View
        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(R.layout.row_pager, null)
            val viewPager = view.findViewById(R.id.FeedFragmentViewPager) as ViewPager
            val feedView = LayoutInflater.from(getContext()).inflate(R.layout.row_feed, null)
            val adapter = FeedPagerAdapter(getContext(), feedView, object : OnSlideListener {

                override fun onLeftSlide(view: View) {
                    if (mUseReadLater) {
                        viewPager.setCurrentItem(1)
                    } else {
                        viewPager.setCurrentItem(0)
                    }
                    mListener.onFeedLeftSlide(view)
                }

                override fun onRightSlide(view: View) {
                    viewPager.setCurrentItem(1)
                    mListener.onFeedRightSlide(view)
                }
            }, mUseReadLater, mUseRead)
            viewPager.setAdapter(adapter)
            viewPager.setOnPageChangeListener(adapter)
            if (mUseReadLater) {
                viewPager.setCurrentItem(1, false)
            } else {
                viewPager.setCurrentItem(0, false)
            }

            val holder = ViewHolder(feedView,
                    feedView.findViewById(R.id.FeedFragmentImageViewThumbnail) as ImageView,
                    feedView.findViewById(R.id.FeedFragmentImageViewFavicon) as ImageView,
                    feedView.findViewById(R.id.FeedFragmentImageViewShare) as ImageView,
                    feedView.findViewById(R.id.FeedFragmentTextViewTitle) as TextView,
                    feedView.findViewById(R.id.FeedFragmentTextViewContent) as TextView,
                    feedView.findViewById(R.id.FeedFragmentTextViewDomain) as TextView,
                    feedView.findViewById(R.id.FeedFragmentImageViewBookmarkCount) as TextView)
            view.setTag(holder)
        } else {
            view = convertView
        }

        val holder = view.getTag() as ViewHolder
        val feed = getItem(position)
        holder.mFeedView.setTag(feed)
        holder.mFeedView.setOnClickListener(this)
        holder.mFeedView.setOnLongClickListener(this)
        holder.mShare.setTag(feed)
        holder.mShare.setOnClickListener(this)
        holder.mShare.setOnLongClickListener(this)
        holder.mTitle.setText(feed.title)
        holder.mContent.setText(feed.content)
        holder.mDomain.setText(feed.linkUrl)

        try {
            val oldSubscription = holder.mDomain.getTag() as Subscription
            oldSubscription.unsubscribe()
            holder.mBookmarkCount.getEditableText().clear()
        } catch (e: TypeCastException) {
        }
        val subscription = ViewObservable.bindView<String>(holder.mBookmarkCount,
                BookmarkCountApi.request(RequestQueueSingleton.get(getContext()), feed.linkUrl))
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({ s ->
                    holder.mBookmarkCount.getEditableText().clear()
                    holder.mBookmarkCount.getEditableText().append(s)
                }, { e ->
                    holder.mBookmarkCount.getEditableText().clear()
                })
        holder.mBookmarkCount.setTag(subscription)
        holder.mThumbnail.setImageResource(R.drawable.no_image)

        if (!feed.thumbnailUrl.isEmpty()) {
            Picasso.with(getContext()).load(feed.thumbnailUrl).into(holder.mThumbnail)
        }
        if (!feed.faviconUrl.isEmpty()) {
            Picasso.with(getContext()).load(feed.faviconUrl).into(holder.mFavicon)
        }
        return view
    }

    override fun onClick(v: View) {
        if (v.getId() == R.id.FeedFragmentImageViewShare) {
            mListener.onFeedShareClick(v)
        } else {
            mListener.onFeedClick(v)
        }
    }

    override fun onLongClick(v: View): Boolean {
        if (v.getId() == R.id.FeedFragmentImageViewShare) {
            mListener.onFeedShareLongClick(v)
        } else {
            mListener.onFeedLongClick(v)
        }
        return false
    }<commit_msg>シェアボタン長押し時のイベント消費を修正<commit_after>package me.kirimin.mitsumine.ui.adapter

import com.squareup.picasso.Picasso

import me.kirimin.mitsumine.R
import me.kirimin.mitsumine.model.Feed
import me.kirimin.mitsumine.network.RequestQueueSingleton
import me.kirimin.mitsumine.network.api.BookmarkCountApi
import me.kirimin.mitsumine.ui.adapter.FeedPagerAdapter.OnSlideListener
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.android.view.ViewObservable
import rx.functions.Action1
import rx.schedulers.Schedulers

import android.content.Context
import android.support.v4.view.ViewPager
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnClickListener
import android.view.View.OnLongClickListener
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView

public class FeedAdapter(context: Context, private val mListener: FeedAdapter.FeedAdapterListener, private val mUseReadLater: Boolean, private val mUseRead: Boolean) : ArrayAdapter<Feed>(context, 0), OnClickListener, OnLongClickListener {

    public trait FeedAdapterListener {
        public fun onFeedLeftSlide(view: View)

        public fun onFeedRightSlide(view: View)

        public fun onFeedClick(view: View)

        public fun onFeedLongClick(view: View)

        public fun onFeedShareClick(view: View)

        public fun onFeedShareLongClick(view: View)
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view: View
        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(R.layout.row_pager, null)
            val viewPager = view.findViewById(R.id.FeedFragmentViewPager) as ViewPager
            val feedView = LayoutInflater.from(getContext()).inflate(R.layout.row_feed, null)
            val adapter = FeedPagerAdapter(getContext(), feedView, object : OnSlideListener {

                override fun onLeftSlide(view: View) {
                    if (mUseReadLater) {
                        viewPager.setCurrentItem(1)
                    } else {
                        viewPager.setCurrentItem(0)
                    }
                    mListener.onFeedLeftSlide(view)
                }

                override fun onRightSlide(view: View) {
                    viewPager.setCurrentItem(1)
                    mListener.onFeedRightSlide(view)
                }
            }, mUseReadLater, mUseRead)
            viewPager.setAdapter(adapter)
            viewPager.setOnPageChangeListener(adapter)
            if (mUseReadLater) {
                viewPager.setCurrentItem(1, false)
            } else {
                viewPager.setCurrentItem(0, false)
            }

            val holder = ViewHolder(feedView,
                    feedView.findViewById(R.id.FeedFragmentImageViewThumbnail) as ImageView,
                    feedView.findViewById(R.id.FeedFragmentImageViewFavicon) as ImageView,
                    feedView.findViewById(R.id.FeedFragmentImageViewShare) as ImageView,
                    feedView.findViewById(R.id.FeedFragmentTextViewTitle) as TextView,
                    feedView.findViewById(R.id.FeedFragmentTextViewContent) as TextView,
                    feedView.findViewById(R.id.FeedFragmentTextViewDomain) as TextView,
                    feedView.findViewById(R.id.FeedFragmentImageViewBookmarkCount) as TextView)
            view.setTag(holder)
        } else {
            view = convertView
        }

        val holder = view.getTag() as ViewHolder
        val feed = getItem(position)
        holder.mFeedView.setTag(feed)
        holder.mFeedView.setOnClickListener(this)
        holder.mFeedView.setOnLongClickListener(this)
        holder.mShare.setTag(feed)
        holder.mShare.setOnClickListener(this)
        holder.mShare.setOnLongClickListener(this)
        holder.mTitle.setText(feed.title)
        holder.mContent.setText(feed.content)
        holder.mDomain.setText(feed.linkUrl)

        try {
            val oldSubscription = holder.mDomain.getTag() as Subscription
            oldSubscription.unsubscribe()
            holder.mBookmarkCount.getEditableText().clear()
        } catch (e: TypeCastException) {
        }
        val subscription = ViewObservable.bindView<String>(holder.mBookmarkCount,
                BookmarkCountApi.request(RequestQueueSingleton.get(getContext()), feed.linkUrl))
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({ s ->
                    holder.mBookmarkCount.getEditableText().clear()
                    holder.mBookmarkCount.getEditableText().append(s)
                }, { e ->
                    holder.mBookmarkCount.getEditableText().clear()
                })
        holder.mBookmarkCount.setTag(subscription)
        holder.mThumbnail.setImageResource(R.drawable.no_image)

        if (!feed.thumbnailUrl.isEmpty()) {
            Picasso.with(getContext()).load(feed.thumbnailUrl).into(holder.mThumbnail)
        }
        if (!feed.faviconUrl.isEmpty()) {
            Picasso.with(getContext()).load(feed.faviconUrl).into(holder.mFavicon)
        }
        return view
    }

    override fun onClick(v: View) {
        if (v.getId() == R.id.FeedFragmentImageViewShare) {
            mListener.onFeedShareClick(v)
        } else {
            mListener.onFeedClick(v)
        }
    }

    override fun onLongClick(v: View): Boolean {
        if (v.getId() == R.id.FeedFragmentImageViewShare) {
            mListener.onFeedShareLongClick(v)
        } else {
            mListener.onFeedLongClick(v)
        }
        return true
    }
{'fraction_non_alphanumeric': 0.08763966480446927, 'fraction_numerical': 0.0013966480446927375, 'mean_word_length': 2.3926562037311223, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2275755', 'n_tokens_mistral': 3256, 'n_tokens_neox': 3115, 'n_words': 506}