Skip to content

Commit

Permalink
Merge branch 'release/1.6.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
ofirelarat committed Dec 16, 2018
2 parents 9b75afd + 6e8a046 commit 2e18895
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
16 changes: 12 additions & 4 deletions tubeLoadNative/tubeLoadNative.Droid/Activities/SplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected override void OnCreate(Bundle savedInstanceState)
protected override void OnResume()
{
base.OnResume();

Task.Run(async () =>
{
try
Expand All @@ -68,6 +68,12 @@ protected override void OnResume()
() => Toast.MakeText(Application.Context, "Could not connect, please check your internet connection", ToastLength.Long).Show()));
};
});

if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) == Permission.Granted &&
ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) == Permission.Granted)
{
StartActivity(new Intent(Application.Context, typeof(SongsPlayer)));
}
}

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
Expand Down Expand Up @@ -96,17 +102,19 @@ private async void checkForUpdateVersionAsync()
private void checkReadWriteToStorage()
{
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) != Permission.Granted &&
ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != Permission.Granted)
ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) != Permission.Granted &&
ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadPhoneState) != Permission.Granted)
{
if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.WriteExternalStorage) &&
ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.ReadExternalStorage))
ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.ReadExternalStorage) &&
ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.ReadPhoneState))
{
Toast.MakeText(Application.Context, "Permission to storage has been denied", ToastLength.Long).Show();
}
else
{
ActivityCompat.RequestPermissions(this,
new string[] { Manifest.Permission.WriteExternalStorage, Manifest.Permission.ReadExternalStorage },
new string[] { Manifest.Permission.WriteExternalStorage, Manifest.Permission.ReadExternalStorage, Manifest.Permission.ReadPhoneState},
0);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly" package="com.okey.tubeload" android:versionName="1.6.6" android:versionCode="7">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly" package="com.okey.tubeload" android:versionName="1.6.8" android:versionCode="10">
<uses-sdk android:minSdkVersion="17" android:targetSdkVersion="26" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="@android:color/white"
android:id="@+id/notificationTitle"
android:layout_margin="5dp" />
<TextView
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:id="@+id/notificationContent" />
</LinearLayout>
<ImageButton
Expand Down
19 changes: 18 additions & 1 deletion tubeLoadNative/tubeLoadNative.Droid/Utils/NotificationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Widget;
using tubeLoadNative.Droid.BroadcastReceivers;

namespace tubeLoadNative.Droid.Utils
{
Expand All @@ -17,14 +18,15 @@ public class NotificationHandler
static Notification.Builder builder;
static NotificationManager notificationManager;
const int SONG_NOTIFICATION_ID = 0;
const string CHANNEL_ID = "tubeload_song_notification";

static NotificationHandler()
{
Intent intent = new Intent(Application.Context, typeof(CurrentSong));
intent.AddFlags(ActivityFlags.SingleTop);
PendingIntent pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent);

builder = new Notification.Builder(Application.Context);
builder = new Notification.Builder(Application.Context, CHANNEL_ID);
builder.SetContentIntent(pendingIntent);

builder.SetOngoing(true);
Expand All @@ -35,6 +37,15 @@ static NotificationHandler()
}

notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;

if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
/* Create or update. */
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
"tubeload song notification",
NotificationImportance.Min);
notificationManager.CreateNotificationChannel(channel);
}
}

public static void BuildNotification(String songId)
Expand Down Expand Up @@ -70,6 +81,7 @@ public static void BuildNotification(String songId)
notificationLayoutExpanded.SetImageViewBitmap(Resource.Id.songImg, bitmap);
CreateNotificationMediaActions(notificationLayoutExpanded);
builder.SetCustomBigContentView(notificationLayoutExpanded);
builder.SetContentTitle(title);
}
else
{
Expand All @@ -91,21 +103,25 @@ public static void DeleteNotification()
private static void CreateNotificationMediaActions(RemoteViews notificationLayoutExpanded)
{
Intent prevIntent = new Intent("ACTION_MEDIA_BUTTON");
prevIntent.SetClass(Application.Context, typeof(BluetoothRemoteControlReciever));
prevIntent.PutExtra(Intent.ExtraKeyEvent, new KeyEvent(KeyEventActions.Down, Keycode.MediaPrevious));
PendingIntent prevPendingIntent = PendingIntent.GetBroadcast(Application.Context, 0, prevIntent, PendingIntentFlags.UpdateCurrent);
notificationLayoutExpanded.SetOnClickPendingIntent(Resource.Id.prevBtn, prevPendingIntent);

Intent playPauseIntent = new Intent("ACTION_MEDIA_BUTTON");
playPauseIntent.SetClass(Application.Context, typeof(BluetoothRemoteControlReciever));
playPauseIntent.PutExtra(Intent.ExtraKeyEvent, new KeyEvent(KeyEventActions.Down, Keycode.MediaPlayPause));
PendingIntent playPausePendingIntent = PendingIntent.GetBroadcast(Application.Context, 1, playPauseIntent, PendingIntentFlags.UpdateCurrent);
notificationLayoutExpanded.SetOnClickPendingIntent(Resource.Id.playBtn, playPausePendingIntent);

Intent nextIntent = new Intent("ACTION_MEDIA_BUTTON");
nextIntent.SetClass(Application.Context, typeof(BluetoothRemoteControlReciever));
nextIntent.PutExtra(Intent.ExtraKeyEvent, new KeyEvent(KeyEventActions.Down, Keycode.MediaNext));
PendingIntent nextPendingIntent = PendingIntent.GetBroadcast(Application.Context, 2, nextIntent, PendingIntentFlags.UpdateCurrent);
notificationLayoutExpanded.SetOnClickPendingIntent(Resource.Id.nextBtn, nextPendingIntent);

Intent stopIntent = new Intent("ACTION_MEDIA_BUTTON");
stopIntent.SetClass(Application.Context, typeof(BluetoothRemoteControlReciever));
stopIntent.PutExtra(Intent.ExtraKeyEvent, new KeyEvent(KeyEventActions.Down, Keycode.MediaStop));
PendingIntent stopPendingIntent = PendingIntent.GetBroadcast(Application.Context, 3, stopIntent, PendingIntentFlags.UpdateCurrent);
notificationLayoutExpanded.SetOnClickPendingIntent(Resource.Id.closeBtn, stopPendingIntent);
Expand All @@ -114,6 +130,7 @@ private static void CreateNotificationMediaActions(RemoteViews notificationLayou
private static void CreateNotificationMediaActions()
{
Intent stopIntent = new Intent("ACTION_MEDIA_BUTTON");
stopIntent.SetClass(Application.Context, typeof(BluetoothRemoteControlReciever));
stopIntent.PutExtra(Intent.ExtraKeyEvent, new KeyEvent(KeyEventActions.Down, Keycode.MediaStop));
PendingIntent stopPendingIntent = PendingIntent.GetBroadcast(Application.Context, 3, stopIntent, PendingIntentFlags.UpdateCurrent);
Notification.Action stopAction = new Notification.Action(Resource.Drawable.ic_cancel_blue, string.Empty, stopPendingIntent);
Expand Down

0 comments on commit 2e18895

Please sign in to comment.