Skip to content

Commit

Permalink
fixed onSaveInstanceState issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sovegetables committed Aug 24, 2020
1 parent 7b873cf commit 28b52ab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
25 changes: 20 additions & 5 deletions agronweb/src/main/java/cn/sovegetables/web/CommonWebActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cn.sovegetables.web
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.text.TextUtils
import android.view.ContextMenu
import android.view.View
Expand Down Expand Up @@ -37,7 +38,7 @@ open class CommonWebActivity : BaseActivity() {

fun start(activity: Activity, webConfig: WebConfig){
val intent = Intent(activity, CommonWebActivity::class.java)
intent.putExtra(KEY_WEB_CONFIG, webConfig)
putWebConfig(intent, webConfig)
activity.startActivity(intent)
}

Expand All @@ -47,7 +48,7 @@ open class CommonWebActivity : BaseActivity() {

fun start(fragment: Fragment, webConfig: WebConfig){
val intent = Intent(fragment.requireContext(), CommonWebActivity::class.java)
intent.putExtra(KEY_WEB_CONFIG, webConfig)
putWebConfig(intent, webConfig)
fragment.startActivity(intent)
}

Expand All @@ -57,10 +58,14 @@ open class CommonWebActivity : BaseActivity() {

fun getIntent(webConfig: WebConfig) : Intent{
val intent = Intent()
intent.putExtra(KEY_WEB_CONFIG, webConfig)
putWebConfig(intent, webConfig)
return intent
}

fun putWebConfig(intent: Intent, webConfig: WebConfig) {
intent.putExtra(KEY_WEB_CONFIG, webConfig)
}

fun getWebConfig(activity: CommonWebActivity) : WebConfig{
return activity.intent?.getParcelableExtra(KEY_WEB_CONFIG) as WebConfig
}
Expand All @@ -70,8 +75,8 @@ open class CommonWebActivity : BaseActivity() {

@CallSuper
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
webConfig = getWebConfig(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_common_web)

val updater : TopBarItemUpdater = topBarAction.leftItemUpdater()
Expand Down Expand Up @@ -154,6 +159,16 @@ open class CommonWebActivity : BaseActivity() {
web.loadUrl(url)
}

override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
super.onSaveInstanceState(outState, outPersistentState)
outState.putParcelable(KEY_WEB_CONFIG, webConfig)
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
webConfig = getWebConfig(this)
}

protected open fun onPrepareWeb(web: ArgonWebView?, webConfig: WebConfig) {
}

Expand Down Expand Up @@ -204,7 +219,7 @@ open class CommonWebActivity : BaseActivity() {
}

override fun createSystemBarConfig(): SystemBarConfig? {
val config = getWebConfig(this)
val config = webConfig
val builder = SystemBarConfig.Builder()
if(config.statusColorInt != null){
builder.setStatusBarColor(config.statusColorInt!!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
package cn.sovegetables.web

import android.os.Bundle
import android.app.Activity
import android.content.Intent
import androidx.fragment.app.Fragment

open class ProcessCommonWebActivity : CommonWebActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
companion object{

fun start(activity: Activity, url: String){
start(activity, WebConfig(url = url, enableAutoTitle = true))
}

fun start(activity: Activity, webConfig: WebConfig){
val intent = Intent(activity, ProcessCommonWebActivity::class.java)
putWebConfig(intent, webConfig)
activity.startActivity(intent)
}

fun start(fragment: Fragment, url: String){
start(fragment, WebConfig(url = url, enableAutoTitle = true))
}

fun start(fragment: Fragment, webConfig: WebConfig){
val intent = Intent(fragment.requireContext(), ProcessCommonWebActivity::class.java)
putWebConfig(intent, webConfig)
fragment.startActivity(intent)
}

fun setIWebModule(module: IWebModule){
CommonWebActivity.setIWebModule(module)
}
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

0 comments on commit 28b52ab

Please sign in to comment.