diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d19981..fbb6828 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/app-release.apk b/app/app-release.apk index 718fd06..ffb8f72 100644 Binary files a/app/app-release.apk and b/app/app-release.apk differ diff --git a/app/app.iml b/app/app.iml index 2ed2a92..1a1ece7 100644 --- a/app/app.iml +++ b/app/app.iml @@ -90,6 +90,7 @@ + @@ -99,6 +100,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 698a2e6..43ec902 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { applicationId "sanskritcode.sanskritdictionaryupdater" minSdkVersion 17 - targetSdkVersion 21 - versionCode 20 + targetSdkVersion 20 + versionCode 21 versionName "2.9" multiDexEnabled = true } diff --git a/app/src/main/java/sanskritcode/sanskritdictionaryupdater/GetDictionariesActivity.java b/app/src/main/java/sanskritcode/sanskritdictionaryupdater/GetDictionariesActivity.java index 911d0b2..154663f 100644 --- a/app/src/main/java/sanskritcode/sanskritdictionaryupdater/GetDictionariesActivity.java +++ b/app/src/main/java/sanskritcode/sanskritdictionaryupdater/GetDictionariesActivity.java @@ -2,7 +2,6 @@ import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; @@ -10,6 +9,7 @@ import android.util.Log; import android.view.View; import android.widget.Button; +import android.widget.CheckBox; import android.widget.ProgressBar; import android.widget.TextView; @@ -42,17 +42,18 @@ public class GetDictionariesActivity extends Activity { private List dictFiles = new ArrayList(); private List dictFailure = new ArrayList(); - private TextView topText; - private Button button; - private ProgressBar progressBar; + static private List checkBoxes = new ArrayList(); + static private TextView topText; + static private Button button; + static private ProgressBar progressBar; private File sdcard; private File downloadsDir; private File dictDir; private boolean allDone = false; - SharedPreferences sharedDictVersionStore; - SharedPreferences.Editor dictVersionEditor; + static SharedPreferences sharedDictVersionStore; + static SharedPreferences.Editor dictVersionEditor; public static String[] getDictNameAndVersion(String fileName) { // handle filenames of the type: kRdanta-rUpa-mAlA__2016-02-20_23-22-27.tar.gz @@ -63,7 +64,7 @@ public static String[] getDictNameAndVersion(String fileName) { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - sharedDictVersionStore = getSharedPreferences( + sharedDictVersionStore = getSharedPreferences( getString(R.string.dict_version_store), Context.MODE_PRIVATE); dictVersionEditor = sharedDictVersionStore.edit(); allDone = false; @@ -71,7 +72,7 @@ protected void onCreate(Bundle savedInstanceState) { topText = (TextView) findViewById(R.id.textView); button = (Button) findViewById(R.id.button); button.setText(getString(R.string.buttonWorking)); - button.setEnabled(false); + button.setClickable(false); progressBar = (ProgressBar) findViewById(R.id.progressBar); dictionariesSelectedLst.addAll(dictionariesSelected); dictFailure = new ArrayList(Collections.nCopies(dictionariesSelectedLst.size(), false)); @@ -91,11 +92,7 @@ protected void onCreate(Bundle savedInstanceState) { } public void buttonPressed1(View v) { - Button button = (Button) findViewById(R.id.button); - button.setText(getString(R.string.buttonWorking)); - button.setEnabled(false); - Intent intent = new Intent(this, MainActivity.class); - startActivity(intent); + finish(); } protected void getDictionaries(int index) { @@ -103,7 +100,7 @@ protected void getDictionaries(int index) { topText.setText("No dictionaries selected!"); topText.append(getString(R.string.txtTryAgain)); button.setText(R.string.proceed_button); - button.setEnabled(true); + button.setClickable(true); } else { if (index >= dictionariesSelectedLst.size()) { extractDicts(0); @@ -140,13 +137,12 @@ public String apply(String in) { } if (successes.length() > 0) topText.append("\n" + "Succeeded on:" + successes); - button.setEnabled(true); + button.setClickable(true); button.setText(R.string.buttonValQuit); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finishAffinity(); - System.exit(0); } }); return; diff --git a/app/src/main/java/sanskritcode/sanskritdictionaryupdater/GetUrlActivity.java b/app/src/main/java/sanskritcode/sanskritdictionaryupdater/GetUrlActivity.java index 7aed8d6..8076751 100644 --- a/app/src/main/java/sanskritcode/sanskritdictionaryupdater/GetUrlActivity.java +++ b/app/src/main/java/sanskritcode/sanskritdictionaryupdater/GetUrlActivity.java @@ -39,21 +39,22 @@ public class GetUrlActivity extends Activity { private static final String DICTIONARY_LOCATION = "dict"; private static final String DOWNLOAD_LOCATION = "dict"; - private TextView topText; - private Button button; + static private TextView topText; + static private Button button; + static private List checkBoxes = new ArrayList(); SharedPreferences sharedDictVersionStore; - private List checkBoxes = new ArrayList(); public static HashSet dictionariesSelected = new HashSet(); CompoundButton.OnCheckedChangeListener checkboxListener = new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isChecked) { - dictionariesSelected.add(buttonView.getHint().toString()); - } else { - dictionariesSelected.remove(buttonView.getHint().toString()); - } - button.setEnabled(dictionariesSelected.size() > 0); + if (isChecked) { + dictionariesSelected.add(buttonView.getHint().toString()); + } else { + dictionariesSelected.remove(buttonView.getHint().toString()); + } + button.setClickable(!dictionariesSelected.isEmpty()); + Log.d(ACTIVITY_NAME, "button enablement " + button.isClickable()); } }; @@ -62,7 +63,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(getLocalClassName(), "whenActivityLoaded indexedDicts " + indexedDicts); - sharedDictVersionStore = getSharedPreferences( + sharedDictVersionStore = getSharedPreferences( getString(R.string.dict_version_store), Context.MODE_PRIVATE); indexesSelected = MainActivity.indexesSelected; @@ -72,20 +73,13 @@ protected void onCreate(Bundle savedInstanceState) { topText = (TextView) findViewById(R.id.textView); button = (Button) findViewById(R.id.button); button.setText(getString(R.string.buttonWorking)); - button.setEnabled(false); + button.setClickable(false); setContentView(R.layout.activity_get_url); DictUrlGetter dictUrlGetter = new DictUrlGetter(); dictUrlGetter.execute(indexesSelected.keySet().toArray(new String[0])); } - @Override - protected void onRestart() { - super.onRestart(); - button.setText(getString(R.string.proceed_button)); - button.setEnabled(true); - } - public void buttonPressed1(View v) { Button button = (Button) findViewById(R.id.button); Intent intent = new Intent(this, GetDictionariesActivity.class); @@ -95,14 +89,14 @@ public void buttonPressed1(View v) { protected void selectCheckboxes() { boolean currentVersionsKnown = (sharedDictVersionStore.getAll().size() > 0); int autoUnselectedDicts = 0; - for(CheckBox cb : checkBoxes) { + for (CheckBox cb : checkBoxes) { // handle values: kRdanta-rUpa-mAlA -> 2016-02-20_23-22-27 String filename = cb.getHint().toString(); boolean proposedVersionNewer = true; String[] dictnameParts = GetDictionariesActivity.getDictNameAndVersion(filename); String dictname = dictnameParts[0]; - if(dictnameParts.length > 1) { + if (dictnameParts.length > 1) { String currentVersion = sharedDictVersionStore.getString(dictname, "0000"); String proposedVersion = dictnameParts[1]; proposedVersionNewer = (proposedVersion.compareTo(currentVersion) > 1); @@ -111,6 +105,7 @@ protected void selectCheckboxes() { if (proposedVersionNewer) { cb.setChecked(true); } else { + cb.setChecked(false); autoUnselectedDicts++; } } @@ -179,7 +174,7 @@ protected void onPostExecute(Integer result) { text.setText("From " + indexName); layout.addView(text); - for(String url: indexedDicts.get(indexName)) { + for (String url : indexedDicts.get(indexName)) { CheckBox cb = new CheckBox(getApplicationContext()); cb.setText(url.replaceAll(".*/", "")); cb.setHint(url); @@ -195,6 +190,7 @@ protected void onPostExecute(Integer result) { } } + @Override public void onBackPressed() { indexedDicts = new LinkedHashMap>(); diff --git a/app/src/main/java/sanskritcode/sanskritdictionaryupdater/MainActivity.java b/app/src/main/java/sanskritcode/sanskritdictionaryupdater/MainActivity.java index b08e033..44bba8b 100644 --- a/app/src/main/java/sanskritcode/sanskritdictionaryupdater/MainActivity.java +++ b/app/src/main/java/sanskritcode/sanskritdictionaryupdater/MainActivity.java @@ -33,7 +33,7 @@ * Flow: MainActivity::OnCreate -> IndexGetter -> (user chooses indices, checkboxListener) -> buttonPressed1 -> * GetUrlActivity::DictUrlGetter -> (user chooses dictionaries) * GetDictionariesActivity -> (getDictionaries <-> downloadDict) -> (extractDict <-> DictExtracter) - * + *

* IntraActivity lifecycle looks like this: http://stackoverflow.com/questions/6509791/onrestart-vs-onresume-android-lifecycle-question */ public class MainActivity extends Activity { @@ -42,9 +42,9 @@ public class MainActivity extends Activity { public static Map indexUrls = new LinkedHashMap(); public static Map indexesSelected = new LinkedHashMap(); - private TextView topText; - private Button button; - private List checkBoxes = new ArrayList(); + static private TextView topText; + static private Button button; + static private List checkBoxes = new ArrayList(); CompoundButton.OnCheckedChangeListener checkboxListener = new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -53,6 +53,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { } else { indexesSelected.remove(buttonView.getText().toString()); } + button.setClickable(!indexesSelected.isEmpty()); } }; @@ -60,7 +61,7 @@ private void addCheckboxes() { // retainOnlyOneDictForDebugging(); checkBoxes = new ArrayList(); LinearLayout layout = (LinearLayout) findViewById(R.id.layout); - for (String name: indexUrls.keySet()) { + for (String name : indexUrls.keySet()) { CheckBox cb = new CheckBox(getApplicationContext()); cb.setText(name); cb.setHint(indexUrls.get(name)); @@ -69,7 +70,7 @@ private void addCheckboxes() { layout.addView(cb, layout.getChildCount()); checkBoxes.add(cb); } - for(CheckBox checkBox : checkBoxes) { + for (CheckBox checkBox : checkBoxes) { if (indexesSelected.keySet().contains(checkBox.getText())) { checkBox.setChecked(true); } else { @@ -78,7 +79,6 @@ private void addCheckboxes() { } button.setText(getString(R.string.proceed_button)); - button.setEnabled(true); // getDictionaries(0); } @@ -95,9 +95,9 @@ protected void onCreate(Bundle savedInstanceState) { button = (Button) findViewById(R.id.button); button.setText(getString(R.string.buttonWorking)); - button.setEnabled(false); + button.setClickable(false); - if(indexUrls.size() == 0) { + if (indexUrls.size() == 0) { MainActivity.IndexGetter indexGetter = new MainActivity.IndexGetter(); indexGetter.execute(index_indexorum); } else { @@ -115,7 +115,7 @@ protected void onStart() { protected void onResume() { super.onResume(); button.setText(R.string.proceed_button); - button.setEnabled(true); + button.setClickable(true); Log.d(MAIN_ACTIVITY, "onResume Indices selected " + indexesSelected.toString()); } @@ -130,7 +130,7 @@ protected class IndexGetter extends AsyncTask { private final String INDEX_GETTER = MainActivity.IndexGetter.class.getName(); @Override - public Integer doInBackground(String ... params) { + public Integer doInBackground(String... params) { String indexList = params[0]; Log.i(INDEX_GETTER, indexList); try {