mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 17:59:39 +02:00
make basic contact options work
This commit is contained in:
parent
1bdf106f84
commit
979d3368d1
3 changed files with 64 additions and 7 deletions
|
@ -3,7 +3,8 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/profile_toolbar_background"
|
||||
android:background="?attr/conversation_list_item_background"
|
||||
android:focusable="true"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView android:id="@+id/label"
|
||||
|
|
|
@ -194,7 +194,9 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
|
|||
locale, Collections.emptySet(), false);
|
||||
}
|
||||
else if(holder.itemView instanceof ProfileSettingsItem) {
|
||||
int settingsId = itemData.get(i).settingsId;
|
||||
ProfileSettingsItem profileSettingsItem = (ProfileSettingsItem) holder.itemView;
|
||||
profileSettingsItem.setOnClickListener(view -> clickListener.onSettingsClicked(settingsId));
|
||||
profileSettingsItem.set(itemData.get(i).label);
|
||||
}
|
||||
}
|
||||
|
@ -205,8 +207,7 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
|
|||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onItemClick(ContactSelectionListItem item, boolean handleActionMode);
|
||||
void onItemLongClick(ContactSelectionListItem view);
|
||||
void onSettingsClicked(int settingsId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -264,6 +265,7 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
|
|||
itemDataContact = dcContact;
|
||||
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_ADDR,dcContact.getAddr()));
|
||||
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_NAME, context.getString(R.string.menu_edit_name)));
|
||||
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_ENCRYPTION, context.getString(R.string.profile_encryption)));
|
||||
itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_NEW_CHAT, context.getString(R.string.menu_new_chat)));
|
||||
itemDataSharedChats = sharedChats;
|
||||
int sharedChatsCnt = sharedChats.getCnt();
|
||||
|
@ -279,7 +281,6 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
|
|||
}
|
||||
|
||||
if (dcContact!=null) {
|
||||
itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_ENCRYPTION, context.getString(R.string.profile_encryption)));
|
||||
itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_BLOCK_CONTACT, context.getString(R.string.menu_block_contact)));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,14 @@ package org.thoughtcrime.securesms;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcChatlist;
|
||||
|
@ -17,11 +20,12 @@ import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
|||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class ProfileSettingsFragment extends Fragment {
|
||||
public class ProfileSettingsFragment extends Fragment implements ProfileSettingsAdapter.ItemClickListener {
|
||||
|
||||
public static final String LOCALE_EXTRA = "locale_extra";
|
||||
public static final String CHAT_ID_EXTRA = "chat_id";
|
||||
|
@ -55,7 +59,7 @@ public class ProfileSettingsFragment extends Fragment {
|
|||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.profile_settings_fragment, container, false);
|
||||
adapter = new ProfileSettingsAdapter(getContext(), GlideApp.with(this), locale,null);
|
||||
adapter = new ProfileSettingsAdapter(getContext(), GlideApp.with(this), locale,this);
|
||||
|
||||
recyclerView = ViewUtil.findById(view, R.id.recycler_view);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
@ -79,7 +83,58 @@ public class ProfileSettingsFragment extends Fragment {
|
|||
sharedChats = dcContext.getChatlist(0, null, contactId);
|
||||
}
|
||||
|
||||
|
||||
adapter.changeData(memberList, dcContact, sharedChats, dcChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSettingsClicked(int settingsId) {
|
||||
switch(settingsId) {
|
||||
case ProfileSettingsAdapter.SETTING_CONTACT_ADDR:
|
||||
onContactAddrClicked();
|
||||
break;
|
||||
case ProfileSettingsAdapter.SETTING_CONTACT_NAME:
|
||||
onEditContactName();
|
||||
break;
|
||||
case ProfileSettingsAdapter.SETTING_ENCRYPTION:
|
||||
onEncrInfo();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void onContactAddrClicked() {
|
||||
String address = dcContact.getAddr();
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(address)
|
||||
.setItems(new CharSequence[]{
|
||||
getContext().getString(R.string.menu_copy_to_clipboard)
|
||||
},
|
||||
(dialogInterface, i) -> {
|
||||
Util.writeTextToClipboard(getContext(), address);
|
||||
Toast.makeText(getContext(), getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void onEncrInfo() {
|
||||
String info_str = dcContext.getContactEncrInfo(contactId);
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(info_str)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void onEditContactName() {
|
||||
final EditText txt = new EditText(getActivity());
|
||||
txt.setText(dcContact.getName());
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.menu_edit_name)
|
||||
.setView(txt)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> {
|
||||
String newName = txt.getText().toString();
|
||||
dcContext.createContact(newName, dcContact.getAddr());
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue