Skip to content

Commit

Permalink
[Version] 🎉 Welcome to 1.00.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercandj committed Sep 13, 2018
1 parent 121914c commit 7076481
Show file tree
Hide file tree
Showing 39 changed files with 1,140 additions and 172 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
versionCode rootProject.ext.appVersionCode
versionName rootProject.ext.appVersionName + "." + new Date().format('yyyyMMdd')
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resConfigs "en", "fr"
resConfigs "en", "fr", "pt-rBR"
}

dexOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import com.mercandalli.android.browser.ad_blocker.AdBlockerModule
import com.mercandalli.android.browser.product.ProductModule
import com.mercandalli.android.browser.remote_config.RemoteConfigModule
import com.mercandalli.android.browser.search_engine.SearchEngineModule
import com.mercandalli.android.browser.theme.ThemeModule
import com.mercandalli.android.browser.thread.MainThreadModule
import com.mercandalli.android.browser.toast.ToastModule
Expand All @@ -19,6 +20,7 @@ class ApplicationGraph(
private val productManagerInternal by lazy { ProductModule().createProductManager() }
private val mainThreadPostInternal by lazy { MainThreadModule().createMainThreadPost() }
private val remoteConfigInternal by lazy { RemoteConfigModule().createRemoteConfig(mainThreadPostInternal) }
private val searchEngineManagerInternal by lazy { SearchEngineModule().createSearchEngineManager() }
private val themeManagerInternal by lazy { ThemeModule(context).createThemeManager() }
private val toastManagerInternal by lazy { ToastModule().createToastManager(context, mainThreadPostInternal) }
private val updateManagerInternal by lazy { UpdateModule().createUpdateManager(context, versionManagerInternal) }
Expand Down Expand Up @@ -46,6 +48,9 @@ class ApplicationGraph(
@JvmStatic
fun getRemoteConfig() = graph!!.remoteConfigInternal

@JvmStatic
fun getSearchEngineManager() = graph!!.searchEngineManagerInternal

@JvmStatic
fun getThemeManager() = graph!!.themeManagerInternal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.Toolbar
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
Expand All @@ -32,16 +31,15 @@ import com.mercandalli.android.libs.monetization.MonetizationGraph

class MainActivity : AppCompatActivity(), MainActivityContract.Screen {

private val toolbar: Toolbar by bind(R.id.activity_main_toolbar)
private val toolbar: View by bind(R.id.activity_main_toolbar)
private val toolbarShadow: View by bind(R.id.activity_main_toolbar_shadow)
private val webView: BrowserView by bind(R.id.activity_main_web_view)
private val emptyView: View by bind(R.id.activity_main_empty_view)
private val emptyTextView: TextView by bind(R.id.activity_main_empty_view_text)
private val progress: ProgressBar by bind(R.id.activity_main_progress)
private val input: EditText by bind(R.id.activity_main_search)
private val more: View by bind(R.id.activity_main_more)
private val fabClear: FloatingActionButton by bind(R.id.activity_main_fab_clear)
private val fabFullScreen: FloatingActionButton by bind(R.id.activity_main_fab_fullscreen)
private val fab: FloatingActionButton by bind(R.id.activity_main_fab_clear)

private val browserWebViewListener = createBrowserWebViewListener()
private val userAction = createUserAction()
Expand All @@ -56,7 +54,6 @@ class MainActivity : AppCompatActivity(), MainActivityContract.Screen {
return
}
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
more.setOnClickListener { showOverflowPopupMenu(more) }
webView.browserWebViewListener = browserWebViewListener
input.setOnEditorActionListener(createOnEditorActionListener())
Expand All @@ -65,13 +62,10 @@ class MainActivity : AppCompatActivity(), MainActivityContract.Screen {
navigateHome()
}

fabClear.setOnClickListener {
userAction.onFabClicked(false)
fab.setOnClickListener {
userAction.onFabClicked()
}
fabFullScreen.setOnClickListener {
userAction.onFabClicked(true)
}
userAction.onCreate(savedInstanceState == null)
userAction.onCreate(savedInstanceState)
}

override fun onDestroy() {
Expand All @@ -83,16 +77,18 @@ class MainActivity : AppCompatActivity(), MainActivityContract.Screen {
userAction.onDestroy()
}

override fun onSaveInstanceState(outState: Bundle?) {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (forceDestroy) {
return
}
userAction.onSaveInstanceState(outState)
webView.saveState(outState)
}

override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
userAction.onRestoreInstanceState(savedInstanceState)
webView.restoreState(savedInstanceState)
}

Expand Down Expand Up @@ -180,6 +176,15 @@ class MainActivity : AppCompatActivity(), MainActivityContract.Screen {
window.statusBarColor = color
}

@RequiresApi(api = Build.VERSION_CODES.M)
override fun setStatusBarDark(statusBarDark: Boolean) {
val flags = window.decorView.systemUiVisibility
window.decorView.systemUiVisibility = if (statusBarDark)
flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
else
flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}

override fun setToolbarBackgroundColorRes(@ColorRes colorRes: Int) {
val color = ContextCompat.getColor(this, colorRes)
toolbar.setBackgroundColor(color)
Expand All @@ -191,23 +196,14 @@ class MainActivity : AppCompatActivity(), MainActivityContract.Screen {
emptyTextView.setTextColor(color)
}

override fun showFabClear() {
if (!fabClear.isShown) {
fabClear.show()
}
fabFullScreen.hide()
}

override fun showFabExpand() {
if (!fabFullScreen.isShown) {
fabFullScreen.show()
override fun showFab() {
if (!fab.isShown) {
fab.show()
}
fabClear.hide()
}

override fun hideFab() {
fabClear.hide()
fabFullScreen.hide()
fab.hide()
}

override fun showWebView() {
Expand Down Expand Up @@ -278,9 +274,11 @@ class MainActivity : AppCompatActivity(), MainActivityContract.Screen {

private fun createUserAction(): MainActivityContract.UserAction {
val themeManager = ApplicationGraph.getThemeManager()
val searchEngineManager = ApplicationGraph.getSearchEngineManager()
return MainActivityPresenter(
this,
themeManager
themeManager,
searchEngineManager
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.mercandalli.android.browser.main

import android.os.Build
import android.os.Bundle
import androidx.annotation.ColorRes
import androidx.annotation.RequiresApi

internal class MainActivityContract {

internal interface UserAction {

fun onCreate(firstActivityLaunch: Boolean)
fun onCreate(savedInstanceState: Bundle?)

fun onDestroy()

fun onSaveInstanceState(outState: Bundle)

fun onRestoreInstanceState(outState: Bundle)

fun onSearchPerformed(search: String)

fun onHomeClicked()
Expand All @@ -26,7 +31,7 @@ internal class MainActivityContract {

fun onBackPressed(emptyViewVisible: Boolean)

fun onFabClicked(expand: Boolean)
fun onFabClicked()
}

internal interface Screen {
Expand Down Expand Up @@ -62,13 +67,14 @@ internal class MainActivityContract {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
fun setStatusBarBackgroundColorRes(@ColorRes colorRes: Int)

@RequiresApi(api = Build.VERSION_CODES.M)
fun setStatusBarDark(statusBarDark: Boolean)

fun setToolbarBackgroundColorRes(@ColorRes colorRes: Int)

fun setInputTextColorRes(@ColorRes colorRes: Int)

fun showFabClear()

fun showFabExpand()
fun showFab()

fun hideFab()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
package com.mercandalli.android.browser.main

import android.os.Build
import android.os.Bundle
import com.mercandalli.android.browser.search_engine.SearchEngineManager
import com.mercandalli.android.browser.theme.Theme
import com.mercandalli.android.browser.theme.ThemeManager

internal class MainActivityPresenter(
private val screen: MainActivityContract.Screen,
private val themeManager: ThemeManager
private val themeManager: ThemeManager,
private val searchEngineManager: SearchEngineManager
) : MainActivityContract.UserAction {

private val themeListener = createThemeListener()
private var webViewVisible = false

override fun onCreate(firstActivityLaunch: Boolean) {
override fun onCreate(savedInstanceState: Bundle?) {
themeManager.registerThemeListener(themeListener)
updateTheme()
val firstActivityLaunch = savedInstanceState == null
if (firstActivityLaunch) {
screen.hideFab()
screen.hideWebView()
screen.showEmptyView()
screen.showKeyboard()
screen.showToolbar()
setWebViewVisible(webViewVisible)
}
}

override fun onDestroy() {
themeManager.unregisterThemeListener(themeListener)
}

override fun onSaveInstanceState(outState: Bundle) {
outState.putBoolean("webViewVisible", webViewVisible)
}

override fun onRestoreInstanceState(outState: Bundle) {
webViewVisible = outState.getBoolean("webViewVisible")
setWebViewVisible(webViewVisible)
}

override fun onSearchPerformed(search: String) {
val url = searchToUrl(search)
screen.showLoader(0)
screen.showUrl(url)
screen.resetSearchInput()
screen.hideKeyboard()
screen.showFabExpand()
screen.showWebView()
screen.hideEmptyView()
screen.hideToolbar()
setWebViewVisible(true)
}

override fun onHomeClicked() {
screen.hideLoader()
screen.navigateHome()
setWebViewVisible(false)
}

override fun onClearDataClicked() {
screen.clearData()
screen.showClearDataMessage()
screen.hideLoader()
screen.navigateHome()
screen.hideWebView()
screen.showEmptyView()
screen.showToolbar()
setWebViewVisible(false)
}

override fun onSettingsClicked() {
screen.hideLoader()
screen.navigateSettings()
}

Expand All @@ -79,27 +79,32 @@ internal class MainActivityPresenter(
screen.back()
}

override fun onFabClicked(expand: Boolean) {
screen.showToolbar()
if (expand) {
screen.showFabClear()
return
}
override fun onFabClicked() {
screen.clearData()
screen.showClearDataMessage()
screen.hideLoader()
screen.navigateHome()
screen.hideFab()
screen.hideWebView()
screen.showEmptyView()
screen.showKeyboard()
setWebViewVisible(false)
}

private fun searchToUrl(search: String): String {
return if (search.startsWith("https://") || search.startsWith("http://")) {
search
return searchEngineManager.createSearchUrl(search)
}

private fun setWebViewVisible(visible: Boolean) {
webViewVisible = visible
if (visible) {
screen.showFab()
screen.hideToolbar()
screen.showWebView()
screen.hideEmptyView()
screen.showLoader(0)
screen.hideKeyboard()
} else {
"https://www.google.fr/search?q=" + search.replace(" ", "+")
screen.hideFab()
screen.showToolbar()
screen.hideWebView()
screen.showEmptyView()
screen.hideLoader()
screen.showKeyboard()
}
}

Expand All @@ -110,6 +115,9 @@ internal class MainActivityPresenter(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
screen.setStatusBarBackgroundColorRes(theme.statusBarBackgroundColorRes)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
screen.setStatusBarDark(theme.statusBarDark)
}
}

private fun createThemeListener() = object : ThemeManager.ThemeListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mercandalli.android.browser.search_engine

import androidx.annotation.StringDef

data class SearchEngine(
@SearchEngineKey val searchEngineKey: String,
val name: String
) {

companion object {

@StringDef(
SEARCH_ENGINE_GOOGLE,
SEARCH_ENGINE_YOUTUBE,
SEARCH_ENGINE_DUCK_DUCK_GO
)
@Retention(AnnotationRetention.SOURCE)
annotation class SearchEngineKey

const val SEARCH_ENGINE_GOOGLE = "search-engine-google"
const val SEARCH_ENGINE_YOUTUBE = "search-engine-youtube"
const val SEARCH_ENGINE_DUCK_DUCK_GO = "search-engine-duck-duck-go"
}
}
Loading

0 comments on commit 7076481

Please sign in to comment.