开发冲刺四

今天做了聊天页面和加好友界面但是没有添加具体的功能,由于课程较多所以代码量不太大

ChatInfoActivity.java

package com.imooc.meet.ui;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.imooc.meet.R;
import com.liuguilin.framework.base.BaseBackActivity;
import com.liuguilin.framework.bmob.BmobManager;
import com.liuguilin.framework.bmob.IMUser;
import com.liuguilin.framework.entity.Constants;
import com.liuguilin.framework.event.EventManager;
import com.liuguilin.framework.helper.GlideHelper;
import com.liuguilin.framework.manager.DialogManager;
import com.liuguilin.framework.utils.CommonUtils;
import com.liuguilin.framework.view.DialogView;

import java.util.List;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.UpdateListener;
import de.hdodenhof.circleimageview.CircleImageView;

public class ChatInfoActivity extends BaseBackActivity implements View.OnClickListener {

    private CircleImageView iv_photo;
    private TextView tv_name;
    private TextView tv_phone;
    private Button btn_delete;

    private String objectId;

    private DialogView mDeleteDialog;
    private TextView tvText;
    private TextView tv_confirm;
    private TextView tv_cancel;

    public static void startChatInfo(Activity mActivity, String objectId, int requestCode) {
        Intent intent = new Intent(mActivity, ChatInfoActivity.class);
        intent.putExtra(Constants.INTENT_USER_ID, objectId);
        mActivity.startActivityForResult(intent, requestCode);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat_info);

        initView();
    }

    private void initView() {

        initDeleteDialog();

        iv_photo = (CircleImageView) findViewById(R.id.iv_photo);
        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_phone = (TextView) findViewById(R.id.tv_phone);
        btn_delete = (Button) findViewById(R.id.btn_delete);

        btn_delete.setOnClickListener(this);
        tv_phone.setOnClickListener(this);

        objectId = getIntent().getStringExtra(Constants.INTENT_USER_ID);
        if (!TextUtils.isEmpty(objectId)) {
            BmobManager.getInstance().queryObjectIdUser(objectId, new FindListener<IMUser>() {
                @Override
                public void done(List<IMUser> list, BmobException e) {
                    if (e == null) {
                        if (CommonUtils.isEmpty(list)) {
                            IMUser imUser = list.get(0);
                            GlideHelper.loadUrl(ChatInfoActivity.this, imUser.getPhoto(), iv_photo);
                            tv_phone.setText(imUser.getMobilePhoneNumber());
                            tv_name.setText(imUser.getNickName());
                        }
                    }
                }
            });
        }
    }

    private void initDeleteDialog() {
        mDeleteDialog = DialogManager.getInstance().initView(this, R.layout.dialog_delete_friend);
        tvText = (TextView) mDeleteDialog.findViewById(R.id.tvText);
        tvText.setText(getString(R.string.text_chat_info_del_text));

        tv_confirm = (TextView) mDeleteDialog.findViewById(R.id.tv_confirm);
        tv_confirm.setOnClickListener(this);

        tv_cancel = (TextView) mDeleteDialog.findViewById(R.id.tv_cancel);
        tv_cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_phone:
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + tv_phone.getText().toString().trim()));
                startActivity(intent);
                break;
            case R.id.btn_delete:
                DialogManager.getInstance().show(mDeleteDialog);
                break;
            case R.id.tv_confirm:
                DialogManager.getInstance().show(mDeleteDialog);
                BmobManager.getInstance().deleteFriend(objectId, new UpdateListener() {
                    @Override
                    public void done(BmobException e) {
                        if (e == null) {
                            //刷新列表
                            EventManager.post(EventManager.FLAG_UPDATE_FRIEND_LIST);
                            setResult(RESULT_OK);
                            finish();
                        } else {
                            Toast.makeText(ChatInfoActivity.this, getString(R.string.text_chat_info_del_error) + e.toString(), Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                break;
            case R.id.tv_cancel:
                DialogManager.getInstance().hide(mDeleteDialog);
                break;
        }
    }
}

ChatThemeActivity.java

package com.imooc.meet.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

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

import com.imooc.meet.R;
import com.liuguilin.framework.adapter.CommonAdapter;
import com.liuguilin.framework.adapter.CommonViewHolder;
import com.liuguilin.framework.base.BaseBackActivity;
import com.liuguilin.framework.entity.Constants;
import com.liuguilin.framework.utils.SpUtils;

import java.util.ArrayList;
import java.util.List;

public class ChatThemeActivity extends BaseBackActivity {

    private RecyclerView mThemeView;
    private List<Integer> mThemeList = new ArrayList<>();
    private CommonAdapter<Integer> mThemeAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat_theme);

        initView();
    }

    private void initView() {

        mThemeList.add(R.drawable.img_chat_bg_1);
        mThemeList.add(R.drawable.img_chat_bg_2);
        mThemeList.add(R.drawable.img_chat_bg_3);
        mThemeList.add(R.drawable.img_chat_bg_4);
        mThemeList.add(R.drawable.img_chat_bg_5);
        mThemeList.add(R.drawable.img_chat_bg_6);
        mThemeList.add(R.drawable.img_chat_bg_7);
        mThemeList.add(R.drawable.img_chat_bg_8);
        mThemeList.add(R.drawable.img_chat_bg_9);

        mThemeView = (RecyclerView) findViewById(R.id.mThemeView);
        mThemeView.setLayoutManager(new GridLayoutManager(this, 3));
        mThemeAdapter = new CommonAdapter<>(mThemeList, new CommonAdapter.OnBindDataListener<Integer>() {
            @Override
            public void onBindViewHolder(Integer model, CommonViewHolder viewHolder, int type, int position) {
                viewHolder.setImageResource(R.id.iv_theme, model);

                viewHolder.itemView.setOnClickListener(v -> {
                    SpUtils.getInstance().putInt(Constants.SP_CHAT_THEME, (position + 1));
                    Toast.makeText(ChatThemeActivity.this, "设置成功", Toast.LENGTH_SHORT).show();
                });
            }

            @Override
            public int getLayoutId(int type) {
                return R.layout.layout_theme_item;
            }
        });
        mThemeView.setAdapter(mThemeAdapter);
    }
}

 

activity_char_theme.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:background="@android:color/white"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="10dp">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/iv_photo"
            android:layout_width="40dp"
            android:layout_height="40dp" />

        <TextView
            android:id="@+id/tv_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Name"
            android:textColor="@android:color/black" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:background="@android:color/white"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="10dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/text_login_phone" />

        <TextView
            android:id="@+id/tv_phone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Phone"
            android:textColor="@color/colorAccent" />

    </LinearLayout>

    <Button
        android:id="@+id/btn_delete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:background="@drawable/chat_info_btn_bg"
        android:text="@string/text_delete"
        android:textColor="@android:color/white" />

</LinearLayout>

 

posted @ 2020-04-21 21:37  yizhixiaozhu  阅读(121)  评论(0编辑  收藏  举报