preferences
This commit is contained in:
parent
48fa899a97
commit
cd0b72a887
7 changed files with 171 additions and 17 deletions
|
@ -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'";
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -65,6 +65,30 @@
|
|||
android:inputType="number"
|
||||
android:textColorHint="?attr/colorOnSecondary"/>
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/isplaylist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:text="@string/playlist_playback"
|
||||
android:textSize="24sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/playlisttime"
|
||||
android:textAlignment="center"
|
||||
android:textSize="25sp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/playlisttime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
android:focusable="true"
|
||||
android:hint="@string/playlisttime"
|
||||
android:inputType="number"
|
||||
android:textColorHint="?attr/colorOnSecondary"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/saveprefs"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -93,6 +93,8 @@
|
|||
<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>
|
||||
<string name="playlist_playback">Habilitar listas de reproducción</string>
|
||||
<string name="playlisttime">Tiempo de expiración para listas de reproducción (en horas)</string>
|
||||
<string name="buffersize">Tamaño del buffer del reproductor multimedia (en milisegundos)</string>
|
||||
<string name="buffersize_error">El tamaño del búfer debe ser de al menos 2001 milisegundos</string>
|
||||
<string name="mediaplayer_multierror">Solo se puede reproducir un archivo multimedia a la vez</string>
|
||||
|
|
|
@ -101,6 +101,8 @@
|
|||
<string name="videotime">Expiration time for media viewer (in hours)</string>
|
||||
<string name="buffersize">Media player buffer size (in milliseconds)</string>
|
||||
<string name="buffersize_error">Buffer size must be at least 2001 milliseconds</string>
|
||||
<string name="playlist_playback">Enable playlists</string>
|
||||
<string name="playlisttime">Expiration time for media playlists (in hours)</string>
|
||||
<string name="mediaplayer_multierror">Only one media file can be played at once</string>
|
||||
<string name="playback_channel_name">Video Playback</string>
|
||||
<string name="not_zero">This value cannot be zero</string>
|
||||
|
|
Loading…
Reference in a new issue