Fixed reference to dialerFragment in LinphoneActivity

Fixed DialerFragment instance
Improved fragment transactions commits
This commit is contained in:
Sylvain Berfini 2016-05-13 14:25:36 +02:00
parent 08b763479a
commit 839353de7a
2 changed files with 30 additions and 37 deletions

View file

@ -53,7 +53,6 @@ public class DialerFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
instance = this;
View view = inflater.inflate(R.layout.dialer, container, false); View view = inflater.inflate(R.layout.dialer, container, false);
mAddress = (AddressText) view.findViewById(R.id.address); mAddress = (AddressText) view.findViewById(R.id.address);
@ -133,9 +132,16 @@ public class DialerFragment extends Fragment {
return instance; return instance;
} }
@Override
public void onPause() {
instance = null;
super.onPause();
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
instance = this;
if (LinphoneActivity.isInstanciated()) { if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.DIALER); LinphoneActivity.instance().selectMenu(FragmentsAvailable.DIALER);

View file

@ -110,9 +110,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
private View contacts_selected, history_selected, dialer_selected, chat_selected; private View contacts_selected, history_selected, dialer_selected, chat_selected;
private RelativeLayout mTopBar; private RelativeLayout mTopBar;
private ImageView cancel; private ImageView cancel;
private FragmentsAvailable currentFragment, nextFragment; private FragmentsAvailable pendingFragmentTransaction, currentFragment, nextFragment;
private List<FragmentsAvailable> fragmentsHistory; private List<FragmentsAvailable> fragmentsHistory;
private Fragment dialerFragment;
private Fragment.SavedState dialerSavedState; private Fragment.SavedState dialerSavedState;
private boolean newProxyConfig; private boolean newProxyConfig;
private boolean isAnimationDisabled = true, emptyFragment = false, permissionAsked = false; private boolean isAnimationDisabled = true, emptyFragment = false, permissionAsked = false;
@ -176,19 +175,14 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
setContentView(R.layout.main); setContentView(R.layout.main);
instance = this; instance = this;
fragmentsHistory = new ArrayList<FragmentsAvailable>(); fragmentsHistory = new ArrayList<FragmentsAvailable>();
pendingFragmentTransaction = FragmentsAvailable.UNKNOW;
initButtons(); initButtons();
initSideMenu(); initSideMenu();
currentFragment = nextFragment = FragmentsAvailable.DIALER; currentFragment = nextFragment = FragmentsAvailable.EMPTY;
fragmentsHistory.add(currentFragment);
if (savedInstanceState == null) { if (savedInstanceState == null) {
if (findViewById(R.id.fragmentContainer) != null) { changeCurrentFragment(FragmentsAvailable.DIALER, getIntent().getExtras());
dialerFragment = new DialerFragment();
dialerFragment.setArguments(getIntent().getExtras());
getFragmentManager().beginTransaction().add(R.id.fragmentContainer, dialerFragment, currentFragment.toString()).commit();
selectMenu(FragmentsAvailable.DIALER);
}
} }
mListener = new LinphoneCoreListenerBase(){ mListener = new LinphoneCoreListenerBase(){
@ -356,6 +350,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
if (currentFragment == FragmentsAvailable.DIALER) { if (currentFragment == FragmentsAvailable.DIALER) {
try { try {
DialerFragment dialerFragment = DialerFragment.instance();
dialerSavedState = getFragmentManager().saveFragmentInstanceState(dialerFragment); dialerSavedState = getFragmentManager().saveFragmentInstanceState(dialerFragment);
} catch (Exception e) { } catch (Exception e) {
} }
@ -390,7 +385,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
if (extras == null) { if (extras == null) {
newFragment.setInitialSavedState(dialerSavedState); newFragment.setInitialSavedState(dialerSavedState);
} }
dialerFragment = newFragment;
break; break;
case SETTINGS: case SETTINGS:
newFragment = new SettingsFragment(); newFragment = new SettingsFragment();
@ -465,7 +459,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString()); transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString());
transaction.commitAllowingStateLoss(); transaction.commit();
fm.executePendingTransactions(); fm.executePendingTransactions();
currentFragment = newFragmentType; currentFragment = newFragmentType;
@ -488,7 +482,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
ll.setVisibility(View.VISIBLE); ll.setVisibility(View.VISIBLE);
emptyFragment = true; emptyFragment = true;
transaction.replace(R.id.fragmentContainer2, newFragment); transaction.replace(R.id.fragmentContainer2, newFragment);
transaction.commitAllowingStateLoss(); transaction.commit();
getFragmentManager().executePendingTransactions(); getFragmentManager().executePendingTransactions();
} else { } else {
if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) { if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) {
@ -524,7 +518,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
}*/ }*/
transaction.replace(R.id.fragmentContainer, newFragment); transaction.replace(R.id.fragmentContainer, newFragment);
} }
transaction.commitAllowingStateLoss(); transaction.commit();
getFragmentManager().executePendingTransactions(); getFragmentManager().executePendingTransactions();
currentFragment = newFragmentType; currentFragment = newFragmentType;
@ -621,11 +615,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, extras); changeCurrentFragment(FragmentsAvailable.CONTACTS_LIST, extras);
} }
public void displayChatList() {
Bundle extras = new Bundle();
changeCurrentFragment(FragmentsAvailable.CHAT_LIST, extras);
}
public void displayContactsForEdition(String sipAddress) { public void displayContactsForEdition(String sipAddress) {
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putBoolean("EditOnClick", true); extras.putBoolean("EditOnClick", true);
@ -791,7 +780,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
public void updateDialerFragment(DialerFragment fragment) { public void updateDialerFragment(DialerFragment fragment) {
dialerFragment = fragment;
// Hack to maintain soft input flags // Hack to maintain soft input flags
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
} }
@ -973,17 +961,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
LinphoneManager.getInstance().newOutgoingCall(address); LinphoneManager.getInstance().newOutgoingCall(address);
} }
public void setAddressAndGoToDialer(String number) {
Bundle extras = new Bundle();
extras.putString("SipUri", number);
changeCurrentFragment(FragmentsAvailable.DIALER, extras);
}
@Override
public void goToDialer() {
changeCurrentFragment(FragmentsAvailable.DIALER, null);
}
public void startVideoActivity(LinphoneCall currentCall) { public void startVideoActivity(LinphoneCall currentCall) {
Intent intent = new Intent(this, CallActivity.class); Intent intent = new Intent(this, CallActivity.class);
intent.putExtra("VideoEnabled", true); intent.putExtra("VideoEnabled", true);
@ -1065,12 +1042,14 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
private void initInCallMenuLayout(boolean callTransfer) { private void initInCallMenuLayout(boolean callTransfer) {
selectMenu(FragmentsAvailable.DIALER); selectMenu(FragmentsAvailable.DIALER);
DialerFragment dialerFragment = DialerFragment.instance();
if (dialerFragment != null) { if (dialerFragment != null) {
((DialerFragment) dialerFragment).resetLayout(callTransfer); ((DialerFragment) dialerFragment).resetLayout(callTransfer);
} }
} }
public void resetClassicMenuLayoutAndGoBackToCallIfStillRunning() { public void resetClassicMenuLayoutAndGoBackToCallIfStillRunning() {
DialerFragment dialerFragment = DialerFragment.instance();
if (dialerFragment != null) { if (dialerFragment != null) {
((DialerFragment) dialerFragment).resetLayout(false); ((DialerFragment) dialerFragment).resetLayout(false);
} }
@ -1123,6 +1102,16 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
finish(); finish();
stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
} }
@Override
protected void onPostResume() {
super.onPostResume();
if (pendingFragmentTransaction != FragmentsAvailable.UNKNOW) {
changeCurrentFragment(pendingFragmentTransaction, null, true);
selectMenu(pendingFragmentTransaction);
pendingFragmentTransaction = FragmentsAvailable.UNKNOW;
}
}
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@ -1130,16 +1119,14 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
if (data.getExtras().getBoolean("Exit", false)) { if (data.getExtras().getBoolean("Exit", false)) {
quit(); quit();
} else { } else {
FragmentsAvailable newFragment = (FragmentsAvailable) data.getExtras().getSerializable("FragmentToDisplay"); pendingFragmentTransaction = (FragmentsAvailable) data.getExtras().getSerializable("FragmentToDisplay");
changeCurrentFragment(newFragment, null, true);
selectMenu(newFragment);
} }
} else if (resultCode == Activity.RESULT_FIRST_USER && requestCode == CALL_ACTIVITY) { } else if (resultCode == Activity.RESULT_FIRST_USER && requestCode == CALL_ACTIVITY) {
getIntent().putExtra("PreviousActivity", CALL_ACTIVITY); getIntent().putExtra("PreviousActivity", CALL_ACTIVITY);
boolean callTransfer = data == null ? false : data.getBooleanExtra("Transfer", false); boolean callTransfer = data == null ? false : data.getBooleanExtra("Transfer", false);
boolean chat = data == null ? false : data.getBooleanExtra("chat", false); boolean chat = data == null ? false : data.getBooleanExtra("chat", false);
if(chat){ if(chat){
displayChatList(); pendingFragmentTransaction = FragmentsAvailable.CHAT_LIST;
} }
if (LinphoneManager.getLc().getCallsNb() > 0) { if (LinphoneManager.getLc().getCallsNb() > 0) {
initInCallMenuLayout(callTransfer); initInCallMenuLayout(callTransfer);
@ -1291,6 +1278,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
} }
} else { } else {
DialerFragment dialerFragment = DialerFragment.instance();
if (dialerFragment != null) { if (dialerFragment != null) {
if (extras != null && extras.containsKey("SipUriOrNumber")) { if (extras != null && extras.containsKey("SipUriOrNumber")) {
if (getResources().getBoolean(R.bool.automatically_start_intercepted_outgoing_gsm_call)) { if (getResources().getBoolean(R.bool.automatically_start_intercepted_outgoing_gsm_call)) {
@ -1564,5 +1552,4 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
interface ContactPicked { interface ContactPicked {
void setAddresGoToDialerAndCall(String number, String name, Uri photo); void setAddresGoToDialerAndCall(String number, String name, Uri photo);
void goToDialer();
} }