Search in sources :

Example 1 with CircleAdapter

use of com.yiw.circledemo.adapter.CircleAdapter in project CircleDemo by Naoki2015.

the class MainActivity method initView.

@SuppressLint({ "ClickableViewAccessibility", "InlinedApi" })
private void initView() {
    initTitle();
    initUploadDialog();
    recyclerView = (SuperRecyclerView) findViewById(R.id.recyclerView);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(new DivItemDecoration(2, true));
    recyclerView.getMoreProgressView().getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
    recyclerView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (edittextbody.getVisibility() == View.VISIBLE) {
                updateEditTextBodyVisible(View.GONE, null);
                return true;
            }
            return false;
        }
    });
    refreshListener = new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    presenter.loadData(TYPE_PULLREFRESH);
                }
            }, 2000);
        }
    };
    recyclerView.setRefreshListener(refreshListener);
    recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                Glide.with(MainActivity.this).resumeRequests();
            } else {
                Glide.with(MainActivity.this).pauseRequests();
            }
        }
    });
    circleAdapter = new CircleAdapter(this);
    circleAdapter.setCirclePresenter(presenter);
    recyclerView.setAdapter(circleAdapter);
    edittextbody = (LinearLayout) findViewById(R.id.editTextBodyLl);
    editText = (EditText) findViewById(R.id.circleEt);
    sendIv = (ImageView) findViewById(R.id.sendIv);
    sendIv.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (presenter != null) {
                //发布评论
                String content = editText.getText().toString().trim();
                if (TextUtils.isEmpty(content)) {
                    Toast.makeText(MainActivity.this, "评论内容不能为空...", Toast.LENGTH_SHORT).show();
                    return;
                }
                presenter.addComment(content, commentConfig);
            }
            updateEditTextBodyVisible(View.GONE, null);
        }
    });
    setViewTreeObserver();
}
Also used : Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CommentListView(com.yiw.circledemo.widgets.CommentListView) ImageView(android.widget.ImageView) View(android.view.View) SuperRecyclerView(com.malinskiy.superrecyclerview.SuperRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) SuperRecyclerView(com.malinskiy.superrecyclerview.SuperRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) DivItemDecoration(com.yiw.circledemo.widgets.DivItemDecoration) CircleAdapter(com.yiw.circledemo.adapter.CircleAdapter) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Handler (android.os.Handler)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SuperRecyclerView (com.malinskiy.superrecyclerview.SuperRecyclerView)1 CircleAdapter (com.yiw.circledemo.adapter.CircleAdapter)1 CommentListView (com.yiw.circledemo.widgets.CommentListView)1 DivItemDecoration (com.yiw.circledemo.widgets.DivItemDecoration)1