[app] start SwapService when trying to add a swap repo

This commit is contained in:
Torsten Grote
2023-10-13 10:17:48 -03:00
parent e61886c6b6
commit bf557417ab
2 changed files with 24 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
package org.fdroid.fdroid.nearby;
import static org.fdroid.fdroid.views.main.MainActivity.ACTION_REQUEST_SWAP;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
@@ -462,6 +464,10 @@ public class SwapService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent startUiIntent = new Intent(this, SwapWorkflowActivity.class);
if (intent.getData() != null) {
startUiIntent.setData(intent.getData());
startUiIntent.setAction(ACTION_REQUEST_SWAP);
}
startUiIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startUiIntent);
return START_NOT_STICKY;

View File

@@ -1,11 +1,13 @@
package org.fdroid.fdroid.views.repos
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.compose.runtime.collectAsState
import androidx.core.content.ContextCompat
import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
@@ -15,6 +17,7 @@ import org.fdroid.fdroid.FDroidApp
import org.fdroid.fdroid.Preferences
import org.fdroid.fdroid.UpdateService
import org.fdroid.fdroid.compose.ComposeUtils.FDroidContent
import org.fdroid.fdroid.nearby.SwapService
import org.fdroid.fdroid.views.apps.AppListActivity
import org.fdroid.fdroid.views.apps.AppListActivity.EXTRA_REPO_ID
import org.fdroid.repo.AddRepoError
@@ -51,9 +54,7 @@ class AddRepoActivity : ComponentActivity() {
}
AddRepoIntroScreen(
state = state,
onFetchRepo = { url ->
repoManager.fetchRepositoryPreview(url, proxy = NetCipher.getProxy())
},
onFetchRepo = this::onFetchRepo,
onAddRepo = { repoManager.addFetchedRepository() },
onBackClicked = { onBackPressedDispatcher.onBackPressed() },
)
@@ -61,8 +62,7 @@ class AddRepoActivity : ComponentActivity() {
}
addOnNewIntentListener { intent ->
intent.dataString?.let { uri ->
repoManager.abortAddingRepository()
repoManager.fetchRepositoryPreview(uri, proxy = NetCipher.getProxy())
onFetchRepo(uri)
}
}
intent?.let {
@@ -80,4 +80,17 @@ class AddRepoActivity : ComponentActivity() {
super.onDestroy()
if (!isChangingConfigurations) repoManager.abortAddingRepository()
}
private fun onFetchRepo(uriStr: String) {
val uri = Uri.parse(uriStr)
if (repoManager.isSwapUri(uri)) {
val i = Intent(this, SwapService::class.java).apply {
data = uri
}
ContextCompat.startForegroundService(this, i)
} else {
repoManager.abortAddingRepository()
repoManager.fetchRepositoryPreview(uriStr, proxy = NetCipher.getProxy())
}
}
}