Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Cn beta rxu #1080

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ open class SettingAction(
data class UnlockWithFingerprint(val unlockWithFingerprint: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_fingerprint, unlockWithFingerprint.toString())
data class UnlockWithFingerprintPendingAuth(val unlockWithFingerprintPendingAuth: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_fingerprint_pending_auth, unlockWithFingerprintPendingAuth.toString())
data class SendUsageData(val sendUsageData: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_record_usage_data, null)
data class UseLocalService(val useLocalService: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_use_local_service, null)
data class ItemListSortOrder(val sortOrder: Setting.ItemListSort) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_item_list_order, null)
data class AutoLockTime(val time: Setting.AutoLockTime) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_autolock_time, time.seconds.toString())
data class Autofill(val enable: Boolean) : SettingAction(TelemetryEventMethod.setting_changed, TelemetryEventObject.settings_autofill, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ enum class TelemetryEventObject {
settings_autolock,
settings_reset,
settings_record_usage_data,
settings_use_local_service,
settings_account,
settings_faq,
settings_provide_feedback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class AppRoutePresenter(
R.id.fragment_welcome to R.id.fragment_fxa_login -> R.id.action_welcome_to_fxaLogin
R.id.fragment_welcome to R.id.fragment_item_list -> R.id.action_welcome_to_autoLogin
R.id.fragment_welcome to R.id.fragment_webview -> R.id.action_welcome_to_faq
R.id.fragment_welcome to R.id.fragment_setting -> R.id.action_welcome_to_settings

R.id.fragment_fxa_login to R.id.fragment_item_list -> R.id.action_fxaLogin_to_itemList
R.id.fragment_fxa_login to R.id.fragment_fingerprint_onboarding -> R.id.action_fxaLogin_to_fingerprint_onboarding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.reactivex.Observable
import io.reactivex.functions.Consumer
import io.reactivex.rxkotlin.Observables
import io.reactivex.rxkotlin.addTo
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.lockbox.BuildConfig
import mozilla.lockbox.R
import mozilla.lockbox.action.AppWebPageAction
Expand All @@ -27,6 +28,7 @@ import mozilla.lockbox.adapter.TextSettingConfiguration
import mozilla.lockbox.adapter.ToggleSettingConfiguration
import mozilla.lockbox.flux.Dispatcher
import mozilla.lockbox.flux.Presenter
import mozilla.lockbox.store.AccountStore
import mozilla.lockbox.store.FingerprintStore
import mozilla.lockbox.store.SettingStore

Expand All @@ -37,9 +39,12 @@ interface SettingView {
)
}

@ExperimentalCoroutinesApi
class SettingPresenter(
val view: SettingView,
val chinaBuild: Boolean,
private val dispatcher: Dispatcher = Dispatcher.shared,
private val accountStore: AccountStore = AccountStore.shared,
private val settingStore: SettingStore = SettingStore.shared,
private val fingerprintStore: FingerprintStore = FingerprintStore.shared
) : Presenter() {
Expand Down Expand Up @@ -83,6 +88,11 @@ class SettingPresenter(
dispatcher.dispatch(SettingAction.SendUsageData(newValue))
}

private val useLocalServiceObserver: Consumer<Boolean>
get() = Consumer { newValue ->
dispatcher.dispatch((SettingAction.UseLocalService(newValue)))
}

private val learnMoreSendUsageDataObserver: Consumer<Unit>
get() = Consumer {
dispatcher.dispatch(AppWebPageAction.Privacy)
Expand Down Expand Up @@ -163,11 +173,31 @@ class SettingPresenter(
)
)

val serviceSettings = listOf(
ToggleSettingConfiguration(
title = R.string.use_local_service,
contentDescription = R.string.use_local_service_description,
toggleDriver = settingStore.useLocalService,
toggleObserver = useLocalServiceObserver
)
)
val sections = listOf(
SectionedAdapter.Section(0, R.string.configuration_title),
SectionedAdapter.Section(configurationSettings.size, R.string.support_title)
)
val sectionsSync = listOf(
SectionedAdapter.Section(0, R.string.service_title),
SectionedAdapter.Section(serviceSettings.size, R.string.support_title)
)

view.updateSettingList(configurationSettings + supportSettings, sections)
if (chinaBuild) {
if (accountStore.checkAccountExisting()) {
view.updateSettingList(configurationSettings + supportSettings, sections)
} else {
view.updateSettingList(serviceSettings + supportSettings, sectionsSync)
}
} else {
view.updateSettingList(configurationSettings + supportSettings, sections)
}
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/mozilla/lockbox/presenter/WelcomePresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ interface WelcomeView {
val getStartedAutomaticallyClicks: Observable<Unit>
val getStartedManuallyClicks: Observable<Unit>
val learnMoreClicks: Observable<Unit>
val switchServiceClicks: Observable<Unit>
fun hideSwitchService()
fun showExistingAccount(email: String)
fun hideExistingAccount()
}

@ExperimentalCoroutinesApi
class WelcomePresenter(
private val view: WelcomeView,
private val chinaBuild: Boolean,
private val dispatcher: Dispatcher = Dispatcher.shared,
private val accountStore: AccountStore = AccountStore.shared,
private val fingerprintStore: FingerprintStore = FingerprintStore.shared
Expand All @@ -51,6 +54,10 @@ class WelcomePresenter(
view.hideExistingAccount()
}

if (!chinaBuild) {
view.hideSwitchService()
}

view.getStartedManuallyClicks
.map {
routeToLoginManually()
Expand All @@ -63,6 +70,13 @@ class WelcomePresenter(
dispatcher.dispatch(AppWebPageAction.FaqWelcome)
}
.addTo(compositeDisposable)

view.switchServiceClicks
.map {
RouteAction.SettingList
}
.subscribe(dispatcher::dispatch)
.addTo(compositeDisposable)
}

private fun routeToExistingAccount(account: ShareableAccount) =
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/java/mozilla/lockbox/store/AccountStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import kotlin.coroutines.CoroutineContext
@ExperimentalCoroutinesApi
open class AccountStore(
private val lifecycleStore: LifecycleStore = LifecycleStore.shared,
private val settingStore: SettingStore = SettingStore.shared,
private val dispatcher: Dispatcher = Dispatcher.shared,
private val securePreferences: SecurePreferences = SecurePreferences.shared,
private val timingSupport: SystemTimingSupport = DeviceSystemTimingSupport.shared
Expand Down Expand Up @@ -142,6 +143,9 @@ open class AccountStore(
this.context = context
}

fun checkAccountExisting(): Boolean {
return (storedAccountJSON != null)
}
fun shareableAccount(): ShareableAccount? {
return AccountSharing.queryShareableAccounts(context).firstOrNull()
}
Expand Down Expand Up @@ -266,9 +270,17 @@ open class AccountStore(

private fun generateNewFirefoxAccount() {
try {
val config = ServerConfig.release(Constant.FxA.clientID, Constant.FxA.redirectUri)
fxa = FirefoxAccount(config)
generateLoginURL()
settingStore.useLocalService.subscribe {
val config: ServerConfig
if (it)
config = ServerConfig("https://accounts.firefox.com.cn", Constant.FxA.clientID, Constant.FxA.redirectUri)
else
config = ServerConfig.release(Constant.FxA.clientID, Constant.FxA.redirectUri)

fxa = FirefoxAccount(config)
generateLoginURL()
}
.addTo(compositeDisposable)
} catch (e: FxaException) {
this.pushError(e)
}
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/mozilla/lockbox/store/SettingStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ open class SettingStore(
const val AUTO_LOCK_TIME = "auto_lock_time"
const val DEVICE_SECURITY_PRESENT = "device_security_present"
const val UNLOCK_WITH_FINGERPRINT_PENDING_AUTH = "unlock_with_fingerprint_pending_auth"
const val USE_LOCAL_SERVICE = "use_local_service"
}

private lateinit var preferences: SharedPreferences
Expand All @@ -53,6 +54,7 @@ open class SettingStore(
private val _autoLockTime = ReplaySubject.createWithSize<Setting.AutoLockTime>(1)

open val sendUsageData: Observable<Boolean> = ReplaySubject.createWithSize(1)
open val useLocalService: Observable<Boolean> = ReplaySubject.createWithSize(1)
open val itemListSortOrder: Observable<Setting.ItemListSort> = ReplaySubject.createWithSize(1)
open val unlockWithFingerprint: Observable<Boolean> = ReplaySubject.createWithSize(1)
open val autoLockTime: Observable<Setting.AutoLockTime>
Expand Down Expand Up @@ -86,6 +88,8 @@ open class SettingStore(
when (it) {
is SettingAction.SendUsageData ->
edit.putBoolean(Keys.SEND_USAGE_DATA, it.sendUsageData)
is SettingAction.UseLocalService ->
edit.putBoolean(Keys.USE_LOCAL_SERVICE, it.useLocalService)
is SettingAction.ItemListSortOrder ->
edit.putString(Keys.ITEM_LIST_SORT_ORDER, it.sortOrder.name)
is SettingAction.UnlockWithFingerprint ->
Expand All @@ -98,6 +102,7 @@ open class SettingStore(
handleAutofill(it.enable)
is SettingAction.Reset -> {
edit.putBoolean(Keys.SEND_USAGE_DATA, Constant.SettingDefault.sendUsageData)
edit.putBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceFalse)
edit.putString(Keys.ITEM_LIST_SORT_ORDER, Constant.SettingDefault.itemListSort.name)
edit.putBoolean(Keys.UNLOCK_WITH_FINGERPRINT, Constant.SettingDefault.unlockWithFingerprint)
edit.putString(Keys.AUTO_LOCK_TIME, Constant.SettingDefault.autoLockTime.name)
Expand All @@ -110,7 +115,15 @@ open class SettingStore(
}

override fun injectContext(context: Context) {
val chinaBuild = context.resources.configuration.locales.get(0).toString().equals("zh_CN_#Hans") &&
context.resources.configuration.locales.get(0).displayLanguage.equals("中文") &&
(!"com.android.vending".equals(context.packageManager.getInstallerPackageName(context.packageName)))
preferences = PreferenceManager.getDefaultSharedPreferences(context)
if (chinaBuild) {
preferences.edit().putBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceTrue).apply()
} else {
preferences.edit().putBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceFalse).apply()
}

val rxPrefs = RxSharedPreferences.create(preferences)

Expand All @@ -119,6 +132,18 @@ open class SettingStore(
.asObservable()
.subscribe(sendUsageData as Subject)

if (chinaBuild) {
rxPrefs
.getBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceTrue)
.asObservable()
.subscribe(useLocalService as Subject)
} else {
rxPrefs
.getBoolean(Keys.USE_LOCAL_SERVICE, Constant.SettingDefault.useLocalServiceFalse)
.asObservable()
.subscribe(useLocalService as Subject)
}

rxPrefs
.getString(Keys.ITEM_LIST_SORT_ORDER, Constant.SettingDefault.itemListSort.name)
.asObservable()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/mozilla/lockbox/support/Constant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ object Constant {
val autoLockTime = Setting.AutoLockTime.FiveMinutes
val noSecurityAutoLockTime = Setting.AutoLockTime.Never
const val sendUsageData = true
const val useLocalServiceFalse = false
const val useLocalServiceTrue = true
const val unlockWithFingerprint = false
}

Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/mozilla/lockbox/view/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.view.ViewGroup
import com.github.magiepooh.recycleritemdecoration.ItemDecorations
import kotlinx.android.synthetic.main.fragment_setting.view.*
import kotlinx.android.synthetic.main.list_cell_setting_toggle.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.lockbox.R
import mozilla.lockbox.adapter.SectionedAdapter
import mozilla.lockbox.adapter.SettingCellConfiguration
Expand All @@ -24,6 +25,7 @@ import mozilla.lockbox.adapter.SettingListAdapter.Companion.SETTING_TOGGLE_TYPE
import mozilla.lockbox.presenter.SettingPresenter
import mozilla.lockbox.presenter.SettingView

@ExperimentalCoroutinesApi
class SettingFragment : BackableFragment(), SettingView {

private val adapter = SettingListAdapter()
Expand All @@ -39,7 +41,10 @@ class SettingFragment : BackableFragment(), SettingView {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
presenter = SettingPresenter(this)
val chinaBuild = resources.configuration.locales.get(0).toString().equals("zh_CN_#Hans") &&
resources.configuration.locales.get(0).displayLanguage.equals("中文") &&
(!"com.android.vending".equals(context!!.packageManager.getInstallerPackageName(context!!.packageName)))
presenter = SettingPresenter(this, chinaBuild)

// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_setting, container, false)
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/mozilla/lockbox/view/WelcomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class WelcomeFragment : Fragment(), WelcomeView {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
presenter = WelcomePresenter(this)
val chinaBuild = resources.configuration.locales.get(0).toString().equals("zh_CN_#Hans") &&
resources.configuration.locales.get(0).displayLanguage.equals("中文") &&
(!"com.android.vending".equals(context!!.packageManager.getInstallerPackageName(context!!.packageName)))
presenter = WelcomePresenter(this, chinaBuild)
val view = inflater.inflate(R.layout.fragment_welcome, container, false)
val appLabel = getString(R.string.app_label)
view.textViewInstructions.text = getString(R.string.welcome_instructions, appLabel)
Expand Down Expand Up @@ -53,6 +56,12 @@ class WelcomeFragment : Fragment(), WelcomeView {
}
}

override fun hideSwitchService() {
view?.apply {
textViewSwitchService.visibility = View.GONE
}
}

override val getStartedAutomaticallyClicks: Observable<Unit>
get() = view!!.buttonGetStarted.clicks()

Expand All @@ -61,4 +70,7 @@ class WelcomeFragment : Fragment(), WelcomeView {

override val learnMoreClicks: Observable<Unit>
get() = view!!.textViewLearnMore.clicks()

override val switchServiceClicks: Observable<Unit>
get() = view!!.textViewSwitchService.clicks()
}
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_welcome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,21 @@
android:letterSpacing="0.04"
android:layout_gravity="center"
/>

<TextView
android:id="@+id/textViewSwitchService"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/welcome_switch_service_btn"
android:textStyle="bold"
android:textAllCaps="true"
android:background="@android:color/transparent"
android:textColor="@color/link_pressed"
android:textSize="12sp"
android:textAlignment="center"
android:letterSpacing="0.04"
android:layout_gravity="center"
/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/navigation/graph_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<action
android:id="@+id/action_welcome_to_fxaLogin"
app:destination="@id/fragment_fxa_login"/>
<action
android:id="@+id/action_welcome_to_settings"
app:destination="@id/fragment_setting"/>
<action
android:id="@+id/action_welcome_to_faq"
app:destination="@id/fragment_webview"/>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<!-- This is the link on the first-run welcome screen to learn more about the requirements of the application -->
<string name="welcome_learn_more_btn">Learn More</string>

<string name="welcome_switch_service_btn" tools:ignore = "MissingTranslation">Switch Service</string>
<!-- This is the label used for the title in the web view of the account's authentication instances. -->
<string name="get_started_title">Get Started</string>

Expand Down Expand Up @@ -96,6 +97,7 @@
<!-- This describes an icon to screenreaders that the button tapped will display the password in plain text for immediate reading or use -->
<string name="display_password_content_description">Display your password in plain text</string>

<string name="service_title" tools:ignore= "MissingTranslation">Service</string>
<!-- This is a heading that appears above a group of application settings to configure the user experience -->
<string name="configuration_title">Configuration</string>
<!-- This is a heading that appears above a group of application settings or links related to what is supported by the application -->
Expand Down Expand Up @@ -134,6 +136,8 @@
<!-- This is the sub-title of a setting that allows the user to automatically fill forms in Android applications and websites using username and password data from this application -->
<string name="send_usage_data_summary">Mozilla strives to only collect what we need to provide and improve Firefox for everyone. </string>

<string name="use_local_service" tools:ignore = "MissingTranslation">Use Local Service</string>
<string name="use_local_service_description" tools:ignore = "MissingTranslation">Switch Sync Service</string>
<!-- This is the label a screenreader uses to inform the user they selected a label on the screen that includes the application version number -->
<string name="app_version_description">Application version number</string>

Expand Down
Loading