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 0000000..5e4b2c5 Binary files /dev/null and b/app/src/main/res/drawable-v24/textfile.png differ