mirror of
https://github.com/gsantner/dandelion
synced 2024-11-22 12:22:08 +01:00
Don't use startActivityForResult on SettingsActivity
This commit is contained in:
parent
d27e03553b
commit
dd98ce4389
2 changed files with 45 additions and 25 deletions
|
@ -108,8 +108,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
static final int INPUT_FILE_REQUEST_CODE = 1;
|
static final int INPUT_FILE_REQUEST_CODE = 1;
|
||||||
private static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
|
private static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
|
||||||
public static final int REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE = 124;
|
public static final int REQUEST_CODE_ASK_PERMISSIONS_SAVE_IMAGE = 124;
|
||||||
public static final int REQUEST_CODE_SETTINGS = 125;
|
|
||||||
public static final int RESULT_CODE_CHANGE_ACCOUNT = 130;
|
public static final String ACTION_OPEN_URL = "com.github.dfa.diaspora_android.MainActivity.open_url";
|
||||||
|
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
|
||||||
public static final String URL_MESSAGE = "URL_MESSAGE";
|
public static final String URL_MESSAGE = "URL_MESSAGE";
|
||||||
|
|
||||||
private App app;
|
private App app;
|
||||||
|
@ -243,6 +244,8 @@ public class MainActivity extends AppCompatActivity
|
||||||
snackbarNoInternet.show();
|
snackbarNoInternet.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupWebView(Bundle savedInstanceState) {
|
private void setupWebView(Bundle savedInstanceState) {
|
||||||
|
@ -420,18 +423,26 @@ public class MainActivity extends AppCompatActivity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onNewIntent(Intent intent) {
|
||||||
if(requestCode == REQUEST_CODE_SETTINGS) {
|
super.onNewIntent(intent);
|
||||||
if(resultCode == Activity.RESULT_OK) {
|
|
||||||
String url = data.getStringExtra(URL_MESSAGE);
|
handleIntent(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleIntent(Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
if(ACTION_OPEN_URL.equals(action)) {
|
||||||
|
String url = intent.getStringExtra(URL_MESSAGE);
|
||||||
webView.loadUrl(url);
|
webView.loadUrl(url);
|
||||||
} else if(resultCode == RESULT_CODE_CHANGE_ACCOUNT) {
|
} else if(ACTION_CHANGE_ACCOUNT.equals(action)) {
|
||||||
app.resetPodData(webView);
|
app.resetPodData(webView);
|
||||||
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
|
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
|
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
return;
|
return;
|
||||||
|
@ -931,7 +942,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.nav_settings_app: {
|
case R.id.nav_settings_app: {
|
||||||
startActivityForResult(new Intent(this, SettingsActivity.class), REQUEST_CODE_SETTINGS);
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.github.dfa.diaspora_android.activity;
|
package com.github.dfa.diaspora_android.activity;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -31,7 +30,6 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
setPreferenceSummaries();
|
setPreferenceSummaries();
|
||||||
setResult(Activity.RESULT_CANCELED);
|
|
||||||
sharedPreferences.edit().putBoolean(AppSettings.PREF.PROXY_WAS_ENABLED,
|
sharedPreferences.edit().putBoolean(AppSettings.PREF.PROXY_WAS_ENABLED,
|
||||||
sharedPreferences.getBoolean(AppSettings.PREF.PROXY_ENABLED, false)).apply();
|
sharedPreferences.getBoolean(AppSettings.PREF.PROXY_ENABLED, false)).apply();
|
||||||
}
|
}
|
||||||
|
@ -65,21 +63,21 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
|
||||||
Intent results = new Intent();
|
Intent intent = new Intent(this, MainActivity.class);
|
||||||
String podDomain = ((App)getApplication()).getSettings().getPodDomain();
|
String podDomain = ((App)getApplication()).getSettings().getPodDomain();
|
||||||
switch(preference.getKey()) {
|
switch(preference.getKey()) {
|
||||||
case "pref_key_personal_settings":
|
case "pref_key_personal_settings":
|
||||||
results.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/user/edit");
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
||||||
setResult(Activity.RESULT_OK, results);
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/user/edit");
|
||||||
finish();
|
break;
|
||||||
case "pref_key_manage_tags":
|
case "pref_key_manage_tags":
|
||||||
results.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/tag_followings/manage");
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
||||||
setResult(Activity.RESULT_OK, results);
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/tag_followings/manage");
|
||||||
finish();
|
break;
|
||||||
case "pref_key_manage_contacts":
|
case "pref_key_manage_contacts":
|
||||||
results.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/contacts");
|
intent.setAction(MainActivity.ACTION_OPEN_URL);
|
||||||
setResult(Activity.RESULT_OK, results);
|
intent.putExtra(MainActivity.URL_MESSAGE, "https://" + podDomain + "/contacts");
|
||||||
finish();
|
break;
|
||||||
case "pref_key_change_account":
|
case "pref_key_change_account":
|
||||||
new AlertDialog.Builder(SettingsActivity.this)
|
new AlertDialog.Builder(SettingsActivity.this)
|
||||||
.setTitle(getString(R.string.confirmation))
|
.setTitle(getString(R.string.confirmation))
|
||||||
|
@ -88,11 +86,22 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
.setPositiveButton(android.R.string.yes,
|
.setPositiveButton(android.R.string.yes,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
setResult(MainActivity.RESULT_CODE_CHANGE_ACCOUNT);
|
Intent intent = new Intent(SettingsActivity.this, MainActivity.class);
|
||||||
|
intent.setAction(MainActivity.ACTION_CHANGE_ACCOUNT);
|
||||||
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
intent = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(intent != null) {
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return super.onPreferenceTreeClick(screen, preference);
|
return super.onPreferenceTreeClick(screen, preference);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue