Initial commit

This commit is contained in:
Mike Nolan 2022-10-04 05:44:09 -05:00
commit dcd6d64191
63 changed files with 2995 additions and 0 deletions

398
.gitignore vendored Normal file
View File

@ -0,0 +1,398 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml

1046
TYTD.Common/Class1.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M14.35,12.15Q13.3,12.15 12.575,12.875Q11.85,13.6 11.85,14.65Q11.85,15.7 12.575,16.425Q13.3,17.15 14.35,17.15Q15.4,17.15 16.125,16.425Q16.85,15.7 16.85,14.65Q16.85,13.6 16.125,12.875Q15.4,12.15 14.35,12.15ZM14.35,32.85Q13.3,32.85 12.575,33.575Q11.85,34.3 11.85,35.35Q11.85,36.4 12.575,37.125Q13.3,37.85 14.35,37.85Q15.4,37.85 16.125,37.125Q16.85,36.4 16.85,35.35Q16.85,34.3 16.125,33.575Q15.4,32.85 14.35,32.85ZM7.7,6.05H40.25Q41.05,6.05 41.525,6.525Q42,7 42,7.8V21.25Q42,22.1 41.525,22.7Q41.05,23.3 40.25,23.3H7.7Q6.95,23.3 6.475,22.7Q6,22.1 6,21.25V7.8Q6,7 6.475,6.525Q6.95,6.05 7.7,6.05ZM9,9.05V20.3H39V9.05ZM7.7,26.7H40.05Q40.8,26.7 41.4,27.325Q42,27.95 42,28.75V41.95Q42,42.95 41.4,43.475Q40.8,44 40.05,44H7.95Q7.15,44 6.575,43.475Q6,42.95 6,41.95V28.75Q6,27.95 6.475,27.325Q6.95,26.7 7.7,26.7ZM9,29.7V41H39V29.7ZM9,9.05V20.3ZM9,29.7V41Z"/>
</vector>

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Tesses.YouTubeDownloader.Droid</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Tesses.WebServer.Swagme" Version="1.0.0" />
<PackageReference Include="Tesses.YouTubeDownloader" Version="1.1.9" />
<PackageReference Include="Tesses.YouTubeDownloader.ExtensionLoader" Version="1.1.2" />
<PackageReference Include="Tesses.YouTubeDownloader.Server" Version="1.1.7" />
<PackageReference Include="Tesses.YouTubeDownloader.SFTP" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.0.2" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,27 @@
using Android.Content;
namespace Tesses.YouTubeDownloader.Droid;
[BroadcastReceiver]
public class TYTDReceiver : BroadcastReceiver
{
public const string RECEIVER_KEY="tytdRequest";
public const int COMMAND_CLOSE_SERVER = 0;
public override void OnReceive(Context? context, Intent? intent)
{
if(intent == null) return;
int reqId = intent.GetIntExtra(RECEIVER_KEY,-1);
if(reqId == -1) return;
switch(reqId)
{
case COMMAND_CLOSE_SERVER:
TYTDCommon.Close();
if(context != null){
Intent? intent1= new Intent(context,typeof(TYTDServerService));
context.StopService(intent1);
}
break;
}
}
}

View File

@ -0,0 +1,65 @@

using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Provider;
using Android.Runtime;
using Java.Security;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tesses.YouTubeDownloader.Droid;
namespace Tesses.YouTubeDownloader.Droid
{
[Service]
public class TYTDServerService : Service
{
public override IBinder? OnBind(Intent? intent)
{
return null;
}
public const int SERVER_NOTIFICATION_ID = 42;
public const string SERVER_CHANNEL_ID = "TYTDServerNotificationChannel";
public override void OnCreate()
{
if(TYTDCommon.MainActivity == null || TYTDCommon.SettingsActivity == null || TYTDCommon.Context == null) return;
Intent mainIntent = new Intent(TYTDCommon.Context, TYTDCommon.MainActivity);
PendingIntent? mainPendingIntent = PendingIntent.GetActivity(TYTDCommon.Context, 0, mainIntent, PendingIntentFlags.Immutable);
Intent settingsIntent = new Intent(TYTDCommon.Context,TYTDCommon.SettingsActivity);
PendingIntent? settingsPendingIntent = PendingIntent.GetActivity(TYTDCommon.Context,0,settingsIntent,PendingIntentFlags.Immutable);
Intent shutdownServerIntent = new Intent(TYTDCommon.Context,typeof(TYTDReceiver));
PendingIntent? shutdownServerPendingIntent =PendingIntent.GetBroadcast(this,0,shutdownServerIntent,PendingIntentFlags.Immutable);
shutdownServerIntent.PutExtra(TYTDReceiver.RECEIVER_KEY,TYTDReceiver.COMMAND_CLOSE_SERVER);
Notification notification = new Notification.Builder(TYTDCommon.Context, SERVER_CHANNEL_ID).SetContentTitle("TYTD Server").SetSmallIcon(Resource.Drawable.dns_48px).SetContentText($"TYTD Server is bound to:\nhttp://{(TYTDCommon.ServerAccessable ? "0.0.0.0" : "127.0.0.1")}:{TYTDCommon.ServerPort}/").AddAction(new Notification.Action(-1, "Shutdown Server", shutdownServerPendingIntent)).AddAction(new Notification.Action(-1,"Settings",settingsPendingIntent)).SetContentIntent(mainPendingIntent).Build();
StartForeground(SERVER_NOTIFICATION_ID, notification);
}
[return: GeneratedEnum]
public override StartCommandResult OnStartCommand(Intent? intent, [GeneratedEnum] StartCommandFlags flags, int startId)
{
return StartCommandResult.Sticky;
}
public override void OnDestroy()
{
}
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:usesCleartextTraffic="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true">
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
</manifest>

12
TYTD.Mobile/Extensions.cs Normal file
View File

@ -0,0 +1,12 @@
namespace TYTD.Mobile
{
public static class Extensions{
public static string GetValOrDefault(this string? str)
{
if(string.IsNullOrWhiteSpace(str))
return "";
return str;
}
}
}

184
TYTD.Mobile/MainActivity.cs Normal file
View File

@ -0,0 +1,184 @@
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using AndroidX.AppCompat.App;
using AndroidX.AppCompat.Widget;
using AndroidX.Core.View;
using AndroidX.DrawerLayout.Widget;
using Google.Android.Material.FloatingActionButton;
using Google.Android.Material.Navigation;
using Google.Android.Material.Snackbar;
using Tesses.YouTubeDownloader;
using Tesses.YouTubeDownloader.Droid;
using Toolbar = AndroidX.AppCompat.Widget.Toolbar;
namespace TYTD.Mobile
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity, NavigationView.IOnNavigationItemSelectedListener
{
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
TYTDCommon.MainActivity = typeof(MainActivity);
TYTDCommon.SettingsActivity = typeof(PrefenceActivity);
TYTDCommon.Init(this);
Toolbar? toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
if(toolbar != null)
SetSupportActionBar(toolbar);
FloatingActionButton? fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
if(fab != null)
fab.Click += FabOnClick;
DrawerLayout? drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
if(drawer != null)
{
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);
drawer.AddDrawerListener(toggle);
toggle.SyncState();
}
NavigationView? navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
if(navigationView != null)
navigationView.SetNavigationItemSelectedListener(this);
TYTDCommon.StartBootCache<ProgressDialog>(()=>{
var dlg=new ProgressDialog(this);
dlg.SetTitle("TYTD Cache");
dlg.SetMessage("Please wait, caching");
dlg.Show();
return dlg;
},(e)=>{
this.RunOnUiThread(()=>{
e.Dismiss();
});
});
}
public override void OnBackPressed()
{
DrawerLayout? drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
if (drawer != null && drawer.IsDrawerOpen(GravityCompat.Start))
{
drawer.CloseDrawer(GravityCompat.Start);
}
else
{
base.OnBackPressed();
}
}
public override bool OnCreateOptionsMenu(IMenu? menu)
{
MenuInflater.Inflate(Resource.Menu.menu_main, menu);
return true;
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
int id = item.ItemId;
if (id == Resource.Id.action_settings)
{
Intent intent=new Intent(this,typeof(PrefenceActivity));
StartActivity(intent);
return true;
}
if(id == Resource.Id.action_servers)
{
Intent servers=new Intent(this,typeof(ServersActivity));
StartActivity(servers);
return true;
}
return base.OnOptionsItemSelected(item);
}
private void FabOnClick(object? sender, EventArgs eventArgs)
{
/* View? view = (View?)sender;
if(view != null)
Snackbar.Make(view, "Replace with your own action", Snackbar.LengthLong)
.SetAction("Action",(e)=>{}).Show();*/
var builder=new AndroidX.AppCompat.App.AlertDialog.Builder(this);
builder.SetView(Resource.Layout.add_item);
builder.SetTitle(Resource.String.add_item_text);
EditText? video_id = null; //you would put https://www.youtube.com/watch?v=PzUKeGZiEl0 in here
builder.SetNegativeButton(Resource.String.cancel_text,(sender0,e)=>{
});
builder.SetPositiveButton(Resource.String.add_text,(sender0,e)=>{
if(video_id!= null)
{
string? id=video_id.Text;
if(TYTDCommon.TYTD != null && !string.IsNullOrWhiteSpace(id))
{
Task.Factory.StartNew(async()=>{
await TYTDCommon.TYTD.CastIfAsync<ITYTDBase,IDownloader>(async (e2)=>{
await e2.AddItemAsync(id,Resolution.PreMuxed);
});
}).Wait(0);
}
}
});
var res=builder.Show();
if(res!= null)
{
video_id=res.FindViewById<EditText>(Resource.Id.video_url);
}
}
public bool OnNavigationItemSelected(IMenuItem item)
{
int id = item.ItemId;
if (id == Resource.Id.nav_camera)
{
// Handle the camera action
}
else if (id == Resource.Id.nav_gallery)
{
}
else if (id == Resource.Id.nav_slideshow)
{
}
else if (id == Resource.Id.nav_manage)
{
}
else if (id == Resource.Id.nav_share)
{
}
else if (id == Resource.Id.nav_send)
{
}
DrawerLayout? drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
if(drawer != null)
drawer.CloseDrawer(GravityCompat.Start);
return true;
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

56
TYTD.Mobile/Preference.cs Normal file
View File

@ -0,0 +1,56 @@
using AndroidX.AppCompat.App;
using AndroidX.Preference;
using Tesses.YouTubeDownloader.Droid;
using Toolbar = AndroidX.AppCompat.Widget.Toolbar;
namespace TYTD.Mobile;
[Activity(Theme = "@style/AppTheme.NoActionBar",Label ="@string/action_settings")]
class PrefenceActivity : AppCompatActivity, PreferenceFragmentCompat.IOnPreferenceStartFragmentCallback
{
public bool OnPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref)
{
throw new NotImplementedException();
}
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.settings_layout);
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.settings,new MainPreference()).Commit();
Toolbar? toolbar = FindViewById<Toolbar>(Resource.Id.toolbar_settings);
if(toolbar != null){
SetSupportActionBar(toolbar);
SupportActionBar?.SetDisplayHomeAsUpEnabled(true);
SupportActionBar?.SetDisplayShowHomeEnabled(true);
}
}
public override bool OnSupportNavigateUp()
{
OnBackPressed();
return true;
}
public class MainPreference : PreferenceFragmentCompat
{
public MainPreference()
{
}
public override void OnCreatePreferences(Bundle? savedInstanceState, string? rootKey)
{
if(this.PreferenceManager != null)
this.PreferenceManager.PreferenceDataStore = new TYTDPreferences();
SetPreferencesFromResource(Resource.Xml.preference_screen,rootKey);
}
}
}

View File

@ -0,0 +1,77 @@
using System.Collections;
using Android.Views;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace TYTD.Mobile;
public class ObservableCollectionRecyclerViewAdapter<T> : IList<T>
{
private ObservableCollection<T> _coll=new ObservableCollection<T>();
public int Count {get{return _coll.Count;}}
public bool IsReadOnly {get{return false;}}
public T this[int index] { get {return _coll[index];} set {_coll[index]=value;} }
public ObservableCollectionRecyclerViewAdapter(RecylerView,Action<View,T> viewCb)
{
}
public void Add(T item)
{
_coll.Add(item);
}
public void Clear()
{
_coll.Clear();
}
public void AddRange(IEnumerable<T> items)
{
foreach(var item in items)
{
_coll.Add(item);
}
}
public int IndexOf(T item)
{
return _coll.IndexOf(item);
}
public void Insert(int index, T item)
{
_coll.Insert(index,item);
}
public void RemoveAt(int index)
{
_coll.RemoveAt(index);
}
public bool Contains(T item)
{
return _coll.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
_coll.CopyTo(array,arrayIndex);
}
public bool Remove(T item)
{
_coll.Remove(item);
throw new NotImplementedException();
}
public IEnumerator<T> GetEnumerator()
{
return _coll.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _coll.GetEnumerator();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

View File

@ -0,0 +1,44 @@
Images, layout descriptions, binary blobs and string dictionaries can be included
in your application as resource files. Various Android APIs are designed to
operate on the resource IDs instead of dealing with images, strings or binary blobs
directly.
For example, a sample Android app that contains a user interface layout (main.xml),
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
would keep its resources in the "Resources" directory of the application:
Resources/
drawable/
icon.png
layout/
main.xml
values/
strings.xml
In order to get the build system to recognize Android resources, set the build action to
"AndroidResource". The native Android APIs do not operate directly with filenames, but
instead operate on resource IDs. When you compile an Android application that uses resources,
the build system will package the resources for distribution and generate a class called "Resource"
(this is an Android convention) that contains the tokens for each one of the resources
included. For example, for the above Resources layout, this is what the Resource class would expose:
public class Resource {
public class Drawable {
public const int icon = 0x123;
}
public class Layout {
public const int main = 0x456;
}
public class Strings {
public const int first_string = 0xabc;
public const int second_string = 0xbcd;
}
}
You would then use Resource.Drawable.icon to reference the drawable/icon.png file, or
Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string
to reference the first string in the dictionary file values/strings.xml.

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
<path
android:fillColor="#FF000000"
android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M22,16V4c0,-1.1 -0.9,-2 -2,-2H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2zm-11,-4l2.03,2.71L16,11l4,5H8l3,-4zM2,6v14c0,1.1 0.9,2 2,2h14v-2H4V6H2z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M22.7,19l-9.1,-9.1c0.9,-2.3 0.4,-5 -1.5,-6.9 -2,-2 -5,-2.4 -7.4,-1.3L9,6 6,9 1.6,4.7C0.4,7.1 0.9,10.1 2.9,12.1c1.9,1.9 4.6,2.4 6.9,1.5l9.1,9.1c0.4,0.4 1,0.4 1.4,0l2.3,-2.3c0.5,-0.4 0.5,-1.1 0.1,-1.4z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M4,6H2v14c0,1.1 0.9,2 2,2h14v-2H4V6zm16,-4H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2zm-8,12.5v-9l6,4.5 -6,4.5z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/black"
android:pathData="M22.5,38V25.5H10V22.5H22.5V10H25.5V22.5H38V25.5H25.5V38Z"/>
</vector>

View File

@ -0,0 +1,9 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:centerColor="#2c3e50"
android:endColor="#1B3147"
android:startColor="#42586E"
android:type="linear" />
</shape>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_servers"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_servers" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="?attr/colorPrimary"
app:tint="@android:color/white"
app:srcCompat="@drawable/add_48px" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,13 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/video_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/video_url"
android:singleLine="true"
/>
</RelativeLayout>

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="?attr/colorPrimary"
app:tint="@android:color/white"
app:srcCompat="@drawable/add_48px" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:showIn="@layout/app_bar_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello World!" />
</RelativeLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:showIn="@layout/activity_servers">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/server_list"
/>
</RelativeLayout>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/server_name_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/server_name_field"
android:singleLine="true"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/server_uri_field"
android:id="@+id/server_uri_field"
android:layout_below="@+id/server_name_field"
android:singleLine="true"
/>
<Button
android:layout_below="@+id/server_uri_field"
android:id="@+id/server_ssh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/server_ssh_button"
/>
</RelativeLayout>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ssh_uri"
android:id="@+id/ssh_uri"
android:singleLine="true"
/>
<EditText
android:id="@+id/ssh_port"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ssh_port"
android:inputType="number"
android:singleLine="true"
android:layout_below="@+id/ssh_uri"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ssh_username"
android:id="@+id/ssh_username"
android:layout_below="@+id/ssh_port"
android:singleLine="true"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ssh_password"
android:id="@+id/ssh_password"
android:layout_below="@+id/ssh_username"
android:singleLine="true"
android:password="true"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ssh_path"
android:id="@+id/ssh_path"
android:layout_below="@+id/ssh_password"
android:singleLine="true"
/>
</RelativeLayout>

View File

@ -0,0 +1,24 @@
<?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:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:srcCompat="@mipmap/ic_launcher" />
</LinearLayout>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_settings"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_camera"
android:icon="@drawable/ic_menu_camera"
android:title="Import" />
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/ic_menu_gallery"
android:title="Gallery" />
<item
android:id="@+id/nav_slideshow"
android:icon="@drawable/ic_menu_slideshow"
android:title="Slideshow" />
<item
android:id="@+id/nav_manage"
android:icon="@drawable/ic_menu_manage"
android:title="Tools" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="@+id/nav_share"
android:icon="@drawable/ic_menu_share"
android:title="Share" />
<item
android:id="@+id/nav_send"
android:icon="@drawable/ic_menu_send"
android:title="Send" />
</menu>
</item>
</menu>

View File

@ -0,0 +1,14 @@
<menu 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">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
<item
android:id="@+id/action_servers"
android:orderInCategory="100"
android:title="@string/servers_name"
app:showAsAction="never" />
</menu>

View File

@ -0,0 +1,17 @@
<menu 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">
<item
android:id="@+id/action_storage_set"
android:title="@string/action_storage_set"/>
<item
android:id="@+id/action_download_set"
android:title="@string/action_download_set"
/>
<item
android:id="@+id/action_edit_server"
android:title="@string/action_edit_server"/>
<item
android:id="@+id/action_delete_server"
android:title="@string/action_delete_server"/>
</menu>

View File

@ -0,0 +1,11 @@
<menu 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">
<item
android:id="@+id/action_storage_setne"
android:title="@string/action_storage_set"/>
<item
android:id="@+id/action_download_setne"
android:title="@string/action_download_set"
/>
</menu>

View File

@ -0,0 +1,9 @@
<menu 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">
<!-- <item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />-->
</menu>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_adaptive_back"/>
<foreground android:drawable="@mipmap/ic_launcher_adaptive_fore"/>
</adaptive-icon>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_adaptive_back"/>
<foreground android:drawable="@mipmap/ic_launcher_adaptive_fore"/>
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#EE0000</color>
<color name="colorPrimaryDark">#770000</color>
<color name="colorAccent">#9900cc</color>
<!--
<color name="colorPrimary">#2c3e50</color>
<color name="colorPrimaryDark">#1B3147</color>
<color name="colorAccent">#3498db</color>-->
</resources>

View File

@ -0,0 +1,8 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="nav_header_vertical_spacing">8dp</dimen>
<dimen name="nav_header_height">176dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@ -0,0 +1,8 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<item name="ic_menu_camera" type="drawable">@android:drawable/ic_menu_camera</item>
<item name="ic_menu_gallery" type="drawable">@android:drawable/ic_menu_gallery</item>
<item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item>
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#2C3E50</color>
</resources>

View File

@ -0,0 +1,46 @@
<resources>
<string name="app_name">TYTD</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="action_settings">Settings</string>
<string name="server_settings">Server settings</string>
<string name="tytdServerAccessable_title">Accessable on network</string>
<string name="tytdServerAccessable_summary">Make TYTD accessable on network</string>
<string name="tytdServerPort_title">TYTD port</string>
<string name="tytdServerPort_summary">Set port for TYTD server</string>
<string name="cache_settings">Cache settings (Not using cache directory)</string>
<string name="tytdNoExternalInfoThumb_title">Use internal thumbnails/metadata</string>
<string name="tytdNoExternalInfoThumb_summary">Do not fetch thumbnails/metadata (when listing videos, playlists and channels) from other devices</string>
<string name="tytdCacheThumbnailsOnStart_title">Cache thumbnails on start</string>
<string name="tytdCacheThumbnailsOnStart_summary">Download uncached thumbnails from all servers when app starts</string>
<string name="tytdCacheInfoOnStart_title">Cache metadata files on start</string>
<string name="tytdCacheInfoOnStart_summary">Download uncached metadata from all servers when app starts</string>
<string name="tytdFetchThumbYouTube_title">Cache thumbnails via YouTube</string>
<string name="tytdFetchThumbYouTube_summary">Download unavailable thumbnails from YouTube</string>
<string name="tytdCacheLazy_title">Cache thumbnails/metadata</string>
<string name="tytdCacheLazy_summary">Download and cache thumbnails/metadata (when listing videos, playlists and channels) from other devices</string>
<string name="tytdTag_title">Instance Tag</string>
<string name="tytdTag_summary">Name of this TYTD instance</string>
<string name="servers_name">Servers</string>
<string name="server_ssh_button">Edit as SFTP</string>
<string name="server_uri_field">Server Url</string>
<string name="server_name_field">Server Name</string>
<string name="ssh_uri">IP Or FQDN</string>
<string name="ssh_port">Port</string>
<string name="ssh_username">Username</string>
<string name="ssh_password">Password</string>
<string name="ssh_path">Path</string>
<string name="ok_text">Ok</string>
<string name="add_text">Add</string>
<string name="cancel_text">Cancel</string>
<string name="action_storage_set">Set as storage</string>
<string name="action_download_set">Set as download to</string>
<string name="action_edit_server">Edit</string>
<string name="action_delete_server">Delete</string>
<string name="video_url">YouTube Id Or Url</string>
<string name="add_item_text">Add Item</string>
<string name="add_server_text">Add Server</string>
<string name="edit_server_text">Edit Server</string>
<string name="edit_ssh_text">Edit SFTP Info</string>
</resources>

View File

@ -0,0 +1,20 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
</resources>

View File

@ -0,0 +1,41 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/server_settings">
<SwitchPreferenceCompat
app:key="tytdServerAccessable"
app:title="@string/tytdServerAccessable_title"
app:summary="@string/tytdServerAccessable_summary" />
<EditTextPreference
app:key="tytdServerPort"
app:title="@string/tytdServerPort_title"
app:summary="@string/tytdServerPort_summary"/>
<EditTextPreference
app:key="tytdTag"
app:title="@string/tytdTag_title"
app:summary="@string/tytdTag_summary"/>
</PreferenceCategory>
<PreferenceCategory app:title="@string/cache_settings">
<SwitchPreferenceCompat
app:key="tytdCacheThumbnailsOnStart"
app:title="@string/tytdCacheThumbnailsOnStart_title"
app:summary="@string/tytdCacheThumbnailsOnStart_summary" />
<SwitchPreferenceCompat
app:key="tytdCacheInfoOnStart"
app:title="@string/tytdCacheInfoOnStart_title"
app:summary="@string/tytdCacheInfoOnStart_summary" />
<SwitchPreferenceCompat
app:key="tytdCacheLazy"
app:title="@string/tytdCacheLazy_title"
app:summary="@string/tytdCacheLazy_summary" />
<SwitchPreferenceCompat
app:key="tytdFetchThumbYouTube"
app:title="@string/tytdFetchThumbYouTube_title"
app:summary="@string/tytdFetchThumbYouTube_summary" />
<SwitchPreferenceCompat
app:key="tytdNoExternalInfoThumb"
app:title="@string/tytdNoExternalInfoThumb_title"
app:summary="@string/tytdNoExternalInfoThumb_summary" />
</PreferenceCategory>
</PreferenceScreen>

441
TYTD.Mobile/Servers.cs Normal file
View File

@ -0,0 +1,441 @@
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using AndroidX.AppCompat.App;
using AndroidX.AppCompat.Widget;
using AndroidX.Core.View;
using AndroidX.DrawerLayout.Widget;
using Google.Android.Material.FloatingActionButton;
using Google.Android.Material.Navigation;
using Google.Android.Material.Snackbar;
using Tesses.YouTubeDownloader.Droid;
using Toolbar = AndroidX.AppCompat.Widget.Toolbar;
namespace TYTD.Mobile
{
public interface IServerItem
{
bool IsEditable {get;}
string Name {get;set;}
string InnerValue {get;set;}
bool Update();
void Delete();
}
public sealed class LocalItem : IServerItem
{
string name;
string value;
public LocalItem(string name,string value)
{
this.name = name;
this.value = value;
}
public bool IsEditable => false;
public string Name { get => name; set => throw new NotImplementedException(); }
public string InnerValue { get => value; set => throw new NotImplementedException(); }
public void Delete()
{
throw new NotImplementedException();
}
public bool Update()
{
throw new NotImplementedException();
}
}
public sealed class ServerItem : IServerItem
{
string oldname;
Dictionary<string,string> dict;
public ServerItem(Dictionary<string,string> dict,string name,string url)
{
oldname=name;
Name = name;
InnerValue=url;
this.dict=dict;
}
public bool IsEditable => true;
public string Name {get;set;}
public string InnerValue {
get;set;
}
public void Delete()
{
dict.Remove(oldname);
TYTDCommon.SaveServers(dict);
}
public bool Update()
{
if(oldname != Name)
{
dict.Remove(oldname);
dict.Add(Name,InnerValue);
TYTDCommon.SaveServers(dict);
return true;
}
dict[Name]=InnerValue;
TYTDCommon.SaveServers(dict);
return false;
}
}
public static class ServerItemHandler
{
public static string AddUnique<T>(this Dictionary<string,T> items,string key,T value)
{
string keyOut=key;
int i = 2;
while(items.ContainsKey(keyOut))
{
keyOut = $"{key} ({i++})";
}
items.Add(keyOut,value);
return keyOut;
}
private static IEnumerable<string> getNames(this IEnumerable<IServerItem> items)
{
foreach(var item in items)
{
yield return item.Name;
}
}
public static string[] GetNames(this IEnumerable<IServerItem> items)
{
return items.getNames().ToArray();
}
}
[Activity(Label = "@string/servers_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = false)]
public class ServersActivity : AppCompatActivity
{
public void UpdateItem(IServerItem item)
{
var builder=new AndroidX.AppCompat.App.AlertDialog.Builder(this);
builder.SetView(Resource.Layout.edit_server);
EditText? name =null;
EditText? url=null;
Button? sftp=null;
AndroidX.AppCompat.App.AlertDialog? alert=null;
builder.SetNegativeButton(Resource.String.cancel_text,(sender,e)=>{
if(alert != null) alert.Dismiss();
});
builder.SetTitle(Resource.String.edit_server_text);
builder.SetPositiveButton(Resource.String.ok_text,(sender,e)=>{
if(svrs != null&&name!= null && url !=null && !string.IsNullOrWhiteSpace(name.Text) && !string.IsNullOrWhiteSpace(url.Text)){
item.Name = name.Text;
item.InnerValue = url.Text;
if(item.Update())
UpdateLV();
}
if(alert != null) alert.Dismiss();
});
alert= builder.Show();
if(alert != null)
{
//this.GetExternalFilesDirs(null)
name=alert.FindViewById<EditText>(Resource.Id.server_name_field);
if(name!= null)
name.Text = item.Name;
url = alert.FindViewById<EditText>(Resource.Id.server_uri_field);
if(url != null)
url.Text = item.InnerValue;
sftp = alert.FindViewById<Button>(Resource.Id.server_ssh_button);
if(sftp != null)
{
sftp.Click += (sender,e)=>{
if(url != null)
{
SftpEditor(url);
}
};
}
}
}
Dictionary<string,string> svrs=new();
List<IServerItem> items=new List<IServerItem>();
ListView? listView=null;
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_servers);
Toolbar? toolbar = FindViewById<Toolbar>(Resource.Id.toolbar_servers);
if(toolbar != null)
{
SetSupportActionBar(toolbar);
SupportActionBar?.SetDisplayHomeAsUpEnabled(true);
SupportActionBar?.SetDisplayShowHomeEnabled(true);
}
FloatingActionButton? fab = FindViewById<FloatingActionButton>(Resource.Id.add_server);
if(fab != null)
fab.Click += FabOnClick;
listView = FindViewById<ListView>(Resource.Id.server_list);
if(listView!=null)
{
listView.ItemClick += (sender,e)=>{
IServerItem item = items[e.Position];
Android.Widget.PopupMenu menu=new Android.Widget.PopupMenu(this,e.View);
menu.MenuItemClick += (sender2,e2)=>{
if(e2.Item != null)
switch(e2.Item.ItemId)
{
case Resource.Id.action_storage_set:
case Resource.Id.action_storage_setne:
TYTDCommon.AppStorageLocation = item.InnerValue;
//set storage
break;
case Resource.Id.action_download_set:
case Resource.Id.action_download_setne:
TYTDCommon.AppDownloadLocation = item.InnerValue;
//set download to
break;
case Resource.Id.action_edit_server:
if(item.IsEditable){
UpdateItem(item);
}
break;
case Resource.Id.action_delete_server:
if(item.IsEditable){
item.Delete();
UpdateLV();
}
break;
}
};
menu.Inflate(item.IsEditable ? Resource.Menu.menu_server_editable : Resource.Menu.menu_server_not_editable);
menu.Show();
};
UpdateLV();
}
}
public void UpdateLV()
{
if(listView != null)
{
items.Clear();
foreach(var storage in TYTDCommon.GetStorageDevices())
{
items.Add(new LocalItem(storage.Label,storage.Path));
}
svrs=TYTDCommon.GetServers();
foreach(var svr in svrs)
{
items.Add(new ServerItem(svrs,svr.Key,svr.Value));
}
listView.Adapter = new ArrayAdapter<string>(this,Android.Resource.Layout.SimpleListItem1,items.GetNames());
}
}
public override bool OnSupportNavigateUp()
{
OnBackPressed();
return true;
}
public override bool OnCreateOptionsMenu(IMenu? menu)
{
MenuInflater.Inflate(Resource.Menu.menu_servers, menu);
return true;
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
int id = item.ItemId;
return base.OnOptionsItemSelected(item);
}
private void FabOnClick(object? sender, EventArgs eventArgs)
{
var builder=new AndroidX.AppCompat.App.AlertDialog.Builder(this);
builder.SetView(Resource.Layout.edit_server);
EditText? name =null;
EditText? url=null;
Button? sftp=null;
AndroidX.AppCompat.App.AlertDialog? alert=null;
builder.SetTitle(Resource.String.add_server_text);
builder.SetNegativeButton(Resource.String.cancel_text,(sender,e)=>{
if(alert != null) alert.Dismiss();
});
builder.SetPositiveButton(Resource.String.ok_text,(sender,e)=>{
if(svrs != null&&name!= null && url !=null && !string.IsNullOrWhiteSpace(name.Text) && !string.IsNullOrWhiteSpace(url.Text)){
svrs.AddUnique(name.Text,url.Text);
TYTDCommon.SaveServers(svrs);
UpdateLV();
}
if(alert != null) alert.Dismiss();
});
alert= builder.Show();
if(alert != null)
{
//this.GetExternalFilesDirs(null)
name=alert.FindViewById<EditText>(Resource.Id.server_name_field);
url = alert.FindViewById<EditText>(Resource.Id.server_uri_field);
sftp = alert.FindViewById<Button>(Resource.Id.server_ssh_button);
if(sftp != null)
{
sftp.Click += (sender,e)=>{
if(url != null)
{
SftpEditor(url);
}
};
}
}
}
private void SftpEditor(EditText uriText)
{
Uri? uri;
string ipOrFqdn="";
string port="";
string username="";
string password="";
string path="";
if(Uri.TryCreate(uriText.Text,UriKind.Absolute,out uri) && uri.Scheme == "sftp")
{
ipOrFqdn = uri.Host;
port = uri.Port.ToString();
string userInfo=uri.UserInfo;
if(!string.IsNullOrWhiteSpace(userInfo))
{
string[] userInfoSplit = userInfo.Split(':',2,StringSplitOptions.RemoveEmptyEntries);
if(userInfoSplit.Length == 2)
{
//username:password
username = userInfoSplit[0];
password = userInfoSplit[1];
}else if(userInfoSplit.Length == 1)
{
//username only
username = userInfoSplit[0];
}
}
path=uri.PathAndQuery;
}
EditText? fqdnTb=null;
EditText? portTb=null;
EditText? usernameTb=null;
EditText? passwordTb=null;
EditText? pathTb=null;
AndroidX.AppCompat.App.AlertDialog? alert=null;
var builder=new AndroidX.AppCompat.App.AlertDialog.Builder(this);
builder.SetTitle(Resource.String.edit_ssh_text);
builder.SetView(Resource.Layout.edit_ssh_server);
builder.SetPositiveButton(Resource.String.ok_text,(sender,e)=>{
if(fqdnTb != null)
{
ipOrFqdn=fqdnTb.Text.GetValOrDefault();
}
if(portTb != null)
{
ushort portN;
if(ushort.TryParse(portTb.Text,out portN))
{
port=portN.ToString();
}else{
port="22";
}
}
if(usernameTb != null)
{
username=usernameTb.Text.GetValOrDefault();
}
if(passwordTb != null)
{
password = passwordTb.Text.GetValOrDefault();
}
if(pathTb != null)
{
path = pathTb.Text.GetValOrDefault();
}
string userInfoStr="";
bool hasUserName = !string.IsNullOrWhiteSpace(username);
bool hasPassword = !string.IsNullOrWhiteSpace(password);
if(hasUserName || hasPassword)
{
if(hasUserName && !hasPassword)
{
userInfoStr = $"{username}@";
}
else if(hasPassword && !hasUserName)
{
userInfoStr = $"root:{password}@";
}else{
userInfoStr = $"{username}:{password}@";
}
}
if(string.IsNullOrWhiteSpace(path)) path="/";
string url = $"sftp://{userInfoStr}{ipOrFqdn}:{port}{path}";
uriText.Text=url;
if(alert!= null) alert.Dismiss();
});
builder.SetNegativeButton(Resource.String.cancel_text,(sender,e)=>{
if(alert != null) alert.Dismiss();
});
alert=builder.Show();
if(alert != null){
fqdnTb=alert.FindViewById<EditText>(Resource.Id.ssh_uri);
if(fqdnTb != null)
fqdnTb.Text = ipOrFqdn;
portTb=alert.FindViewById<EditText>(Resource.Id.ssh_port);
if(portTb != null)
portTb.Text = port;
usernameTb=alert.FindViewById<EditText>(Resource.Id.ssh_username);
if(usernameTb!= null)
usernameTb.Text=username;
passwordTb = alert.FindViewById<EditText>(Resource.Id.ssh_password);
if(passwordTb !=null)
passwordTb.Text=password;
pathTb = alert.FindViewById<EditText>(Resource.Id.ssh_path);
if(pathTb != null)
pathTb.Text = path;
}
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net6.0-android</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<ApplicationId>net.tesses.TYTD</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.5.1" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.6.1.1" />
<PackageReference Include="Xamarin.AndroidX.Leanback" Version="1.0.0.16" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TYTD.Common\TYTD.Common.csproj" />
</ItemGroup>
</Project>