Merge pull request 'settings' (#11) from settings into main

Reviewed-on: https://patrice.asgardius.company/gitea/asgardius/s3manager/pulls/11
This commit is contained in:
Page Asgardius 2022-10-06 10:25:29 -07:00
commit 1b850d922f
15 changed files with 391 additions and 29 deletions

View file

@ -9,8 +9,8 @@ android {
applicationId "asgardius.page.s3manager"
minSdk 24
targetSdk 33
versionCode 23
versionName "0.1.21"
versionCode 24
versionName "0.1.22"
setProperty("archivesBaseName", "s3-manager-$versionName")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View file

@ -19,6 +19,14 @@
android:supportsRtl="true"
android:theme="@style/Theme.AsgardiusS3Manager"
tools:targetApi="31">
<activity
android:name=".Settings"
android:exported="false"
android:label="@string/settings">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".ObjectInfo"
android:configChanges="orientation|keyboardHidden|screenSize|uiMode|keyboardHidden"

View file

@ -47,6 +47,7 @@ public class BucketSelect extends AppCompatActivity {
AWSCredentials myCredentials;
AmazonS3 s3client;
ProgressBar simpleProgressBar;
int videocache, videotime;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -56,6 +57,8 @@ public class BucketSelect extends AppCompatActivity {
password = getIntent().getStringExtra("password");
location = getIntent().getStringExtra("region");
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
videocache = getIntent().getIntExtra("videocache", 40);
videotime = getIntent().getIntExtra("videotime", 1);
prefix = "";
setContentView(R.layout.activity_bucket_select);
region = Region.getRegion("us-east-1");
@ -193,6 +196,8 @@ public class BucketSelect extends AppCompatActivity {
intent.putExtra("treelevel", treelevel);
intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime);
startActivity(intent);
}

View file

@ -27,6 +27,7 @@ public class MainActivity extends AppCompatActivity {
ArrayList Name;
ArrayList Img;
MyDbHelper dbHelper;
int videocache, videotime;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -40,6 +41,71 @@ public class MainActivity extends AppCompatActivity {
recyclerView.setLayoutManager(linearLayoutManager);
dbHelper = new MyDbHelper(this);
Thread getprefs = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
// Database Queries
try {
db = dbHelper.getWritableDatabase();
String query = "SELECT value FROM preferences where setting='videocache'";
Cursor cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){
videocache = (Integer.parseInt(cursor.getString(0)));
}
db.close();
} catch (Exception e) {
try {
db = dbHelper.getWritableDatabase();
db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')");
videocache = 300;
db.close();
} catch (Exception f) {
db = dbHelper.getWritableDatabase();
db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)");
db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')");
db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')");
videocache = 300;
//videotime = 3;
db.close();
}
}
try {
db = dbHelper.getWritableDatabase();
String query = "SELECT value FROM preferences where setting='videotime'";
Cursor cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){
videotime = (Integer.parseInt(cursor.getString(0)));
}
db.close();
} catch (Exception e) {
try {
db = dbHelper.getWritableDatabase();
db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')");
videotime = 3;
db.close();
} catch (Exception f) {
db = dbHelper.getWritableDatabase();
db.execSQL("CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)");
db.close();
}
}
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
finish();
}
}
});
Thread listaccount = new Thread(new Runnable() {
@Override
@ -47,20 +113,17 @@ public class MainActivity extends AppCompatActivity {
try {
//Your code goes here
db = dbHelper.getWritableDatabase();
if (db != null) {
// Database Queries
Name = new ArrayList<String>();
Img = new ArrayList<String>();
String query = "SELECT id FROM account";
Cursor cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){
Name.add(cursor.getString(0));
Img.add(R.drawable.account);
}
db.close();
} else {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
// Database Queries
Name = new ArrayList<String>();
Img = new ArrayList<String>();
String query = "SELECT id FROM account";
Cursor cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){
Name.add(cursor.getString(0));
Img.add(R.drawable.account);
}
db.close();
getprefs.start();
runOnUiThread(new Runnable() {
@Override
@ -208,12 +271,12 @@ public class MainActivity extends AppCompatActivity {
});
//This is to view app credits
Button about = (Button)findViewById(R.id.about_button);
about.setOnClickListener(new View.OnClickListener(){
Button settings = (Button)findViewById(R.id.settings_button);
settings.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
aboutPage();
settingsPage();
}
});
}
@ -226,6 +289,8 @@ public class MainActivity extends AppCompatActivity {
intent.putExtra("password", password);
intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime);
startActivity(intent);
}
@ -246,11 +311,11 @@ public class MainActivity extends AppCompatActivity {
}
private void aboutPage () {
private void settingsPage() {
Intent intent = new Intent(this, WebBrowser.class);
intent.putExtra("web_url", "file:///android_asset/about.htm");
intent.putExtra("title", getResources().getString(R.string.about_button));
Intent intent = new Intent(this, Settings.class);
//intent.putExtra("web_url", "file:///android_asset/about.htm");
//intent.putExtra("title", getResources().getString(R.string.about_button));
startActivity(intent);
}

View file

@ -5,7 +5,10 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class MyDbHelper extends SQLiteOpenHelper {
private static final String atcreate = "CREATE TABLE IF NOT EXISTS account(id text UNIQUE, endpoint text, username text, password text, region text, pdfendpoint text)";
private static final String usertable = "CREATE TABLE IF NOT EXISTS account(id text UNIQUE, endpoint text, username text, password text, region text, pdfendpoint text)";
private static final String preftable = "CREATE TABLE IF NOT EXISTS preferences(setting text UNIQUE, value text)";
private static final String setvideocache = "INSERT INTO preferences VALUES ('videocache', '300')";
private static final String setvideotime = "INSERT INTO preferences VALUES ('videotime', '3')";
//private static final String upgrade = "ALTER TABLE account add column pdfendpoint text";
private static final int DATABASE_VERSION = 1;
private static final String dbname = "accounts.sqlite3";
@ -15,7 +18,10 @@ public class MyDbHelper extends SQLiteOpenHelper {
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(atcreate);
db.execSQL(usertable);
db.execSQL(preftable);
db.execSQL(setvideocache);
db.execSQL(setvideotime);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

View file

@ -50,6 +50,7 @@ public class ObjectSelect extends AppCompatActivity {
AWSCredentials myCredentials;
AmazonS3 s3client;
ProgressBar simpleProgressBar;
int videocache, videotime;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -62,6 +63,8 @@ public class ObjectSelect extends AppCompatActivity {
pdfendpoint = getIntent().getStringExtra("pdfendpoint");
prefix = getIntent().getStringExtra("prefix");
treelevel = getIntent().getIntExtra("treelevel", 0);
videocache = getIntent().getIntExtra("videocache", 40);
videotime = getIntent().getIntExtra("videotime", 1);
setContentView(R.layout.activity_object_select);
getSupportActionBar().setTitle(bucket+"/"+prefix);
region = Region.getRegion(location);
@ -287,7 +290,7 @@ public class ObjectSelect extends AppCompatActivity {
Calendar mycal = Calendar.getInstance();
mycal.setTime(expiration);
//System.out.println("today is " + mycal.getTime());
mycal.add(Calendar.HOUR, 6);
mycal.add(Calendar.HOUR, videotime);
//System.out.println("Expiration date: " + mycal.getTime());
expiration = mycal.getTime();
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, prefix + Name.get(position).toString()).withExpiration(expiration);;
@ -404,6 +407,7 @@ public class ObjectSelect extends AppCompatActivity {
Intent intent = new Intent(this, VideoPlayer.class);
intent.putExtra("video_url", url);
intent.putExtra("videocache", videocache);
startActivity(intent);
}
@ -444,6 +448,8 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("treelevel", treelevel+1);
intent.putExtra("region", location);
intent.putExtra("pdfendpoint", pdfendpoint);
intent.putExtra("videocache", videocache);
intent.putExtra("videotime", videotime);
startActivity(intent);
}
@ -459,6 +465,7 @@ public class ObjectSelect extends AppCompatActivity {
intent.putExtra("object", object);
intent.putExtra("region", location);
intent.putExtra("mediafile", mediafile);
intent.putExtra("videotime", videotime);
startActivity(intent);
}

View file

@ -0,0 +1,134 @@
package asgardius.page.s3manager;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import asgardius.page.s3manager.databinding.ActivitySettingsBinding;
public class Settings extends AppCompatActivity {
private ActivitySettingsBinding binding;
MyDbHelper dbHelper;
SQLiteDatabase db;
String videocache, videotime;
EditText vcachepick, vtimepick;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivitySettingsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
vcachepick = (EditText)findViewById(R.id.videocache);
vtimepick = (EditText)findViewById(R.id.videotime);
dbHelper = new MyDbHelper(this);
Thread getprefs = new Thread(new Runnable() {
@Override
public void run() {
try {
//Your code goes here
// Database Queries
db = dbHelper.getWritableDatabase();
String query = "SELECT value FROM preferences where setting='videocache'";
Cursor cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){
videocache = (cursor.getString(0));
}
query = "SELECT value FROM preferences where setting='videotime'";
cursor = db.rawQuery(query,null);
while (cursor.moveToNext()){
videotime = (cursor.getString(0));
}
db.close();
runOnUiThread(new Runnable() {
@SuppressLint("SetTextI18n")
@Override
public void run() {
vcachepick.setText(videocache);
vtimepick.setText(videotime);
}
});
} catch (Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
});
//Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show();
finish();
}
}
});
getprefs.start();
//This is to add new user account
Button saveprefs = (Button)findViewById(R.id.saveprefs);
saveprefs.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
try {
videocache = vcachepick.getText().toString();
videotime = vtimepick.getText().toString();
if (videocache.equals("") || videotime.equals("")) {
Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_null), Toast.LENGTH_SHORT).show();
} else {
db = dbHelper.getWritableDatabase();
db.execSQL("UPDATE preferences SET value='"+videocache+"' where setting='videocache'");
db.execSQL("UPDATE preferences SET value='"+videotime+"' where setting='videotime'");
db.close();
mainmenu();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),getResources().getString(R.string.broken_database), Toast.LENGTH_SHORT).show();
}
//This launch account add screen
//addaccount(false);
}
});
//This is to view app credits
Button about = (Button)findViewById(R.id.settings_button);
about.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
aboutPage();
}
});
}
private void aboutPage () {
Intent intent = new Intent(this, WebBrowser.class);
intent.putExtra("web_url", "file:///android_asset/about.htm");
intent.putExtra("title", getResources().getString(R.string.about_button));
startActivity(intent);
}
private void mainmenu() {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
}

View file

@ -36,6 +36,7 @@ public class Share extends AppCompatActivity {
GeneratePresignedUrlRequest request;
Date expiration;
URL objectURL;
int videotime;
public static String URLify(String str) {
str = str.trim();
@ -85,6 +86,7 @@ public class Share extends AppCompatActivity {
location = getIntent().getStringExtra("region");
object = getIntent().getStringExtra("object");
mediafile = getIntent().getBooleanExtra("mediafile", false);
videotime = getIntent().getIntExtra("videotime", 1);
region = Region.getRegion(location);
s3ClientOptions = S3ClientOptions.builder().build();
myCredentials = new BasicAWSCredentials(username, password);
@ -144,7 +146,7 @@ public class Share extends AppCompatActivity {
expiration = new Date();
mycal.setTime(expiration);
//System.out.println("today is " + mycal.getTime());
mycal.add(Calendar.HOUR, 6);
mycal.add(Calendar.HOUR, videotime);
//System.out.println("Expiration date: " + mycal.getTime());
expiration = mycal.getTime();
request = new GeneratePresignedUrlRequest(bucket, object).withExpiration(expiration);

View file

@ -35,8 +35,9 @@ public class VideoPlayer extends AppCompatActivity {
private WifiManager.WifiLock mWifiLock;
private PowerManager.WakeLock mWakeLock;
private PowerManager powerManager;
private long maxCacheSize = 1024 * 1024 * 1024;
private long maxCacheSize;
SimpleCache simpleCache;
int videocache;
ExoPlayer player;
@ -50,6 +51,8 @@ public class VideoPlayer extends AppCompatActivity {
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Transistor:wake_lock");
//Get media url
String videoURL = getIntent().getStringExtra("video_url");
videocache = getIntent().getIntExtra("videocache", 40);
maxCacheSize = (long)videocache * 1024 * 1024;
playerView = findViewById(R.id.player_view);
// creating a variable for exoplayer
player = new ExoPlayer.Builder(this).build();

View file

@ -27,11 +27,11 @@
style="?android:attr/buttonStyle" />
<Button
android:id="@+id/about_button"
android:id="@+id/settings_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/about_button"
android:text="@string/settings"
tools:ignore="MissingConstraints"
style="?android:attr/buttonStyle" />

View file

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Settings">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/videocache"
android:textAlignment="center"
android:textSize="25sp"/>
<EditText
android:id="@+id/videocache"
android:layout_width="match_parent"
android:layout_height="48dp"
android:focusable="true"
android:hint="@string/videocache"
android:inputType="number"
android:textColorHint="?attr/colorOnSecondary"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/videotime"
android:textAlignment="center"
android:textSize="25sp"/>
<EditText
android:id="@+id/videotime"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_weight="1"
android:focusable="true"
android:hint="@string/videotime"
android:inputType="number"
android:textColorHint="?attr/colorOnSecondary"/>
<Button
android:id="@+id/saveprefs"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="@string/save_settings"
android:textColor="#ffffff"
android:textSize="24sp" />
<Button
android:id="@+id/settings_button"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="@string/about_button"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>

View file

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Settings"
tools:showIn="@layout/activity_settings">
<LinearLayout
android:id="@+id/linearLayoutSubmit"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/expiration_date"
android:textAlignment="center"
android:textSize="25sp" />
<Button
android:id="@+id/saveprefs"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/accountadd_button"
tools:ignore="MissingConstraints"
style="?android:attr/buttonStyle" />
<Button
android:id="@+id/settings_button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/about_button"
tools:ignore="MissingConstraints"
style="?android:attr/buttonStyle" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View file

@ -85,4 +85,8 @@
<string name="file_count">Archivos</string>
<string name="null_expiration_date">Debe establecer una fecha de expiración para compartir archivos</string>
<string name="download_canceled">Descarga cancelada</string>
<string name="settings">Ajustes</string>
<string name="save_settings">Guardar ajustes</string>
<string name="videocache">Tamaño máximo de cache multimedia (en MiB)</string>
<string name="videotime">Tiempo de expiración para visor multimedia (en horas)</string>
</resources>

View file

@ -89,4 +89,8 @@
<string name="about_button">About this app</string>
<string name="dummy_button">Dummy Button</string>
<string name="dummy_content">DUMMY\nCONTENT</string>
<string name="settings">Settings</string>
<string name="save_settings">Save settings</string>
<string name="videocache">Max media cache size (in MiB)</string>
<string name="videotime">Expiration time for media viewer (in hours)</string>
</resources>

View file

@ -26,4 +26,13 @@
<item name="fullscreenBackgroundColor">@color/light_blue_600</item>
<item name="fullscreenTextColor">@color/light_blue_A200</item>
</style>
<style name="Theme.AsgardiusS3Manager.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Theme.AsgardiusS3Manager.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="Theme.AsgardiusS3Manager.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>