-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #989 from hyperskill/release/1.55
Release 1.55
- Loading branch information
Showing
203 changed files
with
2,394 additions
and
1,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 62 additions & 1 deletion
63
...rskillApp/src/main/java/org/hyperskill/app/android/core/extensions/CustomTabsExtention.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,75 @@ | ||
package org.hyperskill.app.android.core.extensions | ||
|
||
import android.app.Activity | ||
import android.content.ActivityNotFoundException | ||
import android.content.Context | ||
import android.net.Uri | ||
import android.widget.Toast | ||
import androidx.browser.customtabs.CustomTabColorSchemeParams | ||
import androidx.browser.customtabs.CustomTabsIntent | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.Fragment | ||
import co.touchlab.kermit.Logger | ||
import org.hyperskill.app.R | ||
|
||
fun CustomTabsIntent.Builder.setHyperskillColors(context: Context): CustomTabsIntent.Builder = | ||
setDefaultColorSchemeParams( | ||
CustomTabColorSchemeParams.Builder() | ||
.setToolbarColor(ContextCompat.getColor(context, R.color.color_primary_variant)) | ||
.build() | ||
) | ||
) | ||
|
||
fun Fragment.launchUrlInCustomTabs( | ||
url: String, | ||
logger: Logger | ||
) { | ||
launchUrlInCustomTabs(url) { e -> | ||
logger.e(e) { | ||
"Unable to launch url in custom tabs nor in browser." | ||
} | ||
Toast.makeText( | ||
requireContext(), | ||
getString(R.string.external_link_error), | ||
Toast.LENGTH_SHORT | ||
).show() | ||
} | ||
} | ||
|
||
fun Fragment.launchUrlInCustomTabs( | ||
url: String, | ||
onError: (e: Throwable) -> Unit | ||
) { | ||
CustomTabsIntent.Builder() | ||
.setHyperskillColors(requireContext()) | ||
.build() | ||
.launchUrlSafe( | ||
requireActivity(), | ||
Uri.parse(url), | ||
onError | ||
) | ||
} | ||
|
||
fun CustomTabsIntent.launchUrlSafe( | ||
activity: Activity, | ||
url: Uri, | ||
onError: (e: Throwable) -> Unit | ||
) { | ||
// ActivityNotFoundException means there is no browser on the device | ||
try { | ||
launchUrl(activity, url) | ||
} catch (e: ActivityNotFoundException) { | ||
onError(e) | ||
} | ||
} | ||
|
||
@Deprecated( | ||
message = "Don't call launchUrl directly. Use launchUrlSafe instead.", | ||
replaceWith = ReplaceWith( | ||
expression = "launchUrlSafe", | ||
imports = arrayOf("org.hyperskill.app.android.core.extensions.launchUrlSafe") | ||
), | ||
level = DeprecationLevel.ERROR | ||
) | ||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER", "UnusedParameter") | ||
fun CustomTabsIntent.launchUrl(context: Context, url: Uri): Nothing = | ||
error("Don't call launchUrl directly. Use launchUrlSafe instead.") |
21 changes: 21 additions & 0 deletions
21
androidHyperskillApp/src/main/java/org/hyperskill/app/android/core/extensions/LoggerUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.hyperskill.app.android.core.extensions | ||
|
||
import co.touchlab.kermit.Logger | ||
import org.hyperskill.app.android.HyperskillApp | ||
|
||
/** | ||
* Provides logger with specified [tag], | ||
* taking it from [HyperskillApp.graph] | ||
*/ | ||
fun logger(tag: String): Lazy<Logger> = | ||
LazyLoggerProvider(tag) | ||
|
||
private class LazyLoggerProvider(private val tag: String) : Lazy<Logger> { | ||
|
||
private var logger: Logger? = null | ||
override val value: Logger | ||
get() = logger ?: HyperskillApp.graph().loggerComponent.logger.withTag(tag) | ||
|
||
override fun isInitialized(): Boolean = | ||
logger != null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.