diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 75b0999ea..a78c16ae7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -60,6 +60,15 @@
android:resource="@xml/searchable" />
+
+
+
-
-
-
-
-
-
cookieList = conn.getHeaderFields().get("Set-Cookie");
if (cookieList == null)
return;
- SharedPreferences.Editor editor = mInfoPref.edit();
- for (String str : cookieList) {
- ipb_member_id = getCookie(str, KEY_MEMBER_ID);
- ipb_pass_hash = getCookie(str, KEY_PASS_HASH);
- if (ipb_member_id != null)
- editor.putString(KEY_MEMBER_ID, ipb_member_id);
- if (ipb_pass_hash != null)
- editor.putString(KEY_PASS_HASH, ipb_pass_hash);
+ for (String str : cookieList) {
+ setCookie(str);
}
+ }
+
+ public void setCookie(String cookie) {
+ SharedPreferences.Editor editor = mInfoPref.edit();
+ String ipb_member_id = getCookie(cookie, KEY_MEMBER_ID);
+ String ipb_pass_hash = getCookie(cookie, KEY_PASS_HASH);
+
+ if (ipb_member_id != null)
+ editor.putString(KEY_MEMBER_ID, ipb_member_id);
+ if (ipb_pass_hash != null)
+ editor.putString(KEY_PASS_HASH, ipb_pass_hash);
editor.apply();
}
diff --git a/app/src/main/java/com/hippo/ehviewer/receiver/NetworkChangeReceiver.java b/app/src/main/java/com/hippo/ehviewer/receiver/NetworkChangeReceiver.java
deleted file mode 100644
index be963880a..000000000
--- a/app/src/main/java/com/hippo/ehviewer/receiver/NetworkChangeReceiver.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2014 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.receiver;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.net.ConnectivityManager;
-
-import com.hippo.ehviewer.network.Network;
-import com.hippo.ehviewer.util.Secret;
-
-public class NetworkChangeReceiver extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
-
- // Update secret image here
- int state = Network.getNetworkState(context);
- if (state == Network.NETWORK_STATE_WIFI) {
- Secret.updateSecretImage(context);
- }
-
- // TODO stop download when mobile network
- }
- }
-}
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/GalleryListActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/GalleryListActivity.java
index 09168ae68..3d958128d 100644
--- a/app/src/main/java/com/hippo/ehviewer/ui/GalleryListActivity.java
+++ b/app/src/main/java/com/hippo/ehviewer/ui/GalleryListActivity.java
@@ -16,15 +16,10 @@
package com.hippo.ehviewer.ui;
-import java.io.File;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActionBar;
+import android.app.Activity;
import android.app.AlertDialog;
import android.app.SearchManager;
import android.content.Context;
@@ -97,6 +92,12 @@ import com.hippo.ehviewer.widget.TagsAdapter;
import com.hippo.ehviewer.widget.recyclerview.EasyRecyclerView;
import com.hippo.ehviewer.windowsanimate.WindowsAnimate;
+import java.io.File;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
/*
*
* Footer 显示产生的 refresh 手动 pull 显示产生的 refresh 按键或其他产生的 refresh
@@ -130,7 +131,8 @@ public class GalleryListActivity extends AbsTranslucentActivity implements View.
@SuppressWarnings("unused")
private static final String TAG = GalleryListActivity.class.getSimpleName();
- private static int RESULT_LOAD_SEARCH_IMAGE = 1;
+ private static int REQUST_WEB_WIEW_LOGIN = 0;
+ private static int REQUST_LOAD_SEARCH_IMAGE = 1;
public static final String ACTION_GALLERY_LIST = "com.hippo.ehviewer.intent.action.GALLERY_LIST";
@@ -246,25 +248,31 @@ public class GalleryListActivity extends AbsTranslucentActivity implements View.
View view = ViewUtils.inflateDialogView(R.layout.login, false);
return new MaterialAlertDialog.Builder(this).setCancelable(false).setTitle(R.string.login).setView(view, true)
- .setPositiveButton(android.R.string.ok).setNegativeButton(android.R.string.cancel)
- .setNeutralButton(R.string.register).setButtonListener(new MaterialAlertDialog.OnClickListener() {
+ .setPositiveButton(android.R.string.ok)
+ .setNegativeButton(android.R.string.cancel)
+ .setNeutralButton(R.string.register)
+ .setActionButton(" ! ")
+ .setButtonListener(new MaterialAlertDialog.OnClickListener() {
@Override
public boolean onClick(MaterialAlertDialog dialog, int which) {
switch (which) {
- case MaterialAlertDialog.POSITIVE:
- setUserPanel(WAIT);
- String username = ((EditText) loginDialog.findViewById(R.id.username)).getText().toString();
- String password = ((EditText) loginDialog.findViewById(R.id.password)).getText().toString();
- mClient.login(username, password, GalleryListActivity.this);
- return true;
- case MaterialAlertDialog.NEGATIVE:
- setUserPanel();
- return true;
- case MaterialAlertDialog.NEUTRAL:
- toRegister();
- return false;
- default:
- return false;
+ case MaterialAlertDialog.POSITIVE:
+ setUserPanel(WAIT);
+ String username = ((EditText) loginDialog.findViewById(R.id.username)).getText().toString();
+ String password = ((EditText) loginDialog.findViewById(R.id.password)).getText().toString();
+ mClient.login(username, password, GalleryListActivity.this);
+ return true;
+ case MaterialAlertDialog.NEGATIVE:
+ setUserPanel();
+ return true;
+ case MaterialAlertDialog.NEUTRAL:
+ toRegister();
+ return false;
+ case MaterialAlertDialog.ACTION:
+ Intent intent = new Intent(GalleryListActivity.this, WebViewLoginActivity.class);
+ startActivityForResult(intent, REQUST_WEB_WIEW_LOGIN);
+ default:
+ return false;
}
}
}).create();
@@ -300,7 +308,7 @@ public class GalleryListActivity extends AbsTranslucentActivity implements View.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == RESULT_LOAD_SEARCH_IMAGE && resultCode == RESULT_OK && null != data) {
+ if (requestCode == REQUST_LOAD_SEARCH_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
@@ -313,6 +321,11 @@ public class GalleryListActivity extends AbsTranslucentActivity implements View.
mSearchImageText.setVisibility(View.VISIBLE);
mSearchImageText.setText(ImagePath);
+ } else if (REQUST_WEB_WIEW_LOGIN == requestCode) {
+ if (resultCode == Activity.RESULT_OK) {
+ loginDialog.dismiss();
+ onSuccess();
+ }
}
}
@@ -351,7 +364,7 @@ public class GalleryListActivity extends AbsTranslucentActivity implements View.
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
- startActivityForResult(i, RESULT_LOAD_SEARCH_IMAGE);
+ startActivityForResult(i, REQUST_LOAD_SEARCH_IMAGE);
}
});
}
diff --git a/app/src/main/java/com/hippo/ehviewer/ui/WebViewLoginActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/WebViewLoginActivity.java
new file mode 100644
index 000000000..f575a19a2
--- /dev/null
+++ b/app/src/main/java/com/hippo/ehviewer/ui/WebViewLoginActivity.java
@@ -0,0 +1,47 @@
+package com.hippo.ehviewer.ui;
+
+import android.os.Bundle;
+import android.webkit.CookieManager;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+import com.hippo.ehviewer.ehclient.EhClient;
+import com.hippo.ehviewer.ehclient.EhInfo;
+
+public class WebViewLoginActivity extends AbsActivity {
+
+ private static final String TITLE_LOGIN_SUCCESS = "Please stand by...";
+
+ public static final String KEY_ERROR = "error";
+
+
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ CookieManager.getInstance().removeAllCookie();
+ WebView wv = new WebView(this);
+ wv.setWebViewClient(new LoginWebViewClient());
+ wv.loadUrl(EhClient.LOGIN_URL);
+ setContentView(wv);
+ }
+
+ private class LoginWebViewClient extends WebViewClient {
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ if (TITLE_LOGIN_SUCCESS.equals(view.getTitle())) {
+ // Login OK
+ String cookies = CookieManager.getInstance().getCookie(url);
+ if (cookies != null) {
+ // Store cookie
+ EhInfo ehInfo = EhInfo.getInstance(WebViewLoginActivity.this);
+ ehInfo.setCookie(cookies);
+ ehInfo.login("User", "User");
+ setResult(RESULT_OK);
+ } else {
+ setResult(RESULT_CANCELED);
+ }
+ finish();
+ }
+ }
+ }
+}