Contact edit page
This commit is contained in:
@ -32,6 +32,9 @@
|
||||
<activity
|
||||
android:name="i2p.bote.android.addressbook.AddressBookActivity"
|
||||
android:parentActivityName="i2p.bote.android.EmailListActivity" />
|
||||
<activity
|
||||
android:name="i2p.bote.android.addressbook.EditContactActivity"
|
||||
android:parentActivityName="i2p.bote.android.addressbook.AddressBookActivity" />
|
||||
<activity
|
||||
android:name="i2p.bote.android.config.SettingsActivity"
|
||||
android:parentActivityName="i2p.bote.android.EmailListActivity" />
|
||||
|
59
res/layout/fragment_edit_contact.xml
Normal file
59
res/layout/fragment_edit_contact.xml
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:paddingTop="10dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_picture"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_launcher" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/contact_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/contact_picture"
|
||||
android:layout_toRightOf="@+id/contact_picture"
|
||||
android:ems="10"
|
||||
android:hint="@string/public_name"
|
||||
android:inputType="text" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/destination"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/contact_picture"
|
||||
android:ems="10"
|
||||
android:hint="@string/email_destination"
|
||||
android:inputType="text" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/import_destination_from_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@+id/destination"
|
||||
android:layout_alignBaseline="@+id/destination"
|
||||
android:layout_alignParentRight="true"
|
||||
android:text="@string/label_browse" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/destination"
|
||||
android:ems="10"
|
||||
android:hint="@string/description"
|
||||
android:inputType="text" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/error"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/text"
|
||||
android:textColor="@color/error_color" />
|
||||
|
||||
</RelativeLayout>
|
11
res/menu/edit_contact.xml
Normal file
11
res/menu/edit_contact.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_save_contact"
|
||||
android:icon="@drawable/ic_content_save"
|
||||
android:title="@string/save_contact"
|
||||
i2pandroid:showAsAction="ifRoom"/>
|
||||
|
||||
</menu>
|
@ -43,6 +43,10 @@
|
||||
<string name="address_book_empty">Address book is empty</string>
|
||||
<string name="action_new_contact">New contact</string>
|
||||
|
||||
<string name="email_destination">Email destination</string>
|
||||
<string name="label_browse">Browse</string>
|
||||
<string name="save_contact">Save contact</string>
|
||||
|
||||
<string name="pref_title_general">General</string>
|
||||
<string name="pref_summ_general">General settings and default identity settings</string>
|
||||
<string name="pref_title_autoMail">Auto-check mail</string>
|
||||
|
@ -1,6 +1,8 @@
|
||||
package i2p.bote.android.addressbook;
|
||||
|
||||
import i2p.bote.packet.dht.Contact;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
@ -22,6 +24,15 @@ public class AddressBookActivity extends ActionBarActivity implements
|
||||
|
||||
@Override
|
||||
public void onContactSelected(Contact contact) {
|
||||
// TODO
|
||||
if (getIntent().getAction() == Intent.ACTION_PICK) {
|
||||
Intent result = new Intent();
|
||||
result.putExtra(EditContactFragment.CONTACT_DESTINATION, contact.getBase64Dest());
|
||||
setResult(Activity.RESULT_OK, result);
|
||||
finish();
|
||||
} else {
|
||||
Intent i = new Intent(this, EditContactActivity.class);
|
||||
i.putExtra(EditContactFragment.CONTACT_DESTINATION, contact.getBase64Dest());
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.util.SortedSet;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
@ -72,8 +73,10 @@ public class AddressBookFragment extends ListFragment implements
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_new_contact:
|
||||
// TODO
|
||||
Intent nci = new Intent(getActivity(), EditContactActivity.class);
|
||||
startActivity(nci);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
24
src/i2p/bote/android/addressbook/EditContactActivity.java
Normal file
24
src/i2p/bote/android/addressbook/EditContactActivity.java
Normal file
@ -0,0 +1,24 @@
|
||||
package i2p.bote.android.addressbook;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
public class EditContactActivity extends ActionBarActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Enable ActionBar app icon to behave as action to go back
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
String destination = null;
|
||||
Bundle args = getIntent().getExtras();
|
||||
if (args != null)
|
||||
destination = args.getString(EditContactFragment.CONTACT_DESTINATION);
|
||||
EditContactFragment f = EditContactFragment.newInstance(destination);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(android.R.id.content, f).commit();
|
||||
}
|
||||
}
|
||||
}
|
165
src/i2p/bote/android/addressbook/EditContactFragment.java
Normal file
165
src/i2p/bote/android/addressbook/EditContactFragment.java
Normal file
@ -0,0 +1,165 @@
|
||||
package i2p.bote.android.addressbook;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import i2p.bote.android.R;
|
||||
import i2p.bote.android.util.BoteHelper;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.packet.dht.Contact;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class EditContactFragment extends Fragment {
|
||||
public static final String CONTACT_DESTINATION = "contact_destination";
|
||||
|
||||
static final int REQUEST_DESTINATION_FILE = 1;
|
||||
|
||||
private String mDestination;
|
||||
EditText mNameField;
|
||||
EditText mDestinationField;
|
||||
EditText mTextField;
|
||||
TextView mError;
|
||||
|
||||
public static EditContactFragment newInstance(String destination) {
|
||||
EditContactFragment f = new EditContactFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(CONTACT_DESTINATION, destination);
|
||||
f.setArguments(args);
|
||||
return f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_edit_contact, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mDestination = getArguments().getString(CONTACT_DESTINATION);
|
||||
|
||||
mNameField = (EditText) view.findViewById(R.id.contact_name);
|
||||
mDestinationField = (EditText) view.findViewById(R.id.destination);
|
||||
mTextField = (EditText) view.findViewById(R.id.text);
|
||||
mError = (TextView) view.findViewById(R.id.error);
|
||||
|
||||
if (mDestination != null) {
|
||||
try {
|
||||
Contact contact = BoteHelper.getContact(mDestination);
|
||||
mNameField.setText(contact.getName());
|
||||
mDestinationField.setText(mDestination);
|
||||
mTextField.setText(contact.getText());
|
||||
} catch (PasswordException e) {
|
||||
// TODO Handle
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Button b = (Button) view.findViewById(R.id.import_destination_from_file);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
i.setType("text/plain");
|
||||
i.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
try {
|
||||
startActivityForResult(
|
||||
Intent.createChooser(i,"Select file containing Email Destination"),
|
||||
REQUEST_DESTINATION_FILE);
|
||||
} catch (android.content.ActivityNotFoundException ex) {
|
||||
Toast.makeText(getActivity(), "Please install a File Manager.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.edit_contact, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_save_contact:
|
||||
String name = mNameField.getText().toString();
|
||||
String destination = mDestinationField.getText().toString();
|
||||
String text = mTextField.getText().toString();
|
||||
|
||||
mError.setText("");
|
||||
|
||||
try {
|
||||
String err = BoteHelper.saveContact(destination, name, null, text);
|
||||
if (err == null)
|
||||
getActivity().finish();
|
||||
else
|
||||
mError.setText(err);
|
||||
} catch (PasswordException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
mError.setText(e.getLocalizedMessage());
|
||||
} catch (GeneralSecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
mError.setText(e.getLocalizedMessage());
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQUEST_DESTINATION_FILE) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Uri result = data.getData();
|
||||
String path = result.getPath();
|
||||
File file = new File(path);
|
||||
BufferedReader br;
|
||||
try {
|
||||
br = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new FileInputStream(file)));
|
||||
try {
|
||||
mDestinationField.setText(br.readLine());
|
||||
} catch (IOException ioe) {
|
||||
Toast.makeText(getActivity(), "Failed to read Email Destination file.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
Toast.makeText(getActivity(), "Could not find Email Destination file.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user