HotAccAreaView.java 源代码


package com.x8zs.ui.main;

import android.content.Context;
import android.content.Intent;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.anythink.expressad.video.module.a.a.m;
import com.x8zs.ds2.R;
import com.x8zs.model.ServerApi;
import com.x8zs.ui.AppDetailActivity;
import com.x8zs.ui.LatestActivity;
import com.x8zs.ui.search.SearchActivity;
import com.x8zs.widget.SectionHeaderView;
import java.util.List;
import o2.f;

public class HotAccAreaView extends LinearLayout implements View.OnClickListener {

    private SectionHeaderView f22036q;

    private TextView f22037r;

    private List<ServerApi.n0> f22038s;

    private boolean f22039t;

    public class a implements View.OnClickListener {
        a() {
        }

        @Override
        public void onClick(View view) {
            String str = com.x8zs.ui.b.a(view) + "/ViewMore";
            Intent intent = new Intent(HotAccAreaView.this.getContext(), (Class<?>) LatestActivity.class);
            intent.putExtra("from_source", str);
            HotAccAreaView.this.getContext().startActivity(intent);
        }
    }

    public class b implements Runnable {

        final int f22041q;

        final TranslateAnimation f22042r;

        b(int i6, TranslateAnimation translateAnimation) {
            this.f22041q = i6;
            this.f22042r = translateAnimation;
        }

        @Override
        public void run() {
            HotAccAreaView.this.setMsg((ServerApi.n0) HotAccAreaView.this.f22038s.get((this.f22041q + 1) % HotAccAreaView.this.f22038s.size()));
            HotAccAreaView.this.f22037r.clearAnimation();
            HotAccAreaView.this.f22037r.startAnimation(this.f22042r);
        }
    }

    public class c implements Runnable {

        final int f22044q;

        c(int i6) {
            this.f22044q = i6;
        }

        @Override
        public void run() {
            HotAccAreaView.this.f22037r.clearAnimation();
            HotAccAreaView.this.h(this.f22044q + 1);
        }
    }

    public class d extends ClickableSpan {

        final ServerApi.n0 f22046q;

        d(ServerApi.n0 n0Var) {
            this.f22046q = n0Var;
        }

        @Override
        public void onClick(View view) {
            HotAccAreaView.this.f(this.f22046q, view);
        }

        @Override
        public void updateDrawState(TextPaint textPaint) {
            super.updateDrawState(textPaint);
            textPaint.setColor(ContextCompat.getColor(HotAccAreaView.this.getContext(), R.color.blue));
        }
    }

    public HotAccAreaView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        g();
    }

    public void f(ServerApi.n0 n0Var, View view) {
        if (n0Var.f21685c == 0) {
            String a7 = com.x8zs.ui.b.a(view);
            Intent intent = new Intent(getContext(), (Class<?>) SearchActivity.class);
            intent.putExtra("keyword", n0Var.f21686d);
            intent.putExtra("from_source", a7);
            getContext().startActivity(intent);
            return;
        }
        String a8 = com.x8zs.ui.b.a(view);
        Intent intent2 = new Intent(getContext(), (Class<?>) AppDetailActivity.class);
        intent2.putExtra("app_id", n0Var.f21685c);
        intent2.putExtra("app_name", n0Var.f21686d);
        intent2.putExtra("from_source", a8);
        getContext().startActivity(intent2);
    }

    private void g() {
        LayoutInflater.from(getContext()).inflate(R.layout.hot_acc_view, (ViewGroup) this, true);
        setOrientation(1);
        SectionHeaderView sectionHeaderView = (SectionHeaderView) findViewById(R.id.section_header);
        this.f22036q = sectionHeaderView;
        sectionHeaderView.setText(R.string.player_feed);
        this.f22036q.a(getContext().getString(R.string.more), false, new a());
        this.f22037r = (TextView) findViewById(R.id.msg_view);
        if (com.x8zs.app.a.b().f21553g) {
            this.f22037r.setOnClickListener(this);
        }
    }

    public void h(int i6) {
        List<ServerApi.n0> list = this.f22038s;
        setMsg(list.get(i6 % list.size()));
        TranslateAnimation translateAnimation = new TranslateAnimation(2, 0.0f, 2, 0.0f, 1, 0.0f, 1, -1.0f);
        translateAnimation.setDuration(1000L);
        translateAnimation.setStartOffset(m.ad);
        this.f22037r.startAnimation(translateAnimation);
        TranslateAnimation translateAnimation2 = new TranslateAnimation(2, 0.0f, 2, 0.0f, 1, 1.0f, 1, 0.0f);
        translateAnimation2.setDuration(500L);
        this.f22037r.postDelayed(new b(i6, translateAnimation2), 4000L);
        this.f22037r.postDelayed(new c(i6), 4500L);
    }

    public void setMsg(ServerApi.n0 n0Var) {
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        spannableStringBuilder.append((CharSequence) n0Var.f21684b).append((CharSequence) " ");
        spannableStringBuilder.append(n0Var.f21683a, new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.gray)), 33).append((CharSequence) " ");
        double F = f.F(n0Var.f21687e);
        if (n0Var.f21687e > 0.0d) {
            spannableStringBuilder.append((CharSequence) "加速 ").append("+" + F, new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.green)), 33).append((CharSequence) " ");
        } else {
            spannableStringBuilder.append((CharSequence) "变速 ").append(F + "", new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.green)), 33).append((CharSequence) " ");
        }
        if (n0Var.f21688f && com.x8zs.app.a.b().f21548b) {
            spannableStringBuilder.append(n0Var.f21686d, new d(n0Var), 33);
        } else {
            spannableStringBuilder.append(n0Var.f21686d, new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.gray)), 33);
        }
        this.f22037r.setText(spannableStringBuilder);
        this.f22037r.setTag(n0Var);
    }

    @Override
    public void onClick(View view) {
        ServerApi.n0 n0Var = (ServerApi.n0) this.f22037r.getTag();
        if (n0Var != null && n0Var.f21688f) {
            f(n0Var, view);
        }
    }

    public void setHotAccList(List<ServerApi.n0> list) {
        this.f22038s = list;
        if (!this.f22039t) {
            this.f22037r.clearAnimation();
            this.f22037r.removeCallbacks(null);
            h(0);
            this.f22039t = true;
        }
    }
}