Skip to content

Commit

Permalink
[ADD] 增加刷新 和 分享cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuSky committed Oct 20, 2021
1 parent 3004407 commit b61278c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.app.jdcookie"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
30 changes: 24 additions & 6 deletions app/src/main/java/com/app/jdcookie/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.app.jdcookie.activity;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand Down Expand Up @@ -32,6 +30,8 @@
import com.app.jdcookie.CookieListener;
import com.app.jdcookie.MyAdapter;
import com.app.jdcookie.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

Expand Down Expand Up @@ -68,6 +68,7 @@ private void initView() {
findViewById(R.id.main_back).setOnClickListener(this);
findViewById(R.id.main_clear).setOnClickListener(this);
findViewById(R.id.main_set).setOnClickListener(this);
findViewById(R.id.main_refresh).setOnClickListener(this);
webBridgeProgressBar = findViewById(R.id.main_progress_bar);

recyclerView = findViewById(R.id.main_recycler_view);
Expand All @@ -82,6 +83,22 @@ private void initView() {
cm.setPrimaryClip(mClipData);
Toast.makeText(MainActivity.this, "复制成功", Toast.LENGTH_SHORT).show();
});
adapter.addChildClickViewIds(R.id.item_main_share);
adapter.setOnItemChildClickListener(new OnItemChildClickListener() {
@Override
public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
if (view.getId() == R.id.item_main_share) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
// 比如发送文本形式的数据内容
// 指定发送的内容
sendIntent.putExtra(Intent.EXTRA_TEXT, adapter.getItem(position).toString());
// 指定发送内容的类型
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "分享京东cookie到..."));
}
}
});

adapter.setEmptyView(R.layout.empty_layout);
}
Expand Down Expand Up @@ -128,9 +145,7 @@ private void initWebView() {
oldTime = time;
}
})));
webBridgeWebView.setWebChromeClient(new

MyWebChromeClient(webBridgeProgressBar));
webBridgeWebView.setWebChromeClient(new MyWebChromeClient(webBridgeProgressBar));
}

public static class MyWebViewClient extends WebViewClient {
Expand Down Expand Up @@ -233,6 +248,9 @@ public void onClick(View v) {
}
} else if (v.getId() == R.id.main_set) {
setLauncher.launch(new Intent(this, SetActivity.class));
} else if (v.getId() == R.id.main_refresh) {
//刷新
webBridgeWebView.reload();
}
}
}
Binary file added app/src/main/res/drawable/icon_refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/icon_share.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@
android:layout_height="0dp"
android:layout_weight="1" />

<ImageView
android:id="@+id/main_refresh"
android:layout_width="45dp"
android:layout_height="45dp"
android:padding="12dp"
android:src="@drawable/icon_refresh"
app:tint="#fff" />

<ImageView
android:id="@+id/main_set"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentEnd="true"
app:tint="#fff"
android:padding="12dp"
android:src="@drawable/icon_set" />
android:src="@drawable/icon_set"
app:tint="#fff" />
</LinearLayout>


Expand Down
35 changes: 27 additions & 8 deletions app/src/main/res/layout/item_main_layout.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/item_main_text"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="12dp"
android:paddingTop="15dp"
android:paddingEnd="12dp"
android:paddingBottom="15dp"
android:textColor="#333"
android:textSize="16sp" />
android:gravity="center"
android:orientation="horizontal">

<TextView
android:id="@+id/item_main_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="12dp"
android:paddingTop="15dp"
android:paddingEnd="12dp"
android:paddingBottom="15dp"
android:text="这里是cookie"
android:textColor="#333"
android:textSize="16sp" />

<ImageView
android:id="@+id/item_main_share"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="15dp"
android:src="@drawable/icon_share" />

</LinearLayout>


<View
android:layout_width="match_parent"
Expand Down

0 comments on commit b61278c

Please sign in to comment.