linked: improve fragment robustness, save cookies through destroyed fragment
This commit is contained in:
@@ -85,6 +85,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
|
|
||||||
public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKeyringParcel,EditKeyResult> {
|
public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKeyringParcel,EditKeyResult> {
|
||||||
|
|
||||||
|
public static final String ARG_GITHUB_COOKIE = "github_cookie";
|
||||||
private Button mRetryButton;
|
private Button mRetryButton;
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
@@ -229,18 +230,18 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
|
|||||||
protected void onPostExecute(JSONObject result) {
|
protected void onPostExecute(JSONObject result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
// we couldn't show an error anyways
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Log.d(Constants.TAG, "response: " + result);
|
Log.d(Constants.TAG, "response: " + result);
|
||||||
|
|
||||||
if (result == null || result.optString("access_token", null) == null) {
|
if (result == null || result.optString("access_token", null) == null) {
|
||||||
setState(State.AUTH_ERROR);
|
setState(State.AUTH_ERROR);
|
||||||
showRetryForOAuth();
|
showRetryForOAuth();
|
||||||
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity == null) {
|
|
||||||
// we couldn't show an error anyways
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
Notify.create(activity, R.string.linked_error_auth_failed, Style.ERROR).show();
|
Notify.create(activity, R.string.linked_error_auth_failed, Style.ERROR).show();
|
||||||
return;
|
return;
|
||||||
@@ -317,16 +318,16 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
|
|||||||
|
|
||||||
Log.d(Constants.TAG, "response: " + result);
|
Log.d(Constants.TAG, "response: " + result);
|
||||||
|
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
// we couldn't show an error anyways
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
setState(State.POST_ERROR);
|
setState(State.POST_ERROR);
|
||||||
showRetryForOAuth();
|
showRetryForOAuth();
|
||||||
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity == null) {
|
|
||||||
// we couldn't show an error anyways
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mException instanceof SocketTimeoutException) {
|
if (mException instanceof SocketTimeoutException) {
|
||||||
Notify.create(activity, R.string.linked_error_timeout, Style.ERROR).show();
|
Notify.create(activity, R.string.linked_error_timeout, Style.ERROR).show();
|
||||||
} else if (mException instanceof HttpResultException) {
|
} else if (mException instanceof HttpResultException) {
|
||||||
@@ -458,9 +459,29 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onStop();
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
|
// cookies are automatically saved, we don't want that
|
||||||
|
CookieManager cookieManager = CookieManager.getInstance();
|
||||||
|
String cookie = cookieManager.getCookie("https://github.com/");
|
||||||
|
outState.putString(ARG_GITHUB_COOKIE, cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
String cookie = savedInstanceState.getString(ARG_GITHUB_COOKIE);
|
||||||
|
CookieManager cookieManager = CookieManager.getInstance();
|
||||||
|
cookieManager.setCookie("https://github.com/", cookie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
try {
|
try {
|
||||||
// cookies are automatically saved, we don't want that
|
// cookies are automatically saved, we don't want that
|
||||||
CookieManager cookieManager = CookieManager.getInstance();
|
CookieManager cookieManager = CookieManager.getInstance();
|
||||||
@@ -469,6 +490,11 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// no biggie if this fails
|
// no biggie if this fails
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
|
||||||
if (mFinishOnStop) {
|
if (mFinishOnStop) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
|||||||
Reference in New Issue
Block a user