Skip to content

Commit

Permalink
Contacts can now be shared via different messaging-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
dakhnod committed Jul 16, 2018
1 parent 1d9e69f commit d863a80
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/src/main/java/d/d/meshenger/ContactListActivity.java
Expand Up @@ -46,6 +46,7 @@
import android.widget.Toast;

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

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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());
Expand Down

0 comments on commit d863a80

Please sign in to comment.