text viewer fix

This commit is contained in:
Page Asgardius 2022-09-07 11:36:43 -07:00
parent 2347474a11
commit 1ecc379d96
5 changed files with 76 additions and 6 deletions

View file

@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "asgardius.page.s3manager"
minSdk 23
minSdk 24
targetSdk 32
versionCode 1
versionName "0.1.0"

View file

@ -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();
}

View file

@ -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) {

View file

@ -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();
}
}*/
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7 KiB