mirror of
https://github.com/zoriya/Opus.git
synced 2026-05-31 21:28:03 +00:00
Solving auto-updater bugs.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
Version: 2.0.2
|
||||
Link: https://github.com/AnonymusRaccoon/MusicApp/releases/download/2.0.2/MusicApp.v.2.0.2.apk
|
||||
Version: 2.0.3
|
||||
Link: https://github.com/AnonymusRaccoon/MusicApp/releases/download/2.0.3/MusicApp.v2.0.3.apk
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace MusicApp
|
||||
public BottomSheetBehavior SheetBehavior;
|
||||
|
||||
private const int RequestCode = 8539;
|
||||
public const int NotifUpdateID = 4626;
|
||||
private const string versionURI = "https://raw.githubusercontent.com/AnonymusRaccoon/MusicApp/master/MusicApp/Assets/Version.txt";
|
||||
|
||||
private const string clientID = "112086459272-8m4do6aehtdg4a7nffd0a84jk94c64e8.apps.googleusercontent.com";
|
||||
@@ -1282,7 +1283,7 @@ namespace MusicApp
|
||||
snackBar.View.FindViewById<TextView>(Resource.Id.snackbar_text).SetTextColor(Color.White);
|
||||
snackBar.Show();
|
||||
}
|
||||
else if(Preferences.instance != null)
|
||||
if(Preferences.instance != null)
|
||||
{
|
||||
Snackbar snackBar = Snackbar.Make(Preferences.instance.FindViewById(Android.Resource.Id.Content), "You are not connected to internet, can't check for updates.", Snackbar.LengthLong);
|
||||
snackBar.View.FindViewById<TextView>(Resource.Id.snackbar_text).SetTextColor(Color.White);
|
||||
@@ -1313,16 +1314,13 @@ namespace MusicApp
|
||||
{
|
||||
string GitVersion = await client.DownloadStringTaskAsync(new System.Uri(versionURI));
|
||||
gitVersionID = GitVersion.Substring(9, 5);
|
||||
gitVersionID = gitVersionID.Remove(1, 1);
|
||||
gitVersion = int.Parse(gitVersionID.Remove(2, 1));
|
||||
downloadPath = GitVersion.Substring(18);
|
||||
string gitID = gitVersionID.Remove(1, 1);
|
||||
gitVersion = int.Parse(gitID.Remove(2, 1));
|
||||
downloadPath = GitVersion.Substring(GitVersion.IndexOf("Link: ") + 6);
|
||||
}
|
||||
|
||||
Console.WriteLine("&Version: " + version + " GitVersion: " + gitVersion);
|
||||
|
||||
if(gitVersion > version)
|
||||
{
|
||||
Console.WriteLine("&An update is available");
|
||||
Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(activity, dialogTheme);
|
||||
builder.SetTitle(string.Format("The version {0} is available", gitVersionID));
|
||||
builder.SetMessage("An update is available, do you want to download it now ?");
|
||||
@@ -1352,10 +1350,23 @@ namespace MusicApp
|
||||
public async static void InstallUpdate(string version, string downloadPath)
|
||||
{
|
||||
Toast.MakeText(Application.Context, "Downloading update, you will be prompt for the installation soon.", ToastLength.Short).Show();
|
||||
|
||||
NotificationCompat.Builder notification = new NotificationCompat.Builder(Application.Context, "MusicApp.Channel")
|
||||
.SetVisibility(NotificationCompat.VisibilityPublic)
|
||||
.SetSmallIcon(Resource.Drawable.MusicIcon)
|
||||
.SetContentTitle("Updating app...")
|
||||
.SetOngoing(true);
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager)Application.Context.GetSystemService(NotificationService);
|
||||
notificationManager.Notify(NotifUpdateID, notification.Build());
|
||||
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
await client.DownloadFileTaskAsync(downloadPath, Android.OS.Environment.ExternalStorageDirectory + "/download/" + "MusicApp-v" + version + ".apk");
|
||||
}
|
||||
|
||||
notificationManager.Cancel(NotifUpdateID);
|
||||
|
||||
Intent intent = new Intent(Intent.ActionView);
|
||||
intent.SetDataAndType(Android.Net.Uri.FromFile(new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory + "/download/" + "MusicApp-v" + version + ".apk")), "application/vnd.android.package-archive");
|
||||
intent.SetFlags(ActivityFlags.NewTask);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.musicapp.android" android:installLocation="preferExternal" android:versionName="2.0.2" android:versionCode="14">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.musicapp.android" android:installLocation="preferExternal" android:versionName="2.0.3" android:versionCode="15">
|
||||
<uses-sdk android:minSdkVersion="21" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
@@ -89,16 +89,17 @@ namespace MusicApp.Resources.Portable_Class
|
||||
currentStrike++;
|
||||
CreateNotification(file.name);
|
||||
|
||||
if (YoutubeEngine.FileIsAlreadyDownloaded(file.videoID) && !file.skipCheck)
|
||||
{
|
||||
Snackbar snackBar = Snackbar.Make(MainActivity.instance.FindViewById(Resource.Id.snackBar), file.name + " is already on your device.", Snackbar.LengthShort).SetAction("Download Anyway", (v) =>
|
||||
{
|
||||
file.skipCheck = true;
|
||||
Download(file);
|
||||
});
|
||||
snackBar.View.FindViewById<TextView>(Resource.Id.snackbar_text).SetTextColor(Android.Graphics.Color.White);
|
||||
snackBar.Show();
|
||||
}
|
||||
//if (YoutubeEngine.FileIsAlreadyDownloaded(file.videoID) && !file.skipCheck)
|
||||
//{
|
||||
// Snackbar snackBar = Snackbar.Make(MainActivity.instance.FindViewById(Resource.Id.snackBar), file.name + " is already on your device.", Snackbar.LengthShort).SetAction("Download Anyway", (v) =>
|
||||
// {
|
||||
// file.skipCheck = true;
|
||||
// Download(file);
|
||||
// });
|
||||
// snackBar.View.FindViewById<TextView>(Resource.Id.snackbar_text).SetTextColor(Android.Graphics.Color.White);
|
||||
// snackBar.Show();
|
||||
// return;
|
||||
//}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -740,11 +740,11 @@ namespace MusicApp.Resources.Portable_Class
|
||||
}
|
||||
}
|
||||
|
||||
ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
|
||||
if (YoutubeEngine.FileIsAlreadyDownloaded(song.Path) && !prefManager.GetBoolean("skipExistVerification", false))
|
||||
{
|
||||
GetTrackSong(YoutubeEngine.GetLocalPathFromYTID(song.Path), out song);
|
||||
}
|
||||
//ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
|
||||
//if (!prefManager.GetBoolean("skipExistVerification", false) && YoutubeEngine.FileIsAlreadyDownloaded(song.Path))
|
||||
//{
|
||||
// GetTrackSong(YoutubeEngine.GetLocalPathFromYTID(song.Path), out song);
|
||||
//}
|
||||
|
||||
Play(song, false);
|
||||
|
||||
|
||||
@@ -527,39 +527,39 @@ namespace MusicApp.Resources.Portable_Class
|
||||
|
||||
public static bool FileIsAlreadyDownloaded(string youtubeID)
|
||||
{
|
||||
Android.Net.Uri musicUri = MediaStore.Audio.Media.ExternalContentUri;
|
||||
//Android.Net.Uri musicUri = MediaStore.Audio.Media.ExternalContentUri;
|
||||
|
||||
CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
|
||||
ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
//CursorLoader cursorLoader = new CursorLoader(Android.App.Application.Context, musicUri, null, null, null, null);
|
||||
//ICursor musicCursor = (ICursor)cursorLoader.LoadInBackground();
|
||||
|
||||
if (musicCursor != null && musicCursor.MoveToFirst())
|
||||
{
|
||||
int pathKey = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
|
||||
do
|
||||
{
|
||||
string path = musicCursor.GetString(pathKey);
|
||||
//if (musicCursor != null && musicCursor.MoveToFirst())
|
||||
//{
|
||||
// int pathKey = musicCursor.GetColumnIndex(MediaStore.Audio.Media.InterfaceConsts.Data);
|
||||
// do
|
||||
// {
|
||||
// string path = musicCursor.GetString(pathKey);
|
||||
|
||||
try
|
||||
{
|
||||
Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var meta = TagLib.File.Create(new StreamFileAbstraction(path, stream, stream));
|
||||
string ytID = meta.Tag.Comment;
|
||||
stream.Dispose();
|
||||
// try
|
||||
// {
|
||||
// Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
// var meta = TagLib.File.Create(new StreamFileAbstraction(path, stream, stream));
|
||||
// string ytID = meta.Tag.Comment;
|
||||
// stream.Dispose();
|
||||
|
||||
if (ytID == youtubeID)
|
||||
{
|
||||
musicCursor.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (CorruptFileException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
while (musicCursor.MoveToNext());
|
||||
musicCursor.Close();
|
||||
}
|
||||
// if (ytID == youtubeID)
|
||||
// {
|
||||
// musicCursor.Close();
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// catch (CorruptFileException)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// while (musicCursor.MoveToNext());
|
||||
// musicCursor.Close();
|
||||
//}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user