Skip to content

Commit

Permalink
update: refactoring code and bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
amirisback committed Jul 3, 2022
1 parent 3d6f2ca commit 107dcca
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ inline fun <reified Model> Fragment.getInstanceExt(argsKey: String): Model {

// -------------------------------------------------------------------------------------------------

@Deprecated("Use newInstanceExt instead")
fun <Model> Fragment.singleNewInstance(argsKey: String, data: Model) {
val argsData = Gson().toJson(data)
val bundleArgs = Bundle().apply {
Expand All @@ -43,6 +44,7 @@ fun <Model> Fragment.singleNewInstance(argsKey: String, data: Model) {
this.arguments = bundleArgs
}

@Deprecated("Use getInstanceExt instead")
inline fun <reified Model> Fragment.singleGetInstance(argsKey: String): Model {
val argsData = this.arguments?.getString(argsKey)
return Gson().fromJson(argsData, Model::class.java)
Expand Down
38 changes: 18 additions & 20 deletions frogosdk/src/main/java/com/frogobox/sdk/view/FrogoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.os.Bundle
import android.view.*
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.Keep
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
Expand Down Expand Up @@ -62,9 +61,8 @@ abstract class FrogoActivity: AppCompatActivity(),

// ---------------------------------------------------------------------------------------------

@Deprecated("Use onCreateExt instead")
open fun setupOnCreate(savedInstanceState: Bundle?) {
}
@Deprecated("Use onCreateExt instead", ReplaceWith("onCreateExt"))
open fun setupOnCreate(savedInstanceState: Bundle?) {}

open fun onCreateExt(savedInstanceState: Bundle?) {
showLogD<FrogoActivity>("onCreateExt()")
Expand All @@ -85,9 +83,9 @@ abstract class FrogoActivity: AppCompatActivity(),
setupUtilDelegates(this)
showLogDebug("$TAG Internet Status : ${isNetworkConnected()}")
}
setupViewModel()
setupOnCreate(savedInstanceState)
onCreateExt(savedInstanceState)
setupViewModel()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down Expand Up @@ -151,21 +149,6 @@ abstract class FrogoActivity: AppCompatActivity(),
fragment.frogoNewInstance(argumentKey, extraDataResult)
}

protected inline fun <reified ClassActivity> frogoStartActivity() {
singleStartActivity<ClassActivity>()
}

protected inline fun <reified ClassActivity, reified Model> frogoStartActivity(
extraKey: String,
data: Model
) {
singleStartActivity<ClassActivity, Model>(extraKey, data)
}

protected inline fun <reified Model> frogoGetExtraData(extraKey: String): Model {
return singleGetExtraData(extraKey)
}

override fun setupFullScreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val controller = window.insetsController
Expand All @@ -189,4 +172,19 @@ abstract class FrogoActivity: AppCompatActivity(),
showLogDebug("$TAG Hide System UI a.k.a Status Bar Android CutOut")
}

protected inline fun <reified ClassActivity> frogoStartActivity() {
startActivityExt<ClassActivity>()
}

protected inline fun <reified ClassActivity, reified Model> frogoStartActivity(
extraKey: String,
data: Model
) {
startActivityExt<ClassActivity, Model>(extraKey, data)
}

protected inline fun <reified Model> frogoGetExtraData(extraKey: String): Model {
return getExtraDataExt(extraKey)
}

}
26 changes: 15 additions & 11 deletions frogosdk/src/main/java/com/frogobox/sdk/view/FrogoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ abstract class FrogoFragment : Fragment(),

// ---------------------------------------------------------------------------------------------

@Deprecated("Use onViewCreatedExt instead")
open fun setupOnViewCreated(view: View, savedInstanceState: Bundle?) {
}
@Deprecated("Use onViewCreatedExt instead", ReplaceWith("onViewCreatedExt"))
open fun setupOnViewCreated(view: View, savedInstanceState: Bundle?) {}

open fun onViewCreatedExt(view: View, savedInstanceState: Bundle?) {}
open fun onViewCreatedExt(view: View, savedInstanceState: Bundle?) {
showLogD<FrogoFragment>("Call onViewCreatedExt()")
}

open fun setupViewModel() {}
open fun setupViewModel() {
showLogD<FrogoFragment>("Call setupViewModel()")
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -74,11 +77,12 @@ abstract class FrogoFragment : Fragment(),

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupOnViewCreated(view, savedInstanceState)
onViewCreatedExt(view, savedInstanceState)
if (savedInstanceState == null) {
showLogDebug("$TAG : Overriding on ViewCreated")
}
setupViewModel()
setupOnViewCreated(view, savedInstanceState)
onViewCreatedExt(view, savedInstanceState)
}

// ---------------------------------------------------------------------------------------------
Expand All @@ -95,22 +99,22 @@ abstract class FrogoFragment : Fragment(),
}

override fun <Model> frogoNewInstance(argsKey: String, data: Model) {
singleNewInstance(argsKey, data)
newInstanceExt(argsKey, data)
}

protected inline fun <reified Model> frogoGetInstance(argsKey: String): Model {
return singleGetInstance(argsKey)
return getInstanceExt(argsKey)
}

protected inline fun <reified ClassActivity> frogoStartActivity() {
context?.singleStartActivity<ClassActivity>()
requireContext().startActivityExt<ClassActivity>()
}

protected inline fun <reified ClassActivity, reified Model> frogoStartActivity(
extraKey: String,
data: Model
) {
context?.singleStartActivity<ClassActivity, Model>(extraKey, data)
requireContext().startActivityExt<ClassActivity, Model>(extraKey, data)
}

}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 107dcca

Please sign in to comment.