Skip to content

Commit

Permalink
Merge pull request #126 from arunkumar9t2/develop
Browse files Browse the repository at this point in the history
Release 2.1.1
  • Loading branch information
arunkumar9t2 authored Sep 28, 2019
2 parents 521b2eb + fea49ee commit 1c13984
Show file tree
Hide file tree
Showing 23 changed files with 272 additions and 121 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 53
versionName "2.1"
versionCode 54
versionName "2.1.1"

multiDexEnabled true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import arun.com.chromer.data.webarticle.WebArticleRepository
import arun.com.chromer.data.webarticle.model.WebArticle
import arun.com.chromer.search.provider.SearchProvider
import arun.com.chromer.search.provider.SearchProviders
import arun.com.chromer.settings.RxPreferences
import arun.com.chromer.util.SchedulerProvider
import io.reactivex.Observable
import rx.subjects.PublishSubject
Expand All @@ -40,9 +39,7 @@ class BrowsingArticleViewModel
@Inject
constructor(
private val webArticleRepository: WebArticleRepository,
private val schedulerProvider: dev.arunkumar.android.rxschedulers.SchedulerProvider,
private val searchProviders: SearchProviders,
private val rxPreferences: RxPreferences
searchProviders: SearchProviders
) : ViewModel() {
private val subs = CompositeSubscription()

Expand All @@ -60,21 +57,7 @@ constructor(
}.subscribe { articleLiveData.value = it })
}

val selectedSearchProvider: Observable<SearchProvider> = rxPreferences
.searchEngine
.observe()
.observeOn(schedulerProvider.pool)
.switchMap { selectedEngine ->
searchProviders
.availableProviders
.toObservable()
.flatMapIterable { it }
.filter { it.name == selectedEngine }
.first(SearchProviders.GOOGLE_SEARCH_PROVIDER)
.toObservable()
}.replay(1)
.refCount()
.observeOn(schedulerProvider.ui)
val selectedSearchProvider: Observable<SearchProvider> = searchProviders.selectedProvider

fun loadArticle(url: String) = loadingQueue.onNext(url)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ArticleBackgroundLoadingStrategy
@Inject
constructor(private val articlePreloader: ArticlePreloader) : BackgroundLoadingStrategy {

override fun perform(url: String) {
override fun prepare(url: String) {
articlePreloader.preloadArticle(Uri.parse(url)) { success ->
Timber.d("Article mode preloading for $url: $success")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package arun.com.chromer.browsing.backgroundloading

interface BackgroundLoadingStrategy {

fun perform(url: String)
fun prepare(url: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package arun.com.chromer.browsing.backgroundloading

import android.app.Activity
import android.app.Application
import android.os.Handler
import android.os.Looper
import arun.com.chromer.browsing.customtabs.CustomTabActivity
import arun.com.chromer.browsing.webview.EmbeddableWebViewActivity
import arun.com.chromer.browsing.webview.WebViewActivity
import arun.com.chromer.util.ActivityLifeCycleCallbackAdapter
import dev.arunkumar.android.rxschedulers.SchedulerProvider
import timber.log.Timber
import java.util.concurrent.TimeUnit.MILLISECONDS
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -19,6 +20,7 @@ private fun Application.safeActivityStarted(action: (Activity, UnRegisterAction)
override fun onActivityStarted(activity: Activity?) {
super.onActivityStarted(activity)
val unRegisterAction: UnRegisterAction = {
Timber.i("Unregistering lifecycle callbacks")
unregisterActivityLifecycleCallbacks(this)
}
activity?.let { startedActivity ->
Expand All @@ -40,17 +42,19 @@ abstract class BrowsingBackgroundLoadingStrategy(

abstract val activityClasses: List<Class<out Activity>>

override fun perform(url: String) {
override fun prepare(url: String) {
application.safeActivityStarted { startedActivity, unRegisterAction ->
if (activityClasses.any { it.isAssignableFrom(startedActivity.javaClass) }) {
val activityUrl = startedActivity.intent?.dataString
if (url == activityUrl) {
schedulerProvider.ui.scheduleDirect({
Handler(Looper.getMainLooper()).postDelayed({
startedActivity.moveTaskToBack(true)
Timber.d("Moved $activityUrl to back")
unRegisterAction()
}, 150, MILLISECONDS)
}, 1000)
}
} else {
Timber.d("No match for $startedActivity")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,31 @@ package arun.com.chromer.browsing.shareintercept

import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.Intent
import android.content.Intent.*
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import arun.com.chromer.R
import arun.com.chromer.data.website.model.Website
import arun.com.chromer.di.activity.ActivityComponent
import arun.com.chromer.shared.Constants
import arun.com.chromer.search.provider.SearchProviders
import arun.com.chromer.shared.base.activity.BaseActivity
import arun.com.chromer.tabs.TabsManager
import arun.com.chromer.util.SafeIntent
import arun.com.chromer.util.Utils
import io.reactivex.rxkotlin.subscribeBy
import timber.log.Timber
import javax.inject.Inject

@SuppressLint("GoogleAppIndexingApiWarning")
class ShareInterceptActivity : BaseActivity() {

override fun getLayoutRes() = 0

@Inject
lateinit var tabsManager: TabsManager
@Inject
lateinit var searchProviders: SearchProviders

@TargetApi(Build.VERSION_CODES.M)
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -49,12 +55,14 @@ class ShareInterceptActivity : BaseActivity() {
val action = safeIntent.action
var text: String? = null
when (action) {
Intent.ACTION_SEND -> if (safeIntent.hasExtra(Intent.EXTRA_TEXT)) {
text = intent.extras?.getCharSequence(Intent.EXTRA_TEXT)?.toString()
ACTION_SEND -> if (safeIntent.hasExtra(EXTRA_TEXT)) {
text = intent.extras?.getCharSequence(EXTRA_TEXT)?.toString()
}
Intent.ACTION_PROCESS_TEXT -> text = safeIntent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)
ACTION_PROCESS_TEXT -> text = safeIntent.getStringExtra(EXTRA_PROCESS_TEXT)
}
if (text?.isNotEmpty() == true) {
findAndOpenLink(text)
}
findAndOpenLink(text)
} catch (exception: Exception) {
invalidLink()
} finally {
Expand All @@ -66,27 +74,29 @@ class ShareInterceptActivity : BaseActivity() {
activityComponent.inject(this)
}

override fun getLayoutRes(): Int = 0


private fun findAndOpenLink(receivedText: String?) {
var text: String? = receivedText ?: return
val urls = Utils.findURLs(text)
if (!urls.isEmpty()) {
@SuppressLint("CheckResult")
private fun findAndOpenLink(receivedText: String) {
val urls = Utils.findURLs(receivedText)
if (urls.isNotEmpty()) {
// use only the first link
val url = urls[0]
openLink(url)
} else {
// No urls were found, so lets do a google search with the text received.
text = Constants.G_SEARCH_URL + text!!.replace(" ", "+")
openLink(text)
searchProviders.selectedProvider
.firstOrError()
.map { it.getSearchUrl(receivedText) }
.subscribeBy(
onSuccess = ::openLink,
onError = Timber::e
)
}
}

private fun openLink(url: String?) {
if (url != null) {
tabsManager.openUrl(this, website = Website(url))
} else invalidLink()
when (url) {
null -> invalidLink()
else -> tabsManager.openUrl(this, website = Website(url))
}
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import arun.com.chromer.data.website.model.Website
import arun.com.chromer.extenstions.StringResource
import arun.com.chromer.extenstions.appName
import arun.com.chromer.home.epoxycontroller.model.CustomTabProviderInfo
import arun.com.chromer.settings.Preferences
import arun.com.chromer.settings.RxPreferences
import arun.com.chromer.shared.Constants
import arun.com.chromer.util.glide.appicon.ApplicationIcon
Expand All @@ -27,7 +28,8 @@ constructor(
private val application: Application,
private val rxPreferences: RxPreferences,
private val schedulerProvider: SchedulerProvider,
private val historyRepository: HistoryRepository
private val historyRepository: HistoryRepository,
private val preferences: Preferences
) : RxViewModel() {

val providerInfoLiveData = MutableLiveData<CustomTabProviderInfo>()
Expand All @@ -51,7 +53,12 @@ constructor(

private fun bindProviderInfo() {
Observable.combineLatest(
rxPreferences.customTabProviderPref.observe(),
rxPreferences.customTabProviderPref.observe().map { packageName ->
when {
packageName.isEmpty() -> preferences.defaultCustomTabApp ?: ""
else -> packageName
}
},
rxPreferences.incognitoPref.observe(),
rxPreferences.webviewPref.observe(),
Function3 { customTabProvider: String, isIncognito: Boolean, isWebView: Boolean ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package arun.com.chromer.home

import androidx.lifecycle.LifecycleOwner
import arun.com.chromer.data.website.WebsiteRepository
import arun.com.chromer.di.scopes.PerActivity
import arun.com.chromer.tabs.TabsManager
import arun.com.chromer.util.lifecycle.ActivityLifecycle
import arun.com.chromer.util.lifecycle.LifecycleEvents
import dev.arunkumar.android.rxschedulers.SchedulerProvider
import hu.akarnokd.rxjava.interop.RxJavaInterop
import hu.akarnokd.rxjava.interop.RxJavaInterop.toV2Observable
import hu.akarnokd.rxjava.interop.RxJavaInterop.toV2Single
import io.reactivex.Observable
import io.reactivex.rxkotlin.toObservable
import java.util.concurrent.TimeUnit
import javax.inject.Inject

Expand All @@ -18,14 +21,28 @@ constructor(
@ActivityLifecycle
lifecycleOwner: LifecycleOwner,
private val tabsManager: TabsManager,
private val schedulerProvider: SchedulerProvider
private val schedulerProvider: SchedulerProvider,
private val websiteRepository: WebsiteRepository
) : LifecycleEvents(lifecycleOwner) {
fun activeTabs(): Observable<List<TabsManager.Tab>> = starts.flatMap {
Observable.interval(750, TimeUnit.MILLISECONDS)
.flatMapSingle {
RxJavaInterop.toV2Single(tabsManager.getActiveTabs())
}.startWith(RxJavaInterop.toV2Single(tabsManager.getActiveTabs()).toObservable())
.flatMapSingle { toV2Single(tabsManager.getActiveTabs()) }
.startWith(toV2Single(tabsManager.getActiveTabs()).toObservable())
.distinctUntilChanged()
.switchMap { tabs ->
tabs.toObservable()
.flatMap { tab ->
toV2Observable(websiteRepository.getWebsiteReadOnly(tab.url)
.map { website -> tab.copy(website = website) })
.sorted { o1, o2 ->
val createdAt = o1.website?.createdAt ?: 0
val createdAt2 = o2.website?.createdAt ?: 0
createdAt.compareTo(createdAt2)
}
}.toList()
.toObservable()
.startWith(tabs)
}
.takeUntil(stops)
.compose(schedulerProvider.poolToUi())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package arun.com.chromer.home.epoxycontroller.model

import arun.com.chromer.R
import arun.com.chromer.data.website.model.Website
import arun.com.chromer.tabs.TabsManager
import arun.com.chromer.util.glide.GlideApp
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import dev.arunkumar.android.epoxy.model.KotlinEpoxyModelWithHolder
import dev.arunkumar.android.epoxy.model.KotlinHolder
import kotlinx.android.synthetic.main.widget_tab_model_preview.*

@EpoxyModelClass(layout = R.layout.widget_tab_model_preview)
abstract class TabModel : KotlinEpoxyModelWithHolder<TabModel.ViewHolder>() {
@EpoxyAttribute
lateinit var tab: TabsManager.Tab

override fun bind(holder: ViewHolder) {
super.bind(holder)
GlideApp.with(holder.containerView.context)
.load(tab.website ?: Website(tab.url))
.circleCrop()
.into(holder.icon)
}

class ViewHolder : KotlinHolder()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package arun.com.chromer.home.epoxycontroller.model

import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import arun.com.chromer.R
import arun.com.chromer.extenstions.gone
import arun.com.chromer.extenstions.show
import arun.com.chromer.tabs.TabsManager
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyAttribute.Option.DoNotHash
Expand All @@ -16,7 +21,7 @@ abstract class TabsInfoModel : KotlinEpoxyModelWithHolder<TabsInfoModel.ViewHold
@EpoxyAttribute(DoNotHash)
lateinit var tabsManager: TabsManager

private var revealed = false
private var init = false

override fun bind(holder: ViewHolder) {
super.bind(holder)
Expand All @@ -28,21 +33,30 @@ abstract class TabsInfoModel : KotlinEpoxyModelWithHolder<TabsInfoModel.ViewHold
holder.containerView.setOnClickListener {
tabsManager.showTabsActivity()
}
/*holder.containerView.post {
if (!revealed) {
holder.tabsRevealView.run {
post {
circularRevealWithSelfCenter {
postDelayed(50) {
(holder.containerView as ViewGroup).prepareAutoTransition()
gone()
}
}
if (!init) {
holder.tabsPreviewRecyclerView.apply {
(itemAnimator as? DefaultItemAnimator)?.supportsChangeAnimations = false
layoutManager = LinearLayoutManager(
holder.containerView.context,
RecyclerView.HORIZONTAL,
false
)
}
init = true
}
if (tabs.isEmpty()) {
holder.tabsPreviewRecyclerView.gone()
} else {
holder.tabsPreviewRecyclerView.show()
holder.tabsPreviewRecyclerView.withModels {
tabs.forEach { tab ->
tab {
id(tab.hashCode())
tab(tab)
}
}
revealed = true
}
}*/
}
}

class ViewHolder : KotlinHolder()
Expand Down
Loading

0 comments on commit 1c13984

Please sign in to comment.