Skip to content
Permalink
Browse files

Contacts can now be shared via different messaging-apps

  • Loading branch information...
dakhnod committed Jul 16, 2018
1 parent 1d9e69f commit d863a807c9d8a4d0aba134f1501725b6a2b83469
Showing with 21 additions and 1 deletion.
  1. +21 −1 app/src/main/java/d/d/meshenger/ContactListActivity.java
@@ -46,6 +46,7 @@
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.List;
@@ -276,14 +277,17 @@ public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, lon
PopupMenu menu = new PopupMenu(ContactListActivity.this, view);
menu.getMenu().add("delete");
menu.getMenu().add("rename");
menu.getMenu().add("share");
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
if(menuItem.getTitle().equals("delete")) {
mainBinder.deleteContact(contacts.get(i));
refreshContactList();
}else{
}else if(menuItem.getTitle().equals("rename")){
showContactEditDialog(contacts.get(i));
}else{
shareContact(contacts.get(i));
}
return false;
}
@@ -296,6 +300,22 @@ public boolean onMenuItemClick(MenuItem menuItem) {
});
}

private void shareContact(Contact c){
try {
JSONObject object = new JSONObject();
object.put("username", c.getName());
object.put("address", c.getAddress());
object.put("identifier", c.getIdentifier());

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/json");
intent.putExtra(Intent.EXTRA_TEXT, object.toString());
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}

private void showContactEditDialog(Contact c){
EditText et = new EditText(this);
et.setText(c.getInfo());

0 comments on commit d863a80

Please sign in to comment.
You can’t perform that action at this time.