Skip to content

Commit

Permalink
Refactor CustomBridgesActivity to a fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
meenbeese committed Nov 20, 2024
1 parent aa9e1ad commit 50618ba
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 31 deletions.
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@
android:value=".OrbotActivity"/>
</activity>

<activity
android:name=".ui.onboarding.CustomBridgesActivity"
android:label="@string/use_custom_bridges" />

<provider
android:name=".ui.v3onionservice.OnionServiceContentProvider"
android:authorities="${applicationId}.ui.v3onionservice"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package org.torproject.android.ui.onboarding

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.TextView

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment

import com.google.zxing.integration.android.IntentIntegrator

Expand All @@ -31,31 +34,32 @@ import java.net.URLDecoder
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

class CustomBridgesActivity : AppCompatActivity(), TextWatcher {
class CustomBridgesFragment : Fragment(), TextWatcher {
private var mEtPastedBridges: EditText? = null

@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_custom_bridges)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_custom_bridges, container, false)

val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
val toolbar = view.findViewById<Toolbar>(R.id.toolbar)
toolbar.setNavigationOnClickListener { activity?.onBackPressed() }

supportActionBar?.setDisplayHomeAsUpEnabled(true)
view.findViewById<TextView>(R.id.tvDescription).text = getString(R.string.in_a_browser, URL_TOR_BRIDGES)

findViewById<TextView>(R.id.tvDescription).text = getString(R.string.in_a_browser, URL_TOR_BRIDGES)

findViewById<View>(R.id.btCopyUrl).setOnClickListener {
copyToClipboard("bridge_url", URL_TOR_BRIDGES, getString(R.string.done), this)
view.findViewById<View>(R.id.btCopyUrl).setOnClickListener {
copyToClipboard("bridge_url", URL_TOR_BRIDGES, getString(R.string.done), requireContext())
}

var bridges: String? = Prefs.getBridgesList().trim { it <= ' ' }
if (!Prefs.bridgesEnabled() || userHasSetPreconfiguredBridge(bridges)) {
bridges = null
}

mEtPastedBridges = findViewById(R.id.etPastedBridges)
mEtPastedBridges = view.findViewById(R.id.etPastedBridges)
mEtPastedBridges?.setOnTouchListener { v, event ->
if (v.hasFocus()) {
v.parent.requestDisallowInterceptTouchEvent(true)
Expand All @@ -69,10 +73,10 @@ class CustomBridgesActivity : AppCompatActivity(), TextWatcher {

mEtPastedBridges?.setText(bridges)
mEtPastedBridges?.addTextChangedListener(this)
val integrator = IntentIntegrator(this)
val integrator = IntentIntegrator(requireActivity())

findViewById<View>(R.id.btScanQr).setOnClickListener { integrator.initiateScan() }
findViewById<View>(R.id.btShareQr).setOnClickListener {
view.findViewById<View>(R.id.btScanQr).setOnClickListener { integrator.initiateScan() }
view.findViewById<View>(R.id.btShareQr).setOnClickListener {
Prefs.getBridgesList().takeIf { it.isNotEmpty() }?.let { setBridges ->
try {
integrator.shareText("bridge://${URLEncoder.encode(setBridges, "UTF-8")}")
Expand All @@ -81,7 +85,7 @@ class CustomBridgesActivity : AppCompatActivity(), TextWatcher {
}
}
}
findViewById<View>(R.id.btEmail).setOnClickListener {
view.findViewById<View>(R.id.btEmail).setOnClickListener {
val requestText = "get transport"
val emailUrl = "mailto:${Uri.encode(EMAIL_TOR_BRIDGES)}?subject=${Uri.encode(requestText)}&body=${Uri.encode(requestText)}"
val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.parse(emailUrl)).apply {
Expand All @@ -90,11 +94,13 @@ class CustomBridgesActivity : AppCompatActivity(), TextWatcher {
}
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email)))
}

return view
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
activity?.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down Expand Up @@ -124,7 +130,7 @@ class CustomBridgesActivity : AppCompatActivity(), TextWatcher {
Log.e(javaClass.simpleName, "unsupported", e)
}
}
setResult(RESULT_OK)
activity?.setResult(Activity.RESULT_OK)
}
}

Expand All @@ -146,9 +152,9 @@ class CustomBridgesActivity : AppCompatActivity(), TextWatcher {
Prefs.setBridgesList(trimmedBridges)
Prefs.putBridgesEnabled(trimmedBridges != null)

Intent(this, OrbotService::class.java).apply {
Intent(requireContext(), OrbotService::class.java).apply {
action = TorControlCommands.SIGNAL_RELOAD
startService(this)
requireContext().startService(this)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_purple"
tools:context=".ui.onboarding.CustomBridgesActivity">
tools:context=".ui.onboarding.CustomBridgesFragment">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-guc/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<string name="request_bridges_from_torproject">püchunta sülatia sünainje torproject.org</string>
<string name="custom_bridges">sülatia wanewaii</string>
<string name="configure_custom_bridges">sükümajia sülatia wanewaii</string>
<!--CustomBridgesActivity-->
<!--CustomBridgesFragment-->
<string name="use_custom_bridges">paapa tü sülatiakat wanewai</string>
<string name="in_a_browser">sünain wane navegador , pünala%sy toque \"einjatüin sülatia\"&gt;\"¡shiyane papüinjatka sülatia!\"</string>
<string name="paste_bridges">pü´ntirera sülatia</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-gum/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Trek tamaramikwane asha mar</string>
<string name="request_bridges_from_torproject">torproject.org piuntsik teilkan miamik</string>
<string name="custom_bridges">Neteelɵ Piuntsikmera </string>
<string name="configure_custom_bridges">Na isuikmei piuntsik teiklan tamaramik</string>
<!--CustomBridgesActivity-->
<!--CustomBridgesFragment-->
<string name="use_custom_bridges">Piuntsikmera teiklan naaship tamara pɵnsramik</string>
<string name="in_a_browser">Kan wampirishipiku, \"piuntsikmera\" chipiku kepintrɵ %s&gt; \"piuntsikmerantɵ trantra!\"</string>
<string name="paste_bridges">Pasta piuntsik teiklɵ</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nah/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ atl oquitlapatic</string>
<string name="request_bridges_from_torproject">Ipan torprojet.org xictlani in cuauhpanco</string>
<string name="custom_bridges">Neuhyantica cuauhpanco</string>
<string name="configure_custom_bridges">Quitlayocoya neuhyantica cuauhpanco</string>
<!--CustomBridgesActivity-->
<!--CustomBridgesFragment-->
<string name="use_custom_bridges">Xicchihua neuhyantica cuauhpanco</string>
<string name="in_a_browser">Ipan ce panoliztli, quitetlapalo %s ihuan xicmahpilhuia \"Quipia cuauhpanco\" &gt; \"¡ Zan xinechnamaca cuauhpanco!\" </string>
<string name="paste_bridges">Quitzaloa in cuauhpanco</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pbb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Notificaciones ampliadas</string>
<string name="request_bridges_from_torproject">Wehtxi’ ayte mpẽhy torproject.org </string>
<string name="custom_bridges">Idx weh.</string>
<string name="configure_custom_bridges">Idx wehtx Mphuse\'j</string>
<!--CustomBridgesActivity-->
<!--CustomBridgesFragment-->
<string name="use_custom_bridges">Idx wehtx miikseelpi’j </string>
<string name="in_a_browser">Internette pakwenxite, na’s %s mtheg jĩiçxa ayte miikxtheth \"weh muy\" &gt; \"¡wehçxaatx mah!\"</string>
<string name="paste_bridges">Wehtx miikne’ta’j</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<string name="request_bridges_from_torproject">Request Bridges from torproject.org</string>
<string name="custom_bridges">Custom Bridges</string>
<string name="configure_custom_bridges">Configure Custom Bridges</string>
<!-- CustomBridgesActivity -->
<!-- CustomBridgesFragment -->
<string name="use_custom_bridges">Use Custom Bridges</string>
<string name="in_a_browser">In a browser, visit %s and tap "Get Bridges" &gt; "Just Give Me Bridges!"</string>
<string name="paste_bridges">Paste Bridges</string>
Expand Down

0 comments on commit 50618ba

Please sign in to comment.