Skip to content

Commit

Permalink
1.1 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
CyborgPatrick committed Jan 3, 2014
1 parent c18b5a7 commit c5ddee9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 88 deletions.
5 changes: 0 additions & 5 deletions src/is/hi/hbv/kjarninn/ImageDownloaderTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ protected Bitmap doInBackground(String... params) {
if (isFileNameInLocalstorage){
File thumb = localstorage.getFile(thumbName);
String path = thumb.getPath();
//Log.d("Getting bitmap form path...", path);
Bitmap bMap = BitmapFactory.decodeFile(path);
return bMap;
}
Expand Down Expand Up @@ -103,8 +102,6 @@ static Bitmap downloadBitmap(String url, String version) {
HttpResponse response = client.execute(getRequest);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w("ImageDownloader", "Error " + statusCode
+ " while retrieving bitmap from " + url);
return null;
}

Expand All @@ -118,7 +115,6 @@ static Bitmap downloadBitmap(String url, String version) {
try {
Context context = MainActivity.getAppContext();
String path = context.getFilesDir().getAbsolutePath()+"/thumb"+version+".jpg";
//Log.d("Saving file to path..",path);
FileOutputStream fos = context.openFileOutput("thumb"+version+".jpg", Context.MODE_PRIVATE);
File thumb = new File(path);
thumb.setReadable(true, false);
Expand All @@ -139,7 +135,6 @@ static Bitmap downloadBitmap(String url, String version) {
// Could provide a more explicit error message for IOException or
// IllegalStateException
getRequest.abort();
Log.w("ImageDownloader", "Error while retrieving bitmap from " + url);
} finally {
if (client != null) {
client.close();
Expand Down
52 changes: 3 additions & 49 deletions src/is/hi/hbv/kjarninn/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,7 @@ protected void onCreate(Bundle savedInstanceState) {
navbarListView.setAdapter(NavAdapter); //

navbarListView.setOnItemClickListener(new DrawerItemClickListener());

Log.d("Getting","Json");
Log.d("isOnline:",Boolean.toString(isOnline()));
getJson();

//Tests
TDD tdd = new TDD();
tdd.testSharedPrefsInt();
tdd.testSharedPrefsString();
}


Expand Down Expand Up @@ -143,7 +135,6 @@ protected String doInBackground(String... savePdfAs) {
long correctPdfSize = 0;

for (int j=0; j<versionNames.length; j++){
Log.d(namePdf,versionNames[j]+"_//_"+ Integer.toString(versionsSizes[j]));
if (namePdf.equals(versionNames[j])){
correctPdfSize = versionsSizes[j];
}
Expand All @@ -154,7 +145,6 @@ protected String doInBackground(String... savePdfAs) {
boolean[] localCheckResult = localstorage.isInLocal(namePdf,correctPdfSize);

if (localCheckResult[0] && localCheckResult[1]){
Log.d("Correct file exists","Cancelling download");
cancel(true);
}

Expand All @@ -165,7 +155,6 @@ protected String doInBackground(String... savePdfAs) {
String urlToPdf = savePdfAs[0];
FileOutputStream fileOutputStream = openFileOutput(namePdf, Context.MODE_PRIVATE);//
String pathRootInternalMemory = getFilesDir().getAbsolutePath() + "/" + namePdf; // path to the root of internal memory.
Log.d("Saving to path:",pathRootInternalMemory);
File f = new File(pathRootInternalMemory);
f.setReadable(true, false);
URL url = new URL(urlToPdf);
Expand All @@ -180,7 +169,6 @@ protected String doInBackground(String... savePdfAs) {


int file_size = connection.getContentLength();
Log.d("Download: file_size", Integer.toString(file_size));
input = connection.getInputStream();

byte[] buffer = new byte[1024];
Expand All @@ -205,7 +193,6 @@ protected String doInBackground(String... savePdfAs) {

}
catch (Exception e) {
Log.e("Something broke while fetching PDF", e.toString());
}
finally {
try {
Expand Down Expand Up @@ -293,7 +280,6 @@ public void OpenPDF(File filz) {
Intent intent = new Intent(Intent.ACTION_VIEW);
String uri = (Uri.fromFile(filz)).toString();
Uri newUri = Uri.parse(uri);
Log.d("OpenPDF checking path",newUri.toString());
intent.setDataAndType(newUri,"application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

Expand All @@ -308,7 +294,6 @@ public void OpenPDF(File filz) {
}
catch (Exception e)
{
Log.e("Something went wrong!", "Error log below:");

}
}
Expand All @@ -331,20 +316,17 @@ protected Void doInBackground(Void...as) {
if (isOnline()){
try {
JSONObject json = getJson("http://kjarninn.com/json");
Log.d("test", "Finished fetching JSON: ");

versions = json.getJSONArray("versions");
Assert.assertNotNull(versions);

return null;
}
catch (Exception e) {
Log.e("Error in getJson","");

}
}
else {
Log.e("Entering JsonFallback",".");
JsonFallback();
return null;
}
Expand All @@ -353,7 +335,6 @@ protected Void doInBackground(Void...as) {

@Override
protected void onPostExecute(Void v) {
Log.d("Entering Post", "Post");
try{
LoadBooks();
}
Expand Down Expand Up @@ -387,18 +368,13 @@ private void LoadBooks() throws JSONException {
/*
* Updates Bookshelf ListView, changes buttons and buttonOnclickListeners
*/
private void UpdateView() {
Log.d("Entering","UpdateView()");
Log.e("Radom tests","");
Log.e("VersionNames[3]",versionNames[3]);
Log.e("VersionSizes[3]",Integer.toString(versionsSizes[3]));
private void UpdateView() {
int downCounter = versionNames.length;
for (int upCounter = 0; upCounter < versionNames.length; ++upCounter) {
--downCounter;
boolean[] localResult = localstorage.isInLocal(versionNames[downCounter],versionsSizes[downCounter]);//down
BookshelfItem item = BookshelfModel.GetbyId(upCounter);//up
if (localResult[0] && localResult[1]){
Log.d("This PDF is ready in local:",versionNames[downCounter]);//down
//Change Model values
item.Buttontext = "Lesa";
item.Showdelete = true;
Expand All @@ -417,7 +393,6 @@ private void UpdateView() {
*/
public static JSONObject getJson(String url){

Log.d("test", "Starting to get JSON");
InputStream is = null;
String result = "";
JSONObject jsonObject = null;
Expand All @@ -429,9 +404,7 @@ public static JSONObject getJson(String url){
HttpResponse response = httpclient.execute(httppost);
HttpEntity httpEntity = response.getEntity();
is = httpEntity.getContent();
Log.d("test", "JSON loaded");
} catch(Exception e) {
Log.d("test", "Error loading JSON");
return null;
}

Expand All @@ -449,17 +422,13 @@ public static JSONObject getJson(String url){
localstorage.writeToFile(result,"data.json");

} catch(Exception e) {
Log.d("test", "Error reading JSON");
return null;
}

// Convert string to object
try {
jsonObject = new JSONObject(result);
Log.d("test", "JSON string has been converted to an Object");
} catch(JSONException e) {
Log.d("test", "Failed to convert string to JSON");
Log.d("test", e.toString());
jsonObject = new JSONObject(result);
} catch(JSONException e) {
return null;
}

Expand All @@ -484,7 +453,6 @@ private void selectNavbarItem(int position) {
switch(position) {
case 0:
//I lestri
Log.d("Navbar Click","Item 0");
sharedprefs shpref = new sharedprefs();
String last = shpref.getPrefString("lastopened","error");
if (last.equals("error")){
Expand All @@ -497,19 +465,16 @@ private void selectNavbarItem(int position) {
break;
case 3:
//Upplýsingar
Log.d("Navbar Click","Item 3");
Intent browserIntent_toUpplysingar = new Intent(Intent.ACTION_VIEW, Uri.parse("http://kjarninn.com/info"));
startActivity(browserIntent_toUpplysingar);
break;
case 1:
//Kjarnaofninn
Log.d("Navbar Click","Item 1");
Intent browserIntent_toOfninn = new Intent(Intent.ACTION_VIEW, Uri.parse("http://kjarninn.is/kjarnaofninn"));
startActivity(browserIntent_toOfninn);
break;
case 2:
//Pistlar
Log.d("Navbar Click","Item 2");
Intent browserIntent_toSite = new Intent(Intent.ACTION_VIEW, Uri.parse("http://kjarninn.is/#pistlar"));
startActivity(browserIntent_toSite);
break;
Expand All @@ -524,7 +489,6 @@ public void selectBookshelfItem(int position) {
if (isOnline()){
try {
JSONObject version = versions.getJSONObject(position);
Log.d("Selected Bookshelf Item", version.getString("pdfurl"));

// this needs to be bound to a button instead of calling it here
//
Expand All @@ -551,7 +515,6 @@ public void onCancel(DialogInterface dialog) {
}
});

Log.d("Starting Download",nafn);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
download.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, downloads);
Expand All @@ -560,7 +523,6 @@ public void onCancel(DialogInterface dialog) {
}
catch (JSONException e) {
// TODO Auto-generated catch block
Log.e("Error in getJson","");
}
}
else{
Expand All @@ -572,7 +534,6 @@ public void onCancel(DialogInterface dialog) {
*/
public void BookshelfButtonClick(View v) {
int id = v.getId();
Log.d("ListView Button click","id="+id);
ImageButton button = (ImageButton) v.findViewById(id);
String buttontext = button.getTag().toString();
int lastpos = versionNames.length-1;
Expand All @@ -595,7 +556,6 @@ public void BookshelfButtonClick(View v) {
*/
public void DeleteButtonClick(View v) {
final int id = v.getId();
Log.d("Delete Button click","id="+id);

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
Expand All @@ -609,7 +569,6 @@ public void onClick(DialogInterface dialog, int which) {
int delta = 1000;
int deleteButtonsLastPosition = (versionNames.length-1)+delta;
int deleteButtonChosenPosition = deleteButtonsLastPosition-id;
Log.d("Deleting...",versionNames[deleteButtonChosenPosition]);
File dir = getFilesDir();
File file = new File(dir, versionNames[deleteButtonChosenPosition]);
localstorage.deleteFromLocal(file);
Expand Down Expand Up @@ -676,12 +635,10 @@ protected Void doInBackground(Void...as) {
//Critical þarf að laga ef ekki nettenging
}
catch (Exception e){
Log.e("Error in GetFileSizes","");
}
}
}
else{
Log.e("Entering sizesFallback",".");
sizesFallback();
}
return null;
Expand Down Expand Up @@ -731,11 +688,9 @@ public Void JsonFallback(){
try{
JSONObject json = new JSONObject(result);
versions = json.getJSONArray("versions");
Log.e("Loaded json backup",".");

}
catch (Exception e){
Log.e("Error in JsonFallback",".");
}
return null;
}
Expand All @@ -752,7 +707,6 @@ public void sizesFallback(){
versionsSizes[i] = file_size;
}
catch (Exception e){
Log.e("Error in sizesFallback",".");
e.printStackTrace();
}
}
Expand Down
34 changes: 0 additions & 34 deletions src/is/hi/hbv/kjarninn/TDD.java

This file was deleted.

0 comments on commit c5ddee9

Please sign in to comment.