110 lines
3.6 KiB
Java
110 lines
3.6 KiB
Java
|
package org.mercury_im.messenger.ui.roster.contacts.detail;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.os.Bundle;
|
||
|
import android.view.LayoutInflater;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewGroup;
|
||
|
import android.widget.ImageView;
|
||
|
import android.widget.TextView;
|
||
|
|
||
|
import androidx.annotation.NonNull;
|
||
|
import androidx.annotation.Nullable;
|
||
|
import androidx.fragment.app.Fragment;
|
||
|
import androidx.lifecycle.ViewModelProvider;
|
||
|
import androidx.lifecycle.ViewModelStoreOwner;
|
||
|
|
||
|
import com.google.android.material.chip.ChipGroup;
|
||
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||
|
|
||
|
import org.mercury_im.messenger.R;
|
||
|
import org.mercury_im.messenger.ui.chat.ChatActivity;
|
||
|
import org.mercury_im.messenger.util.ColorUtil;
|
||
|
|
||
|
import butterknife.BindView;
|
||
|
import butterknife.ButterKnife;
|
||
|
|
||
|
public class ContactDetailFragment extends Fragment {
|
||
|
|
||
|
@BindView(R.id.contact_avatar)
|
||
|
ImageView contactAvatar;
|
||
|
|
||
|
@BindView(R.id.contact_status_badge)
|
||
|
ImageView contactStatusBadge;
|
||
|
|
||
|
@BindView(R.id.contact_name)
|
||
|
TextView contactName;
|
||
|
|
||
|
@BindView(R.id.contact_address)
|
||
|
TextView contactAddress;
|
||
|
|
||
|
@BindView(R.id.contact_presence)
|
||
|
TextView contactPresence;
|
||
|
|
||
|
@BindView(R.id.contact_account)
|
||
|
TextView contactAccount;
|
||
|
|
||
|
@BindView(R.id.contact_groups)
|
||
|
ChipGroup contactGroups;
|
||
|
|
||
|
@BindView(R.id.fab)
|
||
|
ExtendedFloatingActionButton fab;
|
||
|
|
||
|
private ContactDetailViewModel viewModel;
|
||
|
|
||
|
@Nullable
|
||
|
@Override
|
||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||
|
View view = inflater.inflate(R.layout.fragment_contact_details, container, false);
|
||
|
ButterKnife.bind(this, view);
|
||
|
|
||
|
if (fab != null) {
|
||
|
fab.setOnClickListener(new View.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
Intent intent = new Intent(getContext(), ChatActivity.class);
|
||
|
intent.putExtra(ChatActivity.EXTRA_JID, viewModel.getContactAddress().getValue());
|
||
|
intent.putExtra(ChatActivity.EXTRA_ACCOUNT, viewModel.getAccountId().getValue().toString());
|
||
|
startActivity(intent);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
return view;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onAttach(Context context) {
|
||
|
super.onAttach(context);
|
||
|
viewModel = new ViewModelProvider((ViewModelStoreOwner) context).get(ContactDetailViewModel.class);
|
||
|
|
||
|
observeViewModel();
|
||
|
}
|
||
|
|
||
|
private void observeViewModel() {
|
||
|
viewModel.getContactAvatar().observe(this, drawable -> contactAvatar.setImageDrawable(drawable));
|
||
|
viewModel.getContactPresenceMode().observe(this, mode -> {
|
||
|
int color = 0;
|
||
|
switch (mode) {
|
||
|
case chat:
|
||
|
case available:
|
||
|
color = ColorUtil.rgb(0, 255, 0);
|
||
|
break;
|
||
|
case away:
|
||
|
case xa:
|
||
|
color = ColorUtil.rgb(255, 128, 0);
|
||
|
break;
|
||
|
case dnd:
|
||
|
color = ColorUtil.rgb(255, 0, 0);
|
||
|
break;
|
||
|
}
|
||
|
contactStatusBadge.setColorFilter(color);
|
||
|
});
|
||
|
viewModel.getContactName().observe(this, name -> contactName.setText(name));
|
||
|
viewModel.getContactAddress().observe(this, address -> contactAddress.setText(address));
|
||
|
viewModel.getContactPresenceStatus().observe(this, presenceText -> contactPresence.setText(presenceText));
|
||
|
viewModel.getContactAccountAddress().observe(this, address -> contactAccount.setText(address));
|
||
|
}
|
||
|
}
|