Email viewing structure
This commit is contained in:
@@ -7,10 +7,13 @@ import i2p.bote.email.Email;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.folder.EmailFolder;
|
||||
import i2p.bote.util.BoteHelper;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class FolderFragment extends ListFragment implements
|
||||
LoaderManager.LoaderCallbacks<List<Email>> {
|
||||
@@ -18,6 +21,8 @@ public class FolderFragment extends ListFragment implements
|
||||
|
||||
private static final int EMAIL_LIST_LOADER = 1;
|
||||
|
||||
OnEmailSelectedListener mCallback;
|
||||
|
||||
private EmailListAdapter mAdapter;
|
||||
private EmailFolder mFolder;
|
||||
|
||||
@@ -29,6 +34,25 @@ public class FolderFragment extends ListFragment implements
|
||||
return f;
|
||||
}
|
||||
|
||||
// Container Activity must implement this interface
|
||||
public interface OnEmailSelectedListener {
|
||||
public void onEmailSelected(String folderName, String messageId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
// This makes sure that the container activity has implemented
|
||||
// the callback interface. If not, it throws an exception
|
||||
try {
|
||||
mCallback = (OnEmailSelectedListener) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(activity.toString()
|
||||
+ " must implement OnEmailSelectedListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
@@ -60,6 +84,13 @@ public class FolderFragment extends ListFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView parent, View view, int pos, long id) {
|
||||
super.onListItemClick(parent, view, pos, id);
|
||||
mCallback.onEmailSelected(
|
||||
mFolder.getName(), mAdapter.getItem(pos).getMessageID());
|
||||
}
|
||||
|
||||
// LoaderManager.LoaderCallbacks<List<Email>>
|
||||
|
||||
public Loader<List<Email>> onCreateLoader(int id, Bundle args) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package i2p.bote;
|
||||
import i2p.bote.folder.EmailFolder;
|
||||
import android.os.Bundle;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.support.v4.app.ActionBarDrawerToggle;
|
||||
@@ -15,7 +16,8 @@ import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class MailListActivity extends ActionBarActivity {
|
||||
public class MailListActivity extends ActionBarActivity implements
|
||||
FolderFragment.OnEmailSelectedListener {
|
||||
private CharSequence mDrawerTitle;
|
||||
private CharSequence mTitle;
|
||||
private SharedPreferences mSharedPrefs;
|
||||
@@ -195,4 +197,16 @@ public class MailListActivity extends ActionBarActivity {
|
||||
System.setProperty("wrapper.logfile", myDir + "/wrapper.log");
|
||||
}
|
||||
}
|
||||
|
||||
// FolderFragment.OnEmailSelectedListener
|
||||
|
||||
@Override
|
||||
public void onEmailSelected(String folderName, String messageId) {
|
||||
// In single-pane mode, simply start the detail activity
|
||||
// for the selected message ID.
|
||||
Intent detailIntent = new Intent(this, ViewEmailActivity.class);
|
||||
detailIntent.putExtra(ViewEmailActivity.FOLDER_NAME, folderName);
|
||||
detailIntent.putExtra(ViewEmailActivity.MESSAGE_ID, messageId);
|
||||
startActivity(detailIntent);
|
||||
}
|
||||
}
|
||||
|
||||
92
src/i2p/bote/ViewEmailActivity.java
Normal file
92
src/i2p/bote/ViewEmailActivity.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package i2p.bote;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import i2p.bote.folder.EmailFolder;
|
||||
import i2p.bote.util.BoteHelper;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
|
||||
public class ViewEmailActivity extends ActionBarActivity {
|
||||
public static final String FOLDER_NAME = "folder_name";
|
||||
public static final String MESSAGE_ID = "message_id";
|
||||
|
||||
private EmailFolder mFolder;
|
||||
private ViewPager mPager;
|
||||
private ViewEmailPagerAdapter mPagerAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_view_email);
|
||||
|
||||
Intent i = getIntent();
|
||||
String folderName = i.getStringExtra(FOLDER_NAME);
|
||||
mFolder = BoteHelper.getMailFolder(
|
||||
folderName == null ? "inbox" : folderName);
|
||||
String messageId = i.getStringExtra(MESSAGE_ID);
|
||||
|
||||
// Instantiate the ViewPager and PagerAdapter
|
||||
mPager = (ViewPager) findViewById(R.id.pager);
|
||||
mPagerAdapter = new ViewEmailPagerAdapter(getSupportFragmentManager());
|
||||
mPager.setAdapter(mPagerAdapter);
|
||||
|
||||
// Start with a "fake" list of messageIds containing only
|
||||
// the selected messageId, so the UI starts up quickly
|
||||
List<String> messageIds = new ArrayList<String>();
|
||||
messageIds.add(messageId);
|
||||
mPagerAdapter.setData(messageIds);
|
||||
|
||||
// Now fire off a Loader to fetch the real list
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
private class ViewEmailPagerAdapter extends FragmentStatePagerAdapter {
|
||||
private List<String> mIds;
|
||||
|
||||
public ViewEmailPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
public void setData(List<String> data) {
|
||||
mIds = data;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (mIds == null)
|
||||
return null;
|
||||
|
||||
return ViewEmailFragment.newInstance(
|
||||
mFolder.getName(), mIds.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemPosition(Object item) {
|
||||
ViewEmailFragment f = (ViewEmailFragment) item;
|
||||
String messageId = f.getMessageId();
|
||||
int position = mIds.indexOf(messageId);
|
||||
|
||||
if (position >= 0)
|
||||
return position;
|
||||
else
|
||||
return POSITION_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (mIds == null)
|
||||
return 0;
|
||||
else
|
||||
return mIds.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
65
src/i2p/bote/ViewEmailFragment.java
Normal file
65
src/i2p/bote/ViewEmailFragment.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package i2p.bote;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
import i2p.bote.email.Email;
|
||||
import i2p.bote.fileencryption.PasswordException;
|
||||
import i2p.bote.util.BoteHelper;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ViewEmailFragment extends Fragment {
|
||||
private String mFolderName;
|
||||
private String mMessageId;
|
||||
|
||||
public static ViewEmailFragment newInstance(
|
||||
String folderName, String messageId) {
|
||||
ViewEmailFragment f = new ViewEmailFragment();
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString("folderName", folderName);
|
||||
args.putString("messageId", messageId);
|
||||
f.setArguments(args);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mFolderName = getArguments() != null ? getArguments().getString("folderName") : "inbox";
|
||||
mMessageId = getArguments() != null ? getArguments().getString("messageId") : "1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.fragment_view_email, container, false);
|
||||
TextView subject = (TextView) v.findViewById(R.id.email_subject);
|
||||
|
||||
try {
|
||||
Email e = BoteHelper.getEmail(mFolderName, mMessageId);
|
||||
if (e != null) {
|
||||
subject.setText(e.getSubject());
|
||||
} else {
|
||||
subject.setText("Email not found");
|
||||
}
|
||||
} catch (PasswordException e) {
|
||||
// TODO: Handle
|
||||
e.printStackTrace();
|
||||
} catch (MessagingException e) {
|
||||
// TODO Handle
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public String getMessageId() {
|
||||
return mMessageId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user