diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4e9558c83..1bb3b633d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -15,8 +15,8 @@ --> + android:versionCode="19" + android:versionName="0.5.4" > + android:layout_margin="8.0dp" /> You are now logged in as: ")) - ok = true; - else - eMsg = mAppContext.getString(R.string.em_logout_error); - } else - eMsg = hp.getEMsg(); - } - } - - public void login(String username, String password, - final OnLoginListener listener) { - - final LoginRunnable task = new LoginRunnable(username, password); - mThreadPool.submit(new Job() { - @Override - public Object run(JobContext jc) { - task.run(); - return null; - } - }, new FutureListener() { - @Override - public void onFutureDone(Future future) { - Message msg = new Message(); - msg.what = LOGIN; - msg.obj = new LoginPackage(task.ok, listener, task.eMsg); - mHandler.sendMessage(msg); - } - }); - } - - // Check login get info and logout url - private class CheckLoginPackage { - public boolean ok; - public OnCheckLoginListener listener; - public String eMsg; - - public CheckLoginPackage(boolean ok, OnCheckLoginListener listener, String eMsg) { - this.ok = ok; - this.listener = listener; - this.eMsg = eMsg; - } - } - - private class checkLoginRunnable implements Runnable { - - public String eMsg; - public boolean ok; - public String name; - public String logoutUrl; - - @Override - public void run() { - ok = false; - HttpHelper hp = new HttpHelper(mAppContext); - String pageContent = hp.get(loginUrl); - if (pageContent != null) { - Pattern p = Pattern - .compile("

Logged in as: \"]+\">([^<>]+) \\( \"]+)\">Log Out \\)

"); - Matcher m = p.matcher(pageContent); - if (m.find() && m.groupCount() == 2) { - ok = true; - name = m.group(1); - logoutUrl = StringEscapeUtils.unescapeHtml4(m.group(2)); - } else - eMsg = mAppContext.getString(R.string.em_check_login_error); - } else - eMsg = hp.getEMsg(); - } - } - - public void checkLogin(final OnCheckLoginListener listener) { - final checkLoginRunnable task = new checkLoginRunnable(); - mThreadPool.submit(new Job() { - @Override - public Object run(JobContext jc) { - task.run(); - return null; - } - }, new FutureListener() { - @Override - public void onFutureDone(Future future) { - if (task.ok) { - mLogin = true; - mUsername = task.name; - mLogoutUrl = task.logoutUrl; - } - Message msg = new Message(); - msg.what = CHECK_LOGIN; - msg.obj = new CheckLoginPackage(task.ok, listener, task.eMsg); - mHandler.sendMessage(msg); - } - }); - } - - // Test Ex - - public interface OnTestExListener { + public interface OnLoginListener { public void onSuccess(); + public void onGetAvatar(int code); public void onFailure(String eMsg); } - /* - public void testEx(final OnTestExListener listener) { + + public void login(final String username, final String password, + final OnLoginListener listener) { new Thread(new Runnable() { @Override public void run() { - HttpHelper hp = new HttpHelper(mAppContext); + final HttpHelper hp = new HttpHelper(mAppContext); hp.setOnRespondListener(new HttpHelper.OnRespondListener() { @Override - public void onSuccess(String pageContext) { - if (pageContext.equals("image/gif")) - listener.onFailure("Not login"); - else + public void onSuccess(String body) { + LoginParser parser = new LoginParser(); + if (parser.parser(body)) { + mInfo.login(username, parser.displayname); + getAvatar(listener); + listener.onSuccess(); + } else { + listener.onFailure("parser error"); + } } @Override public void onFailure(String eMsg) { listener.onFailure(eMsg); } }); - hp.contentType(EX_HEADER); + hp.postForm(loginUrl, new String[][] { + new String[] { "UserName", username }, + new String[] { "PassWord", password }, + new String[] { "submit", "Log+me+in" }, + new String[] { "CookieDate", "1" }, + new String[] { "temporary_https", "on" }}); } }).start(); } - */ - // Logout - private class LogoutPackage { - public boolean ok; - public OnLogoutListener listener; - public String eMsg; - - public LogoutPackage(boolean ok, OnLogoutListener listener, String eMsg) { - this.ok = ok; - this.listener = listener; - this.eMsg = eMsg; - } + + private void getAvatar(final OnLoginListener listener) { + new Thread(new Runnable() { + @Override + public void run() { + String body; + Pattern p; + Matcher m; + // Get user profile url + HttpHelper hp = new HttpHelper(mAppContext); + body = hp.get(forumsUrl); + if (body == null) { + listener.onGetAvatar(GET_AVATAR_ERROR); + return; + } + p = Pattern.compile("

.+?"); + m = p.matcher(body); + if (!m.find()) { + listener.onGetAvatar(GET_AVATAR_ERROR); + return; + } + String profileUrl = Util.htmlUnsescape(m.group(1)); + // Get avatar url + body = hp.get(profileUrl); + if (body == null) { + listener.onGetAvatar(GET_AVATAR_ERROR); + return; + } + p = Pattern.compile("

"); + m = p.matcher(body); + if (!m.find()) { + listener.onGetAvatar(NO_AVATAR); + return; + } + String avatarUrl = m.group(1); + // Get avatar + Bitmap avatar = hp.getImage(avatarUrl, null, null, null, true); + // Set avatar if not null + if (avatar != null) + mInfo.setAvatar(avatar); + // notification + listener.onGetAvatar(GET_AVATAR_OK); + } + }).start(); } - private class LogoutRunnable implements Runnable { - - public String eMsg; - public boolean ok; - - @Override - public void run() { - ok = false; - HttpHelper hp = new HttpHelper(mAppContext); - String pageContent = hp.get(mLogoutUrl); - if (pageContent != null) { - if (pageContent.contains("

You are now logged out
")) - ok = true; - else - eMsg = mAppContext.getString(R.string.em_logout_error); - } else - eMsg = hp.getEMsg(); - } - } - - public void logout(final OnLogoutListener listener) { - final LogoutRunnable task = new LogoutRunnable(); - mThreadPool.submit(new Job() { - @Override - public Object run(JobContext jc) { - task.run(); - return null; - } - }, new FutureListener() { - @Override - public void onFutureDone(Future future) { - if (task.ok) - mLogin = false; - Message msg = new Message(); - msg.what = LOGOUT; - msg.obj = new LogoutPackage(task.ok, listener, task.eMsg); - mHandler.sendMessage(msg); - } - }); - } - - // Get Manga List - public interface OnGetMangaListListener { + // Get Gallery List + public interface OnGetGListListener { public void onSuccess(Object checkFlag, List lmdArray, int indexPerPage, int maxPage); public void onFailure(Object checkFlag, String eMsg); } - private class GetMangaListPackage { - public Object checkFlag; - public List lmdArray; - public int indexPerPage; - public int maxPage; - public OnGetMangaListListener listener; - public String eMsg; - - public GetMangaListPackage(Object checkFlag, List lmdArray, int indexPerPage, - int maxPage, OnGetMangaListListener listener, String eMsg) { - this.checkFlag = checkFlag; - this.lmdArray = lmdArray; - this.indexPerPage = indexPerPage; - this.maxPage = maxPage; - this.listener = listener; - this.eMsg = eMsg; - } - } - - private class GetMangaListRunnable implements Runnable { - - private String url; - - public ArrayList lmdArray; - public int indexPerPage; - public int maxPage; - public String eMsg; - - public GetMangaListRunnable(String url) { - this.url = url; - } - - @Override - public void run() { - lmdArray = null; - indexPerPage = 25; - maxPage = 0; - - HttpHelper hp = new HttpHelper(mAppContext); - String pageContent = hp.get(url); - - if (pageContent != null) { - ListParser parser = new ListParser(); - switch (parser.parser(pageContent)) { - case ListParser.ALL: - maxPage = parser.maxPage; - indexPerPage = parser.indexPerPage; - lmdArray = parser.giList; - break; - case ListParser.NOT_FOUND: - maxPage = 0; - indexPerPage = parser.indexPerPage; - lmdArray = new ArrayList(); - break; - case ListParser.PARSER_ERROR: - eMsg = "parser error"; - } - } else - eMsg = hp.getEMsg(); - } - } - - public void getMangaList(String url, final Object checkFlag, - final OnGetMangaListListener listener) { - - final GetMangaListRunnable task = new GetMangaListRunnable(url); - mThreadPool.submit(new Job() { + public void getGList(final String url, final Object checkFlag, + final OnGetGListListener listener) { + new Thread(new Runnable() { @Override - public Object run(JobContext jc) { - task.run(); - return null; + public void run() { + HttpHelper hp = new HttpHelper(mAppContext); + hp.setOnRespondListener(new HttpHelper.OnRespondListener() { + @Override + public void onSuccess(String body) { + ListParser parser = new ListParser(); + switch (parser.parser(body)) { + case ListParser.ALL: + listener.onSuccess(checkFlag, parser.giList, parser.indexPerPage, parser.maxPage); + break; + case ListParser.NOT_FOUND: + listener.onSuccess(checkFlag, new ArrayList(), parser.indexPerPage, 0); + break; + case ListParser.PARSER_ERROR: + listener.onFailure(checkFlag, "parser error"); // TODO + break; + } + } + @Override + public void onFailure(String eMsg) { + listener.onFailure(checkFlag, eMsg); + } + }); + hp.get(url); } - }, new FutureListener() { - @Override - public void onFutureDone(Future future) { - Message msg = new Message(); - msg.what = GET_MANGA_LIST; - msg.obj = new GetMangaListPackage(checkFlag, task.lmdArray, task.indexPerPage, task.maxPage, listener, task.eMsg); - mHandler.sendMessage(msg); - } - }); + }).start(); } - private static String getRate(String rawRate) { - Pattern p = Pattern.compile("\\d+px"); - Matcher m = p.matcher(rawRate); - int num1; - int num2; - int rate = 5; - String re; - if (m.find()) - num1 = Integer.parseInt(m.group().replace("px", "")); - else - return null; - if (m.find()) - num2 = Integer.parseInt(m.group().replace("px", "")); - else - return null; - rate = rate - num1 / 16; - if (num2 == 21) { - rate--; - re = Integer.toString(rate); - re = re + ".5"; - } else - re = Integer.toString(rate); - return re; - } - // Get Manga Detail private class GetMangaDetailPackage { public boolean ok; diff --git a/src/com/hippo/ehviewer/ehclient/EhInfo.java b/src/com/hippo/ehviewer/ehclient/EhInfo.java index 18a6b2951..f8e00e10d 100644 --- a/src/com/hippo/ehviewer/ehclient/EhInfo.java +++ b/src/com/hippo/ehviewer/ehclient/EhInfo.java @@ -16,12 +16,22 @@ package com.hippo.ehviewer.ehclient; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.util.List; +import com.hippo.ehviewer.R; +import com.hippo.ehviewer.util.Util; + import android.content.Context; import android.content.SharedPreferences; -import android.util.Log; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; /** * @@ -32,6 +42,10 @@ public class EhInfo { private static final String TAG = EhInfo.class.getSimpleName(); private static final String PREF_NAME = "eh_info"; + private static final String DIR_NAME = "file"; + private static final String AVATAR_NAME = "avatar.png"; + private static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.PNG; + private static Bitmap DEFAULT_AVATAR; public static final String[] COOKIABLE_HOSTS = {"exhentai.org", "g.e-hentai.org", "forums.e-hentai.org"}; @@ -81,19 +95,47 @@ public class EhInfo { private static final String KEY_LOGIN = "login"; private static final boolean DEFAULT_LOGIN = false; private static final String KEY_USERNAME = "username"; - private static final String DEFAULT_USERNAME = "Hippo"; + private static final String KEY_DISPLAYNAME = "displayname"; + private static final String DEFAULT_NAME = "Hippo"; private Context mContext; private final SharedPreferences mInfoPref; private String mUconfig; - + private boolean mIsLogin; + private String mUsername; + private String mDisplayname; + private Bitmap mAvatar; private static EhInfo sInstance; + private Bitmap getAvatarFromFile() { + File dir = mContext.getDir(DIR_NAME, 0); + File avatarFile = new File(dir, AVATAR_NAME); + if (!avatarFile.exists()) + return null; + + InputStream is = null; + try { + is = new FileInputStream(avatarFile); + return BitmapFactory.decodeStream(is); + } catch (FileNotFoundException e) { + return null; + } finally { + Util.closeStreamQuietly(is); + } + } + private EhInfo(final Context context){ mContext = context; mInfoPref = mContext.getSharedPreferences(PREF_NAME, 0); + if (DEFAULT_AVATAR == null) + DEFAULT_AVATAR = BitmapFactory.decodeStream( + context.getResources().openRawResource(R.drawable.default_avatar)); + mIsLogin = mInfoPref.getBoolean(KEY_LOGIN, DEFAULT_LOGIN); + mUsername = mInfoPref.getString(KEY_USERNAME, DEFAULT_NAME); + mDisplayname = mInfoPref.getString(KEY_DISPLAYNAME, DEFAULT_NAME); + mAvatar = getAvatarFromFile(); updateUconfig(); }; @@ -152,22 +194,61 @@ public class EhInfo { } public boolean isLogin() { - return mInfoPref.getBoolean(KEY_LOGIN, DEFAULT_LOGIN); + return mIsLogin; } - public void login(String username) { + public void login(String username, String displayname) { + mIsLogin = true; + mUsername = username; + mDisplayname = displayname; + mInfoPref.edit().putBoolean(KEY_LOGIN, true) - .putString(KEY_USERNAME, username).apply(); + .putString(KEY_USERNAME, username) + .putString(KEY_DISPLAYNAME, displayname).apply(); } public void logout() { + mIsLogin = false; + // Remove avatar + if (mAvatar != null) { + mAvatar.recycle(); + mAvatar = null; + File dir = mContext.getDir(DIR_NAME, 0); + File avatarFile = new File(dir, AVATAR_NAME); + avatarFile.delete(); + } + mInfoPref.edit().putBoolean(KEY_LOGIN, false) .putString("ipb_member_id", "ipb_member_id") .putString("ipb_pass_hash", "ipb_pass_hash").apply(); } public String getUsername() { - return mInfoPref.getString(KEY_USERNAME, DEFAULT_USERNAME); + return mUsername; + } + + public String getDisplayname() { + return mDisplayname; + } + + public Bitmap getAvatar() { + return isLogin() && mAvatar != null ? mAvatar : DEFAULT_AVATAR; + } + + public void setAvatar(Bitmap avatar) { + mAvatar = avatar; + + File dir = mContext.getDir(DIR_NAME, 0); + File avatarFile = new File(dir, AVATAR_NAME); + OutputStream os = null; + try { + os = new FileOutputStream(avatarFile); + avatar.compress(AVATAR_FORMAT, 100, os); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } finally { + Util.closeStreamQuietly(os); + } } public void setDefaultCat(int defaultCat) { diff --git a/src/com/hippo/ehviewer/ehclient/LoginParser.java b/src/com/hippo/ehviewer/ehclient/LoginParser.java new file mode 100644 index 000000000..023d06c7c --- /dev/null +++ b/src/com/hippo/ehviewer/ehclient/LoginParser.java @@ -0,0 +1,36 @@ +/* + * 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.ehclient; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class LoginParser { + public String displayname; + + public boolean parser(String body) { + Pattern p = Pattern.compile("

You are now logged in as: (.+?)
"); + Matcher m = p.matcher(body); + + if (m.find()) { + displayname = m.group(1); + return true; + } else { + return false; + } + } +} diff --git a/src/com/hippo/ehviewer/network/HttpHelper.java b/src/com/hippo/ehviewer/network/HttpHelper.java index 715f7f84b..52fd88709 100644 --- a/src/com/hippo/ehviewer/network/HttpHelper.java +++ b/src/com/hippo/ehviewer/network/HttpHelper.java @@ -78,29 +78,35 @@ public class HttpHelper { String str; } - private static Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - Package p = (Package)msg.obj; - OnRespondListener listener = p.listener; - String str = p.str; - switch (msg.what) { - case Constants.TRUE: - listener.onSuccess(str); - break; - case Constants.FALSE: - listener.onFailure(str); - break; - } - } - }; + private static Handler mHandler; private Context mContext; private Exception mException; private OnRespondListener mListener; + public static final void createHandler() { + if (mHandler != null) + return; + mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + Package p = (Package)msg.obj; + OnRespondListener listener = p.listener; + String str = p.str; + switch (msg.what) { + case Constants.TRUE: + listener.onSuccess(str); + break; + case Constants.FALSE: + listener.onFailure(str); + break; + } + } + }; + } + public interface OnRespondListener { - void onSuccess(String pageContext); + void onSuccess(String body); void onFailure(String eMsg); } @@ -110,6 +116,8 @@ public class HttpHelper { public HttpHelper(Context context) { mContext = context; + + mContext.getApplicationContext(); } /** @@ -151,7 +159,7 @@ public class HttpHelper { return e.getMessage(); } - private String getPageContext(HttpURLConnection conn) + private String getBody(HttpURLConnection conn) throws IOException { String pageContext = null; InputStream is = null; @@ -240,7 +248,7 @@ public class HttpHelper { // Get body if necessary String body = rh.isNeedBody(); if (body == null) - body = getPageContext(conn); + body = getBody(conn); // Send to UI thread if necessary if (msg != null) { Package p = new Package(); diff --git a/src/com/hippo/ehviewer/ui/FavouriteActivity.java b/src/com/hippo/ehviewer/ui/FavouriteActivity.java index 5017ecfd8..d43ce3f28 100644 --- a/src/com/hippo/ehviewer/ui/FavouriteActivity.java +++ b/src/com/hippo/ehviewer/ui/FavouriteActivity.java @@ -512,7 +512,7 @@ public class FavouriteActivity extends AbstractGalleryActivity @Override protected void doGetGallerys(String url, final long taskStamp, final OnGetListListener listener) { - mClient.getMangaList(url, null, new EhClient.OnGetMangaListListener() { + mClient.getGList(url, null, new EhClient.OnGetGListListener() { @Override public void onSuccess(Object checkFlag, List lmdArray, int indexPerPage, int maxPage) { diff --git a/src/com/hippo/ehviewer/ui/MangaListActivity.java b/src/com/hippo/ehviewer/ui/MangaListActivity.java index b81e8ec56..dfa96ab14 100644 --- a/src/com/hippo/ehviewer/ui/MangaListActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaListActivity.java @@ -16,16 +16,11 @@ package com.hippo.ehviewer.ui; -import java.io.File; -import java.io.IOException; import java.lang.reflect.Field; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang3.StringEscapeUtils; - -import com.hippo.ehviewer.Analytics; import com.hippo.ehviewer.AppContext; import com.hippo.ehviewer.ListUrls; import com.hippo.ehviewer.R; @@ -39,7 +34,6 @@ import com.hippo.ehviewer.service.DownloadService; import com.hippo.ehviewer.service.DownloadServiceConnection; import com.hippo.ehviewer.util.Config; import com.hippo.ehviewer.util.Favorite; -import com.hippo.ehviewer.util.Log; import com.hippo.ehviewer.util.Theme; import com.hippo.ehviewer.util.Ui; import com.hippo.ehviewer.util.Util; @@ -47,11 +41,9 @@ import com.hippo.ehviewer.widget.AlertButton; import com.hippo.ehviewer.widget.CheckTextView; import com.hippo.ehviewer.widget.DialogBuilder; import com.hippo.ehviewer.widget.FswView; -import com.hippo.ehviewer.widget.HfListView; import com.hippo.ehviewer.widget.OnFitSystemWindowsListener; import com.hippo.ehviewer.widget.PrefixEditText; import com.hippo.ehviewer.widget.SuperDialogUtil; -import com.hippo.ehviewer.widget.SuperSwipeRefreshLayout; import com.hippo.ehviewer.widget.SuperToast; import com.hippo.ehviewer.widget.TagListView; import com.hippo.ehviewer.widget.TagsAdapter; @@ -78,8 +70,6 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; -import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; @@ -148,6 +138,7 @@ public class MangaListActivity extends AbstractGalleryActivity private ListView itemListMenu; private TagListView tagListMenu; + private ImageView avatar; private TextView userView; private Button loginButton; private Button registerButton; @@ -203,7 +194,7 @@ public class MangaListActivity extends AbstractGalleryActivity mEhClient.login(username, password, new EhClient.OnLoginListener() { @Override public void onSuccess() { - checkLogin(true); + setUserPanel(); } @Override public void onFailure(String eMsg) { @@ -212,6 +203,26 @@ public class MangaListActivity extends AbstractGalleryActivity if (!MangaListActivity.this.isFinishing()) loginDialog.show(); } + @Override + public void onGetAvatar(final int code) { + MangaListActivity.this.runOnUiThread(new Runnable() { + @Override + public void run() { + switch (code) { + case EhClient.GET_AVATAR_OK: + setUserPanel(); + break; + case EhClient.NO_AVATAR: + new SuperToast(MangaListActivity.this, "无头像").show(); + break; + case EhClient.GET_AVATAR_ERROR: + default: + new SuperToast(MangaListActivity.this, "获取头像失败", SuperToast.ERROR).show(); + break; + } + } + }); + } }); } }).setNegativeButton(android.R.string.cancel, new View.OnClickListener() { @@ -891,28 +902,13 @@ public class MangaListActivity extends AbstractGalleryActivity @Override public void onClick(View v) { - if (v == loginButton) { loginDialog.show(); } else if (v == registerButton) { toRegister(); } else if (v == logoutButton) { - setUserPanel(WAIT); - - mEhClient.logout(new EhClient.OnLogoutListener() { - @Override - public void onSuccess() { - new SuperToast(MangaListActivity.this, R.string.toast_logout_succeeded).show(); - Config.logoutNow(); - setUserPanel(); - } - - @Override - public void onFailure(String eMsg) { - new SuperToast(MangaListActivity.this, eMsg).setIcon(R.drawable.ic_warning).show(); - setUserPanel(); - } - }); + mEhClient.logout(); + setUserPanel(); } } @@ -1006,6 +1002,7 @@ public class MangaListActivity extends AbstractGalleryActivity itemListMenu = (ListView) findViewById(R.id.list_menu_item_list); tagListMenu = (TagListView) findViewById(R.id.list_menu_tag_list); + avatar = (ImageView)mUserPanel.findViewById(R.id.avatar); userView = (TextView)mUserPanel.findViewById(R.id.user); loginButton = (Button)mUserPanel.findViewById(R.id.login); registerButton = (Button)mUserPanel.findViewById(R.id.register); @@ -1228,8 +1225,8 @@ public class MangaListActivity extends AbstractGalleryActivity if (Config.isAutoCheckForUpdate()) checkUpdate(); - // Check login and update user panel - checkLogin(false); + // Update user panel + setUserPanel(); // get MangeList mTitle = mResources.getString(R.string.homepage); @@ -1484,33 +1481,6 @@ public class MangaListActivity extends AbstractGalleryActivity }).autoCheckUpdate(); } - private void checkLogin(final boolean force) { - - if ((Config.isLogin() || force) - && ! mEhClient.isLogin()) { - setUserPanel(WAIT); - mEhClient.checkLogin(new EhClient.OnCheckLoginListener() { - @Override - public void onSuccess() { - Config.loginNow(); - new SuperToast(MangaListActivity.this).setMessage(R.string.toast_login_succeeded).show(); - setUserPanel(); - } - - @Override - public void onFailure(String eMsg) { - if (force && !MangaListActivity.this.isFinishing()) - loginDialog.show(); - setUserPanel(); - new SuperToast(MangaListActivity.this, eMsg).setIcon(R.drawable.ic_warning).show(); - } - }); - } else { - setUserPanel(); - } - - } - private static final int LOGIN = 0x0; private static final int LOGOUT = 0x1; private static final int WAIT = 0x2; @@ -1526,6 +1496,7 @@ public class MangaListActivity extends AbstractGalleryActivity switch (state) { case LOGIN: + avatar.setImageBitmap(mEhClient.getAvatar()); userView.setVisibility(View.GONE); loginButton.setVisibility(View.VISIBLE); registerButton.setVisibility(View.VISIBLE); @@ -1533,7 +1504,8 @@ public class MangaListActivity extends AbstractGalleryActivity waitloginoutView.setVisibility(View.GONE); break; case LOGOUT: - userView.setText(mEhClient.getUsername()); + avatar.setImageBitmap(mEhClient.getAvatar()); + userView.setText(mEhClient.getDisplayname()); userView.setVisibility(View.VISIBLE); loginButton.setVisibility(View.GONE); registerButton.setVisibility(View.GONE); @@ -1541,6 +1513,7 @@ public class MangaListActivity extends AbstractGalleryActivity waitloginoutView.setVisibility(View.GONE); break; case WAIT: + avatar.setImageBitmap(mEhClient.getAvatar()); userView.setVisibility(View.GONE); loginButton.setVisibility(View.GONE); registerButton.setVisibility(View.GONE); @@ -1550,10 +1523,6 @@ public class MangaListActivity extends AbstractGalleryActivity } } - public void buttonCheckLogin(View v) { - checkLogin(false); - } - @Override protected String getTargetUrl(int targetPage) { lus.setPage(targetPage); @@ -1581,7 +1550,7 @@ public class MangaListActivity extends AbstractGalleryActivity } }); } else { - mClient.getMangaList(url, null, new EhClient.OnGetMangaListListener() { + mClient.getGList(url, null, new EhClient.OnGetGListListener() { @Override public void onSuccess(Object checkFlag, List lmdArray, int indexPerPage, int maxPage) { diff --git a/src/com/hippo/ehviewer/util/Config.java b/src/com/hippo/ehviewer/util/Config.java index 65166abfa..abc9e5f48 100644 --- a/src/com/hippo/ehviewer/util/Config.java +++ b/src/com/hippo/ehviewer/util/Config.java @@ -30,7 +30,6 @@ public class Config { private static final String KEY_ALLOWED = "allowed"; private static final String KEY_FIRST = "first_time"; - private static final String KEY_LOGIN = "login"; private static final String KEY_UPDATE_DATE = "update_date"; private static final String KEY_MODE = "mode"; private static final int MODE_DEFAULT = 0; @@ -133,23 +132,6 @@ public class Config { public static void firstTime() { mConfigPre.edit().putBoolean(KEY_FIRST, false).apply(); } - - /** - * Is login last time ? - * - * @return - */ - public static boolean isLogin() { - return mConfigPre.getBoolean(KEY_LOGIN, false); - } - - public static void loginNow() { - mConfigPre.edit().putBoolean(KEY_LOGIN, true).apply(); - } - - public static void logoutNow() { - mConfigPre.edit().putBoolean(KEY_LOGIN, false).apply(); - } public static String getDownloadPath() { return mConfigPre.getString(KEY_DOWNLOAD_PATH, DEFAULT_DOWNLOAD_PATH); diff --git a/src/com/hippo/ehviewer/util/Util.java b/src/com/hippo/ehviewer/util/Util.java index 514b64ce8..5e8fa56c2 100644 --- a/src/com/hippo/ehviewer/util/Util.java +++ b/src/com/hippo/ehviewer/util/Util.java @@ -267,5 +267,11 @@ public class Util { if (v.getLayerType() != View.LAYER_TYPE_SOFTWARE) { v.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } - } + } + + public static String htmlUnsescape(String str) { + return str.replace("&", "&") + .replace("<", "<") + .replace(">", ">"); + } }