v1-t
parent
aeb1099fe0
commit
04e67441b3
|
@ -106,7 +106,7 @@ class SettingsRobot {
|
|||
// ABOUT SECTION
|
||||
fun verifyAboutHeading() = assertAboutHeading()
|
||||
|
||||
fun verifyRateOnGooglePlay() = assertTrue(rateOnGooglePlayHeading().waitForExists(waitingTime))
|
||||
// fun verifyRateOnGooglePlay() = assertTrue(rateOnGooglePlayHeading().waitForExists(waitingTime))
|
||||
fun verifyAboutWaterfoxPreview() = assertTrue(aboutWaterfoxHeading().waitForExists(waitingTime))
|
||||
fun verifyGooglePlayRedirect() = assertGooglePlayRedirect()
|
||||
|
||||
|
@ -561,7 +561,7 @@ private fun assertAboutHeading(): ViewInteraction {
|
|||
// settingsList().scrollToEnd(LISTS_MAXSWIPES)
|
||||
// rateOnGooglePlay.waitForExists(waitingTime)
|
||||
|
||||
return rateOnGooglePlay//
|
||||
// return rateOnGooglePlay//
|
||||
//}
|
||||
|
||||
private fun aboutWaterfoxHeading(): UiObject {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package net.waterfox.android
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import net.waterfox.android.network.OkHttpClientProvider
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
// Beispiel-URL, die abgefragt wird
|
||||
val url = "https://detectportal.firefox.com" // Dies wird blockiert
|
||||
|
||||
// Anfrage senden
|
||||
val response = OkHttpClientProvider.makeRequest(url)
|
||||
|
||||
// Antwort anzeigen
|
||||
Toast.makeText(this, "Antwort: $response", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package net.waterfox.android.network
|
||||
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import java.io.IOException
|
||||
|
||||
object OkHttpClientProvider {
|
||||
|
||||
// Interceptor, der Domains blockiert
|
||||
private val blockDomainInterceptor = Interceptor { chain ->
|
||||
val request = chain.request()
|
||||
|
||||
// Logge die URL der Anfrage
|
||||
println("Intercepting request to: ${request.url.host}")
|
||||
|
||||
// Hier kannst du Domains definieren, die blockiert werden sollen
|
||||
val blockedDomains = listOf("detectportal.firefox.com", "content-signature-2.cdn.mozilla.net")
|
||||
|
||||
// Logge, ob die Domain blockiert werden soll
|
||||
if (blockedDomains.any { request.url.host.contains(it) }) {
|
||||
println("BLOCKING DOMAIN: ${request.url.host}")
|
||||
// Wenn die Domain blockiert werden soll, gib eine Fehlerantwort zurück
|
||||
throw IOException("Blocked domain: ${request.url.host}")
|
||||
}
|
||||
|
||||
// Ansonsten fahre mit der Anfrage fort
|
||||
println("Request allowed to proceed: ${request.url.host}")
|
||||
return@Interceptor chain.proceed(request)
|
||||
}
|
||||
|
||||
// Erstelle einen OkHttpClient mit dem BlockDomainInterceptor
|
||||
fun getOkHttpClient(): OkHttpClient {
|
||||
return OkHttpClient.Builder()
|
||||
.addInterceptor(blockDomainInterceptor) // Hier fügen wir den Interceptor hinzu
|
||||
.build()
|
||||
}
|
||||
|
||||
// Beispiel für eine einfache Anfrage
|
||||
fun makeRequest(url: String): String {
|
||||
val client = getOkHttpClient()
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.build()
|
||||
|
||||
return try {
|
||||
// Führe die Anfrage aus
|
||||
val response = client.newCall(request).execute()
|
||||
// Logge die Antwort
|
||||
println("Antwort: ${response.body?.string()}")
|
||||
response.body?.string() ?: "Leere Antwort"
|
||||
} catch (e: Exception) {
|
||||
// Fehlerbehandlung, wenn eine Ausnahme auftritt
|
||||
println("Fehler: ${e.message}")
|
||||
return "Fehler: ${e.message}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package net.waterfox.android.repository
|
||||
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import net.waterfox.android.network.OkHttpClientProvider
|
||||
|
||||
class NetworkRepository {
|
||||
|
||||
// Diese Funktion holt Daten von einer angegebenen URL
|
||||
fun fetchData(url: String): String {
|
||||
try {
|
||||
val client: OkHttpClient = OkHttpClientProvider.getOkHttpClient()
|
||||
val request = Request.Builder().url(url).build()
|
||||
val response: Response = client.newCall(request).execute()
|
||||
|
||||
// Gib den Antworttext zurück
|
||||
return response.body?.string() ?: "No Data"
|
||||
} catch (e: Exception) {
|
||||
return "Fehler: ${e.message}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package net.waterfox.android.viewmodel
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.liveData
|
||||
import net.waterfox.android.repository.NetworkRepository
|
||||
|
||||
class MainViewModel : ViewModel() {
|
||||
|
||||
private val repository = NetworkRepository() // Instanz des Repositories erstellen
|
||||
|
||||
// Funktion, die die LiveData von der Netzwerkanfrage liefert
|
||||
fun fetchData(url: String) = liveData {
|
||||
val data = repository.fetchData(url) // Netzwerkoperation aufrufen
|
||||
emit(data) // LiveData mit dem Ergebnis versorgen
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello, World!"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue