Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Close #162: Add FxA pairing integration
- Loading branch information
Showing
12 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/mozilla/reference/browser/AppPermissionCodes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* 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.reference.browser | ||
|
||
object AppPermissionCodes { | ||
const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1 | ||
const val REQUEST_CODE_PROMPT_PERMISSIONS = 2 | ||
const val REQUEST_CODE_APP_PERMISSIONS = 3 | ||
const val REQUEST_CODE_CAMERA_PERMISSIONS = 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/src/main/java/org/mozilla/reference/browser/settings/PairSettingsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* 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.reference.browser.settings | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import mozilla.components.feature.qr.QrFeature | ||
import mozilla.components.support.base.feature.BackHandler | ||
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper | ||
import org.mozilla.reference.browser.AppPermissionCodes.REQUEST_CODE_CAMERA_PERMISSIONS | ||
import org.mozilla.reference.browser.R | ||
import org.mozilla.reference.browser.ext.requireComponents | ||
|
||
class PairSettingsFragment : Fragment(), BackHandler { | ||
private val qrFeature = ViewBoundFeatureWrapper<QrFeature>() | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(R.layout.fragment_pairing, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
qrFeature.set( | ||
feature = QrFeature( | ||
requireContext(), | ||
fragmentManager = fragmentManager!!, | ||
onNeedToRequestPermissions = { permissions -> | ||
requestPermissions(permissions, REQUEST_CODE_CAMERA_PERMISSIONS) | ||
}, | ||
onScanResult = { pairingUrl -> | ||
requireComponents.services.accountsAuthFeature.beginPairingAuthentication(pairingUrl) | ||
activity?.finish() | ||
} | ||
), | ||
owner = this, | ||
view = view | ||
) | ||
|
||
qrFeature.withFeature { | ||
it.scan(R.id.pair_layout) | ||
} | ||
} | ||
|
||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { | ||
when (requestCode) { | ||
REQUEST_CODE_CAMERA_PERMISSIONS -> qrFeature.withFeature { | ||
it.onPermissionsResult(permissions, grantResults) | ||
} | ||
} | ||
} | ||
|
||
override fun onBackPressed(): Boolean { | ||
qrFeature.onBackPressed() | ||
fragmentManager?.popBackStack() | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- 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/. --> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<RelativeLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/pair_layout" /> | ||
|
||
<TextView | ||
android:id="@+id/text_view_id" | ||
android:layout_height="wrap_content" | ||
android:layout_width="wrap_content" | ||
android:text="@string/pair_instructions" | ||
android:textSize="20sp" | ||
android:gravity="center" | ||
android:textColor="@color/photonWhite" /> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters