Skip to content

Commit

Permalink
Merge pull request #134 from arunkumar9t2/develop
Browse files Browse the repository at this point in the history
2.1.3
  • Loading branch information
arunkumar9t2 authored Nov 14, 2019
2 parents 368e063 + 187d314 commit 22ae7f9
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 51 deletions.
4 changes: 2 additions & 2 deletions android-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ android {
applicationId "arun.com.chromer"
minSdkVersion 16
targetSdkVersion 28
versionCode 55
versionName "2.1.2"
versionCode 56
versionName "2.1.3"

multiDexEnabled true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package arun.com.chromer.browsing.article

import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
Expand Down Expand Up @@ -256,13 +255,8 @@ class ArticleActivity : BrowsingActivity() {
}

private fun handleBlackTheme() {
val blackDrawable = ColorDrawable(Color.BLACK)
coordinatorLayout.background = blackDrawable
bottomNavigation.apply {
background = blackDrawable
itemIconTintList = ColorStateList.valueOf(Color.WHITE)
itemIconTintList = ColorStateList.valueOf(Color.WHITE)
}
coordinatorLayout.setBackgroundColor(Color.BLACK)
bottomNavigation.setBackgroundColor(Color.BLACK)
articleTextSizeCard.setBackgroundColor(Color.BLACK)
setNavigationBarColor(Color.BLACK)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.widget.Toast
import android.widget.Toast.LENGTH_SHORT
import arun.com.chromer.R
import arun.com.chromer.di.activity.ActivityComponent
import arun.com.chromer.extenstions.finishAndRemoveTaskCompat
import arun.com.chromer.shared.base.activity.BaseActivity
import arun.com.chromer.tabs.TabsManager
import arun.com.chromer.util.SafeIntent
Expand All @@ -47,11 +48,9 @@ class BrowserInterceptActivity : BaseActivity() {
return
}
defaultTabsManager.processIncomingIntent(this, intent)
.subscribeBy(onComplete = {
finish()
})
.subscribeBy(onComplete = { finishAndRemoveTaskCompat() })
} ?: run {
finish()
finishAndRemoveTaskCompat()
}

}
Expand All @@ -62,6 +61,6 @@ class BrowserInterceptActivity : BaseActivity() {

private fun invalidLink() {
Toast.makeText(this, getString(R.string.unsupported_link), LENGTH_SHORT).show()
finish()
finishAndRemoveTaskCompat()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import arun.com.chromer.bubbles.FloatingBubble
import arun.com.chromer.data.website.model.Website
import arun.com.chromer.shared.Constants.*
import arun.com.chromer.util.Utils
import dev.arunkumar.android.rxschedulers.SchedulerProvider
import javax.inject.Inject
import javax.inject.Singleton


@Singleton
class WebHeadsFloatingBubble
@Inject
constructor(private val application: Application) : FloatingBubble {
constructor(
private val application: Application,
private val schedulerProvider: SchedulerProvider
) : FloatingBubble {

override fun openBubble(
website: Website,
Expand All @@ -37,7 +41,9 @@ constructor(private val application: Application) : FloatingBubble {
}
ContextCompat.startForegroundService(ctx, webHeadLauncher)
} else {
Utils.openDrawOverlaySettings(ctx)
schedulerProvider.ui.scheduleDirect {
Utils.openDrawOverlaySettings(ctx)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package arun.com.chromer.extenstions

import android.app.Activity
import arun.com.chromer.util.Utils

fun Activity.finishAndRemoveTaskCompat() {
if (Utils.isLollipopAbove()) {
finishAndRemoveTask()
} else {
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ constructor(
}.toList()
.toObservable()
.startWith(tabs)
.debounce(200, TimeUnit.MILLISECONDS)
}
.takeUntil(stops)
.compose(schedulerProvider.poolToUi())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ constructor(
) : AsyncEpoxyController() {

private val suggestionsClicksRelay = PublishRelay.create<SuggestionItem>()
private val suggestionLongClickRelay = PublishRelay.create<SuggestionItem>()
private val searchProviderRelay = PublishRelay.create<SearchProvider>()

val suggestionClicks: Observable<SuggestionItem> = suggestionsClicksRelay.hide()
val suggestionLongClicks: Observable<SuggestionItem> = suggestionLongClickRelay.hide()
val searchProviderClicks: Observable<SearchProvider> = searchProviderRelay.hide()

private val searchIcon: Drawable by lazy {
Expand All @@ -59,6 +61,7 @@ constructor(
.sizeDp(18)
}

var query: String = ""

var copySuggestions: List<SuggestionItem> = emptyList()
set(value) {
Expand Down Expand Up @@ -136,6 +139,10 @@ constructor(
onClickListener { _ ->
suggestionsClicksRelay.accept(suggestion)
}
onLongClickListener { _ ->
suggestionLongClickRelay.accept(suggestion)
return@onLongClickListener true
}
}
}

Expand All @@ -146,6 +153,7 @@ constructor(
id(suggestion.hashCode())
website(suggestion.website)
tabsManager(tabsManager)
query(query)
}
}.count().let { size ->
if (size != 0) {
Expand All @@ -171,9 +179,14 @@ constructor(
historyIcon(historyIcon)
searchIcon(searchIcon)
spanSizeOverride(TotalSpanOverride)
query(query)
onClickListener { _ ->
suggestionsClicksRelay.accept(suggestion)
}
onLongClickListener { _ ->
suggestionLongClickRelay.accept(suggestion)
return@onLongClickListener true
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package arun.com.chromer.search.suggestion

import `in`.arunkumarsampath.suggestions.RxSuggestions
import `in`.arunkumarsampath.suggestions.RxSuggestions.suggestionsTransformer
import android.app.Application
import arun.com.chromer.R
import arun.com.chromer.data.history.HistoryRepository
Expand All @@ -29,12 +29,13 @@ import arun.com.chromer.search.suggestion.items.SuggestionType
import arun.com.chromer.search.suggestion.items.SuggestionType.*
import arun.com.chromer.util.Utils
import dev.arunkumar.android.rxschedulers.SchedulerProvider
import hu.akarnokd.rxjava.interop.RxJavaInterop
import hu.akarnokd.rxjava.interop.RxJavaInterop.toV2Flowable
import hu.akarnokd.rxjava.interop.RxJavaInterop.toV2Transformer
import io.reactivex.Flowable
import io.reactivex.FlowableTransformer
import io.reactivex.functions.Function
import timber.log.Timber
import timber.log.Timber.e
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -50,7 +51,6 @@ constructor(
private val schedulerProvider: SchedulerProvider
) {
private val suggestionsDebounce = 200L
private val suggestionsLimit = 12

/**
* Trims and filters empty strings in stream.
Expand Down Expand Up @@ -91,8 +91,8 @@ constructor(
* clipboard, history and google suggestions.
*/
fun suggestionsTransformer(): FlowableTransformer<String, Pair<SuggestionType, List<SuggestionItem>>> {
return FlowableTransformer { suggestion ->
suggestion
return FlowableTransformer { upstream ->
upstream
.observeOn(schedulerProvider.pool)
.compose(emptyStringFilter())
.switchMap { query ->
Expand All @@ -114,15 +114,30 @@ constructor(
}
}

/**
* A function selector that transforms a source [Flowable] emitted from a [suggestionsTransformer]
* such that each [SuggestionType] and its [List] of [SuggestionItem]s are unique.
*/
fun distinctSuggestionsPublishSelector() = Function<
Flowable<Pair<SuggestionType, List<SuggestionItem>>>,
Flowable<Pair<SuggestionType, List<SuggestionItem>>>
> { source ->
Flowable.mergeArray(
source.filter { it.first == COPY }.distinctUntilChanged(),
source.filter { it.first == GOOGLE }.distinctUntilChanged(),
source.filter { it.first == HISTORY }.distinctUntilChanged()
)
}

/**
* Fetches suggestions from Google and converts it to {@link GoogleSuggestionItem}
*/
private fun googleTransformer(): FlowableTransformer<String, List<SuggestionItem>> {
return FlowableTransformer { query ->
return FlowableTransformer { upstream ->
if (!Utils.isOnline(application)) {
Flowable.just(emptyList())
} else query
.compose(RxJavaInterop.toV2Transformer(RxSuggestions.suggestionsTransformer(suggestionsLimit)))
} else upstream
.compose(toV2Transformer(suggestionsTransformer(5)))
.doOnError(Timber::e)
.map<List<SuggestionItem>> {
it.map { query -> GoogleSuggestionItem(query) }
Expand All @@ -134,9 +149,9 @@ constructor(
* Fetches matching items from History database and converts them to list of suggestions.
*/
private fun historyTransformer(): FlowableTransformer<String, List<SuggestionItem>> {
return FlowableTransformer { query ->
query.debounce(suggestionsDebounce, TimeUnit.MILLISECONDS)
.switchMap { RxJavaInterop.toV2Flowable(historyRepository.search(it)) }
return FlowableTransformer { upstream ->
upstream.debounce(suggestionsDebounce, MILLISECONDS)
.switchMap { toV2Flowable(historyRepository.search(it)) }
.map<List<SuggestionItem>> { suggestions ->
suggestions.asSequence()
.map { website ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package arun.com.chromer.search.suggestion.model
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.view.View
import androidx.core.text.toSpannable
import arun.com.chromer.R
import arun.com.chromer.extenstions.gone
import arun.com.chromer.extenstions.show
import arun.com.chromer.search.suggestion.items.SuggestionItem
import arun.com.chromer.search.suggestion.items.SuggestionType.*
import arun.com.chromer.util.makeMatchingBold
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyAttribute.Option.DoNotHash
import com.airbnb.epoxy.EpoxyModelClass
Expand All @@ -27,11 +29,15 @@ abstract class SuggestionLayoutModel : KotlinEpoxyModelWithHolder<SuggestionLayo
lateinit var searchIcon: Drawable
@EpoxyAttribute(DoNotHash)
lateinit var onClickListener: View.OnClickListener
@EpoxyAttribute(DoNotHash)
lateinit var onLongClickListener: View.OnLongClickListener
@EpoxyAttribute
var query: String = ""

override fun bind(holder: ViewHolder) {
super.bind(holder)
holder.apply {
suggestionsText.text = suggestionItem.title
suggestionsText.text = suggestionItem.title.toSpannable().makeMatchingBold(query)
when (suggestionItem.type) {
COPY -> suggestionIcon.setImageDrawable(copyIcon)
GOOGLE -> suggestionIcon.setImageDrawable(searchIcon)
Expand All @@ -48,6 +54,7 @@ abstract class SuggestionLayoutModel : KotlinEpoxyModelWithHolder<SuggestionLayo
}
}
containerView.setOnClickListener(onClickListener)
containerView.setOnLongClickListener(onLongClickListener)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ import arun.com.chromer.extenstions.gone
import arun.com.chromer.extenstions.inflate
import arun.com.chromer.search.provider.SearchProvider
import arun.com.chromer.search.suggestion.SuggestionController
import arun.com.chromer.search.suggestion.items.SuggestionItem
import arun.com.chromer.search.suggestion.items.SuggestionItem.HistorySuggestionItem
import arun.com.chromer.search.suggestion.items.SuggestionType
import arun.com.chromer.search.suggestion.items.SuggestionType.*
import arun.com.chromer.shared.Constants.REQUEST_CODE_VOICE
import arun.com.chromer.shared.base.ProvidesActivityComponent
Expand Down Expand Up @@ -310,9 +308,7 @@ constructor(

suggestions.takeUntil(viewDetaches)
.observeOn(schedulerProvider.ui)
.subscribe { (suggestionType, suggestions) ->
setSuggestions(suggestionType, suggestions)
}
.subscribe(::setSuggestions)

searchEngines.takeUntil(viewDetaches)
.observeOn(schedulerProvider.ui)
Expand All @@ -329,7 +325,12 @@ constructor(
.map { it.isEmpty() }
.observeOn(schedulerProvider.ui)
.takeUntil(viewDetaches)
.subscribe(searchSuggestions::gone)
.subscribe { isEmpty ->
searchSuggestions.gone(isEmpty)
if (!isEmpty) {
searchSuggestions.scrollToPosition(0)
}
}

suggestionController.suggestionClicks
.observeOn(schedulerProvider.pool)
Expand All @@ -342,6 +343,14 @@ constructor(
.observeOn(schedulerProvider.ui)
.takeUntil(viewDetaches)
.subscribe(::searchPerformed)

suggestionController.suggestionLongClicks
.filter { it.title.isNotEmpty() }
.takeUntil(viewDetaches)
.subscribe {
msvEditText.setText(it.title)
msvEditText.setSelection(it.title.length)
}
}

private fun clearFocus(endAction: (() -> Unit)?) {
Expand Down Expand Up @@ -394,12 +403,13 @@ constructor(
suggestionController.clear()
}

private fun setSuggestions(
suggestionType: SuggestionType,
suggestionItems: List<SuggestionItem>
) = when (suggestionType) {
COPY -> suggestionController.copySuggestions = suggestionItems
GOOGLE -> suggestionController.googleSuggestions = suggestionItems
HISTORY -> suggestionController.historySuggestions = suggestionItems
private fun setSuggestions(suggestionResult: SuggestionResult) {
suggestionController.query = suggestionResult.query.trim()
val suggestion = suggestionResult.suggestions
return when (suggestionResult.suggestionType) {
COPY -> suggestionController.copySuggestions = suggestion
GOOGLE -> suggestionController.googleSuggestions = suggestion
HISTORY -> suggestionController.historySuggestions = suggestion
}
}
}
Loading

0 comments on commit 22ae7f9

Please sign in to comment.