Skip to content

Commit

Permalink
[Version] 🎉 Welcome to 1.00.22 (auto publish - clean onBoarding)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercandj committed Sep 23, 2018
1 parent bb11df0 commit d822f34
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ class DialogActivity : AppCompatActivity() {
positive.setOnClickListener {
finish()
dialogManager.onDialogPositiveClicked(
dialogInput.dialogId,
input.text.toString()
DialogManager.DialogAction(
dialogInput.dialogId,
input.text.toString()
)
)
}
negative.setOnClickListener {
finish()
dialogManager.onDialogNegativeClicked(
dialogInput.dialogId
DialogManager.DialogAction(
dialogInput.dialogId,
input.text.toString()
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,28 @@ interface DialogManager {
@StringRes negativeStringRes: Int
)

fun onDialogPositiveClicked(dialogId: String, userInput: String)
fun consumeDialogActionPositiveClicked(): DialogAction?

fun onDialogNegativeClicked(dialogId: String)
fun onDialogPositiveClicked(dialogAction: DialogAction)

fun onDialogNegativeClicked(dialogAction: DialogAction)

fun registerListener(listener: Listener)

fun unregisterListener(listener: Listener)

class DialogAction(
val dialogId: String,
val userInput: String
)

interface Listener {

fun onDialogPositiveClicked(
dialogId: String,
userInput: String
)
/**
* Return true if consumed
*/
fun onDialogPositiveClicked(dialogAction: DialogAction): Boolean

fun onDialogNegativeClicked(
dialogId: String
)
fun onDialogNegativeClicked(dialogAction: DialogAction)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class DialogManagerImpl(
) : DialogManager {

private val listeners = ArrayList<DialogManager.Listener>()
private var unconsumedDialogActionPositiveClicked: DialogManager.DialogAction? = null

override fun alert(
dialogId: String,
Expand Down Expand Up @@ -50,15 +51,25 @@ class DialogManagerImpl(
))
}

override fun onDialogPositiveClicked(dialogId: String, userInput: String) {
override fun consumeDialogActionPositiveClicked(): DialogManager.DialogAction? {
val tmp = unconsumedDialogActionPositiveClicked
unconsumedDialogActionPositiveClicked = null
return tmp
}

override fun onDialogPositiveClicked(dialogAction: DialogManager.DialogAction) {
unconsumedDialogActionPositiveClicked = dialogAction
for (listener in listeners) {
listener.onDialogPositiveClicked(dialogId, userInput)
if (listener.onDialogPositiveClicked(dialogAction)) {
unconsumedDialogActionPositiveClicked = null
return
}
}
}

override fun onDialogNegativeClicked(dialogId: String) {
override fun onDialogNegativeClicked(dialogAction: DialogManager.DialogAction) {
for (listener in listeners) {
listener.onDialogNegativeClicked(dialogId)
listener.onDialogNegativeClicked(dialogAction)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface FloatingContract {
fun onCollapseClicked()

fun onHomeClicked()

fun onLoad(configuration: FloatingManager.Configuration)
}

interface Screen {
Expand All @@ -38,5 +40,9 @@ interface FloatingContract {
fun isCollapsed(): Boolean

fun loadUrl(url: String)

fun showFullscreenButton()

fun hideFullscreenButton()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,36 @@ package com.mercandalli.android.browser.floating

interface FloatingManager {

fun start(url:String)
fun start(configuration: Configuration)

fun stop()

class Configuration private constructor(
val url: String,
val fullscreenButtonVisible: Boolean
) {

companion object {

fun default(url: String): Configuration {
return Builder().build(url)
}
}

class Builder {

private var fullscreenButtonVisible: Boolean = true

fun setFullscreenButtonVisible(visible: Boolean) {
fullscreenButtonVisible = visible
}

fun build(url: String): Configuration {
return Configuration(
url,
fullscreenButtonVisible
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FloatingManagerImpl(

private val floatingViews = ArrayList<FloatingView>()

override fun start(url: String) {
override fun start(configuration: FloatingManager.Configuration) {
if (!floatingPermission.canDrawOverOtherApps()) {
floatingPermission.launchDrawOverOtherAppPermissionManager()
return
Expand All @@ -28,7 +28,7 @@ class FloatingManagerImpl(
val context = ContextThemeWrapper(context, R.style.AppTheme)
val floatingView = FloatingView(context)
floatingView.setListener(createFloatingView())
floatingView.load(url)
floatingView.load(configuration)
floatingView.setExpandedSize(width, height)
floatingView.setCollapsedSize(ViewUtils.dpToPx(190F), ViewUtils.dpToPx(54F))
val flags = WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class FloatingPresenter(
screen.loadUrl(homeUrl)
}

override fun onLoad(configuration: FloatingManager.Configuration) {
screen.loadUrl(configuration.url)
if (configuration.fullscreenButtonVisible) {
screen.showFullscreenButton()
} else {
screen.hideFullscreenButton()
}
}

private fun updateTheme(theme: Theme = themeManager.getTheme()) {
screen.setPrimaryTextColorRes(theme.textPrimaryColorRes)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class FloatingView @JvmOverloads constructor(
mainWebView.load(url)
}

override fun showFullscreenButton() {
statusBarFullscreen.visibility = VISIBLE
}

override fun hideFullscreenButton() {
statusBarFullscreen.visibility = GONE
}

fun setListener(listener: Listener) {
this.listener = listener
}
Expand All @@ -124,8 +132,8 @@ class FloatingView @JvmOverloads constructor(
collapsedHeight = height.toInt()
}

fun load(url: String) {
mainWebView.load(url)
fun load(configuration: FloatingManager.Configuration) {
userAction.onLoad(configuration)
}

fun close() {
Expand Down Expand Up @@ -194,6 +202,7 @@ class FloatingView @JvmOverloads constructor(
override fun onFullscreenClicked(url: String) {}
override fun onCollapseClicked() {}
override fun onHomeClicked() {}
override fun onLoad(configuration: FloatingManager.Configuration) {}
}
}
val themeManager = ApplicationGraph.getThemeManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ internal class MainActivityPresenter(
val url = convertSearchToUrl(search)
screen.resetSearchInput()
if (!forceNonFloating && screen.isFloatingWindowChecked()) {
floatingManager.start(url)
floatingManager.start(FloatingManager.Configuration.default(url))
return
}
screen.showUrl(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ internal class OnBoardingPagePresenter(

override fun onFullVersionTryClicked() {
analyticsManager.sendEventOnBoardingTryFullVersion()
floatingManager.start("https://www.google.com/")
val builder = FloatingManager.Configuration.Builder()
builder.setFullscreenButtonVisible(false)
floatingManager.start(builder.build("https://www.google.com/"))
}

private fun updateTheme(theme: Theme = themeManager.getTheme()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mercandalli.android.browser.settings.about

import android.os.Build
import android.util.Log
import com.google.android.material.snackbar.Snackbar
import com.mercandalli.android.browser.R
import com.mercandalli.android.browser.dialog.DialogManager
Expand Down Expand Up @@ -29,6 +30,8 @@ class SettingsAboutPresenter(
themeManager.registerThemeListener(themeListener)
updateTheme()
setVersions()
val dialogAction = dialogManager.consumeDialogActionPositiveClicked()
consumeDialogActionPositiveClicked(dialogAction)
}

override fun onDetached() {
Expand Down Expand Up @@ -100,33 +103,41 @@ class SettingsAboutPresenter(
return currentTimestamp < timestamps[timestamps.size - nbClick] + duration
}

private fun consumeDialogActionPositiveClicked(dialogAction: DialogManager.DialogAction?) {
if (dialogAction == null) {
return
}
when (dialogAction.dialogId) {
DIALOG_ID_VERSION_NAME -> {
dialogManager.prompt(
DIALOG_ID_PROMPT_PASS,
R.string.view_settings_developer_activation_message_title,
R.string.view_settings_developer_activation_password,
R.string.view_settings_developer_activation_ok,
R.string.view_settings_developer_activation_cancel
)
}
DIALOG_ID_PROMPT_PASS -> {
val isAppDeveloperModeEnabled = hashManager.sha256(dialogAction.userInput, 32) ==
"4fa93ff20105d1bd93f79c2db51aa1169265130ca810e72e85b3277e92f53820"
setIsAppDeveloperEnabled(isAppDeveloperModeEnabled)
}
}
}

private fun createThemeListener() = object : ThemeManager.ThemeListener {
override fun onThemeChanged() {
updateTheme()
}
}

private fun createDialogListener() = object : DialogManager.Listener {
override fun onDialogPositiveClicked(dialogId: String, userInput: String) {
when (dialogId) {
DIALOG_ID_VERSION_NAME -> {
dialogManager.prompt(
DIALOG_ID_PROMPT_PASS,
R.string.view_settings_developer_activation_message_title,
R.string.view_settings_developer_activation_password,
R.string.view_settings_developer_activation_ok,
R.string.view_settings_developer_activation_cancel
)
}
DIALOG_ID_PROMPT_PASS -> {
val isAppDeveloperModeEnabled = hashManager.sha256(userInput, 32) ==
"4fa93ff20105d1bd93f79c2db51aa1169265130ca810e72e85b3277e92f53820"
setIsAppDeveloperEnabled(isAppDeveloperModeEnabled)
}
}
override fun onDialogPositiveClicked(dialogAction: DialogManager.DialogAction): Boolean {
consumeDialogActionPositiveClicked(dialogAction)
return true
}

override fun onDialogNegativeClicked(dialogId: String) {
override fun onDialogNegativeClicked(dialogAction: DialogManager.DialogAction) {

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mercandalli.android.browser.settings.ad_blocker

import android.util.Log
import com.mercandalli.android.browser.ad_blocker.AdBlockerManager
import com.mercandalli.android.browser.product.ProductManager
import com.mercandalli.android.browser.theme.Theme
Expand All @@ -17,13 +18,15 @@ class SettingsAdBlockerPresenter(
private val productManagerListener = createProductManagerListener()

override fun onAttached() {
Log.d("jm/debug", "onAttached")
themeManager.registerThemeListener(themeListener)
productManager.registerListener(productManagerListener)
updateTheme()
syncRows()
}

override fun onDetached() {
Log.d("jm/debug", "onAttached")
productManager.unregisterListener(productManagerListener)
themeManager.unregisterThemeListener(themeListener)
}
Expand All @@ -48,6 +51,7 @@ class SettingsAdBlockerPresenter(
isSubscribeToFullVersion: Boolean = productManager.isSubscribeToFullVersion(),
isEnabled: Boolean = adBlockerManager.isEnabled()
) {
Log.d("jm/debug", "isSubscribeToFullVersion: $isSubscribeToFullVersion")
if (isSubscribeToFullVersion) {
screen.showAdBlockSection()
screen.showAdBlockSectionLabel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class SettingsAdBlockerView @JvmOverloads constructor(
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
userAction.onDetached()
super.onDetachedFromWindow()
}

override fun setSectionColor(@ColorRes sectionColorRes: Int) {
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/res/floating/drawable/ic_zoom_out_map_white_24dp.xml

This file was deleted.

10 changes: 0 additions & 10 deletions app/src/main/res/floating/layout/view_floating.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,11 @@
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_gravity="end"
android:layout_marginEnd="34dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="6dp"
android:src="@drawable/ic_home_white_24dp"
android:tint="#808080" />

<ImageView
android:id="@+id/view_floating_status_bar_move"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_gravity="end"
android:padding="6dp"
android:src="@drawable/ic_zoom_out_map_white_24dp"
android:tint="#808080" />

</FrameLayout>

<com.mercandalli.android.browser.main.MainWebView
Expand Down
Loading

0 comments on commit d822f34

Please sign in to comment.