mirror of
https://github.com/zoriya/Opus.git
synced 2025-12-06 06:26:15 +00:00
Totally reworking login and acess token management. Also adding a check for access token expire date.
This commit is contained in:
@@ -29,7 +29,6 @@ using MusicApp.Resources.Portable_Class;
|
|||||||
using MusicApp.Resources.values;
|
using MusicApp.Resources.values;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using SQLite;
|
using SQLite;
|
||||||
using Square.OkHttp;
|
|
||||||
using Square.Picasso;
|
using Square.Picasso;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -40,10 +39,10 @@ using System.Threading.Tasks;
|
|||||||
using YoutubeExplode;
|
using YoutubeExplode;
|
||||||
using CursorLoader = Android.Support.V4.Content.CursorLoader;
|
using CursorLoader = Android.Support.V4.Content.CursorLoader;
|
||||||
using Fragment = Android.Support.V4.App.Fragment;
|
using Fragment = Android.Support.V4.App.Fragment;
|
||||||
using ICallback = Square.OkHttp.ICallback;
|
|
||||||
using Playlist = MusicApp.Resources.Portable_Class.Playlist;
|
using Playlist = MusicApp.Resources.Portable_Class.Playlist;
|
||||||
using Request = Square.OkHttp.Request;
|
using Request = Square.OkHttp.Request;
|
||||||
using SearchView = Android.Support.V7.Widget.SearchView;
|
using SearchView = Android.Support.V7.Widget.SearchView;
|
||||||
|
using Toolbar = Android.Support.V7.Widget.Toolbar;
|
||||||
using TransportType = Android.Net.TransportType;
|
using TransportType = Android.Net.TransportType;
|
||||||
|
|
||||||
namespace MusicApp
|
namespace MusicApp
|
||||||
@@ -52,18 +51,15 @@ namespace MusicApp
|
|||||||
[IntentFilter(new[] {Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataHost = "www.youtube.com", DataMimeType = "text/*")]
|
[IntentFilter(new[] {Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataHost = "www.youtube.com", DataMimeType = "text/*")]
|
||||||
[IntentFilter(new[] {Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataHost = "m.youtube.com", DataMimeType = "text/plain")]
|
[IntentFilter(new[] {Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataHost = "m.youtube.com", DataMimeType = "text/plain")]
|
||||||
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataMimeTypes = new[] { "audio/*", "application/ogg", "application/x-ogg", "application/itunes" })]
|
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault }, DataMimeTypes = new[] { "audio/*", "application/ogg", "application/x-ogg", "application/itunes" })]
|
||||||
public class MainActivity : AppCompatActivity, GoogleApiClient.IOnConnectionFailedListener, ICallback, IResultCallback, IMenuItemOnActionExpandListener, View.IOnFocusChangeListener, ISessionManagerListener
|
public class MainActivity : AppCompatActivity, GoogleApiClient.IOnConnectionFailedListener, IResultCallback, IMenuItemOnActionExpandListener, View.IOnFocusChangeListener, ISessionManagerListener
|
||||||
{
|
{
|
||||||
public static MainActivity instance;
|
public static MainActivity instance;
|
||||||
public new static int Theme = 1;
|
public new static int Theme = 1;
|
||||||
public static int dialogTheme;
|
public static int dialogTheme;
|
||||||
|
|
||||||
public Android.Support.V7.Widget.Toolbar ToolBar;
|
|
||||||
public bool NoToolbarMenu = false;
|
public bool NoToolbarMenu = false;
|
||||||
public IMenu menu;
|
public IMenu menu;
|
||||||
public SwipeRefreshLayout contentRefresh;
|
public SwipeRefreshLayout contentRefresh;
|
||||||
public bool usePager;
|
|
||||||
public bool HomeDetails = false;
|
|
||||||
public bool Paused = false;
|
public bool Paused = false;
|
||||||
|
|
||||||
public bool prepared = false;
|
public bool prepared = false;
|
||||||
@@ -75,9 +71,9 @@ namespace MusicApp
|
|||||||
private const string versionURI = "https://raw.githubusercontent.com/AnonymusRaccoon/MusicApp/master/MusicApp/Assets/Version.txt";
|
private const string versionURI = "https://raw.githubusercontent.com/AnonymusRaccoon/MusicApp/master/MusicApp/Assets/Version.txt";
|
||||||
|
|
||||||
public static GoogleSignInAccount account;
|
public static GoogleSignInAccount account;
|
||||||
public GoogleApiClient googleClient;
|
private Intent AskIntent;
|
||||||
private bool canAsk;
|
|
||||||
public bool waitingForYoutube;
|
public bool waitingForYoutube;
|
||||||
|
private DateTime NextRefreshDate;
|
||||||
private bool? PermissionGot;
|
private bool? PermissionGot;
|
||||||
public bool ResumeKiller;
|
public bool ResumeKiller;
|
||||||
|
|
||||||
@@ -98,8 +94,7 @@ namespace MusicApp
|
|||||||
|
|
||||||
int statusHeight = Resources.GetDimensionPixelSize(Resources.GetIdentifier("status_bar_height", "dimen", "android"));
|
int statusHeight = Resources.GetDimensionPixelSize(Resources.GetIdentifier("status_bar_height", "dimen", "android"));
|
||||||
FindViewById(Resource.Id.contentLayout).SetPadding(0, statusHeight, 0, 0);
|
FindViewById(Resource.Id.contentLayout).SetPadding(0, statusHeight, 0, 0);
|
||||||
ToolBar = (Android.Support.V7.Widget.Toolbar)FindViewById(Resource.Id.toolbar);
|
SetSupportActionBar(FindViewById<Toolbar>(Resource.Id.toolbar));
|
||||||
SetSupportActionBar(ToolBar);
|
|
||||||
SupportActionBar.Title = "MusicApp";
|
SupportActionBar.Title = "MusicApp";
|
||||||
((CoordinatorLayout.LayoutParams)FindViewById(Resource.Id.contentLayout).LayoutParameters).TopMargin = -Resources.GetDimensionPixelSize(Resources.GetIdentifier("status_bar_height", "dimen", "android"));
|
((CoordinatorLayout.LayoutParams)FindViewById(Resource.Id.contentLayout).LayoutParameters).TopMargin = -Resources.GetDimensionPixelSize(Resources.GetIdentifier("status_bar_height", "dimen", "android"));
|
||||||
|
|
||||||
@@ -192,31 +187,31 @@ namespace MusicApp
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Login(bool canAsk = true, bool skipSilentLog = false)
|
public void Login(bool canAsk = true, bool skipSilentLog = false)
|
||||||
{
|
{
|
||||||
waitingForYoutube = true;
|
waitingForYoutube = true;
|
||||||
|
|
||||||
|
if(account == null)
|
||||||
|
account = GoogleSignIn.GetLastSignedInAccount(this);
|
||||||
|
|
||||||
|
|
||||||
if (account != null)
|
if (account != null)
|
||||||
{
|
{
|
||||||
CreateYoutube();
|
CreateYoutube();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(googleClient == null)
|
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
|
||||||
{
|
.RequestIdToken(GetString(Resource.String.clientID))
|
||||||
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
|
.RequestServerAuthCode(GetString(Resource.String.clientID))
|
||||||
.RequestIdToken(GetString(Resource.String.clientID))
|
.RequestScopes(new Scope(YouTubeService.Scope.Youtube))
|
||||||
.RequestServerAuthCode(GetString(Resource.String.clientID))
|
.Build();
|
||||||
.RequestEmail()
|
|
||||||
.RequestScopes(new Scope(YouTubeService.Scope.Youtube))
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
googleClient = new GoogleApiClient.Builder(this)
|
GoogleApiClient googleClient = new GoogleApiClient.Builder(this)
|
||||||
.AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
|
.AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
googleClient.Connect();
|
googleClient.Connect();
|
||||||
}
|
|
||||||
|
|
||||||
if (!skipSilentLog)
|
if (!skipSilentLog)
|
||||||
{
|
{
|
||||||
@@ -233,7 +228,7 @@ namespace MusicApp
|
|||||||
}
|
}
|
||||||
else if (silentLog != null)
|
else if (silentLog != null)
|
||||||
{
|
{
|
||||||
this.canAsk = canAsk;
|
AskIntent = Auth.GoogleSignInApi.GetSignInIntent(googleClient);
|
||||||
silentLog.SetResultCallback(this);
|
silentLog.SetResultCallback(this);
|
||||||
}
|
}
|
||||||
else if (canAsk)
|
else if (canAsk)
|
||||||
@@ -241,10 +236,8 @@ namespace MusicApp
|
|||||||
ResumeKiller = true;
|
ResumeKiller = true;
|
||||||
StartActivityForResult(Auth.GoogleSignInApi.GetSignInIntent(googleClient), 1598);
|
StartActivityForResult(Auth.GoogleSignInApi.GetSignInIntent(googleClient), 1598);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (canAsk)
|
else if (canAsk)
|
||||||
{
|
{
|
||||||
ResumeKiller = true;
|
ResumeKiller = true;
|
||||||
StartActivityForResult(Auth.GoogleSignInApi.GetSignInIntent(googleClient), 1598);
|
StartActivityForResult(Auth.GoogleSignInApi.GetSignInIntent(googleClient), 1598);
|
||||||
@@ -278,49 +271,159 @@ namespace MusicApp
|
|||||||
RunOnUiThread(() => { Picasso.With(this).Load(account.PhotoUrl).Transform(new CircleTransformation()).Into(new AccountTarget()); });
|
RunOnUiThread(() => { Picasso.With(this).Load(account.PhotoUrl).Transform(new CircleTransformation()).Into(new AccountTarget()); });
|
||||||
CreateYoutube();
|
CreateYoutube();
|
||||||
}
|
}
|
||||||
else if(canAsk)
|
else if(AskIntent != null)
|
||||||
{
|
{
|
||||||
ResumeKiller = true;
|
ResumeKiller = true;
|
||||||
StartActivityForResult(Auth.GoogleSignInApi.GetSignInIntent(googleClient), 1598);
|
StartActivityForResult(AskIntent, 1598);
|
||||||
|
AskIntent = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateYoutube()
|
public async void CreateYoutube()
|
||||||
{
|
{
|
||||||
OkHttpClient client = new OkHttpClient();
|
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(this);
|
||||||
RequestBody body = new FormEncodingBuilder()
|
string refreshToken = prefManager.GetString("refresh-token", null);
|
||||||
.Add("grant_type", "authorization_code")
|
Console.WriteLine("&Current refresh token: " + refreshToken);
|
||||||
.Add("client_id", GetString(Resource.String.clientID))
|
|
||||||
.Add("client_secret", GetString(Resource.String.clientSecret))
|
|
||||||
.Add("redirect_uri", "")
|
|
||||||
.Add("code", account.ServerAuthCode)
|
|
||||||
.Add("id_token", account.IdToken)
|
|
||||||
.Build();
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.Url("https://www.googleapis.com/oauth2/v4/token")
|
|
||||||
.Post(body)
|
|
||||||
.Build();
|
|
||||||
client.NewCall(request).Enqueue(this);
|
|
||||||
|
|
||||||
Console.WriteLine("&Requesting access token");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnResponse(Square.OkHttp.Response response)
|
|
||||||
{
|
|
||||||
string jsonFile = response.Body().String();
|
|
||||||
Console.WriteLine(jsonFile);
|
|
||||||
if (jsonFile.Contains("error"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
JToken json = JObject.Parse(jsonFile);
|
//This method do not return refresh-token if the app has already been aprouved by google for this user, should force request
|
||||||
GoogleCredential credential = GoogleCredential.FromAccessToken((string)json.SelectToken("access_token"));
|
if (refreshToken == null)
|
||||||
YoutubeEngine.youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
|
||||||
{
|
{
|
||||||
HttpClientInitializer = credential,
|
Console.WriteLine("&Getting refresh-token and creating a youtube service");
|
||||||
ApplicationName = "MusicApp"
|
Console.WriteLine("&Code = " + account.ServerAuthCode);
|
||||||
});
|
|
||||||
|
|
||||||
Console.WriteLine("&Youtube created");
|
if(account.ServerAuthCode == null)
|
||||||
|
{
|
||||||
|
Login(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, string> fields = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "grant_type", "authorization_code" },
|
||||||
|
{ "client_id", GetString(Resource.String.clientID) },
|
||||||
|
{ "client_secret", GetString(Resource.String.clientSecret) },
|
||||||
|
{ "redirect_uri", "" },
|
||||||
|
{ "code", account.ServerAuthCode },
|
||||||
|
{ "id_token", account.IdToken },
|
||||||
|
};
|
||||||
|
|
||||||
|
var items = from kvp in fields
|
||||||
|
select kvp.Key + "=" + kvp.Value;
|
||||||
|
|
||||||
|
string content = string.Join("&", items);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/oauth2/v4/token");
|
||||||
|
request.Host = "www.googleapis.com";
|
||||||
|
|
||||||
|
request.Method = "POST";
|
||||||
|
request.ContentType = "application/x-www-form-urlencoded";
|
||||||
|
request.ContentLength = content.Length;
|
||||||
|
|
||||||
|
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
|
||||||
|
{
|
||||||
|
writer.Write(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("&Content: " + content);
|
||||||
|
|
||||||
|
HttpWebResponse resp = (HttpWebResponse)await request.GetResponseAsync();
|
||||||
|
|
||||||
|
string response;
|
||||||
|
using (StreamReader responseReader = new StreamReader(request.GetResponse().GetResponseStream()))
|
||||||
|
{
|
||||||
|
response = responseReader.ReadToEnd();
|
||||||
|
Console.WriteLine("&" + response);
|
||||||
|
}
|
||||||
|
|
||||||
|
JToken json = JObject.Parse(response);
|
||||||
|
GoogleCredential credential = GoogleCredential.FromAccessToken((string)json.SelectToken("access_token"));
|
||||||
|
YoutubeEngine.youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||||
|
{
|
||||||
|
HttpClientInitializer = credential,
|
||||||
|
ApplicationName = "MusicApp"
|
||||||
|
});
|
||||||
|
|
||||||
|
refreshToken = (string)json.SelectToken("refresh_token");
|
||||||
|
if(refreshToken != null)
|
||||||
|
{
|
||||||
|
ISharedPreferencesEditor editor = prefManager.Edit();
|
||||||
|
editor.PutString("refresh-token", refreshToken);
|
||||||
|
editor.Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
int expireIn = (int)json.SelectToken("expires_in");
|
||||||
|
NextRefreshDate = DateTime.UtcNow.AddSeconds(expireIn - 30); //Should refresh a bit before the expiration of the acess token
|
||||||
|
}
|
||||||
|
catch (WebException ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("&Refresh token get error: " + ex.Message);
|
||||||
|
UnknowError(new Action(() => { CreateYoutube(); }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(account != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("&Getting a new access-token and creating a youtube service");
|
||||||
|
Dictionary<string, string> fields = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "refresh_token", refreshToken },
|
||||||
|
{ "client_id", GetString(Resource.String.clientID) },
|
||||||
|
{ "client_secret", GetString(Resource.String.clientSecret) },
|
||||||
|
{ "grant_type", "refresh_token" },
|
||||||
|
};
|
||||||
|
|
||||||
|
var items = from kvp in fields
|
||||||
|
select kvp.Key + "=" + kvp.Value;
|
||||||
|
|
||||||
|
string content = string.Join("&", items);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/oauth2/v4/token");
|
||||||
|
request.Host = "www.googleapis.com";
|
||||||
|
|
||||||
|
request.Method = "POST";
|
||||||
|
request.ContentType = "application/x-www-form-urlencoded";
|
||||||
|
request.ContentLength = content.Length;
|
||||||
|
|
||||||
|
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
|
||||||
|
{
|
||||||
|
writer.Write(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("&Content: " + content);
|
||||||
|
|
||||||
|
HttpWebResponse resp = (HttpWebResponse)await request.GetResponseAsync();
|
||||||
|
|
||||||
|
string response;
|
||||||
|
using (StreamReader responseReader = new StreamReader(request.GetResponse().GetResponseStream()))
|
||||||
|
{
|
||||||
|
response = responseReader.ReadToEnd();
|
||||||
|
Console.WriteLine("&" + response);
|
||||||
|
}
|
||||||
|
|
||||||
|
JToken json = JObject.Parse(response);
|
||||||
|
GoogleCredential credential = GoogleCredential.FromAccessToken((string)json.SelectToken("access_token"));
|
||||||
|
YoutubeEngine.youtubeService = new YouTubeService(new BaseClientService.Initializer()
|
||||||
|
{
|
||||||
|
HttpClientInitializer = credential,
|
||||||
|
ApplicationName = "MusicApp"
|
||||||
|
});
|
||||||
|
|
||||||
|
int expireIn = (int)json.SelectToken("expires_in");
|
||||||
|
NextRefreshDate = DateTime.UtcNow.AddSeconds(expireIn - 30); //Should refresh a bit before the expiration of the acess token
|
||||||
|
}
|
||||||
|
catch (WebException ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine("&New access token get error: " + ex.Message);
|
||||||
|
UnknowError(new Action(() => { CreateYoutube(); }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Login(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnFailure(Request request, Java.IO.IOException iOException)
|
public void OnFailure(Request request, Java.IO.IOException iOException)
|
||||||
@@ -350,6 +453,11 @@ namespace MusicApp
|
|||||||
await Task.Delay(10);
|
await Task.Delay(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(NextRefreshDate <= DateTime.UtcNow) //Acess token has expired
|
||||||
|
{
|
||||||
|
waitingForYoutube = true;
|
||||||
|
CreateYoutube();
|
||||||
|
}
|
||||||
waitingForYoutube = false;
|
waitingForYoutube = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -816,10 +924,13 @@ namespace MusicApp
|
|||||||
snackBar.Show();
|
snackBar.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unknow()
|
public void UnknowError(Action action = null)
|
||||||
{
|
{
|
||||||
Snackbar snackBar = Snackbar.Make(FindViewById(Resource.Id.snackBar), Resource.String.unknow, Snackbar.LengthIndefinite);
|
Snackbar snackBar = Snackbar.Make(FindViewById(Resource.Id.snackBar), Resource.String.unknow, Snackbar.LengthIndefinite);
|
||||||
snackBar.SetAction("Dismiss", (sender) => { snackBar.Dismiss(); });
|
if (action != null)
|
||||||
|
snackBar.SetAction("Try Again", (sender) => { action.Invoke(); snackBar.Dismiss(); });
|
||||||
|
else
|
||||||
|
snackBar.SetAction("Dismiss", (sender) => { snackBar.Dismiss(); });
|
||||||
snackBar.View.FindViewById<TextView>(Resource.Id.snackbar_text).SetTextColor(Color.White);
|
snackBar.View.FindViewById<TextView>(Resource.Id.snackbar_text).SetTextColor(Color.White);
|
||||||
snackBar.Show();
|
snackBar.Show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,20 +94,20 @@
|
|||||||
<Reference Include="ExoPlayer.UI, Version=2.8.8.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="ExoPlayer.UI, Version=2.8.8.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Xam.Plugins.Android.ExoPlayer.UI.2.8.8\lib\monoandroid81\ExoPlayer.UI.dll</HintPath>
|
<HintPath>..\packages\Xam.Plugins.Android.ExoPlayer.UI.2.8.8\lib\monoandroid81\ExoPlayer.UI.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Google.Apis, Version=1.37.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
<Reference Include="Google.Apis, Version=1.38.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Google.Apis.1.37.0\lib\netstandard2.0\Google.Apis.dll</HintPath>
|
<HintPath>..\packages\Google.Apis.1.38.0\lib\netstandard2.0\Google.Apis.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Google.Apis.Auth, Version=1.37.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
<Reference Include="Google.Apis.Auth, Version=1.38.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Google.Apis.Auth.1.37.0\lib\netstandard2.0\Google.Apis.Auth.dll</HintPath>
|
<HintPath>..\packages\Google.Apis.Auth.1.38.0\lib\netstandard2.0\Google.Apis.Auth.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Google.Apis.Auth.PlatformServices, Version=1.37.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
<Reference Include="Google.Apis.Auth.PlatformServices, Version=1.38.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Google.Apis.Auth.1.37.0\lib\netstandard2.0\Google.Apis.Auth.PlatformServices.dll</HintPath>
|
<HintPath>..\packages\Google.Apis.Auth.1.38.0\lib\netstandard2.0\Google.Apis.Auth.PlatformServices.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Google.Apis.Core, Version=1.37.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
<Reference Include="Google.Apis.Core, Version=1.38.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Google.Apis.Core.1.37.0\lib\netstandard2.0\Google.Apis.Core.dll</HintPath>
|
<HintPath>..\packages\Google.Apis.Core.1.38.0\lib\netstandard2.0\Google.Apis.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Google.Apis.YouTube.v3, Version=1.37.0.1469, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
<Reference Include="Google.Apis.YouTube.v3, Version=1.38.0.1488, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Google.Apis.YouTube.v3.1.37.0.1469\lib\netstandard2.0\Google.Apis.YouTube.v3.dll</HintPath>
|
<HintPath>..\packages\Google.Apis.YouTube.v3.1.38.0.1488\lib\netstandard2.0\Google.Apis.YouTube.v3.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Java.Interop" />
|
<Reference Include="Java.Interop" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using MusicApp;
|
|||||||
using MusicApp.Resources.Portable_Class;
|
using MusicApp.Resources.Portable_Class;
|
||||||
using Square.Picasso;
|
using Square.Picasso;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
public class AccountPreference : Preference, IResultCallback
|
public class AccountPreference : Preference, IResultCallback
|
||||||
{
|
{
|
||||||
@@ -60,6 +61,27 @@ public class AccountPreference : Preference, IResultCallback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void LogIn()
|
||||||
|
{
|
||||||
|
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
|
||||||
|
.RequestIdToken(Preferences.instance.GetString(Resource.String.clientID))
|
||||||
|
.RequestServerAuthCode(Preferences.instance.GetString(Resource.String.clientID))
|
||||||
|
.RequestEmail()
|
||||||
|
.RequestScopes(new Scope(YouTubeService.Scope.Youtube))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
GoogleApiClient googleClient = new GoogleApiClient.Builder(Preferences.instance)
|
||||||
|
.AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
googleClient.Connect();
|
||||||
|
|
||||||
|
while (!googleClient.IsConnected)
|
||||||
|
await Task.Delay(10);
|
||||||
|
|
||||||
|
Preferences.instance.StartActivityForResult(Auth.GoogleSignInApi.GetSignInIntent(googleClient), 5981);
|
||||||
|
}
|
||||||
|
|
||||||
public void OnSignedIn()
|
public void OnSignedIn()
|
||||||
{
|
{
|
||||||
Button log = (Button)view.FindViewById(Resource.Id.logButton);
|
Button log = (Button)view.FindViewById(Resource.Id.logButton);
|
||||||
@@ -70,6 +92,37 @@ public class AccountPreference : Preference, IResultCallback
|
|||||||
log.Click -= logIn;
|
log.Click -= logIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async void LogOut()
|
||||||
|
{
|
||||||
|
MainActivity.account = null;
|
||||||
|
YoutubeEngine.youtubeService = null;
|
||||||
|
|
||||||
|
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
|
||||||
|
.RequestIdToken(Preferences.instance.GetString(Resource.String.clientID))
|
||||||
|
.RequestServerAuthCode(Preferences.instance.GetString(Resource.String.clientID))
|
||||||
|
.RequestEmail()
|
||||||
|
.RequestScopes(new Scope(YouTubeService.Scope.Youtube))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
GoogleApiClient googleClient = new GoogleApiClient.Builder(Preferences.instance)
|
||||||
|
.AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
googleClient.Connect();
|
||||||
|
|
||||||
|
while (!googleClient.IsConnected)
|
||||||
|
await Task.Delay(10);
|
||||||
|
|
||||||
|
Auth.GoogleSignInApi.RevokeAccess(googleClient).SetResultCallback(this);
|
||||||
|
|
||||||
|
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Preferences.instance);
|
||||||
|
ISharedPreferencesEditor editor = prefManager.Edit();
|
||||||
|
editor.Remove("refresh-token");
|
||||||
|
editor.Apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Log out result
|
||||||
public void OnResult(Java.Lang.Object result)
|
public void OnResult(Java.Lang.Object result)
|
||||||
{
|
{
|
||||||
Button log = (Button)view.FindViewById(Resource.Id.logButton);
|
Button log = (Button)view.FindViewById(Resource.Id.logButton);
|
||||||
@@ -77,39 +130,11 @@ public class AccountPreference : Preference, IResultCallback
|
|||||||
log.Text = Preferences.instance.Resources.GetString(Resource.String.log_in);
|
log.Text = Preferences.instance.Resources.GetString(Resource.String.log_in);
|
||||||
Summary = "";
|
Summary = "";
|
||||||
Picasso.With(Android.App.Application.Context).Load(Resource.Drawable.account).Into(view.FindViewById<ImageView>(Android.Resource.Id.Icon));
|
Picasso.With(Android.App.Application.Context).Load(Resource.Drawable.account).Into(view.FindViewById<ImageView>(Android.Resource.Id.Icon));
|
||||||
if(MainActivity.Theme == 1)
|
if (MainActivity.Theme == 1)
|
||||||
view.FindViewById<ImageView>(Android.Resource.Id.Icon).SetColorFilter(Color.White);
|
view.FindViewById<ImageView>(Android.Resource.Id.Icon).SetColorFilter(Color.White);
|
||||||
else
|
else
|
||||||
view.FindViewById<ImageView>(Android.Resource.Id.Icon).SetColorFilter(Color.Gray);
|
view.FindViewById<ImageView>(Android.Resource.Id.Icon).SetColorFilter(Color.Gray);
|
||||||
log.Click -= logOut;
|
log.Click -= logOut;
|
||||||
MainActivity.instance.InvalidateOptionsMenu();
|
MainActivity.instance.InvalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogIn()
|
|
||||||
{
|
|
||||||
if (MainActivity.instance.googleClient == null)
|
|
||||||
{
|
|
||||||
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
|
|
||||||
.RequestIdToken(Preferences.instance.GetString(Resource.String.clientID))
|
|
||||||
.RequestServerAuthCode(Preferences.instance.GetString(Resource.String.clientID))
|
|
||||||
.RequestEmail()
|
|
||||||
.RequestScopes(new Scope(YouTubeService.Scope.Youtube))
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
MainActivity.instance.googleClient = new GoogleApiClient.Builder(Preferences.instance)
|
|
||||||
.AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
MainActivity.instance.googleClient.Connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
Preferences.instance.StartActivityForResult(Auth.GoogleSignInApi.GetSignInIntent(MainActivity.instance.googleClient), 5981);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogOut()
|
|
||||||
{
|
|
||||||
MainActivity.account = null;
|
|
||||||
YoutubeEngine.youtubeService = null;
|
|
||||||
Auth.GoogleSignInApi.SignOut(MainActivity.instance.googleClient).SetResultCallback(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -196,7 +196,7 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
MainActivity.instance.Unknow();
|
MainActivity.instance.UnknowError();
|
||||||
Cancel();
|
Cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ using static Android.Provider.MediaStore.Audio;
|
|||||||
using CursorLoader = Android.Support.V4.Content.CursorLoader;
|
using CursorLoader = Android.Support.V4.Content.CursorLoader;
|
||||||
using PopupMenu = Android.Support.V7.Widget.PopupMenu;
|
using PopupMenu = Android.Support.V7.Widget.PopupMenu;
|
||||||
using RecyclerView = Android.Support.V7.Widget.RecyclerView;
|
using RecyclerView = Android.Support.V7.Widget.RecyclerView;
|
||||||
|
using Toolbar = Android.Support.V7.Widget.Toolbar;
|
||||||
|
|
||||||
namespace MusicApp.Resources.Portable_Class
|
namespace MusicApp.Resources.Portable_Class
|
||||||
{
|
{
|
||||||
@@ -835,7 +836,7 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
if (instance == null)
|
if (instance == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (System.Math.Abs(verticalOffset) <= appBarLayout.TotalScrollRange - MainActivity.instance.ToolBar.Height)
|
if (System.Math.Abs(verticalOffset) <= appBarLayout.TotalScrollRange - MainActivity.instance.FindViewById<Toolbar>(Resource.Id.toolbar).Height)
|
||||||
{
|
{
|
||||||
Activity.FindViewById<RelativeLayout>(Resource.Id.playlistHeader).Visibility = ViewStates.Visible;
|
Activity.FindViewById<RelativeLayout>(Resource.Id.playlistHeader).Visibility = ViewStates.Visible;
|
||||||
MainActivity.instance.SupportActionBar.SetDisplayShowTitleEnabled(false);
|
MainActivity.instance.SupportActionBar.SetDisplayShowTitleEnabled(false);
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
{
|
{
|
||||||
MainActivity.account = result.SignInAccount;
|
MainActivity.account = result.SignInAccount;
|
||||||
PreferencesFragment.instance?.SignedIn();
|
PreferencesFragment.instance?.SignedIn();
|
||||||
|
MainActivity.instance.CreateYoutube();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -976,7 +976,7 @@ namespace MusicApp.Resources.Portable_Class
|
|||||||
if (ex is System.Net.Http.HttpRequestException)
|
if (ex is System.Net.Http.HttpRequestException)
|
||||||
MainActivity.instance.Timout();
|
MainActivity.instance.Timout();
|
||||||
else
|
else
|
||||||
MainActivity.instance.Unknow();
|
MainActivity.instance.UnknowError();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,11 @@
|
|||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
|
<assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-1.36.1.0" newVersion="1.36.1.0" />
|
<bindingRedirect oldVersion="0.0.0.0-1.38.0.0" newVersion="1.38.0.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="Google.Apis" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
|
<assemblyIdentity name="Google.Apis" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-1.36.1.0" newVersion="1.36.1.0" />
|
<bindingRedirect oldVersion="0.0.0.0-1.38.0.0" newVersion="1.38.0.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="PInvoke.BCrypt" publicKeyToken="9e300f9f87f04a7a" culture="neutral" />
|
<assemblyIdentity name="PInvoke.BCrypt" publicKeyToken="9e300f9f87f04a7a" culture="neutral" />
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="AngleSharp" version="0.9.11" targetFramework="monoandroid90" />
|
<package id="AngleSharp" version="0.9.11" targetFramework="monoandroid90" />
|
||||||
<package id="Google.Apis" version="1.37.0" targetFramework="monoandroid90" />
|
<package id="Google.Apis" version="1.38.0" targetFramework="monoandroid90" />
|
||||||
<package id="Google.Apis.Auth" version="1.37.0" targetFramework="monoandroid90" />
|
<package id="Google.Apis.Auth" version="1.38.0" targetFramework="monoandroid90" />
|
||||||
<package id="Google.Apis.Core" version="1.37.0" targetFramework="monoandroid90" />
|
<package id="Google.Apis.Core" version="1.38.0" targetFramework="monoandroid90" />
|
||||||
<package id="Google.Apis.YouTube.v3" version="1.37.0.1469" targetFramework="monoandroid90" />
|
<package id="Google.Apis.YouTube.v3" version="1.38.0.1488" targetFramework="monoandroid90" />
|
||||||
<package id="Karamunting.Android.AnderWeb.DiscreteSeekBar" version="1.0.1.1" targetFramework="monoandroid81" />
|
<package id="Karamunting.Android.AnderWeb.DiscreteSeekBar" version="1.0.1.1" targetFramework="monoandroid81" />
|
||||||
<package id="Microsoft.CSharp" version="4.5.0" targetFramework="monoandroid81" />
|
<package id="Microsoft.CSharp" version="4.5.0" targetFramework="monoandroid81" />
|
||||||
<package id="Microsoft.NETCore.Platforms" version="2.2.0" targetFramework="monoandroid81" />
|
<package id="Microsoft.NETCore.Platforms" version="2.2.0" targetFramework="monoandroid81" />
|
||||||
|
|||||||
Reference in New Issue
Block a user