Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Commit

Permalink
properly handle onnewintent, move cancommitsafely in onresumefragments
Browse files Browse the repository at this point in the history
  • Loading branch information
fgei committed Sep 29, 2015
1 parent f71198e commit c48ef18
Showing 1 changed file with 48 additions and 34 deletions.
82 changes: 48 additions & 34 deletions src/com/duckduckgo/mobile/android/activity/DuckDuckGo.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class DuckDuckGo extends AppCompatActivity {
public boolean savedState = false;
private boolean backPressed = false;
private boolean canCommitFragmentSafely = true;
private boolean newIntent = false;

private final int PREFERENCES_RESULT = 0;

Expand Down Expand Up @@ -229,37 +230,7 @@ public void onBackStackChanged() {

// global search intent
Intent intent = getIntent();

if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
intent.setAction(Intent.ACTION_MAIN);
String query = intent.getStringExtra(SearchManager.QUERY);
DDGActionBarManager.getInstance().setSearchBarText(query);
BusProvider.getInstance().post(new WebViewSearchWebTermEvent(query));
}
else if(intent.getBooleanExtra("widget", false)) {
if(!getSearchField().getText().toString().equals("")) {
DDGActionBarManager.getInstance().clearSearchBar();
}
if(!DDGControlVar.mDuckDuckGoContainer.currentFragmentTag.equals(SearchFragment.TAG)
&& !DDGControlVar.mDuckDuckGoContainer.currentFragmentTag.equals(SearchFragment.TAG_HOME_PAGE)) {
displayScreen(SCREEN.SCR_SEARCH, true);
}
}
else if(Intent.ACTION_VIEW.equals(intent.getAction())) {
searchOrGoToUrl(intent.getDataString());
}
else if(Intent.ACTION_ASSIST.equals(intent.getAction())){
if(!DDGControlVar.mDuckDuckGoContainer.currentFragmentTag.equals(SearchFragment.TAG)
&& !DDGControlVar.mDuckDuckGoContainer.currentFragmentTag.equals(SearchFragment.TAG_HOME_PAGE)) {
displayScreen(SCREEN.SCR_SEARCH, true);
}
}
else if(DDGControlVar.mDuckDuckGoContainer.webviewShowing){
Fragment fragment = fragmentManager.findFragmentByTag(WebFragment.TAG);
if(fragmentManager.findFragmentByTag(WebFragment.TAG)== null || !fragment.isVisible()) {
displayScreen(SCREEN.SCR_WEBVIEW, false);
}
}
processIntent(intent);
}

private void initSearchField() {
Expand Down Expand Up @@ -497,14 +468,48 @@ private void displayHomeScreen() {
displayScreen(DDGControlVar.START_SCREEN, true, true);
DDGControlVar.mDuckDuckGoContainer.sessionType = SESSIONTYPE.SESSION_BROWSE;
}
/*

private void processIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
intent.setAction(Intent.ACTION_MAIN);
String query = intent.getStringExtra(SearchManager.QUERY);
DDGActionBarManager.getInstance().setSearchBarText(query);
BusProvider.getInstance().post(new WebViewSearchWebTermEvent(query));
}
else if(intent.getBooleanExtra("widget", false)) {
if(!getSearchField().getText().toString().equals("")) {
DDGActionBarManager.getInstance().clearSearchBar();
}
if(!DDGControlVar.mDuckDuckGoContainer.currentFragmentTag.equals(SearchFragment.TAG)
&& !DDGControlVar.mDuckDuckGoContainer.currentFragmentTag.equals(SearchFragment.TAG_HOME_PAGE)) {
displayScreen(SCREEN.SCR_SEARCH, true);
}
}
else if(Intent.ACTION_VIEW.equals(intent.getAction())) {
searchOrGoToUrl(intent.getDataString());
}
else if(Intent.ACTION_ASSIST.equals(intent.getAction())){
if(!DDGControlVar.mDuckDuckGoContainer.currentFragmentTag.equals(SearchFragment.TAG)
&& !DDGControlVar.mDuckDuckGoContainer.currentFragmentTag.equals(SearchFragment.TAG_HOME_PAGE)) {
displayScreen(SCREEN.SCR_SEARCH, true);
}
}
else if(DDGControlVar.mDuckDuckGoContainer.webviewShowing){
Fragment fragment = fragmentManager.findFragmentByTag(WebFragment.TAG);
if(fragmentManager.findFragmentByTag(WebFragment.TAG)== null || !fragment.isVisible()) {
displayScreen(SCREEN.SCR_WEBVIEW, false);
}
}
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d(TAG, "on new intent: " + intent.toString());
newIntent = true;
setIntent(intent);
}
*/

@Override
protected void onStart() {
super.onStart();
Expand All @@ -517,7 +522,6 @@ protected void onStart() {
public void onResume() {
super.onResume();
Log.d(TAG, "on resume");
canCommitFragmentSafely = true;

DDGUtils.displayStats.refreshStats(this);

Expand All @@ -536,6 +540,16 @@ public void onResume() {
}
}

@Override
protected void onResumeFragments() {
super.onResumeFragments();
canCommitFragmentSafely = true;
if(newIntent) {
processIntent(getIntent());
newIntent = false;
}
}

@Override
public void onPause() {
super.onPause();
Expand Down

0 comments on commit c48ef18

Please sign in to comment.