package com.uiuipad.appstore.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.uiuipad.appstore.R;
import com.uiuipad.appstore.adapter.AppAdapter;
import com.uiuipad.appstore.base.BaseActivity;
import com.uiuipad.appstore.bean.AdminAppInfo;
import com.uiuipad.appstore.bean.AppInfo;
import com.uiuipad.appstore.base.BaseResponse;
import com.uiuipad.appstore.common.CommonConfig;
import com.uiuipad.appstore.fragment.featured.FeaturedFragment;
import com.uiuipad.appstore.network.NetInterfaceManager;
import com.uiuipad.appstore.utils.ToastUtil;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public class MoreAppActivity extends BaseActivity {

    @BindView(R.id.moreapp_tv_title)
    TextView mMoreappTvTitle;
    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;
    @BindView(R.id.iv_nodata)
    ImageView iv_nodata;
    @BindView(R.id.iv_search)
    ImageView iv_search;

    private AppAdapter mAppAdapter;


    /**
     * 设置布局
     */
    @Override
    public int getLayoutId() {
        return R.layout.activity_more_app;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);
        Intent intent = getIntent();
        if (intent == null) {
            finish();
            return;
        }
        String extra = intent.getStringExtra(CommonConfig.MORE_APP_TITLE);
        if (!TextUtils.isEmpty(extra)) {
            mMoreappTvTitle.setText(extra);
        }
        if (FeaturedFragment.EXCLUSIVE_APP.equals(extra)) {
            getExclusiveApp();
        } else if (FeaturedFragment.POPULAR_APP.equals(extra)) {
            getAdminApp();
        }
        iv_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.show("功能暂未开放");
            }
        });
        mAppAdapter = new AppAdapter(this);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
        mRecyclerView.setLayoutManager(gridLayoutManager);
        mRecyclerView.setAdapter(mAppAdapter);
    }

    @Override
    public void initData() {

    }

    private void getExclusiveApp() {

    }

    private void getAdminApp() {

    }

    private void setAllAppError() {
        mRecyclerView.setVisibility(View.GONE);
        iv_nodata.setImageDrawable(getDrawable(R.drawable.app_nonetwork));
        iv_nodata.setVisibility(View.VISIBLE);
    }

    public void finish(View view) {
        finish();
    }
}
