package me.bell.downapp.activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import me.bell.downapp.R;
import me.bell.downapp.bean.YYBData;
import me.bell.downapp.util.DateUtils;
import me.bell.downapp.util.DownLoadUtils;
import me.bell.downapp.util.FileUtils;
import me.bell.downapp.util.ImageUtils;
import me.bell.downapp.util.goodsViewPager.PicMaxActivity;
/**
* @Info 应用详情
* @Auth Bello
* @Time 18-4-11 下午12:46
* @Ver
*/
public class DetailActivity extends AppCompatActivity implements View.OnClickListener {
private Context mContext;
private RelativeLayout _bgLayout;
private LinearLayout _backImg;
private ImageView _dAppImage;
private TextView _dAppId;
private TextView _dAppName;
private TextView _dDescText;
private TextView _dRatingCount;
private TextView _dDownCount;
private TextView _downBtn;
private TextView _dSizeCount;
private TextView _dVersion;
private TextView _dTime;
private TextView _dPackage;
private TextView _dAuthor;
private TextView _dAbout;
private TextView _dUpdate;
private LinearLayout _imageLayout;
private YYBData data;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_detail);
mContext = DetailActivity.this;
initUI();
data = (YYBData) getIntent().getSerializableExtra("data");
if (null !=data){
refreshUI();
}
}
private void initUI() {
_bgLayout = (RelativeLayout) findViewById(R.id.d_bg_layout);
_backImg = (LinearLayout) findViewById(R.id.d_back_image);
_backImg.setOnClickListener(this);
_dAppImage = (ImageView) findViewById(R.id.d_app_image);
_dAppId = (TextView) findViewById(R.id.d_app_id);
_dAppName = (TextView) findViewById(R.id.d_app_name);
_dDescText = (TextView) findViewById(R.id.d_desc);
_dRatingCount = (TextView) findViewById(R.id.d_rating_count);
_dDownCount = (TextView) findViewById(R.id.d_down_count);
_downBtn = (TextView) findViewById(R.id.d_down_button);
_downBtn.setOnClickListener(this);
_dSizeCount = (TextView) findViewById(R.id.d_size_count);
_dVersion = (TextView) findViewById(R.id.d_version);
_dTime = (TextView) findViewById(R.id.d_time);
_dPackage = (TextView) findViewById(R.id.d_package);
_dAuthor = (TextView) findViewById(R.id.d_author);
_dAbout = (TextView) findViewById(R.id.d_about);
_dUpdate = (TextView) findViewById(R.id.d_update);
_imageLayout = (LinearLayout) findViewById(R.id.image_layout);
}
private void refreshUI() {
/* _bgLayout.setAlpha(0.2f);
Glide.with(mContext).load(data.getIconUrl()).asBitmap().into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
Drawable drawable = new BitmapDrawable(getResources(), resource);
_bgLayout.setBackgroundDrawable(drawable);
}
});*/
ImageUtils.displayImg(mContext, _dAppImage, data.getIconUrl());
_dAppId.setText("AppId: "+data.getAppId());
_dAppName.setText(data.getAppName());
_dRatingCount.setText(data.getAverageRating() + "分");
_dDownCount.setText(FileUtils.convertDownCount(data.getAppDownCount()) + "次下载");
_dSizeCount.setText(FileUtils.convertFileSize(data.getFileSize()));
if (TextUtils.isEmpty(data.getDescription())){
_dDescText.setVisibility(View.GONE);
} else {
_dDescText.setText(data.getDescription());
}
_dVersion.setText(data.getVersionName());
_dTime.setText(DateUtils.timeStamp2Date(data.getApkPublishTime()+"", null));
_dPackage.setText(data.getPkgName());
_dAuthor.setText(data.getAuthorName());
_dAbout.setText(data.getEditorIntro());
_dUpdate.setText(data.getNewFeature());
for (int i=0; i< data.getImages().length; i++){
ImageView imageView = new ImageView(mContext);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(360, 640);
imageView.setLayoutParams(lp);
imageView.setPadding(10, 10, 10, 10);
ImageUtils.displayImg(mContext, imageView, data.getImages()[i]);
final int finalI = i;
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putInt("position", finalI);
bundle.putStringArray("picUrls", data.getImages());
Intent intent = new Intent(mContext, PicMaxActivity.class);
intent.putExtras(bundle);
mContext.startActivity(intent);
}
});
_imageLayout.addView(imageView);
}
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.d_back_image:
finish();
break;
case R.id.d_down_button:
//下载
DownLoadUtils.startDownLoad(mContext, data.getApkUrl());
break;
}
}
}