zoukankan      html  css  js  c++  java
  • Activity从未如此清爽,既清又爽

    下一篇细说。

      1 public class MomentActivity extends Activity implements IMomentView, OnClickListener, OnItemLongClickListener, OnItemClickListener {
      2     private MomentPresenter presenter;
      3     
      4     private ImageView imageViewSelfAvatar;
      5     private TextView textViewSelfName;
      6     private TextView textViewSelfContent;
      7     private TextView textViewDate;
      8 
      9     private ScollGridView photoGridView;
     10     private PhotoAdapter adapterPhotos;
     11 
     12     private ScollGridView likeGridView;
     13     private LikeAdapter adapterLikes;
     14     private ScollListView commentListView;
     15     private CommentAdapter adapterComments;
     16     
     17     private View triangle;
     18     private View layoutLikesComments;
     19     private View layoutLikes;
     20     private View divider;
     21     
     22     private EditText editTextComment;
     23 
     24     @Override
     25     protected void onCreate(Bundle savedInstanceState) {
     26         super.onCreate(savedInstanceState);
     27         requestWindowFeature(Window.FEATURE_NO_TITLE);
     28         setContentView(R.layout.activity_moment);
     29         
     30         presenter = new MomentPresenter(this);
     31         
     32         initViews();
     33         presenter.loadData();
     34     }
     35     
     36     private void initViews() {
     37         // 返回按钮。
     38         findViewById(R.id.title_back_image).setOnClickListener(this);
     39 
     40         // 发布者。
     41         imageViewSelfAvatar = (ImageView) findViewById(R.id.user_self_image);
     42         imageViewSelfAvatar.setOnClickListener(this);
     43         textViewSelfName = (TextView) findViewById(R.id.user_self_name);
     44         textViewSelfName.setOnClickListener(this);
     45         
     46         // 正文。
     47         textViewSelfContent = (TextView) findViewById(R.id.user_self_content);
     48         textViewSelfContent.setOnClickListener(this);
     49         
     50         // 正文配图。
     51         photoGridView = (ScollGridView) findViewById(R.id.user_self_photo_gridView);
     52         adapterPhotos = new PhotoAdapter(this);
     53         photoGridView.setAdapter(adapterPhotos);
     54         photoGridView.setOnItemLongClickListener(this);
     55         
     56         // 日期。
     57         textViewDate = (TextView) findViewById(R.id.user_self_dateTime);
     58         textViewDate.setOnClickListener(this);
     59         
     60         // 删除。
     61         findViewById(R.id.textViewDelete).setOnClickListener(this);
     62         
     63         // 点赞。
     64         findViewById(R.id.imageViewAddLike).setOnClickListener(this);
     65         
     66         // 赞和评论的背景。
     67         triangle = findViewById(R.id.triangle);
     68         layoutLikesComments = findViewById(R.id.layout_likes_comments);
     69         // 赞区域。
     70         layoutLikes = findViewById(R.id.layout_likes);
     71         divider = findViewById(R.id.divider_likes_comments);
     72 
     73         // 赞。
     74         likeGridView = (ScollGridView) findViewById(R.id.user_other_photo_gridView);
     75         adapterLikes = new LikeAdapter(this);
     76         likeGridView.setAdapter(adapterLikes);
     77         likeGridView.setOnItemLongClickListener(this);
     78         
     79         // 发送图片。
     80         findViewById(R.id.bottom_emoji).setOnClickListener(this);
     81 
     82         // 评论。
     83         commentListView = (ScollListView) findViewById(R.id.user_other_comment_listView);
     84         adapterComments = new CommentAdapter(this);
     85         commentListView.setAdapter(adapterComments);
     86         commentListView.setOnItemLongClickListener(this);
     87         commentListView.setOnItemClickListener(this);
     88         
     89         // 发送评论。
     90         editTextComment = (EditText) findViewById(R.id.bottom_editText);
     91         findViewById(R.id.bottom_send).setOnClickListener(this);
     92     }
     93     
     94     @Override
     95     public void onClick(View v) {
     96         switch (v.getId()) {
     97         case R.id.title_back_image:
     98             finish();
     99             break;
    100             
    101         case R.id.user_self_image:
    102 //            presenter.publish(this);
    103 //            break;
    104 //            
    105         case R.id.user_self_name:
    106             presenter.selectPublisher(this);
    107             break;
    108             
    109         case R.id.user_self_content:
    110             presenter.editContent();
    111             break;
    112             
    113         case R.id.user_self_dateTime:
    114             presenter.pickTime();
    115             break;
    116             
    117         case R.id.textViewDelete:
    118             presenter.resetAll();
    119             break;
    120             
    121         case R.id.imageViewAddLike:
    122             presenter.like(this);
    123             break;
    124             
    125         case R.id.bottom_emoji:
    126             presenter.selectImage(this);
    127             break;
    128             
    129         case R.id.bottom_send:
    130             presenter.comment(this, editTextComment.getText().toString().trim());
    131             break;
    132         }
    133     }
    134     
    135     @Override
    136     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    137         switch (parent.getId()) {
    138         case R.id.user_other_comment_listView:
    139             presenter.setReplyTo(adapterComments.getItem(position).user);
    140             break;
    141         }
    142     }
    143     
    144     @Override
    145     public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
    146         switch (parent.getId()) {
    147         case R.id.user_self_photo_gridView:
    148             presenter.deleteImage(position);
    149             break;
    150             
    151         case R.id.user_other_photo_gridView:
    152             presenter.deleteLike(position);
    153             break;
    154             
    155         case R.id.user_other_comment_listView:
    156             presenter.deleteComment(position);
    157             break;
    158         }
    159         return false;
    160     }
    161 
    162     @Override
    163     public void updatePublisher(User publisher) {
    164         imageViewSelfAvatar.setImageBitmap(ImageUtil.getBitmapFromUri(this, publisher.avatar));
    165         textViewSelfName.setText(publisher.name);
    166     }
    167 
    168     @Override
    169     public void updateContent(String content) {
    170         textViewSelfContent.setText(content);
    171     }
    172 
    173     @Override
    174     public void updateImages(List<Image> images) {
    175         adapterPhotos.setData(images);
    176         adapterPhotos.notifyDataSetChanged();
    177     }
    178 
    179     @Override
    180     public void updateDate(String formattedDate) {
    181         textViewDate.setText(formattedDate);
    182     }
    183 
    184     @Override
    185     public void updateLikes(List<Like> likes) {
    186         adapterLikes.setData(likes);
    187         adapterLikes.notifyDataSetChanged();
    188     }
    189 
    190     @Override
    191     public void updateComments(List<Comment> comments) {
    192         adapterComments.setData(comments);
    193         adapterComments.notifyDataSetChanged();
    194     }
    195     
    196     @Override
    197     public void updateImagesVisibility(boolean isVisible) {
    198         photoGridView.setVisibility(isVisible ? View.VISIBLE : View.GONE);
    199     }
    200     
    201     @Override
    202     public void updateLikeCommentAreaVisibility(boolean isVisible) {
    203         triangle.setVisibility(isVisible ? View.VISIBLE : View.GONE);
    204         layoutLikesComments.setVisibility(isVisible ? View.VISIBLE : View.GONE);
    205     }
    206 
    207     @Override
    208     public void updateLikesVisibility(boolean isVisible) {
    209         layoutLikes.setVisibility(isVisible ? View.VISIBLE : View.GONE);
    210         divider.setVisibility(isVisible ? View.VISIBLE : View.GONE);
    211     }
    212     
    213     @Override
    214     public void updateCommentHint(String hint) {
    215         editTextComment.setHint(hint);
    216     }
    217     
    218     @Override
    219     public void clearCommentText() {
    220         editTextComment.setText("");
    221     }
    222     
    223     @Override
    224     public void resetViews() {
    225         setContentView(R.layout.activity_moment);
    226         initViews();
    227     }
    228 
    229     @Override
    230     public Context getContext() {
    231         return this;
    232     }
    233 
    234     @Override
    235     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    236         presenter.handleActivityResult(requestCode, resultCode, data);
    237     }
    238     
    239     @Override
    240     protected void onDestroy() {
    241         super.onDestroy();
    242         presenter.onActivityDestroyed();
    243     }
    244 }
  • 相关阅读:
    可能有点用的东西
    专题整理
    模拟赛x+1
    【原】如何利用 events 提升 k8s 集群可观察性
    【原】k8s ingress-nginx 针对指定 User-Agent 爬虫进行限速
    装饰者模式-动态的包装原有对象的行为
    观察者模式-将消息通知给观察者
    策略模式-定义一个算法族
    工厂模式-将对象的创建封装起来
    单例模式的五种实现方式及优缺点
  • 原文地址:https://www.cnblogs.com/chihane/p/4788111.html
Copyright © 2011-2022 走看看