From 1ecc379d966c6895c61d851cfebce7ad1894ec33 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Wed, 7 Sep 2022 11:36:43 -0700 Subject: [PATCH] text viewer fix --- app/build.gradle | 2 +- .../page/s3manager/MainActivity.java | 4 ++ .../page/s3manager/ObjectSelect.java | 17 ++++- .../asgardius/page/s3manager/TextViewer.java | 59 ++++++++++++++++-- app/src/main/res/drawable-v24/textfile.png | Bin 0 -> 7164 bytes 5 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable-v24/textfile.png diff --git a/app/build.gradle b/app/build.gradle index 8d5e5b8..44b7b11 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ android { defaultConfig { applicationId "asgardius.page.s3manager" - minSdk 23 + minSdk 24 targetSdk 32 versionCode 1 versionName "0.1.0" diff --git a/app/src/main/java/asgardius/page/s3manager/MainActivity.java b/app/src/main/java/asgardius/page/s3manager/MainActivity.java index 4a1ec00..cf1defc 100644 --- a/app/src/main/java/asgardius/page/s3manager/MainActivity.java +++ b/app/src/main/java/asgardius/page/s3manager/MainActivity.java @@ -135,6 +135,7 @@ public class MainActivity extends AppCompatActivity { //Toast.makeText(MainActivity.this, "You Clicked " + menuItem.getTitle(), Toast.LENGTH_SHORT).show(); if (menuItem.getTitle() == getResources().getString(R.string.accountedit_button)) { try { + db = dbHelper.getWritableDatabase(); String query = "SELECT id, endpoint, username, password FROM account where id=\""+ Name.get(position).toString()+ "\""; System.out.println(query); Cursor cursor = db.rawQuery(query,null); @@ -144,6 +145,7 @@ public class MainActivity extends AppCompatActivity { username = cursor.getString(2); password = cursor.getString(3); } + db.close(); addaccount(true); //Toast.makeText(MainActivity.this, "This feature is not yet implemented", Toast.LENGTH_SHORT).show(); } catch (Exception e) { @@ -159,12 +161,14 @@ public class MainActivity extends AppCompatActivity { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { + db = dbHelper.getWritableDatabase(); if (db != null) { // Database Queries try { db.execSQL("DELETE FROM account where id=\""+ Name.get(position).toString()+ "\""); Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountdel_success), Toast.LENGTH_SHORT).show(); mainmenu(); + db.close(); } catch (Exception e) { Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java index c8978c2..7785e4d 100644 --- a/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java +++ b/app/src/main/java/asgardius/page/s3manager/ObjectSelect.java @@ -118,6 +118,9 @@ public class ObjectSelect extends AppCompatActivity { if (Name.get(i).toString().endsWith("/")) { Img.add(R.drawable.folder); } + else if (Name.get(i).toString().endsWith(".txt") || Name.get(i).toString().endsWith(".md")) { + Img.add(R.drawable.textfile); + } else if (Name.get(i).toString().endsWith(".opus") || Name.get(i).toString().endsWith(".ogg") || Name.get(i).toString().endsWith(".oga") || Name.get(i).toString().endsWith(".mp3") || Name.get(i).toString().endsWith(".m4a") || Name.get(i).toString().endsWith(".flac") @@ -186,12 +189,17 @@ public class ObjectSelect extends AppCompatActivity { if (Img.get(position).equals(R.drawable.folder)) { //go to subfolder explorer(Name.get(position).toString()); + } else if (Img.get(position).equals(R.drawable.textfile)) { + //load media file + GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()); + URL objectURL = s3client.generatePresignedUrl(request); + textviewer(objectURL.toString()); } else if (Img.get(position).equals(R.drawable.webpage)) { //load media file GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()); URL objectURL = s3client.generatePresignedUrl(request); webbrowser(objectURL.toString()); - } else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) { + } else if (Img.get(position).equals(R.drawable.audiofile) || Img.get(position).equals(R.drawable.videofile)) { //load media file GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()); URL objectURL = s3client.generatePresignedUrl(request); @@ -237,6 +245,13 @@ public class ObjectSelect extends AppCompatActivity { intent.putExtra("video_url", url); startActivity(intent); + } + private void textviewer(String url) { + + Intent intent = new Intent(this, TextViewer.class); + intent.putExtra("video_url", url); + startActivity(intent); + } private void webbrowser (String url) { diff --git a/app/src/main/java/asgardius/page/s3manager/TextViewer.java b/app/src/main/java/asgardius/page/s3manager/TextViewer.java index 45f60ed..a046285 100644 --- a/app/src/main/java/asgardius/page/s3manager/TextViewer.java +++ b/app/src/main/java/asgardius/page/s3manager/TextViewer.java @@ -3,14 +3,23 @@ package asgardius.page.s3manager; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; +import android.view.View; import android.widget.EditText; import android.widget.Toast; +import com.amazonaws.services.s3.model.ListObjectsRequest; +import com.amazonaws.services.s3.model.ObjectListing; +import com.amazonaws.services.s3.model.S3ObjectSummary; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.stream.Collectors; public class TextViewer extends AppCompatActivity { EditText filecontent; @@ -21,12 +30,54 @@ public class TextViewer extends AppCompatActivity { setContentView(R.layout.activity_text_viewer); filecontent = (EditText)findViewById(R.id.textShow); - try { + String videoURL = getIntent().getStringExtra("video_url"); + Thread textread = new Thread(new Runnable() { + + @Override + public void run() { + try { + //Your code goes here + URL fileurl = new URL(videoURL); + + // Read all the text returned by the server + BufferedReader in = new BufferedReader(new InputStreamReader(fileurl.openStream())); + String str = in.lines().collect(Collectors.joining()); + in.close(); + + runOnUiThread(new Runnable() { + + @Override + public void run() { + // Sending reference and data to Adapter + filecontent.setText(str); + + } + }); + //System.out.println("tree "+treelevel); + //System.out.println("prefix "+prefix); + + } catch (Exception e) { + e.printStackTrace(); + runOnUiThread(new Runnable() { + + @Override + public void run() { + Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); + } + }); + //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); + finish(); + } + } + }); + textread.start(); + + /*try { // Create a URL for the desired page - URL url = new URL("yoursite.com/thefile.txt"); + URL fileurl = new URL(videoURL); // Read all the text returned by the server - BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); + BufferedReader in = new BufferedReader(new InputStreamReader(fileurl.openStream())); String str = in.readLine(); in.close(); filecontent.setText(str); @@ -34,6 +85,6 @@ public class TextViewer extends AppCompatActivity { Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_conn_fail), Toast.LENGTH_SHORT).show(); } catch (IOException e) { Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_conn_fail), Toast.LENGTH_SHORT).show(); - } + }*/ } } \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/textfile.png b/app/src/main/res/drawable-v24/textfile.png new file mode 100644 index 0000000000000000000000000000000000000000..5e4b2c5cc9ba9be94d948ad8c27ce88e3da05bab GIT binary patch literal 7164 zcmcIpcTiJXx8Dgtnv|#%r3V$2E-Gk<0SST?v4EfyK?Fg1i6KCOiWj8XfU7j&A}9jV zr6m!hDE$J`6D0KBYeL?^Z|42`=6iGRnaO0$-fQo*_A0-1_Bx?gE*lE+@8bsm2%a;- zT?GIRk#NAf1NvKf*uDY%@wpqBdjTL+wf%$Dx@Fvj2KRa!-1NTYcF!As$I~9*@p#qy zuFhU|ciin&-8>!M&gkrenD%Tl>G^m&x_N^0cbt7}<*s?#-*>h59NAn|gXTrI=W+I4 zcAod$z3;oZ0+;(P_TB_{doQir>1`?U|B>S3X=e`{y}jK}si`^LcX7F6r|RP4b>GhM z&VvW4c7FHoF|7cQlst#iyZ$hKx}OjoKO8VHZ%yrQYx6RCbHT<#LZnXW#K0Q-fm~$8 z2@zTl!cPA|p7vqIvO-GU2SLhJtKJVjV)UuJ&TrPg6`FzE;%$1-EYL?!= z4#Y}%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