WIP: hooking up ApkDownloader to swap apps.
This commit is contained in:
parent
ba6d2e7793
commit
0b160d2e04
@ -33,7 +33,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:backgroundTint="@color/swap_light_blue"
|
android:backgroundTint="@color/swap_light_blue"
|
||||||
backgroundTint="@color/swap_light_blue"
|
app:backgroundTint="@color/swap_light_blue"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:text="@string/menu_install"/>
|
android:text="@string/menu_install"/>
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:padding="30dp"
|
android:padding="30dp"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
tools:text="@string/swap_connecting" />
|
tools:text="Connecting with Nexus 4" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -92,6 +92,10 @@ abstract public class Installer {
|
|||||||
this.mCallback = callback;
|
this.mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Installer getActivityInstaller(Activity activity, InstallerCallback callback) {
|
||||||
|
return getActivityInstaller(activity, activity.getPackageManager(), callback);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Installer for installing/deleting processes starting from
|
* Creates a new Installer for installing/deleting processes starting from
|
||||||
* an Activity
|
* an Activity
|
||||||
|
@ -260,10 +260,6 @@ public class SwapService extends Service {
|
|||||||
return peerRepo;
|
return peerRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void install(@NonNull final App app) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that we don't get put into an incorrect state, by forcing people to pass valid
|
* Ensure that we don't get put into an incorrect state, by forcing people to pass valid
|
||||||
* states to setStep. Ideally this would be done by requiring an enum or something to
|
* states to setStep. Ideally this would be done by requiring an enum or something to
|
||||||
|
@ -77,10 +77,6 @@ public class SwapAppsView extends ListView implements
|
|||||||
return (SwapWorkflowActivity)getContext();
|
return (SwapWorkflowActivity)getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SwapService getState() {
|
|
||||||
return getActivity().getState();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int LOADER_SWAPABLE_APPS = 759283741;
|
private static final int LOADER_SWAPABLE_APPS = 759283741;
|
||||||
private static final String TAG = "SwapAppsView";
|
private static final String TAG = "SwapAppsView";
|
||||||
|
|
||||||
@ -127,7 +123,7 @@ public class SwapAppsView extends ListView implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Polling swap repo to see if it has any updates.");
|
Log.d(TAG, "Polling swap repo to see if it has any updates.");
|
||||||
getState().refreshSwap();
|
getActivity().getService().refreshSwap();
|
||||||
if (pollForUpdatesReceiver != null) {
|
if (pollForUpdatesReceiver != null) {
|
||||||
pollForUpdatesReceiver = new BroadcastReceiver() {
|
pollForUpdatesReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@ -200,7 +196,7 @@ public class SwapAppsView extends ListView implements
|
|||||||
|
|
||||||
@ColorRes
|
@ColorRes
|
||||||
public int getToolbarColour() {
|
public int getToolbarColour() {
|
||||||
return getResources().getColor(R.color.swap_bright_blue);
|
return R.color.swap_bright_blue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -327,7 +323,7 @@ public class SwapAppsView extends ListView implements
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (app.hasUpdates() || app.compatible) {
|
if (app.hasUpdates() || app.compatible) {
|
||||||
getState().install(app);
|
getActivity().install(app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,7 @@ import org.fdroid.fdroid.UpdateService;
|
|||||||
import org.fdroid.fdroid.localrepo.SwapService;
|
import org.fdroid.fdroid.localrepo.SwapService;
|
||||||
import org.fdroid.fdroid.localrepo.peers.Peer;
|
import org.fdroid.fdroid.localrepo.peers.Peer;
|
||||||
|
|
||||||
|
// TODO: Use this for the "Preparing local repo" dialog also.
|
||||||
public class SwapConnecting extends LinearLayout implements SwapWorkflowActivity.InnerView {
|
public class SwapConnecting extends LinearLayout implements SwapWorkflowActivity.InnerView {
|
||||||
|
|
||||||
private final static String TAG = "SwapConnecting";
|
private final static String TAG = "SwapConnecting";
|
||||||
|
@ -33,18 +33,26 @@ import org.fdroid.fdroid.AppDetails;
|
|||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.NfcHelper;
|
import org.fdroid.fdroid.NfcHelper;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
|
import org.fdroid.fdroid.ProgressListener;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
|
import org.fdroid.fdroid.data.Apk;
|
||||||
|
import org.fdroid.fdroid.data.ApkProvider;
|
||||||
|
import org.fdroid.fdroid.data.App;
|
||||||
import org.fdroid.fdroid.data.NewRepoConfig;
|
import org.fdroid.fdroid.data.NewRepoConfig;
|
||||||
|
import org.fdroid.fdroid.installer.Installer;
|
||||||
import org.fdroid.fdroid.localrepo.LocalRepoManager;
|
import org.fdroid.fdroid.localrepo.LocalRepoManager;
|
||||||
import org.fdroid.fdroid.localrepo.SwapService;
|
import org.fdroid.fdroid.localrepo.SwapService;
|
||||||
import org.fdroid.fdroid.localrepo.peers.Peer;
|
import org.fdroid.fdroid.localrepo.peers.Peer;
|
||||||
|
import org.fdroid.fdroid.net.ApkDownloader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@ -200,6 +208,10 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showRelevantView() {
|
private void showRelevantView() {
|
||||||
|
showRelevantView(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showRelevantView(boolean forceReload) {
|
||||||
|
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
showInitialLoading();
|
showInitialLoading();
|
||||||
@ -215,10 +227,12 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!forceReload) {
|
||||||
if (container.getVisibility() == View.GONE || currentView != null && currentView.getStep() == service.getStep()) {
|
if (container.getVisibility() == View.GONE || currentView != null && currentView.getStep() == service.getStep()) {
|
||||||
// Already showing the correct step, so don't bother changing anything.
|
// Already showing the correct step, so don't bother changing anything.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch(service.getStep()) {
|
switch(service.getStep()) {
|
||||||
case SwapService.STEP_INTRO:
|
case SwapService.STEP_INTRO:
|
||||||
@ -697,4 +711,43 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void install(@NonNull final App app) {
|
||||||
|
final Apk apkToInstall = ApkProvider.Helper.find(this, app.id, app.suggestedVercode);
|
||||||
|
final ApkDownloader downloader = new ApkDownloader(this, apkToInstall, apkToInstall.repoAddress);
|
||||||
|
downloader.setProgressListener(new ProgressListener() {
|
||||||
|
@Override
|
||||||
|
public void onProgress(Event event) {
|
||||||
|
switch (event.type) {
|
||||||
|
case ApkDownloader.EVENT_APK_DOWNLOAD_COMPLETE:
|
||||||
|
handleDownloadComplete(downloader.localFile());
|
||||||
|
break;
|
||||||
|
case ApkDownloader.EVENT_ERROR:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
downloader.download();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleDownloadComplete(File apkFile) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Installer.getActivityInstaller(SwapWorkflowActivity.this, new Installer.InstallerCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(int operation) {
|
||||||
|
// TODO: Don't reload the view weely-neely, but rather get the view to listen
|
||||||
|
// for broadcasts that say the install was complete.
|
||||||
|
showRelevantView(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(int operation, int errorCode) {
|
||||||
|
// TODO: Boo!
|
||||||
|
}
|
||||||
|
}).installPackage(apkFile);
|
||||||
|
} catch (Installer.AndroidNotCompatibleException e) {
|
||||||
|
// TODO: Handle exception properly
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user