Skip to content

Commit

Permalink
支持自定义显示分享链接功能
Browse files Browse the repository at this point in the history
  • Loading branch information
sovegetables committed Mar 20, 2021
1 parent 321d2f1 commit e398cd3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
20 changes: 10 additions & 10 deletions agronweb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
compileSdkVersion 28
buildToolsVersion "28.0.3"


defaultConfig {
minSdkVersion 14
targetSdkVersion 29
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -28,19 +28,19 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation("com.squareup.okhttp3:okhttp:3.12.0")
implementation "com.squareup.okhttp3:okhttp:3.12.0"
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

implementation 'com.github.sovegetables.shineandroid:absactivity:0.3.1'
implementation 'com.github.sovegetables.shineandroid:topnavbar:0.3.1'
implementation 'com.github.sovegetables.shineandroid:permission:0.3.1'
implementation 'com.github.sovegetables.shineandroid:absactivity:0.4.3'
implementation 'com.github.sovegetables.shineandroid:topnavbar:0.4.3'
implementation 'com.github.sovegetables.shineandroid:permission:0.3.9'
implementation 'com.qmuiteam:qmui:1.4.0'

testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
4 changes: 1 addition & 3 deletions agronweb/src/main/java/cn/sovegetables/web/ArgonWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.annotation.RequiresApi;

import java.lang.reflect.Method;

/**
Expand Down Expand Up @@ -104,7 +102,7 @@ private void init(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
webSettings.setMediaPlaybackRequiresUserGesture(false);
}
webSettings.setDomStorageEnabled(true);
// webSettings.setDomStorageeEnabled(true);
String appCachePath = context.getCacheDir().getAbsolutePath();
webSettings.setAppCachePath(appCachePath);
webSettings.setAllowFileAccess(true);
Expand Down
30 changes: 16 additions & 14 deletions agronweb/src/main/java/cn/sovegetables/web/CommonWebActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.view.View
import android.webkit.WebView
import androidx.annotation.CallSuper
import androidx.fragment.app.Fragment
import cn.sovegetables.web.WebConfig.Companion.TYPE_SHARE_DEFAULT
import com.sovegetables.BaseActivity
import com.sovegetables.SystemBarConfig
import com.sovegetables.titleBuilder
Expand Down Expand Up @@ -134,9 +135,8 @@ open class CommonWebActivity : BaseActivity() {
val pageListener = object : IWebModule.WebProgressViewModuleAdapter(){
override fun onPageFinished(view: WebView?, url: String?) {
if(webConfig.enable){
topBarAction.findRightItemUpdaterById(SHARE_TOP_ITEM_ID)
.visibility(View.VISIBLE)
.update()
val topBarItemUpdater = topBarAction.findRightItemUpdaterById(SHARE_TOP_ITEM_ID)
topBarItemUpdater?.visibility(View.VISIBLE)?.update()
}
}
}
Expand Down Expand Up @@ -240,18 +240,20 @@ open class CommonWebActivity : BaseActivity() {
return TopBar.NO_ACTION_BAR
}else{
val items = arrayListOf<TopBarItem>()
items.add(TopBarItem.Builder()
.icon(R.drawable.ic_agron_web_share)
.listener {
val shareIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, webConfig.realUrl?:"")
type = "text/*"
if(webConfig.shareType == TYPE_SHARE_DEFAULT){
items.add(TopBarItem.Builder()
.icon(R.drawable.ic_agron_web_share)
.listener {
val shareIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, webConfig.realUrl?:"")
type = "text/*"
}
startActivity(Intent.createChooser(shareIntent, resources.getText(R.string.argon_send_to)))
}
startActivity(Intent.createChooser(shareIntent, resources.getText(R.string.argon_send_to)))
}
.visibility(TopBarItem.Visibility.GONE)
.build(this, SHARE_TOP_ITEM_ID))
.visibility(TopBarItem.Visibility.GONE)
.build(this, SHARE_TOP_ITEM_ID))
}
return titleBuilder("")
.rights(items)
.build(this)
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId "cn.sovegetables.web.sample"
minSdkVersion 17
targetSdkVersion 29
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/cn/sovegetables/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

et_input.setText("http://134.175.132.191:18085")
et_input.setText("https://www.baidu.com")
btn_go.setOnClickListener {
CommonWebActivity.start(this, WebConfig(url = et_input.text.toString(), statusColorInt = Color.BLUE, enable = false,
shareType = WebConfig.TYPE_SHARE_DEFAULT,
CommonWebActivity.start(this, WebConfig(url = et_input.text.toString(), statusColorInt = Color.BLUE, enable = true,
// shareType = WebConfig.TYPE_SHARE_DEFAULT,
enableAutoTitle = true,
withCloseIconAndClosePage = false) )
}
Expand Down

0 comments on commit e398cd3

Please sign in to comment.