[fenix] For https://github.com/mozilla-mobile/fenix/issues/2327: Adds error state syncing
parent
99c382f52a
commit
957e4c5bbe
@ -0,0 +1,42 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
class AccountPreference : Preference {
|
||||
|
||||
var title: TextView? = null
|
||||
var summary: TextView? = null
|
||||
var errorIcon: ImageView? = null
|
||||
var background: View? = null
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, attributeSetId: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
attributeSetId
|
||||
)
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.account_preference
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
title = holder.findViewById(R.id.title) as TextView
|
||||
summary = holder.findViewById(R.id.summary) as TextView
|
||||
errorIcon = holder.findViewById(R.id.error_icon) as ImageView
|
||||
background = holder.itemView
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.Navigation
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
|
||||
class SyncProblemFragment : PreferenceFragmentCompat() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
(activity as AppCompatActivity).title = getString(R.string.sync_reconnect)
|
||||
(activity as AppCompatActivity).supportActionBar?.show()
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.sync_problem, rootKey)
|
||||
|
||||
val preferenceSignIn =
|
||||
findPreference<Preference>(context!!.getPreferenceKey(R.string.pref_key_sync_sign_in))
|
||||
val preferenceNewAccount =
|
||||
findPreference<Preference>(context!!.getPreferenceKey(R.string.pref_key_sync_create_account))
|
||||
val preferencePairSignIn =
|
||||
findPreference<Preference>(context!!.getPreferenceKey(R.string.pref_key_sync_pair))
|
||||
preferenceSignIn?.onPreferenceClickListener = getClickListenerForSignIn()
|
||||
preferenceNewAccount?.onPreferenceClickListener = getClickListenerForSignIn()
|
||||
preferencePairSignIn?.onPreferenceClickListener = getClickListenerForPairing()
|
||||
}
|
||||
|
||||
private fun getClickListenerForSignIn(): Preference.OnPreferenceClickListener {
|
||||
return Preference.OnPreferenceClickListener {
|
||||
requireComponents.services.accountsAuthFeature.beginAuthentication()
|
||||
// TODO The sign-in web content populates session history,
|
||||
// so pressing "back" after signing in won't take us back into the settings screen, but rather up the
|
||||
// session history stack.
|
||||
// We could auto-close this tab once we get to the end of the authentication process?
|
||||
// Via an interceptor, perhaps.
|
||||
view?.let {
|
||||
(activity as HomeActivity).openToBrowser(BrowserDirection.FromSyncProblem)
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun getClickListenerForPairing(): Preference.OnPreferenceClickListener {
|
||||
return Preference.OnPreferenceClickListener {
|
||||
val directions = TurnOnSyncFragmentDirections.actionTurnOnSyncFragmentToPairInstructionsFragment()
|
||||
Navigation.findNavController(view!!).navigate(directions)
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M15.853,11.045c0.255,-0.545 0.397,-1.153 0.397,-1.795C16.25,6.903 14.347,5 12,5S7.75,6.903 7.75,9.25 9.653,13.5 12,13.5c1.418,0 2.674,-0.694 3.446,-1.762l-1.24,2.48c-0.71,0.296 -1.453,0.582 -2.206,0.582 -2.132,0 -4.185,-2.3 -5.666,-0.59 -0.42,0.484 -0.454,1.19 -0.094,1.718 1.224,1.801 3.25,3.01 5.576,3.07l-0.531,1.063c-0.296,0.597 -0.36,1.271 -0.197,1.898C5.992,21.499 2,17.215 2,12 2,6.477 6.477,2 12,2s10,4.477 10,10c0,0.735 -0.08,1.452 -0.232,2.142l-1.331,-2.635C19.98,10.587 19.034,10 17.999,10c-0.848,0 -1.635,0.393 -2.146,1.045zM23.864,20.508c0.273,0.549 0.234,1.201 -0.103,1.714 -0.336,0.512 -0.92,0.808 -1.532,0.776h-8.55c-0.588,-0.016 -1.128,-0.33 -1.432,-0.834 -0.303,-0.505 -0.329,-1.129 -0.068,-1.656l4.275,-8.55c0.292,-0.587 0.89,-0.958 1.545,-0.958 0.655,0 1.254,0.371 1.545,0.958l4.32,8.55zM17.189,14.838v2.595c0.057,0.432 0.426,0.756 0.863,0.756 0.436,0 0.805,-0.324 0.862,-0.756v-2.595c0.045,-0.336 -0.11,-0.666 -0.395,-0.848 -0.285,-0.182 -0.65,-0.182 -0.935,0 -0.285,0.182 -0.44,0.512 -0.395,0.848zM19.064,20.013c0,-0.413 -0.248,-0.785 -0.63,-0.943 -0.38,-0.157 -0.82,-0.07 -1.111,0.222 -0.292,0.291 -0.379,0.73 -0.221,1.111s0.53,0.63 0.942,0.63c0.564,0 1.02,-0.457 1.02,-1.02z"
|
||||
android:fillColor="@color/sync_error_text_color"/>
|
||||
</vector>
|
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M12,2C6.477,2 2,6.477 2,12s4.477,10 10,10 10,-4.477 10,-10c-0.006,-5.52 -4.48,-9.994 -10,-10zM12,20c-4.418,0 -8,-3.582 -8,-8s3.582,-8 8,-8 8,3.582 8,8c-0.005,4.416 -3.584,7.995 -8,8zM12,13c0.552,0 1,-0.448 1,-1L13,8c0,-0.552 -0.448,-1 -1,-1s-1,0.448 -1,1v4c0,0.552 0.448,1 1,1zM12,17c0.552,0 1,-0.448 1,-1s-0.448,-1 -1,-1 -1,0.448 -1,1 0.448,1 1,1z"
|
||||
android:fillColor="@color/sync_error_text_color"/>
|
||||
</vector>
|
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/account_preference_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:foreground="?android:attr/selectableItemBackground">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/icon_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<androidx.preference.internal.PreferenceImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:maxWidth="48dp"
|
||||
app:maxHeight="48dp"/>
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?primaryText"
|
||||
android:singleLine="true"
|
||||
android:textSize="16sp"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView android:id="@+id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/title"
|
||||
android:layout_alignStart="@id/title"
|
||||
android:textColor="?primaryText"
|
||||
android:text="@string/preferences_account_default_name"
|
||||
android:maxLines="4"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout android:id="@android:id/widget_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/error_icon"
|
||||
android:src="@drawable/ic_alert"
|
||||
android:padding="16dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<androidx.preference.Preference
|
||||
android:key="@string/pref_key_sync_sign_in"
|
||||
android:title="@string/preferences_sync_sign_in_to_reconnect"
|
||||
android:icon="@drawable/ic_sign_in" />
|
||||
<androidx.preference.Preference
|
||||
android:key="@string/pref_key_sign_out"
|
||||
android:title="@string/preferences_sync_remove_account"/>
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue