Skip to content

Commit

Permalink
Android: Added AddMarker presenter/view/fragment. Fixed crash bug wit…
Browse files Browse the repository at this point in the history
…h notification bar for Android 4.0.3.

Related to issue #406.
  • Loading branch information
ycastonguay committed Sep 27, 2013
1 parent 48517e0 commit 60e5b32
Show file tree
Hide file tree
Showing 20 changed files with 942 additions and 617 deletions.
5 changes: 3 additions & 2 deletions MPfm/MPfm.Android/Classes/Application.cs
@@ -1,4 +1,4 @@
// Copyright © 2011-2013 Yanick Castonguay
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
Expand Down Expand Up @@ -174,7 +174,8 @@ private void BootstrapApp()
container.Register<ILibraryPreferencesView, LibraryPreferencesFragment>().AsMultiInstance();
container.Register<IAboutView, AboutActivity>().AsMultiInstance();
container.Register<ISelectPlaylistView, SelectPlaylistFragment>().AsMultiInstance();
container.Register<IAddNewPlaylistView, AddNewPlaylistFragment>().AsMultiInstance();
container.Register<IAddPlaylistView, AddPlaylistFragment>().AsMultiInstance();
container.Register<IAddMarkerView, AddMarkerFragment>().AsMultiInstance();
}
}
}
109 changes: 109 additions & 0 deletions MPfm/MPfm.Android/Classes/Fragments/AddMarkerFragment.cs
@@ -0,0 +1,109 @@
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
// MPfm is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MPfm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MPfm. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Views;
using Android.Widget;
using MPfm.Android.Classes.Adapters;
using MPfm.Android.Classes.Fragments.Base;
using MPfm.MVP.Presenters;
using MPfm.MVP.Views;

namespace MPfm.Android.Classes.Fragments
{
public class AddMarkerFragment : BaseDialogFragment, IAddMarkerView
{
private View _view;
private RadioButton _radioVerse;
private RadioButton _radioChorus;
private RadioButton _radioBridge;
private RadioButton _radioSolo;
private Button _btnCancel;
private Button _btnCreate;

public AddMarkerFragment() : base(null)
{
}

public AddMarkerFragment(Action<IBaseView> onViewReady)
: base(onViewReady)
{
}

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Dialog.SetTitle("Select marker template");
_view = inflater.Inflate(Resource.Layout.AddMarker, container, false);

_btnCancel = _view.FindViewById<Button>(Resource.Id.addMarker_btnCancel);
_btnCreate = _view.FindViewById<Button>(Resource.Id.addMarker_btnCreate);
_radioVerse = _view.FindViewById<RadioButton>(Resource.Id.addMarker_radioVerse);
_radioChorus = _view.FindViewById<RadioButton>(Resource.Id.addMarker_radioChorus);
_radioBridge = _view.FindViewById<RadioButton>(Resource.Id.addMarker_radioBridge);
_radioSolo = _view.FindViewById<RadioButton>(Resource.Id.addMarker_radioSolo);
_btnCancel.Click += (sender, args) => Dismiss();
_btnCreate.Click += (sender, args) =>
{
MarkerTemplateNameType template = MarkerTemplateNameType.None;
if(_radioVerse.Checked)
template = MarkerTemplateNameType.Verse;
else if (_radioChorus.Checked)
template = MarkerTemplateNameType.Chorus;
else if (_radioBridge.Checked)
template = MarkerTemplateNameType.Bridge;
else if (_radioSolo.Checked)
template = MarkerTemplateNameType.Solo;
OnAddMarker(template);
Dismiss();
};
_radioVerse.Checked = true;

return _view;
}

public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetStyle((int)DialogFragmentStyle.Normal, (int)Resource.Style.DialogTheme);
}

#region IAddMarkerView implementation

public Action<MarkerTemplateNameType> OnAddMarker { get; set; }

public void AddMarkerError(Exception ex)
{
Activity.RunOnUiThread(() =>
{
AlertDialog ad = new AlertDialog.Builder(Activity).Create();
ad.SetCancelable(false);
ad.SetMessage(string.Format("An error has occured in AddMarker: {0}", ex));
ad.SetButton("OK", (sender, args) => ad.Dismiss());
ad.Show();
});
}

#endregion

}
}
@@ -1,4 +1,4 @@
// Copyright © 2011-2013 Yanick Castonguay
// Copyright © 2011-2013 Yanick Castonguay
//
// This file is part of MPfm.
//
Expand Down Expand Up @@ -29,30 +29,30 @@

namespace MPfm.Android.Classes.Fragments
{
public class AddNewPlaylistFragment : BaseDialogFragment, IAddNewPlaylistView
public class AddPlaylistFragment : BaseDialogFragment, IAddPlaylistView
{
private View _view;
private Button _btnCancel;
private Button _btnCreate;
private EditText _txtName;

public AddNewPlaylistFragment() : base(null)
public AddPlaylistFragment() : base(null)
{
}

public AddNewPlaylistFragment(Action<IBaseView> onViewReady)
public AddPlaylistFragment(Action<IBaseView> onViewReady)
: base(onViewReady)
{
}

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
Dialog.SetTitle("Add new playlist");
_view = inflater.Inflate(Resource.Layout.AddNewPlaylist, container, false);
_view = inflater.Inflate(Resource.Layout.AddPlaylist, container, false);

_txtName = _view.FindViewById<EditText>(Resource.Id.addNewPlaylist_txtName);
_btnCancel = _view.FindViewById<Button>(Resource.Id.addNewPlaylist_btnCancel);
_btnCreate = _view.FindViewById<Button>(Resource.Id.addNewPlaylist_btnCreate);
_txtName = _view.FindViewById<EditText>(Resource.Id.addPlaylist_txtName);
_btnCancel = _view.FindViewById<Button>(Resource.Id.addPlaylist_btnCancel);
_btnCreate = _view.FindViewById<Button>(Resource.Id.addPlaylist_btnCreate);
_btnCancel.Click += (sender, args) => Dismiss();
_btnCreate.Click += (sender, args) =>
{
Expand All @@ -72,17 +72,17 @@ public override void OnCreate(Bundle savedInstanceState)
SetStyle((int)DialogFragmentStyle.Normal, (int)Resource.Style.DialogTheme);
}

#region IAddNewPlaylistView implementation
#region IAddPlaylistView implementation

public Action<string> OnSavePlaylist { get; set; }

public void AddNewPlaylistError(Exception ex)
public void AddPlaylistError(Exception ex)
{
Activity.RunOnUiThread(() =>
{
AlertDialog ad = new AlertDialog.Builder(Activity).Create();
ad.SetCancelable(false);
ad.SetMessage(string.Format("An error has occured in AddNewPlaylist: {0}", ex));
ad.SetMessage(string.Format("An error has occured in AddPlaylist: {0}", ex));
ad.SetButton("OK", (sender, args) => ad.Dismiss());
ad.Show();
});
Expand Down
6 changes: 4 additions & 2 deletions MPfm/MPfm.Android/Classes/Fragments/MarkersFragment.cs
Expand Up @@ -50,7 +50,7 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
_view = inflater.Inflate(Resource.Layout.Markers, container, false);
_listView = _view.FindViewById<ListView>(Resource.Id.markers_listView);
_btnAdd = _view.FindViewById<Button>(Resource.Id.markers_btnAdd);
_btnAdd.Click += (sender, args) => OnAddMarker(MarkerTemplateNameType.Verse);
_btnAdd.Click += (sender, args) => OnAddMarker();

_listAdapter = new MarkersListAdapter(Activity, new List<Marker>());
_listView.SetAdapter(_listAdapter);
Expand All @@ -64,6 +64,7 @@ private void ListViewOnItemClick(object sender, AdapterView.ItemClickEventArgs i
{
Console.WriteLine("MarkersFragment - ItemClick - itemPosition: {0}", itemClickEventArgs.Position);
OnSelectMarker(_markers[itemClickEventArgs.Position]);
_listView.ClearFocus();
}

private void ListViewOnItemLongClick(object sender, AdapterView.ItemLongClickEventArgs itemLongClickEventArgs)
Expand Down Expand Up @@ -116,7 +117,8 @@ public override void OnDetach()

#region IMarkersView implementation

public Action<MarkerTemplateNameType> OnAddMarker { get; set; }
public Action OnAddMarker { get; set; }
public Action<MarkerTemplateNameType> OnAddMarkerWithTemplate { get; set; }
public Action<Marker> OnEditMarker { get; set; }
public Action<Marker> OnSelectMarker { get; set; }
public Action<Marker> OnDeleteMarker { get; set; }
Expand Down
29 changes: 18 additions & 11 deletions MPfm/MPfm.Android/Classes/Services/NotificationService.cs
Expand Up @@ -38,8 +38,8 @@

namespace org.sessionsapp.android
{
//[Service(Name = "org.sessionsapp.android.NotificationService", Label = "Sessions Widget Service")]//, Process = ":.widget.process")]
[Service(Label = "Sessions Notification Service")]//, Process = ":widgetprocess")]
//[Service(Name = "org.sessionsapp.android.NotificationService", Label = "Sessions Widget Service")]//, Process = ":.widget.process")] //, Process = ":widgetprocess")]
[Service(Label = "Sessions Notification Service")]
public class NotificationService : Service
{
private ITinyMessengerHub _messengerHub;
Expand Down Expand Up @@ -142,11 +142,14 @@ private void Initialize()

private Notification CreateNotificationView()
{
var notification = new Notification.Builder(this)
.SetOngoing(true)
.SetPriority((int)NotificationPriority.Max)
.SetSmallIcon(Resource.Drawable.Icon)
.Build();
var notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.SetOngoing(true);
notificationBuilder.SetSmallIcon(Resource.Drawable.Icon);

if (((int) global::Android.OS.Build.VERSION.SdkInt) >= 16)
notificationBuilder.SetPriority((int) NotificationPriority.Max);

var notification = notificationBuilder.Build();

// Use the big notification style for Android 4.1+;
//#if __ANDROID_16__
Expand All @@ -168,25 +171,29 @@ private Notification CreateNotificationView()
intentPlayPause.SetAction(SessionsWidgetActions.SessionsWidgetPlayPause.ToString());
PendingIntent pendingIntentPlayPause = PendingIntent.GetService(this, 0, intentPlayPause, PendingIntentFlags.UpdateCurrent);
_notification.ContentView.SetOnClickPendingIntent(Resource.Id.notificationPlayer_btnPlayPause, pendingIntentPlayPause);
_notification.BigContentView.SetOnClickPendingIntent(Resource.Id.bigNotificationPlayer_btnPlayPause, pendingIntentPlayPause);

Intent intentPrevious = new Intent(this, typeof(NotificationService));
intentPrevious.SetAction(SessionsWidgetActions.SessionsWidgetPrevious.ToString());
PendingIntent pendingIntentPrevious = PendingIntent.GetService(this, 0, intentPrevious, PendingIntentFlags.UpdateCurrent);
_notification.ContentView.SetOnClickPendingIntent(Resource.Id.notificationPlayer_btnPrevious, pendingIntentPrevious);
_notification.BigContentView.SetOnClickPendingIntent(Resource.Id.bigNotificationPlayer_btnPrevious, pendingIntentPrevious);

Intent intentNext = new Intent(this, typeof(NotificationService));
intentNext.SetAction(SessionsWidgetActions.SessionsWidgetNext.ToString());
PendingIntent pendingIntentNext = PendingIntent.GetService(this, 0, intentNext, PendingIntentFlags.UpdateCurrent);
_notification.ContentView.SetOnClickPendingIntent(Resource.Id.notificationPlayer_btnNext, pendingIntentNext);
_notification.BigContentView.SetOnClickPendingIntent(Resource.Id.bigNotificationPlayer_btnNext, pendingIntentNext);

Intent intentClose = new Intent(this, typeof(NotificationService));
intentClose.SetAction(SessionsWidgetActions.SessionsWidgetClose.ToString());
PendingIntent pendingIntentClose = PendingIntent.GetService(this, 0, intentClose, PendingIntentFlags.UpdateCurrent);
_notification.ContentView.SetOnClickPendingIntent(Resource.Id.notificationPlayer_btnClose, pendingIntentClose);
_notification.BigContentView.SetOnClickPendingIntent(Resource.Id.bigNotificationPlayer_btnClose, pendingIntentClose);

if (((int) global::Android.OS.Build.VERSION.SdkInt) >= 16)
{
_notification.BigContentView.SetOnClickPendingIntent(Resource.Id.bigNotificationPlayer_btnPlayPause, pendingIntentPlayPause);
_notification.BigContentView.SetOnClickPendingIntent(Resource.Id.bigNotificationPlayer_btnPrevious, pendingIntentPrevious);
_notification.BigContentView.SetOnClickPendingIntent(Resource.Id.bigNotificationPlayer_btnNext, pendingIntentNext);
_notification.BigContentView.SetOnClickPendingIntent(Resource.Id.bigNotificationPlayer_btnClose, pendingIntentClose);
}

Intent notificationIntent = new Intent(this, typeof(PlayerActivity));
//notificationIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTop | ActivityFlags.SingleTop);
Expand Down
8 changes: 6 additions & 2 deletions MPfm/MPfm.Android/MPfm.Android.csproj
Expand Up @@ -100,7 +100,8 @@
<Compile Include="Classes\Fragments\Base\BaseFragment.cs" />
<Compile Include="Classes\Fragments\AudioPreferencesFragment.cs" />
<Compile Include="Classes\Fragments\Base\BaseDialogFragment.cs" />
<Compile Include="Classes\Fragments\AddNewPlaylistFragment.cs" />
<Compile Include="Classes\Fragments\AddPlaylistFragment.cs" />
<Compile Include="Classes\Fragments\AddMarkerFragment.cs" />
<Compile Include="Classes\Fragments\SelectPlaylistFragment.cs" />
<Compile Include="Classes\Fragments\SyncManualConnectFragment.cs" />
<Compile Include="Classes\Fragments\PlayerMetadataFragment.cs" />
Expand Down Expand Up @@ -269,7 +270,10 @@
<AndroidResource Include="Resources\layout\PlaylistCell.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\layout\AddNewPlaylist.axml">
<AndroidResource Include="Resources\layout\AddPlaylist.axml">
<SubType>Designer</SubType>
</AndroidResource>
<AndroidResource Include="Resources\layout\AddMarker.axml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
Expand Down
76 changes: 76 additions & 0 deletions MPfm/MPfm.Android/Resources/Layout/AddMarker.axml
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="56dp"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="12dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingBottom="0dp"
android:text="Please select a marker template:"
android:textColor="#AAAAAA"
android:textSize="14dp" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/addMarker_radioVerse"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Verse"
android:textSize="14dp" />
<RadioButton android:id="@+id/addMarker_radioChorus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Chorus"
android:textSize="14dp" />
<RadioButton android:id="@+id/addMarker_radioBridge"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Bridge"
android:textSize="14dp" />
<RadioButton android:id="@+id/addMarker_radioSolo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Solo"
android:textSize="14dp" />
</RadioGroup>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<Button
android:id="@+id/addMarker_btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/actionbar_cancel"
android:drawablePadding="2dp"
android:background="@drawable/dialogbutton"
android:text="Cancel"
android:textColor="@color/dialogbutton_text"
android:textSize="14dp"
android:padding="6dp" />
<Button
android:id="@+id/addMarker_btnCreate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/selectimage"
android:drawablePadding="2dp"
android:background="@drawable/dialogbutton"
android:text="Create"
android:textColor="@color/dialogbutton_text"
android:textSize="14dp"
android:padding="6dp" />
</LinearLayout>
</LinearLayout>

0 comments on commit 60e5b32

Please sign in to comment.