Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New enhancements #10

Merged
merged 2 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DokiActivity : AppCompatActivity() {
val dokiView = DokiContentView(context = this)
setContentView(dokiView)

api = dokiView.loadContent(manufacturerId = intent.extras?.run {
api = dokiView.loadContent(appName = "Doki App", manufacturerId = intent.extras?.run {
this[MANUFACTURER_EXTRA] as? String
} ?: DONT_KILL_MY_APP_DEFAULT_MANUFACTURER)

Expand Down
24 changes: 22 additions & 2 deletions library/src/main/java/dev/doubledot/doki/views/DokiContentView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class DokiContentView @JvmOverloads constructor(
private var devSolutionMessage: String = ""
var explanationTitleText: String = ""
var solutionTitleText: String = ""
private var appName: String = ""

var device : Device? = null
set(value) {
Expand All @@ -218,7 +219,12 @@ class DokiContentView @JvmOverloads constructor(
manufacturerRatingHeader?.visibleIf(value.award > 0)

contentExplanation?.htmlText = value.explanation
contentSolution?.htmlText = value.user_solution
contentSolution?.htmlText = value.user_solution.let {
if(appName.isNotEmpty())
it.replace("your app", appName, true)
else
it
}

if (value.dev_solution.isNullOrEmpty()) {
contentDeveloperSolutionHeader?.visibility = GONE
Expand Down Expand Up @@ -302,7 +308,11 @@ class DokiContentView @JvmOverloads constructor(
styledAttrs?.recycle()
}

fun loadContent(manufacturerId: String = DONT_KILL_MY_APP_DEFAULT_MANUFACTURER) : DokiApi {
fun loadContent(
manufacturerId: String = DONT_KILL_MY_APP_DEFAULT_MANUFACTURER,
appName: String = ""
) : DokiApi {
this.appName = appName
api.callback = object: DokiApiCallback {
override fun onSuccess(response: DokiManufacturer?) {
manufacturer = response
Expand All @@ -327,6 +337,16 @@ class DokiContentView @JvmOverloads constructor(
divider2?.visibleIf(visible)
}

fun setExplanationVisibility(visible: Boolean) {
contentExplanationHeader?.visibleIf(visible)
contentExplanation?.visibleIf(visible)
}

fun setDeveloperSolutionVisibility(visible: Boolean) {
contentDeveloperSolutionHeader?.visibleIf(visible)
contentDeveloperSolution?.visibleIf(visible)
}

private fun getStyledIconsStyle(attrs : TypedArray?) : DokiRatingView.Style? {
val iconsStyleId = try {
attrs?.getInt(R.styleable.DokiContentView_dokiIconsStyle, -1) ?: -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ class DokiCustomizedActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_doki_custom)

dokiContent?.setOnCloseListener { supportFinishAfterTransition() }
dokiContent?.loadContent()
dokiContent?.apply {
setOnCloseListener { supportFinishAfterTransition() }
setExplanationVisibility(false)
setDeveloperSolutionVisibility(false)
loadContent(appName = "Doki App")
}
}

}