Only show sub toasts when on subs page, WIP import ui

This commit is contained in:
Kelvin 2023-11-06 13:20:33 +01:00
parent 4aade35d19
commit baa26af0c0
11 changed files with 249 additions and 1 deletions

View file

@ -603,6 +603,23 @@ class Settings : FragmentedStorageFileJson() {
fun export() {
StateBackup.startExternalBackup();
}
/*
@FormField(R.string.import_data, FieldForm.BUTTON, R.string.import_data_description, 4)
fun import() {
val act = SettingsActivity.getActivity() ?: return;
StateApp.instance.requestFileReadAccess(act, null) {
if(it != null && it.exists()) {
val name = it.name;
val contents = it.readBytes(act);
if(contents != null) {
if(name != null && name.endsWith(".zip", true))
StateBackup.importZipBytes(act, act.lifecycleScope, contents);
}
}
}
}*/
}
@FormField(R.string.payment, FieldForm.GROUP, -1, 14)

View file

@ -753,6 +753,9 @@ class MainActivity : AppCompatActivity, IWithResultLauncher {
StateSaved.instance.setVideoToOpenBlocking(null);
}
inline fun <reified T> isFragmentActive(): Boolean {
return fragCurrent is T;
}
/**
* Navigate takes a MainFragment, and makes them the current main visible view

View file

@ -239,6 +239,25 @@ class StateApp {
return state;
}
fun requestFileReadAccess(activity: IWithResultLauncher, path: Uri?, handle: (DocumentFile?)->Unit) {
if(activity is Context) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT);
if(path != null)
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, path);
intent.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
.or(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.launchForResult(intent, 98) {
if(it.resultCode == Activity.RESULT_OK) {
val uri = it.data?.data;
if(uri != null)
handle(DocumentFile.fromSingleUri(activity, uri));
}
else
UIDialogs.showDialogOk(context, R.drawable.ic_security_pred, "No access granted");
};
}
}
fun requestDirectoryAccess(activity: IWithResultLauncher, name: String, purpose: String? = null, path: Uri?, handle: (Uri?)->Unit)
{
if(activity is Context)

View file

@ -2,6 +2,7 @@ package com.futo.platformplayer.subscription
import com.futo.platformplayer.Settings
import com.futo.platformplayer.UIDialogs
import com.futo.platformplayer.activities.MainActivity
import com.futo.platformplayer.api.media.models.ResultCapabilities
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
import com.futo.platformplayer.api.media.platforms.js.JSClient
@ -19,6 +20,7 @@ import com.futo.platformplayer.findNonRuntimeException
import com.futo.platformplayer.fragment.mainactivity.main.SubscriptionsFeedFragment
import com.futo.platformplayer.logging.Logger
import com.futo.platformplayer.models.Subscription
import com.futo.platformplayer.states.StateApp
import com.futo.platformplayer.states.StatePlatform
import com.futo.platformplayer.states.StateSubscriptions
import kotlinx.coroutines.CoroutineScope
@ -55,7 +57,7 @@ abstract class SubscriptionsTaskFetchAlgorithm(
for(clientTasks in tasksGrouped) {
val clientTaskCount = clientTasks.value.filter { !it.fromCache }.size;
val clientCacheCount = clientTasks.value.size - clientTaskCount;
if(clientCacheCount > 0) {
if(clientCacheCount > 0 && StateApp.instance.contextOrNull?.let { it is MainActivity && it.isFragmentActive<SubscriptionsFeedFragment>() } == true) {
UIDialogs.toast("[${clientTasks.key.name}] only updating ${clientTaskCount} most urgent channels (rqs). (${clientCacheCount} cached)");
}
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#000000" />
<corners android:radius="4dp" />
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M420,600L540,600L517,471Q537,461 548.5,442Q560,423 560,400Q560,367 536.5,343.5Q513,320 480,320Q447,320 423.5,343.5Q400,367 400,400Q400,423 411.5,442Q423,461 443,471L420,600ZM480,880Q341,845 250.5,720.5Q160,596 160,444L160,200L480,80L800,200L800,444Q800,596 709.5,720.5Q619,845 480,880ZM480,796Q584,763 652,664Q720,565 720,444L720,255L480,165L240,255L240,444Q240,565 308,664Q376,763 480,796ZM480,480Q480,480 480,480Q480,480 480,480L480,480L480,480L480,480L480,480Q480,480 480,480Q480,480 480,480Z"/>
</vector>

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M120,720L120,640L600,640L600,720L120,720ZM120,520L120,440L840,440L840,520L120,520ZM120,320L120,240L840,240L840,320L120,320Z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M640,480L640,400L720,400L720,480L640,480ZM640,560L560,560L560,480L640,480L640,560ZM640,640L640,560L720,560L720,640L640,640ZM447,320L367,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720L560,720L560,640L640,640L640,720L800,720Q800,720 800,720Q800,720 800,720L800,320Q800,320 800,320Q800,320 800,320L640,320L640,400L560,400L560,320L447,320ZM160,800Q127,800 103.5,776.5Q80,753 80,720L80,240Q80,207 103.5,183.5Q127,160 160,160L400,160L480,240L800,240Q833,240 856.5,263.5Q880,287 880,320L880,720Q880,753 856.5,776.5Q833,800 800,800L160,800ZM160,720L160,720Q160,720 160,720Q160,720 160,720L160,320Q160,320 160,320Q160,320 160,320L160,320L160,240L160,240Q160,240 160,240Q160,240 160,240L160,720Q160,720 160,720Q160,720 160,720Z"/>
</vector>

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@color/gray_1d">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="40dp">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/update_spinner"
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/ic_move_up" />
<TextView
android:id="@+id/text_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_gravity="center"
android:textSize="14dp"
android:textColor="@color/white"
android:fontFamily="@font/inter_regular" />
</FrameLayout>
<TextView
android:id="@+id/text_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/there_is_an_update_available_do_you_wish_to_update"
android:textSize="14dp"
android:textColor="@color/white"
android:fontFamily="@font/inter_regular"
android:layout_marginTop="30dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:padding="10dp"
android:layout_marginTop="28dp"
android:layout_marginBottom="28dp">
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@color/gray_1d">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="40dp">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/update_spinner"
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/ic_move_up" />
<TextView
android:id="@+id/text_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_gravity="center"
android:textSize="14dp"
android:textColor="@color/white"
android:fontFamily="@font/inter_regular" />
</FrameLayout>
<TextView
android:id="@+id/text_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/import_options"
android:textAlignment="center"
android:textSize="14dp"
android:textColor="@color/white"
android:fontFamily="@font/inter_regular"
android:layout_marginTop="30dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:padding="10dp"
android:layout_marginTop="28dp"
android:layout_marginBottom="28dp">
<com.futo.platformplayer.views.buttons.BigButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:buttonIcon="@drawable/ic_zip"
app:buttonText="Import Grayjay export (.zip)"
android:layout_margin="5dp"
app:buttonBackground="@drawable/background_big_button_black"
app:buttonSubText="Pick a Grayjay export zip file" />
<com.futo.platformplayer.views.buttons.BigButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:buttonIcon="@drawable/ic_encrypted"
android:alpha="0.5"
app:buttonBackground="@drawable/background_big_button_black"
app:buttonText="Import Grayjay Auto-Backup (.ezip)"
android:layout_margin="5dp"
app:buttonSubText="Pick a Grayjay auto-backup encrypted zip file" />
<com.futo.platformplayer.views.buttons.BigButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:buttonIcon="@drawable/ic_lines"
android:alpha="0.5"
app:buttonBackground="@drawable/background_big_button_black"
app:buttonText="Import Line Text file (.txt)"
app:buttonSubText="Pick a text file with one entry per line" />
<com.futo.platformplayer.views.buttons.BigButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:buttonIcon="@drawable/ic_play"
app:buttonBackground="@drawable/background_big_button_black"
app:buttonText="Import NewPipe Subscriptions (.json)"
app:buttonSubText="Pick a NewPipe subscriptions json file" />
<Button
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/close"
android:layout_marginTop="20dp"
android:textSize="14dp"
android:fontFamily="@font/inter_regular"
android:textColor="@color/colorPrimary"
android:background="@color/transparent" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -28,6 +28,7 @@
<string name="update">Update</string>
<string name="close">Close</string>
<string name="never">Never</string>
<string name="import_options">Select any of the following available import options.</string>
<string name="there_is_an_update_available_do_you_wish_to_update">There is an update available, do you wish to update?</string>
<string name="downloading_update">Downloading update…</string>
<string name="installing_update">Installing update…</string>
@ -302,6 +303,8 @@
<string name="enable_casting">Enable casting</string>
<string name="experimental_background_update_for_subscriptions_cache">Experimental background update for subscriptions cache</string>
<string name="export_data">Export Data</string>
<string name="import_data">Import Data</string>
<string name="import_data_description">Select a file to import, support various files (alternative to opening directly)</string>
<string name="external_storage">External Storage</string>
<string name="feed_style">Feed Style</string>
<string name="fetch_on_app_boot">Fetch on app boot</string>