导航菜单

页面标题

页面副标题

Delta Chat v1.58.3 - GroupCreateActivity.java 源代码

正在查看: Delta Chat v1.58.3 应用的 GroupCreateActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.thoughtcrime.securesms;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;
import androidx.loader.app.LoaderManager;
import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcContact;
import com.b44t.messenger.DcContext;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Objects;
import org.thoughtcrime.securesms.components.AvatarSelector;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
import org.thoughtcrime.securesms.mms.AttachmentManager;
import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.profiles.AvatarHelper;
import org.thoughtcrime.securesms.util.SelectedContactsAdapter;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.ViewUtil;

public class GroupCreateActivity extends PassphraseRequiredActionBarActivity implements SelectedContactsAdapter.ItemClickListener {
    public static final int AVATAR_SIZE = 210;
    public static final String CLONE_CHAT_EXTRA = "clone_chat";
    public static final String CREATE_BROADCAST = "group_create_broadcast";
    public static final String EDIT_GROUP_CHAT_ID = "edit_group_chat_id";
    private static final int PICK_CONTACT = 1;
    private static final int REQUEST_CODE_AVATAR = 2759;
    private AttachmentManager attachmentManager;
    private ImageView avatar;
    private Bitmap avatarBmp;
    private boolean avatarChanged;
    private boolean broadcast;
    private DcContext dcContext;
    private int groupChatId;
    private EditText groupName;
    private boolean imageLoaded;
    private boolean isEdit;
    private ListView lv;
    private boolean verified;

    static void lambda$onCreate$0() {
    }

    @Override
    protected void onCreate(Bundle bundle, boolean z) {
        this.dcContext = DcHelper.getContext(this);
        setContentView(R.layout.group_create_activity);
        this.verified = false;
        this.broadcast = getIntent().getBooleanExtra(CREATE_BROADCAST, false);
        ((ActionBar) Objects.requireNonNull(getSupportActionBar())).setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
        this.groupChatId = getIntent().getIntExtra(EDIT_GROUP_CHAT_ID, 0);
        this.attachmentManager = new AttachmentManager(this, new AttachmentManager.AttachmentListener() {
            @Override
            public final void onAttachmentChanged() {
                GroupCreateActivity.lambda$onCreate$0();
            }
        });
        this.avatarChanged = false;
        int i = this.groupChatId;
        if (i != 0) {
            this.isEdit = true;
            DcChat chat = this.dcContext.getChat(i);
            this.verified = chat.isProtected();
            this.broadcast = chat.isBroadcast();
        }
        int intExtra = getIntent().getIntExtra(CLONE_CHAT_EXTRA, 0);
        if (intExtra != 0) {
            this.broadcast = this.dcContext.getChat(intExtra).isBroadcast();
        }
        initializeResources();
    }

    @Override
    public void onResume() {
        super.onResume();
        updateViewState();
    }

    protected void onDestroy() {
        super.onDestroy();
    }

    private void updateViewState() {
        String string;
        this.avatar.setEnabled(true);
        this.groupName.setEnabled(true);
        if (isEdit()) {
            string = getString(R.string.global_menu_edit_desktop);
        } else if (this.broadcast) {
            string = getString(R.string.new_broadcast_list);
        } else {
            string = getString(R.string.menu_new_group);
        }
        getSupportActionBar().setTitle(string);
    }

    private void initializeResources() {
        this.lv = (ListView) ViewUtil.findById((Activity) this, R.id.selected_contacts_list);
        this.avatar = (ImageView) ViewUtil.findById((Activity) this, R.id.avatar);
        this.groupName = (EditText) ViewUtil.findById((Activity) this, R.id.group_name);
        TextView textView = (TextView) ViewUtil.findById((Activity) this, R.id.chat_hints);
        initializeAvatarView();
        SelectedContactsAdapter selectedContactsAdapter = new SelectedContactsAdapter(this, GlideApp.with((FragmentActivity) this), this.broadcast);
        selectedContactsAdapter.setItemClickListener(this);
        this.lv.setAdapter((ListAdapter) selectedContactsAdapter);
        int intExtra = getIntent().getIntExtra(CLONE_CHAT_EXTRA, 0);
        if (intExtra != 0) {
            DcChat chat = this.dcContext.getChat(intExtra);
            this.groupName.setText(chat.getName());
            File file = new File(chat.getProfileImage());
            if (file.exists()) {
                setAvatarView(Uri.fromFile(file));
            }
            int[] chatContacts = this.dcContext.getChatContacts(intExtra);
            ArrayList arrayList = new ArrayList(chatContacts.length);
            for (int i : chatContacts) {
                arrayList.add(Integer.valueOf(i));
            }
            selectedContactsAdapter.changeData(arrayList);
        } else {
            selectedContactsAdapter.changeData(null);
        }
        if (this.broadcast) {
            this.avatar.setVisibility(8);
            this.groupName.setHint(R.string.broadcast_list_name);
            textView.setVisibility(isEdit() ? 8 : 0);
        } else {
            textView.setVisibility(8);
        }
        if (isEdit()) {
            this.groupName.setText(this.dcContext.getChat(this.groupChatId).getName());
            this.lv.setVisibility(8);
        }
    }

    private void initializeAvatarView() {
        this.imageLoaded = false;
        int i = this.groupChatId;
        if (i != 0) {
            File file = new File(this.dcContext.getChat(i).getProfileImage());
            if (file.exists()) {
                this.imageLoaded = true;
                GlideApp.with((FragmentActivity) this).m1514load(file).circleCrop().into(this.avatar);
            }
        }
        if (!this.imageLoaded) {
            this.avatar.setImageDrawable(new ResourceContactPhoto(R.drawable.ic_group_white_24dp).asDrawable(this, ThemeUtil.getDummyContactColor(this)));
        }
        this.avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                GroupCreateActivity.this.m1238x37933720(view);
            }
        });
    }

    void m1238x37933720(View view) {
        new AvatarSelector(this, LoaderManager.getInstance(this), new AvatarSelectedListener(), this.imageLoaded).show(this, this.avatar);
    }

    public boolean onPrepareOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menu.clear();
        menuInflater.inflate(R.menu.group_create, menu);
        super.onPrepareOptionsMenu(menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        super.onOptionsItemSelected(menuItem);
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
            return true;
        }
        boolean z = false;
        if (itemId != R.id.menu_create_group) {
            return false;
        }
        String groupName = getGroupName();
        if (showGroupNameEmptyToast(groupName)) {
            return true;
        }
        if (this.groupChatId != 0) {
            updateGroup(groupName);
        } else {
            if (!this.broadcast && allMembersVerified()) {
                z = true;
            }
            this.verified = z;
            createGroup(groupName);
        }
        return true;
    }

    private boolean allMembersVerified() {
        Iterator<Integer> it = getAdapter().getContacts().iterator();
        while (it.hasNext()) {
            DcContact contact = this.dcContext.getContact(it.next().intValue());
            if (contact != null && !contact.isVerified()) {
                return false;
            }
        }
        return true;
    }

    @Override
    public void onItemClick(int i) {
        if (i == -3) {
            Intent intent = new Intent((Context) this, (Class<?>) ContactMultiSelectionActivity.class);
            intent.putExtra(ContactSelectionListFragment.SELECT_VERIFIED_EXTRA, this.verified);
            intent.putExtra(ContactSelectionListFragment.PRESELECTED_CONTACTS, new ArrayList(getAdapter().getContacts()));
            startActivityForResult(intent, 1);
        }
    }

    @Override
    public void onItemDeleteClick(int i) {
        getAdapter().remove(Integer.valueOf(i));
    }

    private void createGroup(String str) {
        if (this.broadcast) {
            int createBroadcastList = this.dcContext.createBroadcastList();
            this.groupChatId = createBroadcastList;
            this.dcContext.setChatName(createBroadcastList, str);
        } else {
            this.groupChatId = this.dcContext.createGroupChat(this.verified, str);
        }
        Iterator<Integer> it = getAdapter().getContacts().iterator();
        while (it.hasNext()) {
            this.dcContext.addContactToChat(this.groupChatId, it.next().intValue());
        }
        Bitmap bitmap = this.avatarBmp;
        if (bitmap != null) {
            AvatarHelper.setGroupAvatar(this, this.groupChatId, bitmap);
        }
        this.attachmentManager.cleanup();
        Intent intent = new Intent((Context) this, (Class<?>) ConversationActivity.class);
        intent.putExtra("chat_id", this.groupChatId);
        startActivity(intent);
        finish();
    }

    private boolean showGroupNameEmptyToast(String str) {
        if (str != null) {
            return false;
        }
        Toast.makeText((Context) this, (CharSequence) getString(R.string.group_please_enter_group_name), 1).show();
        return true;
    }

    private void updateGroup(String str) {
        int i = this.groupChatId;
        if (i == 0) {
            return;
        }
        this.dcContext.setChatName(i, str);
        if (this.avatarChanged) {
            AvatarHelper.setGroupAvatar(this, this.groupChatId, this.avatarBmp);
        }
        this.attachmentManager.cleanup();
        Intent intent = new Intent();
        intent.putExtra(EDIT_GROUP_CHAT_ID, this.groupChatId);
        setResult(-1, intent);
        finish();
    }

    private SelectedContactsAdapter getAdapter() {
        return (SelectedContactsAdapter) this.lv.getAdapter();
    }

    private String getGroupName() {
        String obj = this.groupName.getText() != null ? this.groupName.getText().toString() : null;
        if (obj != null) {
            obj = obj.trim();
            if (obj.isEmpty()) {
                return null;
            }
        }
        return obj;
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 != -1) {
            return;
        }
        if (i != 1) {
            if (i == REQUEST_CODE_AVATAR) {
                onFileSelected(intent != null ? intent.getData() : null);
                return;
            } else {
                if (i != 31424) {
                    return;
                }
                setAvatarView(intent.getData());
                return;
            }
        }
        ArrayList arrayList = new ArrayList();
        Iterator it = ((ArrayList) Objects.requireNonNull(intent.getIntegerArrayListExtra(ContactMultiSelectionActivity.CONTACTS_EXTRA))).iterator();
        while (it.hasNext()) {
            Integer num = (Integer) it.next();
            if (num != null) {
                arrayList.add(num);
            }
        }
        getAdapter().changeData(arrayList);
    }

    private void setAvatarView(final Uri uri) {
        GlideApp.with((FragmentActivity) this).asBitmap().m1456load(uri).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerCrop().override(AVATAR_SIZE, AVATAR_SIZE).into(new CustomTarget<Bitmap>() {
            public void onLoadCleared(Drawable drawable) {
            }

            public void onResourceReady(Object obj, Transition transition) {
                onResourceReady((Bitmap) obj, (Transition<? super Bitmap>) transition);
            }

            public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
                GroupCreateActivity.this.setAvatar(uri, bitmap);
            }
        });
    }

    public <T> void setAvatar(T t, Bitmap bitmap) {
        this.avatarBmp = bitmap;
        this.avatarChanged = true;
        this.imageLoaded = true;
        GlideApp.with((FragmentActivity) this).m1516load((Object) t).circleCrop().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(this.avatar);
    }

    private boolean isEdit() {
        return this.isEdit;
    }

    private class AvatarSelectedListener implements AvatarSelector.AttachmentClickedListener {
        private AvatarSelectedListener() {
        }

        @Override
        public void onClick(int i) {
            if (i == 1) {
                AttachmentManager.selectImage(GroupCreateActivity.this, GroupCreateActivity.REQUEST_CODE_AVATAR);
                return;
            }
            if (i == 5) {
                GroupCreateActivity.this.attachmentManager.capturePhoto(GroupCreateActivity.this, GroupCreateActivity.REQUEST_CODE_AVATAR);
                return;
            }
            if (i != 8) {
                return;
            }
            GroupCreateActivity.this.avatarBmp = null;
            GroupCreateActivity.this.imageLoaded = false;
            GroupCreateActivity.this.avatarChanged = true;
            ImageView imageView = GroupCreateActivity.this.avatar;
            ResourceContactPhoto resourceContactPhoto = new ResourceContactPhoto(R.drawable.ic_group_white_24dp);
            AppCompatActivity appCompatActivity = GroupCreateActivity.this;
            imageView.setImageDrawable(resourceContactPhoto.asDrawable(appCompatActivity, ThemeUtil.getDummyContactColor(appCompatActivity)));
        }

        @Override
        public void onQuickAttachment(Uri uri) {
            GroupCreateActivity.this.onFileSelected(uri);
        }
    }

    public void onFileSelected(Uri uri) {
        if (uri == null) {
            uri = this.attachmentManager.getImageCaptureUri();
        }
        AvatarHelper.cropAvatar(this, uri);
    }
}