File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
app/src/main/java/com/app/jdcookie/activity Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
3535 private final static String JD_URL = "https://m.jd.com/" ;
3636 private MyAdapter adapter ;
3737 private RecyclerView recyclerView ;
38+ private long oldTime = 0 ;
3839
3940 @ Override
4041 protected void onCreate (Bundle savedInstanceState ) {
@@ -104,12 +105,19 @@ private void initWebView() {
104105
105106// WebView.setWebContentsDebuggingEnabled(BuilD);
106107 webBridgeWebView .setWebViewClient (new MyWebViewClient (webBridgeProgressBar , (cookie , pt_key ) -> runOnUiThread (() -> {
107- adapter .addData (pt_key );
108- recyclerView .scrollToPosition (adapter .getData ().size () - 1 );
108+
109+ //限制 500 毫秒 刷新一次
110+ long time = System .currentTimeMillis ();
111+ if (time - oldTime > 500 ) {
112+ adapter .addData (pt_key );
113+ recyclerView .scrollToPosition (adapter .getData ().size () - 1 );
114+ oldTime = time ;
115+ }
109116 })));
110- webBridgeWebView .setWebChromeClient (new MyWebChromeClient (webBridgeProgressBar ));
111- }
117+ webBridgeWebView .setWebChromeClient (new
112118
119+ MyWebChromeClient (webBridgeProgressBar ));
120+ }
113121
114122 public static class MyWebViewClient extends WebViewClient {
115123
You can’t perform that action at this time.
0 commit comments