parent
6f22ed7185
commit
8296d4a506
@ -1,4 +1,4 @@ |
||||
package xyz.fycz.myreader.model.third.analyzeRule; |
||||
package xyz.fycz.myreader.model.third2.analyzeRule; |
||||
|
||||
import android.text.TextUtils; |
||||
|
@ -1,4 +1,4 @@ |
||||
package xyz.fycz.myreader.model.third.analyzeRule; |
||||
package xyz.fycz.myreader.model.third2.analyzeRule; |
||||
|
||||
import android.text.TextUtils; |
||||
|
@ -1,4 +1,4 @@ |
||||
package xyz.fycz.myreader.model.third.analyzeRule; |
||||
package xyz.fycz.myreader.model.third2.analyzeRule; |
||||
|
||||
import android.os.Build; |
||||
import android.text.TextUtils; |
@ -1,4 +1,4 @@ |
||||
package xyz.fycz.myreader.model.third.analyzeRule; |
||||
package xyz.fycz.myreader.model.third2.analyzeRule; |
||||
|
||||
import android.text.TextUtils; |
||||
|
@ -1,4 +1,4 @@ |
||||
package xyz.fycz.myreader.model.third.analyzeRule; |
||||
package xyz.fycz.myreader.model.third2.analyzeRule; |
||||
|
||||
import android.annotation.SuppressLint; |
||||
|
@ -1,4 +1,4 @@ |
||||
package xyz.fycz.myreader.model.third.analyzeRule; |
||||
package xyz.fycz.myreader.model.third2.analyzeRule; |
||||
|
||||
import android.annotation.SuppressLint; |
||||
import android.text.TextUtils; |
@ -0,0 +1,111 @@ |
||||
package xyz.fycz.myreader.ui.activity; |
||||
|
||||
import android.graphics.Bitmap; |
||||
import android.os.Bundle; |
||||
import android.view.Menu; |
||||
import android.view.MenuItem; |
||||
import android.webkit.CookieManager; |
||||
import android.webkit.WebSettings; |
||||
import android.webkit.WebView; |
||||
import android.webkit.WebViewClient; |
||||
|
||||
import androidx.appcompat.widget.Toolbar; |
||||
|
||||
import xyz.fycz.myreader.R; |
||||
import xyz.fycz.myreader.base.BaseActivity; |
||||
import xyz.fycz.myreader.common.APPCONST; |
||||
import xyz.fycz.myreader.databinding.ActivitySourceLoginBinding; |
||||
import xyz.fycz.myreader.greendao.DbManager; |
||||
import xyz.fycz.myreader.greendao.entity.CookieBean; |
||||
import xyz.fycz.myreader.greendao.entity.rule.BookSource; |
||||
import xyz.fycz.myreader.util.ToastUtils; |
||||
|
||||
/** |
||||
* @author fengyue |
||||
* @date 2021/5/15 10:43 |
||||
*/ |
||||
public class SourceLoginActivity extends BaseActivity { |
||||
private ActivitySourceLoginBinding binding; |
||||
private BookSource bookSource; |
||||
private boolean checking = false; |
||||
|
||||
@Override |
||||
protected void bindView() { |
||||
binding = ActivitySourceLoginBinding.inflate(getLayoutInflater()); |
||||
setContentView(binding.getRoot()); |
||||
} |
||||
|
||||
@Override |
||||
protected void onDestroy() { |
||||
super.onDestroy(); |
||||
binding.webView.destroy(); |
||||
} |
||||
|
||||
@Override |
||||
protected void setUpToolbar(Toolbar toolbar) { |
||||
super.setUpToolbar(toolbar); |
||||
setStatusBarColor(R.color.colorPrimary, true); |
||||
getSupportActionBar().setTitle(getString(R.string.text_login)); |
||||
} |
||||
|
||||
@Override |
||||
protected void initData(Bundle savedInstanceState) { |
||||
super.initData(savedInstanceState); |
||||
bookSource = getIntent().getParcelableExtra(APPCONST.BOOK_SOURCE); |
||||
} |
||||
|
||||
@Override |
||||
protected void initWidget() { |
||||
WebSettings settings = binding.webView.getSettings(); |
||||
settings.setSupportZoom(true); |
||||
settings.setBuiltInZoomControls(true); |
||||
settings.setDefaultTextEncodingName("UTF-8"); |
||||
settings.setJavaScriptEnabled(true); |
||||
CookieManager cookieManager = CookieManager.getInstance(); |
||||
binding.webView.setWebViewClient(new WebViewClient() { |
||||
@Override |
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) { |
||||
String cookie = cookieManager.getCookie(url); |
||||
DbManager.getDaoSession().getCookieBeanDao().insertOrReplace(new CookieBean(bookSource.getLoginUrl(), cookie)); |
||||
super.onPageStarted(view, url, favicon); |
||||
} |
||||
|
||||
@Override |
||||
public void onPageFinished(WebView view, String url) { |
||||
String cookie = cookieManager.getCookie(url); |
||||
DbManager.getDaoSession().getCookieBeanDao().insertOrReplace(new CookieBean(bookSource.getLoginUrl(), cookie)); |
||||
if (checking) |
||||
finish(); |
||||
else |
||||
ToastUtils.showInfo(getString(R.string.click_check_after_success)); |
||||
super.onPageFinished(view, url); |
||||
} |
||||
}); |
||||
binding.webView.loadUrl(bookSource.getLoginUrl()); |
||||
} |
||||
|
||||
// 添加菜单
|
||||
@Override |
||||
public boolean onCreateOptionsMenu(Menu menu) { |
||||
getMenuInflater().inflate(R.menu.menu_source_login, menu); |
||||
return true; |
||||
} |
||||
|
||||
//菜单
|
||||
@Override |
||||
public boolean onOptionsItemSelected(MenuItem item) { |
||||
int id = item.getItemId(); |
||||
switch (id) { |
||||
case R.id.action_check: |
||||
if (checking) break; |
||||
checking = true; |
||||
ToastUtils.showInfo(getString(R.string.check_host_cookie)); |
||||
binding.webView.loadUrl(bookSource.getLoginUrl()); |
||||
break; |
||||
case android.R.id.home: |
||||
finish(); |
||||
break; |
||||
} |
||||
return super.onOptionsItemSelected(item); |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:id="@+id/ll_content" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:fitsSystemWindows="true" |
||||
android:orientation="vertical"> |
||||
|
||||
<include layout="@layout/toolbar" /> |
||||
|
||||
<WebView |
||||
android:id="@+id/web_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:background="@color/white" /> |
||||
|
||||
</LinearLayout> |
@ -0,0 +1,11 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||
|
||||
<item |
||||
android:id="@+id/action_check" |
||||
android:title="@string/success" |
||||
android:icon="@drawable/ic_check" |
||||
app:showAsAction="always" /> |
||||
|
||||
</menu> |
Loading…
Reference in new issue