turn LocalRepoService Intents into status Intents like other Services
This commit is contained in:
parent
effcf4bfa9
commit
da66949b9e
@ -8,7 +8,6 @@ import android.support.v4.content.LocalBroadcastManager;
|
|||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.views.swap.SwapWorkflowActivity;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -16,11 +15,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.fdroid.fdroid.views.swap.SwapWorkflowActivity.PrepareSwapRepo.EXTRA_TYPE;
|
|
||||||
import static org.fdroid.fdroid.views.swap.SwapWorkflowActivity.PrepareSwapRepo.TYPE_COMPLETE;
|
|
||||||
import static org.fdroid.fdroid.views.swap.SwapWorkflowActivity.PrepareSwapRepo.TYPE_ERROR;
|
|
||||||
import static org.fdroid.fdroid.views.swap.SwapWorkflowActivity.PrepareSwapRepo.TYPE_STATUS;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles setting up and generating the local repo used to swap apps, including
|
* Handles setting up and generating the local repo used to swap apps, including
|
||||||
* the {@code index.jar}, the symlinks to the shared APKs, etc.
|
* the {@code index.jar}, the symlinks to the shared APKs, etc.
|
||||||
@ -35,15 +29,15 @@ import static org.fdroid.fdroid.views.swap.SwapWorkflowActivity.PrepareSwapRepo.
|
|||||||
public class LocalRepoService extends IntentService {
|
public class LocalRepoService extends IntentService {
|
||||||
public static final String TAG = "LocalRepoService";
|
public static final String TAG = "LocalRepoService";
|
||||||
|
|
||||||
public static final String ACTION_PROGRESS = "org.fdroid.fdroid.localrepo.LocalRepoService.action.PROGRESS";
|
|
||||||
public static final String ACTION_COMPLETE = "org.fdroid.fdroid.localrepo.LocalRepoService.action.COMPLETE";
|
|
||||||
public static final String ACTION_ERROR = "org.fdroid.fdroid.localrepo.LocalRepoService.action.ERROR";
|
|
||||||
|
|
||||||
public static final String EXTRA_MESSAGE = "org.fdroid.fdroid.localrepo.LocalRepoService.extra.MESSAGE";
|
|
||||||
|
|
||||||
public static final String ACTION_CREATE = "org.fdroid.fdroid.localrepo.action.CREATE";
|
public static final String ACTION_CREATE = "org.fdroid.fdroid.localrepo.action.CREATE";
|
||||||
public static final String EXTRA_PACKAGE_NAMES = "org.fdroid.fdroid.localrepo.extra.PACKAGE_NAMES";
|
public static final String EXTRA_PACKAGE_NAMES = "org.fdroid.fdroid.localrepo.extra.PACKAGE_NAMES";
|
||||||
|
|
||||||
|
public static final String ACTION_STATUS = "localRepoStatusAction";
|
||||||
|
public static final String EXTRA_STATUS = "localRepoStatusExtra";
|
||||||
|
public static final int STATUS_STARTED = 0;
|
||||||
|
public static final int STATUS_PROGRESS = 1;
|
||||||
|
public static final int STATUS_ERROR = 2;
|
||||||
|
|
||||||
private String[] currentlyProcessedApps = new String[0];
|
private String[] currentlyProcessedApps = new String[0];
|
||||||
|
|
||||||
private GenerateLocalRepoThread thread;
|
private GenerateLocalRepoThread thread;
|
||||||
@ -105,19 +99,19 @@ public class LocalRepoService extends IntentService {
|
|||||||
public static void runProcess(Context context, String[] selectedApps) {
|
public static void runProcess(Context context, String[] selectedApps) {
|
||||||
try {
|
try {
|
||||||
final LocalRepoManager lrm = LocalRepoManager.get(context);
|
final LocalRepoManager lrm = LocalRepoManager.get(context);
|
||||||
broadcast(context, ACTION_PROGRESS, R.string.deleting_repo);
|
broadcast(context, STATUS_PROGRESS, R.string.deleting_repo);
|
||||||
lrm.deleteRepo();
|
lrm.deleteRepo();
|
||||||
for (String app : selectedApps) {
|
for (String app : selectedApps) {
|
||||||
broadcast(context, ACTION_PROGRESS, context.getString(R.string.adding_apks_format, app));
|
broadcast(context, STATUS_PROGRESS, context.getString(R.string.adding_apks_format, app));
|
||||||
lrm.addApp(context, app);
|
lrm.addApp(context, app);
|
||||||
}
|
}
|
||||||
String urlString = Utils.getSharingUri(FDroidApp.repo).toString();
|
String urlString = Utils.getSharingUri(FDroidApp.repo).toString();
|
||||||
lrm.writeIndexPage(urlString);
|
lrm.writeIndexPage(urlString);
|
||||||
broadcast(context, ACTION_PROGRESS, R.string.writing_index_jar);
|
broadcast(context, STATUS_PROGRESS, R.string.writing_index_jar);
|
||||||
lrm.writeIndexJar();
|
lrm.writeIndexJar();
|
||||||
broadcast(context, ACTION_PROGRESS, R.string.linking_apks);
|
broadcast(context, STATUS_PROGRESS, R.string.linking_apks);
|
||||||
lrm.copyApksToRepo();
|
lrm.copyApksToRepo();
|
||||||
broadcast(context, ACTION_PROGRESS, R.string.copying_icons);
|
broadcast(context, STATUS_PROGRESS, R.string.copying_icons);
|
||||||
// run the icon copy without progress, its not a blocker
|
// run the icon copy without progress, its not a blocker
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
@ -127,9 +121,9 @@ public class LocalRepoService extends IntentService {
|
|||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|
||||||
broadcast(context, ACTION_COMPLETE, null);
|
broadcast(context, STATUS_STARTED, null);
|
||||||
} catch (IOException | XmlPullParserException | LocalRepoKeyStore.InitException e) {
|
} catch (IOException | XmlPullParserException | LocalRepoKeyStore.InitException e) {
|
||||||
broadcast(context, ACTION_ERROR, e.getLocalizedMessage());
|
broadcast(context, STATUS_ERROR, e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,30 +131,16 @@ public class LocalRepoService extends IntentService {
|
|||||||
/**
|
/**
|
||||||
* Translate Android style broadcast {@link Intent}s to {@code PrepareSwapRepo}
|
* Translate Android style broadcast {@link Intent}s to {@code PrepareSwapRepo}
|
||||||
*/
|
*/
|
||||||
static void broadcast(Context context, String action, String message) {
|
static void broadcast(Context context, int status, String message) {
|
||||||
Intent intent = new Intent(context, SwapWorkflowActivity.class);
|
Intent intent = new Intent(ACTION_STATUS);
|
||||||
intent.setAction(SwapWorkflowActivity.PrepareSwapRepo.ACTION);
|
intent.putExtra(EXTRA_STATUS, status);
|
||||||
switch (action) {
|
|
||||||
case ACTION_PROGRESS:
|
|
||||||
intent.putExtra(EXTRA_TYPE, TYPE_STATUS);
|
|
||||||
break;
|
|
||||||
case ACTION_COMPLETE:
|
|
||||||
intent.putExtra(EXTRA_TYPE, TYPE_COMPLETE);
|
|
||||||
break;
|
|
||||||
case ACTION_ERROR:
|
|
||||||
intent.putExtra(EXTRA_TYPE, TYPE_ERROR);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("unsupported action");
|
|
||||||
}
|
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
Utils.debugLog(TAG, "Preparing swap: " + message);
|
intent.putExtra(Intent.EXTRA_TEXT, message);
|
||||||
intent.putExtra(EXTRA_MESSAGE, message);
|
|
||||||
}
|
}
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void broadcast(Context context, String action, int resId) {
|
static void broadcast(Context context, int status, int resId) {
|
||||||
broadcast(context, action, context.getString(resId));
|
broadcast(context, status, context.getString(resId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,8 +342,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
localBroadcastManager.registerReceiver(onWifiStateChanged,
|
localBroadcastManager.registerReceiver(onWifiStateChanged,
|
||||||
new IntentFilter(WifiStateChangeService.BROADCAST));
|
new IntentFilter(WifiStateChangeService.BROADCAST));
|
||||||
localBroadcastManager.registerReceiver(prepareSwapReceiver,
|
localBroadcastManager.registerReceiver(localRepoStatus, new IntentFilter(LocalRepoService.ACTION_STATUS));
|
||||||
new IntentFilter(SwapWorkflowActivity.PrepareSwapRepo.ACTION));
|
|
||||||
localBroadcastManager.registerReceiver(repoUpdateReceiver,
|
localBroadcastManager.registerReceiver(repoUpdateReceiver,
|
||||||
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
|
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
|
||||||
localBroadcastManager.registerReceiver(bonjourStatus, new IntentFilter(BonjourManager.ACTION_STATUS));
|
localBroadcastManager.registerReceiver(bonjourStatus, new IntentFilter(BonjourManager.ACTION_STATUS));
|
||||||
@ -361,7 +360,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
localBroadcastManager.unregisterReceiver(onWifiStateChanged);
|
localBroadcastManager.unregisterReceiver(onWifiStateChanged);
|
||||||
localBroadcastManager.unregisterReceiver(prepareSwapReceiver);
|
localBroadcastManager.unregisterReceiver(localRepoStatus);
|
||||||
localBroadcastManager.unregisterReceiver(repoUpdateReceiver);
|
localBroadcastManager.unregisterReceiver(repoUpdateReceiver);
|
||||||
localBroadcastManager.unregisterReceiver(bonjourStatus);
|
localBroadcastManager.unregisterReceiver(bonjourStatus);
|
||||||
}
|
}
|
||||||
@ -777,15 +776,6 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
service.getBluetoothSwap().startInBackground(); // TODO replace with Intent to SwapService
|
service.getBluetoothSwap().startInBackground(); // TODO replace with Intent to SwapService
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PrepareSwapRepo {
|
|
||||||
public static final String ACTION = "PrepareSwapRepo.Action";
|
|
||||||
public static final String EXTRA_MESSAGE = "PrepareSwapRepo.Status.Message";
|
|
||||||
public static final String EXTRA_TYPE = "PrepareSwapRepo.Action.Type";
|
|
||||||
public static final int TYPE_STATUS = 0;
|
|
||||||
public static final int TYPE_COMPLETE = 1;
|
|
||||||
public static final int TYPE_ERROR = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to try and make sense of what the swap workflow is currently doing.
|
* Helper class to try and make sense of what the swap workflow is currently doing.
|
||||||
* The more technologies are involved in the process (e.g. Bluetooth/Wifi/NFC/etc)
|
* The more technologies are involved in the process (e.g. Bluetooth/Wifi/NFC/etc)
|
||||||
@ -1177,10 +1167,10 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
* etc. Icons will be copied to the webroot in the background and so are
|
* etc. Icons will be copied to the webroot in the background and so are
|
||||||
* not part of this process.
|
* not part of this process.
|
||||||
*/
|
*/
|
||||||
private final BroadcastReceiver prepareSwapReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver localRepoStatus = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
setUpConnectingProgressText(intent.getStringExtra(SwapWorkflowActivity.PrepareSwapRepo.EXTRA_MESSAGE));
|
setUpConnectingProgressText(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||||
|
|
||||||
ProgressBar progressBar = container.findViewById(R.id.progress_bar);
|
ProgressBar progressBar = container.findViewById(R.id.progress_bar);
|
||||||
Button tryAgainButton = container.findViewById(R.id.try_again);
|
Button tryAgainButton = container.findViewById(R.id.try_again);
|
||||||
@ -1190,18 +1180,22 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int type = intent.getIntExtra(SwapWorkflowActivity.PrepareSwapRepo.EXTRA_TYPE, -1);
|
switch (intent.getIntExtra(LocalRepoService.EXTRA_STATUS, -1)) {
|
||||||
if (type == SwapWorkflowActivity.PrepareSwapRepo.TYPE_ERROR) {
|
case LocalRepoService.STATUS_PROGRESS:
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
tryAgainButton.setVisibility(View.VISIBLE);
|
tryAgainButton.setVisibility(View.GONE);
|
||||||
return;
|
break;
|
||||||
} else {
|
case LocalRepoService.STATUS_STARTED:
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
tryAgainButton.setVisibility(View.GONE);
|
tryAgainButton.setVisibility(View.GONE);
|
||||||
}
|
|
||||||
|
|
||||||
if (type == SwapWorkflowActivity.PrepareSwapRepo.TYPE_COMPLETE) {
|
|
||||||
onLocalRepoPrepared();
|
onLocalRepoPrepared();
|
||||||
|
break;
|
||||||
|
case LocalRepoService.STATUS_ERROR:
|
||||||
|
progressBar.setVisibility(View.GONE);
|
||||||
|
tryAgainButton.setVisibility(View.VISIBLE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Bogus intent: " + intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user