Add sign out

This commit is contained in:
seven332 committed 2016-03-15 18:31:49 +08:00
1 parent 7ae50430f8
commit 664e830c7b
14 files changed
+117 -10

No files matched your search

@@ -31,7 +31,7 @@ public class EhCookieStore extends CookieDBStore {
public static final String KEY_IPD_MEMBER_ID = "ipb_member_id";
public static final String KEY_IPD_PASS_HASH = "ipb_pass_hash";
public void cleanUpForSignIn() {
public void signOut() {
removeAll();
}
@@ -115,6 +115,12 @@ public class EhUtils {
}
}
public static void signOut(Context context) {
EhApplication.getEhCookieStore(context).signOut();
Settings.putAvatar(null);
Settings.putDisplayName(null);
}
public static boolean hasSignedIn(Context context) {
return EhApplication.getEhCookieStore(context).hasSignedIn();
}
@@ -0,0 +1,68 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.preference;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.util.AttributeSet;
import android.widget.Toast;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.preference.MessagePreference;
public class SignOutPreference extends MessagePreference {
public SignOutPreference(Context context) {
super(context);
init();
}
public SignOutPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SignOutPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public SignOutPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setDialogMessage(getContext().getString(R.string.settings_eh_sign_out_warning));
}
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
builder.setPositiveButton(R.string.settings_eh_sign_out_yes, this);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
EhUtils.signOut(getContext());
Toast.makeText(getContext(), R.string.settings_eh_sign_out_tip, Toast.LENGTH_SHORT).show();
}
}
}
@@ -74,6 +74,8 @@ public final class MainActivity extends StageActivity
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
private static final int REQUEST_CODE_UPDATE_PROFILE = 0;
private static final String KEY_NAV_CHECKED_ITEM = "nav_checked_item";
public static final int CHECK_STEP_WARNING = 0;
@@ -262,7 +264,7 @@ public final class MainActivity extends StageActivity
mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
updateAvatar();
updateProfile();
if (mNavView != null) {
mNavView.setNavigationItemSelectedListener(this);
@@ -350,7 +352,7 @@ public final class MainActivity extends StageActivity
}
}
public void updateAvatar() {
public void updateProfile() {
if (null == mAvatar || null == mDisplayName) {
return;
}
@@ -41,7 +41,7 @@ public abstract class BaseScene extends SceneFragment {
public void updateAvatar() {
FragmentActivity activity = getActivity();
if (activity instanceof MainActivity) {
((MainActivity) activity).updateAvatar();
((MainActivity) activity).updateProfile();
}
}
@@ -34,6 +34,7 @@ import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.EhCookieStore;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.rippleold.RippleSalon;
import com.hippo.util.ActivityHelper;
import com.hippo.yorozuya.AssertUtils;
@@ -196,8 +197,9 @@ public class CookieSignInScene extends BaseScene implements EditText.OnEditorAct
return;
}
EhUtils.signOut(getContext());
EhCookieStore store = EhApplication.getEhCookieStore(context);
store.removeAll();
store.add(newCookie(EhCookieStore.KEY_IPD_MEMBER_ID, id, EhUrl.DOMAIN_E));
store.add(newCookie(EhCookieStore.KEY_IPD_MEMBER_ID, id, EhUrl.DOMAIN_EX));
store.add(newCookie(EhCookieStore.KEY_IPD_PASS_HASH, hash, EhUrl.DOMAIN_E));
@@ -38,6 +38,7 @@ import com.hippo.ehviewer.UrlOpener;
import com.hippo.ehviewer.client.EhClient;
import com.hippo.ehviewer.client.EhRequest;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.parser.ProfileParser;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.rippleold.RippleSalon;
@@ -266,7 +267,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
showProgress(true);
// Clean up for sign in
EhApplication.getEhCookieStore(getContext()).cleanUpForSignIn();
EhUtils.signOut(getContext());
EhCallback callback = new SignInListener(getContext(),
((StageActivity) getActivity()).getStageId(), getTag());
@@ -30,6 +30,7 @@ import android.webkit.WebViewClient;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.client.EhCookieStore;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.client.EhUtils;
import java.util.ArrayList;
import java.util.Collections;
@@ -40,8 +41,6 @@ import okhttp3.HttpUrl;
public class WebViewSignInScene extends BaseScene {
public static final String KEY_DISPLAY_NAME = "display_name";
/*---------------
View life cycle
---------------*/
@@ -56,10 +55,10 @@ public class WebViewSignInScene extends BaseScene {
@Nullable
@Override
@SuppressWarnings("deprecation")
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
@SuppressLint("SetJavaScriptEnabled")
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
EhApplication.getEhCookieStore(getContext()).removeAll();
EhUtils.signOut(getContext());
CookieManager.getInstance().removeAllCookie();
mWebView = new WebView(getContext());
mWebView.getSettings().setJavaScriptEnabled(true);
@@ -68,6 +68,10 @@ public class MessagePreference extends DialogPreference {
a.recycle();
}
public void setDialogMessage(CharSequence message) {
mDialogMessage = message;
}
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);