Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
vvasuki committed Mar 31, 2017
1 parent 38780c6 commit 2dada3c
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified app/app-release.apk
Binary file not shown.
15 changes: 11 additions & 4 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,27 @@
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="lint-api-24.0.0" level="project" />
<orderEntry type="library" exported="" name="httpcore-4.1" level="project" />
<orderEntry type="library" exported="" name="ddmlib-24.0.0" level="project" />
<orderEntry type="library" exported="" name="commons-io-1.3.2" level="project" />
<orderEntry type="library" exported="" name="builder-1.0.0" level="project" />
<orderEntry type="library" exported="" name="httpmime-4.1" level="project" />
<orderEntry type="library" exported="" name="support-fragment-25.0.0" level="project" />
<orderEntry type="library" exported="" name="asm-analysis-4.0" level="project" />
<orderEntry type="library" exported="" name="support-core-ui-25.0.0" level="project" />
<orderEntry type="library" exported="" name="proguard-gradle-5.1" level="project" />
<orderEntry type="library" exported="" name="lint-24.0.0" level="project" />
<orderEntry type="library" exported="" name="support-core-utils-25.0.0" level="project" />
<orderEntry type="library" exported="" name="lint-checks-24.0.0" level="project" />
<orderEntry type="library" exported="" name="sdklib-24.0.0" level="project" />
<orderEntry type="library" exported="" name="ecj-4.2.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="multidex-instrumentation-1.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-25.0.0" level="project" />
<orderEntry type="library" exported="" name="lombok-ast-0.2.2" level="project" />
<orderEntry type="library" exported="" name="builder-test-api-1.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.0" level="project" />
<orderEntry type="library" exported="" name="proguard-base-5.1" level="project" />
<orderEntry type="library" exported="" name="sdk-common-24.0.0" level="project" />
<orderEntry type="library" exported="" name="gradle-1.0.0" level="project" />
Expand All @@ -133,13 +136,17 @@
<orderEntry type="library" exported="" name="commons-compress-1.8.1" level="project" />
<orderEntry type="library" exported="" name="bcpkix-jdk15on-1.48" level="project" />
<orderEntry type="library" exported="" name="kxml2-2.3.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-25.0.0" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-25.0.0" level="project" />
<orderEntry type="library" exported="" name="support-compat-25.0.0" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-25.0.0" level="project" />
<orderEntry type="library" exported="" name="multidex-1.0.1" level="project" />
<orderEntry type="library" exported="" name="javawriter-2.5.0" level="project" />
<orderEntry type="library" exported="" name="manifest-merger-24.0.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-25.0.0" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-25.0.0" level="project" />
<orderEntry type="library" exported="" name="android-async-http-1.4.5" level="project" />
<orderEntry type="library" exported="" name="asm-tree-4.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.0" level="project" />
<orderEntry type="library" exported="" name="builder-model-1.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.0" level="project" />
</component>
</module>
21 changes: 14 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
compileSdkVersion 25
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "sanskritcode.sanskritdictionaryupdater"
minSdkVersion 17
targetSdkVersion 20
versionCode 21
versionName "2.9"
minSdkVersion 16
targetSdkVersion 25
versionCode 30
versionName "3.0"
multiDexEnabled = true
jackOptions {
enabled false
}
}
buildTypes {
release {
Expand All @@ -26,13 +29,17 @@ android {
exclude 'LICENSE'
exclude 'AUTHORS'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
compile 'com.android.tools.build:gradle:1.0.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'org.apache.commons:commons-compress:1.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.Header;
import org.apache.http.client.params.ClientPNames;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -69,11 +68,11 @@ protected void onCreate(Bundle savedInstanceState) {
dictVersionEditor = sharedDictVersionStore.edit();
allDone = false;
setContentView(R.layout.activity_get_dictionaries);
topText = (TextView) findViewById(R.id.textView);
button = (Button) findViewById(R.id.button);
topText = (TextView) findViewById(R.id.get_dict_textView);
button = (Button) findViewById(R.id.get_dict_button);
button.setText(getString(R.string.buttonWorking));
button.setClickable(false);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
button.setEnabled(false);
progressBar = (ProgressBar) findViewById(R.id.get_dict_progressBar);
dictionariesSelectedLst.addAll(dictionariesSelected);
dictFailure = new ArrayList<Boolean>(Collections.nCopies(dictionariesSelectedLst.size(), false));

Expand All @@ -87,7 +86,6 @@ protected void onCreate(Bundle savedInstanceState) {
dictDir.mkdirs();
}

asyncHttpClient.getHttpClient().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
getDictionaries(0);
}

Expand All @@ -100,7 +98,7 @@ protected void getDictionaries(int index) {
topText.setText("No dictionaries selected!");
topText.append(getString(R.string.txtTryAgain));
button.setText(R.string.proceed_button);
button.setClickable(true);
button.setEnabled(true);
} else {
if (index >= dictionariesSelectedLst.size()) {
extractDicts(0);
Expand Down Expand Up @@ -137,7 +135,7 @@ public String apply(String in) {
}
if (successes.length() > 0) topText.append("\n" + "Succeeded on:" + successes);

button.setClickable(true);
button.setEnabled(true);
button.setText(R.string.buttonValQuit);
button.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
Expand All @@ -15,16 +14,11 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.TextHttpResponseHandler;

import org.apache.http.Header;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand All @@ -38,7 +32,9 @@ public class GetUrlActivity extends Activity {
public static Map<String, List<String>> indexedDicts = new LinkedHashMap<String, List<String>>();
private static final String DICTIONARY_LOCATION = "dict";
private static final String DOWNLOAD_LOCATION = "dict";
protected static AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

static private LinearLayout layout;
static private TextView topText;
static private Button button;
static private List<CheckBox> checkBoxes = new ArrayList<CheckBox>();
Expand All @@ -53,8 +49,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
} else {
dictionariesSelected.remove(buttonView.getHint().toString());
}
button.setClickable(!dictionariesSelected.isEmpty());
Log.d(ACTIVITY_NAME, "button enablement " + button.isClickable());
enableButtonIfDictsSelected();
}
};

Expand All @@ -63,25 +58,31 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(getLocalClassName(), "whenActivityLoaded indexedDicts " + indexedDicts);

layout = (LinearLayout) findViewById(R.id.get_url_layout);
sharedDictVersionStore = getSharedPreferences(
getString(R.string.dict_version_store), Context.MODE_PRIVATE);

indexesSelected = MainActivity.indexesSelected;
indexedDicts = new LinkedHashMap<String, List<String>>();
dictionariesSelected = new HashSet<String>();
setContentView(R.layout.activity_get_url);
topText = (TextView) findViewById(R.id.textView);
button = (Button) findViewById(R.id.button);
topText = (TextView) findViewById(R.id.get_url_textView);

button = (Button) findViewById(R.id.get_url_button);
button.setText(getString(R.string.buttonWorking));
button.setClickable(false);
button.setEnabled(false);

setContentView(R.layout.activity_get_url);
DictUrlGetter dictUrlGetter = new DictUrlGetter();
dictUrlGetter.execute(indexesSelected.keySet().toArray(new String[0]));
getDictUrls();
}

void enableButtonIfDictsSelected() {
button = (Button) findViewById(R.id.get_url_button);
button.setEnabled(!dictionariesSelected.isEmpty());
Log.d(ACTIVITY_NAME, "button enablement " + button.isEnabled());
}

public void buttonPressed1(View v) {
Button button = (Button) findViewById(R.id.button);
Intent intent = new Intent(this, GetDictionariesActivity.class);
startActivity(intent);
}
Expand Down Expand Up @@ -109,86 +110,85 @@ protected void selectCheckboxes() {
autoUnselectedDicts++;
}
}
// checkbox-change listener is only called if there is a change - not if all checkboxes are unselected to start off.
enableButtonIfDictsSelected();

String message = String.format(getString(R.string.autoUnselectedDicts), sharedDictVersionStore.getAll().size(), autoUnselectedDicts);
topText.append(message);
Log.d(ACTIVITY_NAME, topText.getText().toString());
Log.d(ACTIVITY_NAME, message);
}

protected class DictUrlGetter extends AsyncTask<String, Integer, Integer> {
private final String DICT_URL_GETTER = DictUrlGetter.class.getName();
private int dictsRetreieved = 0;

@Override
public Integer doInBackground(String... dictionaryListNames) {
Log.i(DICT_URL_GETTER, getString(R.string.use_n_dictionary_indexes) + dictionaryListNames.length);
indexedDicts = new LinkedHashMap<String, List<String>>();
dictsRetreieved = 0;
for (String name : dictionaryListNames) {
String url = indexesSelected.get(name);
Log.i(DICT_URL_GETTER, url);
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();

BufferedHttpEntity buf = new BufferedHttpEntity(ht);

InputStream is = buf.getContent();
BufferedReader r = new BufferedReader(new InputStreamReader(is));

String line;
static String getIndexNameFromUrl(String url) {
for(String key: indexesSelected.keySet()) {
if(indexesSelected.get(key) == url) {
return key;
}
}
return null;
}

// Populates indexedDicts
void getDictUrls() {
indexedDicts = new LinkedHashMap<String, List<String>>();
Log.i(ACTIVITY_NAME, getString(R.string.use_n_dictionary_indexes) + indexesSelected.size());
for (String name : indexesSelected.keySet()) {
final String url = indexesSelected.get(name);
asyncHttpClient.get(url, new TextHttpResponseHandler() {
final String LOGGER_NAME = "getDictUrls";
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
Log.e(LOGGER_NAME, "Failed " + throwable.toString());
}

@Override
public void onSuccess(int statusCode, Header[] headers, String responseString) {
List<String> urls = new ArrayList<String>();
while ((line = r.readLine()) != null) {
for (String line: responseString.split("\n")) {
String dictUrl = line.replace("<", "").replace(">", "");
urls.add(dictUrl);
Log.d(DICT_URL_GETTER, getString(R.string.added_dictionary_url) + dictUrl);
dictsRetreieved++;
publishProgress(dictsRetreieved);
Log.d(LOGGER_NAME, getString(R.string.added_dictionary_url) + dictUrl);
}
Log.d(LOGGER_NAME, "Index handled: " + url);
indexedDicts.put(getIndexNameFromUrl(url), urls);

if(indexesSelected.size() == indexedDicts.size()) {
addCheckboxes();
}
indexedDicts.put(name, urls);
} catch (IOException e) {
Log.e(DICT_URL_GETTER, "Failed " + e.getStackTrace());
}
}
Log.i(DICT_URL_GETTER, getString(R.string.added_n_dictionary_urls) + dictsRetreieved);
return dictsRetreieved;
});
}
}

@Override
protected void onPostExecute(Integer result) {
// retainOnlyOneDictForDebugging();
String message = String.format(getString(R.string.added_n_dictionary_urls), dictsRetreieved);
topText.setText(message);
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
for (String indexName : indexedDicts.keySet()) {
TextView text = new TextView(getApplicationContext());
text.setBackgroundColor(Color.YELLOW);
text.setTextColor(Color.BLACK);
text.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
text.setVisibility(View.VISIBLE);
text.setText("From " + indexName);
layout.addView(text);

for (String url : indexedDicts.get(indexName)) {
CheckBox cb = new CheckBox(getApplicationContext());
cb.setText(url.replaceAll(".*/", ""));
cb.setHint(url);
cb.setTextColor(Color.BLACK);
layout.addView(cb, layout.getChildCount());
cb.setOnCheckedChangeListener(checkboxListener);
checkBoxes.add(cb);
}
private void addCheckboxes() {
layout = (LinearLayout) findViewById(R.id.get_url_layout);
for (String indexName : indexedDicts.keySet()) {
TextView text = new TextView(getApplicationContext());
text.setBackgroundColor(Color.YELLOW);
text.setTextColor(Color.BLACK);
text.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
text.setVisibility(View.VISIBLE);
text.setText("From " + indexName);
layout.addView(text);

for (String url : indexedDicts.get(indexName)) {
CheckBox cb = new CheckBox(getApplicationContext());
cb.setText(url.replaceAll(".*/", ""));
cb.setHint(url);
cb.setTextColor(Color.BLACK);
layout.addView(cb, layout.getChildCount());
cb.setOnCheckedChangeListener(checkboxListener);
checkBoxes.add(cb);
}
selectCheckboxes();
button.setText(getString(R.string.proceed_button));
// getDictionaries(0);
}

String message = String.format(getString(R.string.added_n_dictionary_urls), checkBoxes.size());
Log.i(ACTIVITY_NAME, message);
topText = (TextView) findViewById(R.id.get_url_textView);
topText.setText(message);
selectCheckboxes();
button.setText(getString(R.string.proceed_button));
}

@Override
Expand Down
Loading

0 comments on commit 2dada3c

Please sign in to comment.