fixed recreation issues in StartConversationActivity
This commit is contained in:
parent
f7d8580969
commit
aca7054174
|
@ -51,7 +51,6 @@
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.StartConversationActivity"
|
android:name=".ui.StartConversationActivity"
|
||||||
android:configChanges="orientation|screenSize"
|
|
||||||
android:label="@string/title_activity_start_conversation"
|
android:label="@string/title_activity_start_conversation"
|
||||||
android:launchMode="singleTask">
|
android:launchMode="singleTask">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -120,8 +121,9 @@ public class EnterJidDialog {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public Dialog show() {
|
||||||
this.dialog.show();
|
this.dialog.show();
|
||||||
this.dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this.dialogOnClick);
|
this.dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this.dialogOnClick);
|
||||||
|
return this.dialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@ import android.app.ActionBar;
|
||||||
import android.app.ActionBar.Tab;
|
import android.app.ActionBar.Tab;
|
||||||
import android.app.ActionBar.TabListener;
|
import android.app.ActionBar.TabListener;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.app.FragmentManager;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.app.ListFragment;
|
import android.app.ListFragment;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
@ -24,6 +26,7 @@ import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v13.app.FragmentPagerAdapter;
|
import android.support.v13.app.FragmentPagerAdapter;
|
||||||
|
import android.support.v4.view.PagerAdapter;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
@ -35,6 +38,7 @@ import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
|
@ -83,13 +87,12 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
private Tab mContactsTab;
|
private Tab mContactsTab;
|
||||||
private Tab mConferencesTab;
|
private Tab mConferencesTab;
|
||||||
private ViewPager mViewPager;
|
private ViewPager mViewPager;
|
||||||
private MyListFragment mContactsListFragment = new MyListFragment();
|
private ListPagerAdapter mListPagerAdapter;
|
||||||
private List<ListItem> contacts = new ArrayList<>();
|
private List<ListItem> contacts = new ArrayList<>();
|
||||||
private ArrayAdapter<ListItem> mContactsAdapter;
|
private ArrayAdapter<ListItem> mContactsAdapter;
|
||||||
private MyListFragment mConferenceListFragment = new MyListFragment();
|
private List<ListItem> conferences = new ArrayList<>();
|
||||||
private List<ListItem> conferences = new ArrayList<ListItem>();
|
|
||||||
private ArrayAdapter<ListItem> mConferenceAdapter;
|
private ArrayAdapter<ListItem> mConferenceAdapter;
|
||||||
private List<String> mActivatedAccounts = new ArrayList<String>();
|
private List<String> mActivatedAccounts = new ArrayList<>();
|
||||||
private List<String> mKnownHosts;
|
private List<String> mKnownHosts;
|
||||||
private List<String> mKnownConferenceHosts;
|
private List<String> mKnownConferenceHosts;
|
||||||
private Invite mPendingInvite = null;
|
private Invite mPendingInvite = null;
|
||||||
|
@ -97,6 +100,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
|
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
|
||||||
private final int REQUEST_SYNC_CONTACTS = 0x3b28cf;
|
private final int REQUEST_SYNC_CONTACTS = 0x3b28cf;
|
||||||
private final int REQUEST_CREATE_CONFERENCE = 0x3b39da;
|
private final int REQUEST_CREATE_CONFERENCE = 0x3b39da;
|
||||||
|
private Dialog mCurrentDialog = null;
|
||||||
|
|
||||||
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
|
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
|
||||||
|
|
||||||
|
@ -165,29 +169,27 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before,
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
int count) {
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() {
|
private TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
if (getActionBar().getSelectedNavigationIndex() == 0) {
|
int pos = getActionBar().getSelectedNavigationIndex();
|
||||||
|
if (pos == 0) {
|
||||||
if (contacts.size() == 1) {
|
if (contacts.size() == 1) {
|
||||||
openConversationForContact((Contact) contacts.get(0));
|
openConversationForContact((Contact) contacts.get(0));
|
||||||
} else {
|
return true;
|
||||||
hideKeyboard();
|
|
||||||
mContactsListFragment.getListView().requestFocus();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (conferences.size() == 1) {
|
if (conferences.size() == 1) {
|
||||||
openConversationsForBookmark((Bookmark) conferences.get(0));
|
openConversationsForBookmark((Bookmark) conferences.get(0));
|
||||||
} else {
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
mConferenceListFragment.getListView().requestFocus();
|
mListPagerAdapter.requestFocus(pos);
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -267,50 +269,12 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
actionBar.addTab(mConferencesTab);
|
actionBar.addTab(mConferencesTab);
|
||||||
|
|
||||||
mViewPager.setOnPageChangeListener(mOnPageChangeListener);
|
mViewPager.setOnPageChangeListener(mOnPageChangeListener);
|
||||||
mViewPager.setAdapter(new FragmentPagerAdapter(getFragmentManager()) {
|
mListPagerAdapter = new ListPagerAdapter(getFragmentManager());
|
||||||
|
mViewPager.setAdapter(mListPagerAdapter);
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fragment getItem(int position) {
|
|
||||||
if (position == 0) {
|
|
||||||
return mContactsListFragment;
|
|
||||||
} else {
|
|
||||||
return mConferenceListFragment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mConferenceAdapter = new ListItemAdapter(this, conferences);
|
mConferenceAdapter = new ListItemAdapter(this, conferences);
|
||||||
mConferenceListFragment.setListAdapter(mConferenceAdapter);
|
|
||||||
mConferenceListFragment.setContextMenu(R.menu.conference_context);
|
|
||||||
mConferenceListFragment
|
|
||||||
.setOnListItemClickListener(new OnItemClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> arg0, View arg1,
|
|
||||||
int position, long arg3) {
|
|
||||||
openConversationForBookmark(position);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mContactsAdapter = new ListItemAdapter(this, contacts);
|
mContactsAdapter = new ListItemAdapter(this, contacts);
|
||||||
((ListItemAdapter) mContactsAdapter).setOnTagClickedListener(this.mOnTagClickedListener);
|
((ListItemAdapter) mContactsAdapter).setOnTagClickedListener(this.mOnTagClickedListener);
|
||||||
mContactsListFragment.setListAdapter(mContactsAdapter);
|
|
||||||
mContactsListFragment.setContextMenu(R.menu.contact_context);
|
|
||||||
mContactsListFragment
|
|
||||||
.setOnListItemClickListener(new OnItemClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> arg0, View arg1,
|
|
||||||
int position, long arg3) {
|
|
||||||
openConversationForContact(position);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.mHideOfflineContacts = getPreferences().getBoolean("hide_offline", false);
|
this.mHideOfflineContacts = getPreferences().getBoolean("hide_offline", false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -321,6 +285,14 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
askForContactsPermissions();
|
askForContactsPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
if (mCurrentDialog != null) {
|
||||||
|
mCurrentDialog.dismiss();
|
||||||
|
}
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
protected void openConversationForContact(int position) {
|
protected void openConversationForContact(int position) {
|
||||||
Contact contact = (Contact) contacts.get(position);
|
Contact contact = (Contact) contacts.get(position);
|
||||||
openConversationForContact(contact);
|
openConversationForContact(contact);
|
||||||
|
@ -451,7 +423,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.show();
|
mCurrentDialog = dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
|
@ -476,6 +448,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
builder.setPositiveButton(R.string.join, null);
|
builder.setPositiveButton(R.string.join, null);
|
||||||
final AlertDialog dialog = builder.create();
|
final AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
mCurrentDialog = dialog;
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
|
||||||
new View.OnClickListener() {
|
new View.OnClickListener() {
|
||||||
|
|
||||||
|
@ -516,6 +489,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
xmppConnectionService.joinMuc(conversation);
|
xmppConnectionService.joinMuc(conversation);
|
||||||
}
|
}
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
mCurrentDialog = null;
|
||||||
switchToConversation(conversation);
|
switchToConversation(conversation);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -526,6 +500,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
xmppConnectionService.joinMuc(conversation);
|
xmppConnectionService.joinMuc(conversation);
|
||||||
}
|
}
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
mCurrentDialog = null;
|
||||||
switchToConversation(conversation);
|
switchToConversation(conversation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -560,7 +535,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
builder.setNegativeButton(R.string.cancel, null);
|
||||||
builder.create().show();
|
mCurrentDialog = builder.create();
|
||||||
|
mCurrentDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Account getSelectedAccount(Spinner spinner) {
|
private Account getSelectedAccount(Spinner spinner) {
|
||||||
|
@ -954,6 +930,83 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ListPagerAdapter extends PagerAdapter {
|
||||||
|
FragmentManager fragmentManager;
|
||||||
|
MyListFragment[] fragments;
|
||||||
|
|
||||||
|
public ListPagerAdapter(FragmentManager fm) {
|
||||||
|
fragmentManager = fm;
|
||||||
|
fragments = new MyListFragment[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestFocus(int pos) {
|
||||||
|
if (fragments.length > pos) {
|
||||||
|
fragments[pos].getListView().requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||||
|
assert (0 <= position && position < fragments.length);
|
||||||
|
FragmentTransaction trans = fragmentManager.beginTransaction();
|
||||||
|
trans.remove(fragments[position]);
|
||||||
|
trans.commit();
|
||||||
|
fragments[position] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment instantiateItem(ViewGroup container, int position) {
|
||||||
|
Fragment fragment = getItem(position);
|
||||||
|
FragmentTransaction trans = fragmentManager.beginTransaction();
|
||||||
|
trans.add(container.getId(), fragment, "fragment:" + position);
|
||||||
|
trans.commit();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return fragments.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isViewFromObject(View view, Object fragment) {
|
||||||
|
return ((Fragment) fragment).getView() == view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Fragment getItem(int position) {
|
||||||
|
assert (0 <= position && position < fragments.length);
|
||||||
|
if (fragments[position] == null) {
|
||||||
|
final MyListFragment listFragment = new MyListFragment();
|
||||||
|
if (position == 1) {
|
||||||
|
listFragment.setListAdapter(mConferenceAdapter);
|
||||||
|
listFragment.setContextMenu(R.menu.conference_context);
|
||||||
|
listFragment.setOnListItemClickListener(new OnItemClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> arg0, View arg1,
|
||||||
|
int position, long arg3) {
|
||||||
|
openConversationForBookmark(position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
listFragment.setListAdapter(mContactsAdapter);
|
||||||
|
listFragment.setContextMenu(R.menu.contact_context);
|
||||||
|
listFragment.setOnListItemClickListener(new OnItemClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> arg0, View arg1,
|
||||||
|
int position, long arg3) {
|
||||||
|
openConversationForContact(position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
fragments[position] = listFragment;
|
||||||
|
}
|
||||||
|
return fragments[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class MyListFragment extends ListFragment {
|
public static class MyListFragment extends ListFragment {
|
||||||
private AdapterView.OnItemClickListener mOnItemClickListener;
|
private AdapterView.OnItemClickListener mOnItemClickListener;
|
||||||
private int mResContextMenu;
|
private int mResContextMenu;
|
||||||
|
|
Loading…
Reference in a new issue