From cd0b72a8877514c92ed1fd74735526a6a64637e7 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Mon, 2 Jan 2023 13:49:20 -0700 Subject: [PATCH] preferences --- .../page/s3manager/MainActivity.java | 72 ++++++++++++++++++- .../asgardius/page/s3manager/MyDbHelper.java | 4 ++ .../asgardius/page/s3manager/Settings.java | 29 +++++++- .../asgardius/page/s3manager/VideoPlayer.java | 55 ++++++++++---- app/src/main/res/layout/activity_settings.xml | 24 +++++++ app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 7 files changed, 171 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/asgardius/page/s3manager/MainActivity.java b/app/src/main/java/asgardius/page/s3manager/MainActivity.java index 33539cf..9447245 100644 --- a/app/src/main/java/asgardius/page/s3manager/MainActivity.java +++ b/app/src/main/java/asgardius/page/s3manager/MainActivity.java @@ -33,8 +33,6 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - isplaylist = true; - playlisttime = 1; recyclerView = findViewById(R.id.alist); @@ -70,6 +68,8 @@ public class MainActivity extends AppCompatActivity { db.execSQL("INSERT INTO preferences VALUES ('videocache', '300')"); db.execSQL("INSERT INTO preferences VALUES ('videotime', '3')"); db.execSQL("INSERT INTO preferences VALUES ('buffersize', '12000')"); + db.execSQL("INSERT INTO preferences VALUES ('playlisttime', '5')"); + db.execSQL("INSERT INTO preferences VALUES ('isplaylist', '0')"); videocache = 300; //videotime = 3; db.close(); @@ -119,6 +119,74 @@ public class MainActivity extends AppCompatActivity { //Toast.makeText(getApplicationContext(),getResources().getString(R.string.media_list_fail), Toast.LENGTH_SHORT).show(); finish(); } + try { + db = dbHelper.getWritableDatabase(); + String query = "SELECT value FROM preferences where setting='playlisttime'"; + Cursor cursor = db.rawQuery(query,null); + while (cursor.moveToNext()){ + playlisttime = (Integer.parseInt(cursor.getString(0))); + } + db.close(); + if (playlisttime == 0) { + try { + db = dbHelper.getWritableDatabase(); + db.execSQL("INSERT INTO preferences VALUES ('playlisttime', '5')"); + playlisttime = 5; + db.close(); + } catch (Exception e) { + 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(); + } + try { + db = dbHelper.getWritableDatabase(); + String query = "SELECT value FROM preferences where setting='isplaylist'"; + Cursor cursor = db.rawQuery(query,null); + String update = null; + while (cursor.moveToNext()){ + isplaylist = cursor.getString(0).equals("1"); + if(!isplaylist) { + update = cursor.getString(0); + } + } + db.close(); + if (!isplaylist && update == null) { + try { + db = dbHelper.getWritableDatabase(); + db.execSQL("INSERT INTO preferences VALUES ('isplaylist', '0')"); + isplaylist = false; + db.close(); + } catch (Exception e) { + 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(); + } try { db = dbHelper.getWritableDatabase(); String query = "SELECT value FROM preferences where setting='buffersize'"; diff --git a/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java b/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java index 4bb8c95..931c69f 100644 --- a/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java +++ b/app/src/main/java/asgardius/page/s3manager/MyDbHelper.java @@ -10,6 +10,8 @@ public class MyDbHelper extends SQLiteOpenHelper { 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 setbuffersize = "INSERT INTO preferences VALUES ('buffersize', '12000')"; + private static final String setplaylisttime = "INSERT INTO preferences VALUES ('playlisttime', '5')"; + private static final String setisplaylist = "INSERT INTO preferences VALUES ('isplaylist', '0')"; //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"; @@ -24,6 +26,8 @@ public class MyDbHelper extends SQLiteOpenHelper { db.execSQL(setvideocache); db.execSQL(setvideotime); db.execSQL(setbuffersize); + db.execSQL(setplaylisttime); + db.execSQL(setisplaylist); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { diff --git a/app/src/main/java/asgardius/page/s3manager/Settings.java b/app/src/main/java/asgardius/page/s3manager/Settings.java index 6ac8f05..82f8141 100644 --- a/app/src/main/java/asgardius/page/s3manager/Settings.java +++ b/app/src/main/java/asgardius/page/s3manager/Settings.java @@ -13,6 +13,8 @@ import android.widget.Button; import android.widget.EditText; import android.widget.Toast; +import com.google.android.material.switchmaterial.SwitchMaterial; + import asgardius.page.s3manager.databinding.ActivitySettingsBinding; public class Settings extends AppCompatActivity { @@ -20,9 +22,10 @@ public class Settings extends AppCompatActivity { private ActivitySettingsBinding binding; MyDbHelper dbHelper; SQLiteDatabase db; - String videocache, videotime, buffersize; - EditText vcachepick, vtimepick, bsizepick; + String videocache, videotime, buffersize, playlisttime; + EditText vcachepick, vtimepick, bsizepick, ptimepick; Button saveprefs, about; + SwitchMaterial isplaylist; @Override protected void onCreate(Bundle savedInstanceState) { @@ -33,7 +36,9 @@ public class Settings extends AppCompatActivity { vcachepick = (EditText)findViewById(R.id.videocache); vtimepick = (EditText)findViewById(R.id.videotime); bsizepick = (EditText)findViewById(R.id.buffersize); + ptimepick = (EditText)findViewById(R.id.playlisttime); dbHelper = new MyDbHelper(this); + isplaylist = (SwitchMaterial) findViewById(R.id.isplaylist); Thread getprefs = new Thread(new Runnable() { @Override @@ -57,6 +62,16 @@ public class Settings extends AppCompatActivity { while (cursor.moveToNext()){ buffersize = (cursor.getString(0)); } + query = "SELECT value FROM preferences where setting='isplaylist'"; + cursor = db.rawQuery(query,null); + while (cursor.moveToNext()){ + isplaylist.setChecked(cursor.getString(0).equals("1")); + } + query = "SELECT value FROM preferences where setting='playlisttime'"; + cursor = db.rawQuery(query,null); + while (cursor.moveToNext()){ + playlisttime = (cursor.getString(0)); + } db.close(); runOnUiThread(new Runnable() { @@ -66,6 +81,7 @@ public class Settings extends AppCompatActivity { vcachepick.setText(videocache); vtimepick.setText(videotime); bsizepick.setText(buffersize); + ptimepick.setText(playlisttime); } }); } catch (Exception e) { @@ -94,9 +110,10 @@ public class Settings extends AppCompatActivity { videocache = vcachepick.getText().toString(); videotime = vtimepick.getText().toString(); buffersize = bsizepick.getText().toString(); + playlisttime = ptimepick.getText().toString(); if (videocache.equals("") || videotime.equals("") || buffersize.equals("")) { Toast.makeText(getApplicationContext(),getResources().getString(R.string.accountadd_null), Toast.LENGTH_SHORT).show(); - } else if (videocache.equals("0") || videotime.equals("0")) { + } else if (videocache.equals("0") || videotime.equals("0") || playlisttime.equals("0")) { Toast.makeText(getApplicationContext(),getResources().getString(R.string.not_zero), Toast.LENGTH_SHORT).show(); } else if (Integer.parseInt(buffersize) <= 2000) { Toast.makeText(getApplicationContext(),getResources().getString(R.string.buffersize_error), Toast.LENGTH_SHORT).show(); @@ -107,6 +124,12 @@ public class Settings extends AppCompatActivity { db.execSQL("UPDATE preferences SET value='" + videocache + "' where setting='videocache'"); db.execSQL("UPDATE preferences SET value='" + videotime + "' where setting='videotime'"); db.execSQL("UPDATE preferences SET value='" + buffersize + "' where setting='buffersize'"); + db.execSQL("UPDATE preferences SET value='" + playlisttime + "' where setting='playlisttime'"); + if(isplaylist.isChecked()) { + db.execSQL("UPDATE preferences SET value='1' where setting='isplaylist'"); + } else { + db.execSQL("UPDATE preferences SET value='0' where setting='isplaylist'"); + } db.close(); mainmenu(); } diff --git a/app/src/main/java/asgardius/page/s3manager/VideoPlayer.java b/app/src/main/java/asgardius/page/s3manager/VideoPlayer.java index 01476d0..6059c08 100644 --- a/app/src/main/java/asgardius/page/s3manager/VideoPlayer.java +++ b/app/src/main/java/asgardius/page/s3manager/VideoPlayer.java @@ -146,6 +146,8 @@ public class VideoPlayer extends AppCompatActivity { // Prepare the player. player.setPlayWhenReady(true); playerNotificationManager = new PlayerNotificationManager.Builder(this, notificationId, "playback").build(); + playerNotificationManager.setUseNextActionInCompactView(true); + playerNotificationManager.setUsePreviousActionInCompactView(true); playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken()); playerNotificationManager.setPlayer(player); if (isplaylist) { @@ -225,6 +227,9 @@ public class VideoPlayer extends AppCompatActivity { mWakeLock.acquire(); //System.out.println("WakeLock acquired"); } + if(isplaylist) { + getSupportActionBar().setTitle(names.get(player.getCurrentMediaItemIndex())); + } } else if (state == 2) { // Buffering. //Acquiring WakeLock and WifiLock if not held @@ -236,6 +241,9 @@ public class VideoPlayer extends AppCompatActivity { mWakeLock.acquire(); //System.out.println("WakeLock acquired"); } + if(isplaylist) { + getSupportActionBar().setTitle(names.get(player.getCurrentMediaItemIndex())); + } } else { //Player inactive //Releasing WifiLock and WakeLock if held @@ -323,6 +331,7 @@ public class VideoPlayer extends AppCompatActivity { public void onDestroy() { mediaSessionConnector.setPlayer(null); + standaloneDatabaseProvider.close(); mediaSession.setActive(false); playerNotificationManager.setPlayer(null); player.release(); @@ -350,21 +359,43 @@ public class VideoPlayer extends AppCompatActivity { videocache = intent.getIntExtra("videocache", 40); buffersize = intent.getIntExtra("buffersize", 2000); isplaylist = intent.getBooleanExtra("isplaylist", false); + queue = intent.getStringArrayListExtra("queue"); + names = intent.getStringArrayListExtra("names"); getSupportActionBar().setTitle(title); - mediaSource = new ProgressiveMediaSource.Factory( - new CacheDataSource.Factory() - .setCache(simpleCache) - .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory() - .setUserAgent("ExoplayerDemo")) - .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR) - ).createMediaSource(MediaItem.fromUri(Uri.parse(videoURL))); - if (title.endsWith(".m3u8")) { - MediaItem mediaItem = MediaItem.fromUri(videoURL); - player.setMediaItem(mediaItem); + if (isplaylist) { + for (int i = 0; i < queue.size(); i++) { + if (names.get(i).endsWith(".m3u8")) { + MediaItem mediaItem = MediaItem.fromUri(queue.get(i)); + player.addMediaItem(mediaItem); + } else { + mediaSource = new ProgressiveMediaSource.Factory( + new CacheDataSource.Factory() + .setCache(simpleCache) + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory() + .setUserAgent("S3 Manager")) + .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR) + ).createMediaSource(MediaItem.fromUri(Uri.parse(queue.get(i)))); + player.addMediaSource(mediaSource); + } + } + player.prepare(); + player.seekTo(names.indexOf(title), 0); } else { - player.setMediaSource(mediaSource); + if (title.endsWith(".m3u8")) { + MediaItem mediaItem = MediaItem.fromUri(videoURL); + player.setMediaItem(mediaItem); + } else { + mediaSource = new ProgressiveMediaSource.Factory( + new CacheDataSource.Factory() + .setCache(simpleCache) + .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory() + .setUserAgent("S3 Manager")) + .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR) + ).createMediaSource(MediaItem.fromUri(Uri.parse(videoURL))); + player.setMediaSource(mediaSource); + } + player.prepare(); } - player.prepare(); // Start the playback. player.play(); super.onNewIntent(intent); diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 818b496..e332326 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -65,6 +65,30 @@ android:inputType="number" android:textColorHint="?attr/colorOnSecondary"/> + + + + + +