Add a quick download warning for the DownloaderActivity

This commit is contained in:
DjBushido 2014-04-15 19:39:19 -04:00
parent b20d0aa819
commit 5fb077a40d
2 changed files with 32 additions and 9 deletions

View File

@ -0,0 +1,7 @@
package org.bspeice.minimalbible;
public class MinimalBibleConstants {
public static final String DOWNLOAD_PREFS_FILE = "DOWNLOADER_PREFERENCES";
}

View File

@ -1,22 +1,27 @@
package org.bspeice.minimalbible.activities.downloader; package org.bspeice.minimalbible.activities.downloader;
import org.bspeice.minimalbible.MinimalBibleConstants;
import org.bspeice.minimalbible.R; import org.bspeice.minimalbible.R;
import org.bspeice.minimalbible.R.layout;
import org.bspeice.minimalbible.R.menu;
import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.widget.Toast;
public class DownloaderActivity extends Activity { public class DownloaderActivity extends Activity {
private static final String KEY_DOWNLOAD_ENABLED = "HAS_ENABLED_DOWNLOAD";
public static final String KEY_PERM_DISABLE_DOWNLOAD = "PERMANENTLY_DISABLE_DOWNLOAD";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_downloader); setContentView(R.layout.activity_downloader);
// Display a warning about internet connectivity
displayInternetWarning(); displayInternetWarning();
} }
@ -28,12 +33,17 @@ public class DownloaderActivity extends Activity {
} }
private void displayInternetWarning() { private void displayInternetWarning() {
SharedPreferences prefs = getSharedPreferences(MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
// If downloading has not been enabled, or user has permanently disabled downloading, WARN THEM!
if (!prefs.getBoolean(KEY_DOWNLOAD_ENABLED, false) || prefs.getBoolean(KEY_PERM_DISABLE_DOWNLOAD, false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
DownloadDialogListener dialogListener = new DownloadDialogListener(); DownloadDialogListener dialogListener = new DownloadDialogListener();
builder.setMessage("About to contact servers to download content. Continue?") builder.setMessage("About to contact servers to download content. Continue?")
.setPositiveButton("Yes", dialogListener).setNegativeButton("No", dialogListener) .setPositiveButton("Yes", dialogListener).setNegativeButton("No", dialogListener)
.setCancelable(false).show(); .setCancelable(false).show();
} }
}
private void downloadModules() { private void downloadModules() {
@ -44,7 +54,13 @@ public class DownloaderActivity extends Activity {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which){ switch (which){
case DialogInterface.BUTTON_POSITIVE: case DialogInterface.BUTTON_POSITIVE:
// Clicked ready to continue // Clicked ready to continue - allow downloading in the future
SharedPreferences prefs = getSharedPreferences(MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
prefs.edit().putBoolean(KEY_DOWNLOAD_ENABLED, true).commit();
// And warn them that it has been enabled in the future.
Toast.makeText(DownloaderActivity.this,
"Downloading now enabled. Disable in settings.", Toast.LENGTH_SHORT).show();
downloadModules(); downloadModules();
break; break;