Manual download no longer triggers autoinstallation

This commit is contained in:
Sergey Eremin
2017-06-23 20:00:32 +03:00
parent 0bdcea5894
commit ba2bd8af20
4 changed files with 26 additions and 9 deletions

View File

@@ -51,13 +51,19 @@ public class DetailsDownloadReceiver extends BroadcastReceiver {
}
buttonDownload.setText(R.string.details_download);
buttonDownload.setEnabled(true);
if (state.isEverythingSuccessful()) {
buttonDownload.setVisibility(View.GONE);
buttonInstall.setVisibility(View.VISIBLE);
if (PreferenceActivity.getBoolean(context, PreferenceActivity.PREFERENCE_AUTO_INSTALL)) {
buttonInstall.setEnabled(false);
buttonInstall.setText(R.string.details_installing);
}
if (!state.isEverythingSuccessful()) {
return;
}
buttonDownload.setVisibility(View.GONE);
buttonInstall.setVisibility(View.VISIBLE);
if (PreferenceActivity.getBoolean(context, PreferenceActivity.PREFERENCE_AUTO_INSTALL)
&& !state.getTriggeredBy().equals(DownloadState.TriggeredBy.MANUAL_DOWNLOAD_BUTTON)
) {
buttonInstall.setEnabled(false);
buttonInstall.setText(R.string.details_installing);
} else {
buttonInstall.setEnabled(true);
buttonInstall.setText(R.string.details_install);
}
}
}

View File

@@ -12,7 +12,8 @@ public class DownloadState {
public enum TriggeredBy {
DOWNLOAD_BUTTON,
UPDATE_ALL_BUTTON,
SCHEDULED_UPDATE
SCHEDULED_UPDATE,
MANUAL_DOWNLOAD_BUTTON
}
enum Status {

View File

@@ -4,6 +4,7 @@ import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@@ -43,6 +44,7 @@ public class ManualDownloadActivity extends DetailsActivity {
ManualDownloadTextWatcher textWatcher = new ManualDownloadTextWatcher(
app,
(Button) findViewById(R.id.download),
(Button) findViewById(R.id.install),
downloadOrInstallFragment
);
String versionCode = Integer.toString(app.getVersionCode());
@@ -66,12 +68,14 @@ public class ManualDownloadActivity extends DetailsActivity {
private final App app;
private final Button downloadButton;
private final Button installButton;
private DownloadOrInstall downloadOrInstallManager;
private Timer timer;
public ManualDownloadTextWatcher(App app, Button downloadButton, DownloadOrInstall downloadOrInstallManager) {
public ManualDownloadTextWatcher(App app, Button downloadButton, Button installButton, DownloadOrInstall downloadOrInstallManager) {
this.app = app;
this.downloadButton = downloadButton;
this.installButton = installButton;
this.downloadOrInstallManager = downloadOrInstallManager;
}
@@ -84,8 +88,10 @@ public class ManualDownloadActivity extends DetailsActivity {
public void onTextChanged(CharSequence s, int start, int before, int count) {
try {
app.setVersionCode(Integer.parseInt(s.toString()));
installButton.setVisibility(View.GONE);
downloadButton.setText(R.string.details_download_checking);
downloadButton.setEnabled(false);
downloadButton.setVisibility(View.VISIBLE);
restartTimer();
} catch (NumberFormatException e) {
Log.w(getClass().getName(), s.toString() + " is not a number");

View File

@@ -19,6 +19,9 @@ import com.github.yeriomin.yalpstore.model.App;
import java.io.File;
import static com.github.yeriomin.yalpstore.DownloadState.TriggeredBy.DOWNLOAD_BUTTON;
import static com.github.yeriomin.yalpstore.DownloadState.TriggeredBy.MANUAL_DOWNLOAD_BUTTON;
public class ButtonDownload extends Button {
public ButtonDownload(DetailsActivity activity, App app) {
@@ -96,6 +99,7 @@ public class ButtonDownload extends Button {
purchaseTask.setOnDownloadProgressListener(new OnDownloadProgressListener(progressBar, DownloadState.get(app.getPackageName())));
purchaseTask.setApp(app);
purchaseTask.setContext(activity);
purchaseTask.setTriggeredBy(activity instanceof ManualDownloadActivity ? MANUAL_DOWNLOAD_BUTTON : DOWNLOAD_BUTTON);
purchaseTask.prepareDialog(
R.string.dialog_message_purchasing_app,
R.string.dialog_title_purchasing_app