2009-06-08 23:11:35 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.activity;
|
2009-06-08 23:11:35 -04:00
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.Window;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.Toast;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.Account;
|
2010-03-03 23:00:30 -05:00
|
|
|
import com.fsck.k9.Identity;
|
|
|
|
import com.fsck.k9.Preferences;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.R;
|
2009-12-09 22:16:42 -05:00
|
|
|
import java.util.List;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public class ChooseIdentity extends K9ListActivity
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
Account mAccount;
|
2009-11-21 17:45:39 -05:00
|
|
|
String mUID;
|
2009-06-08 23:11:35 -04:00
|
|
|
ArrayAdapter<String> adapter;
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
public static final String EXTRA_ACCOUNT = "com.fsck.k9.ChooseIdentity_account";
|
|
|
|
public static final String EXTRA_IDENTITY = "com.fsck.k9.ChooseIdentity_identity";
|
2009-06-08 23:11:35 -04:00
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
protected List<Identity> identities = null;
|
2009-06-08 23:11:35 -04:00
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
|
|
|
|
|
|
|
|
getListView().setTextFilterEnabled(true);
|
|
|
|
getListView().setItemsCanFocus(false);
|
|
|
|
getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
|
|
|
|
Intent intent = getIntent();
|
2010-03-03 23:00:30 -05:00
|
|
|
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
|
|
|
|
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
2009-06-08 23:11:35 -04:00
|
|
|
|
|
|
|
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
|
|
|
|
|
|
|
|
setListAdapter(adapter);
|
|
|
|
setupClickListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void onResume()
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
super.onResume();
|
|
|
|
refreshView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
protected void refreshView()
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
adapter.clear();
|
|
|
|
|
|
|
|
identities = mAccount.getIdentities();
|
2010-03-03 23:00:30 -05:00
|
|
|
for (Identity identity : identities)
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
String description = identity.getDescription();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (description == null || description.trim().length() == 0)
|
|
|
|
{
|
2009-11-21 17:45:39 -05:00
|
|
|
description = getString(R.string.message_view_from_format, identity.getName(), identity.getEmail());
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
adapter.add(description);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
protected void setupClickListeners()
|
|
|
|
{
|
|
|
|
this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
|
|
|
|
{
|
2010-04-16 08:20:10 -04:00
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2010-04-16 08:20:10 -04:00
|
|
|
Identity identity = mAccount.getIdentity(position);
|
2009-06-08 23:11:35 -04:00
|
|
|
String email = identity.getEmail();
|
2009-11-24 19:40:29 -05:00
|
|
|
if (email != null && email.trim().equals("") == false)
|
|
|
|
{
|
2009-11-21 17:45:39 -05:00
|
|
|
Intent intent = new Intent();
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
intent.putExtra(EXTRA_IDENTITY, mAccount.getIdentity(position));
|
2009-11-21 17:45:39 -05:00
|
|
|
setResult(RESULT_OK, intent);
|
|
|
|
finish();
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
Toast.makeText(ChooseIdentity.this, getString(R.string.identity_has_no_email),
|
2009-11-21 17:45:39 -05:00
|
|
|
Toast.LENGTH_LONG).show();
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
class ChooseIdentityHandler extends Handler
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
|
|
|
|
private static final int MSG_PROGRESS = 2;
|
|
|
|
private static final int MSG_DATA_CHANGED = 3;
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2009-11-24 19:40:29 -05:00
|
|
|
public void handleMessage(android.os.Message msg)
|
|
|
|
{
|
|
|
|
switch (msg.what)
|
|
|
|
{
|
|
|
|
case MSG_PROGRESS:
|
|
|
|
setProgressBarIndeterminateVisibility(msg.arg1 != 0);
|
|
|
|
break;
|
|
|
|
case MSG_DATA_CHANGED:
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
break;
|
2009-06-08 23:11:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void progress(boolean progress)
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
android.os.Message msg = new android.os.Message();
|
|
|
|
msg.what = MSG_PROGRESS;
|
|
|
|
msg.arg1 = progress ? 1 : 0;
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void dataChanged()
|
|
|
|
{
|
2009-06-08 23:11:35 -04:00
|
|
|
sendEmptyMessage(MSG_DATA_CHANGED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|