UIDocumentInteractionController change title of presented view - ios

I am using the UIDocumentInteractionController to display PDF files. My files are stored in the filesystem using encoded filenames that are not user-friendly. I do have access to a more friendly name for the file, but the file is not stored with this name (for uniqueness reasons).
When I load the document into the UIDocumentInteractionController then the view displays the unfriendly 'real' filename in the title bar.
Is there any way to change the displayed title as presented by the UIDocumentInteractionController?

UIDocumentInteractionController has a name property which you can set to your user-friendly name. That name will be used in the title bar of the presented document.

This is Xamarin (C#) code, but I hope it helps anyways
public class PreviewFile : IPreviewFile
{
public PreviewFile()
{
}
public void Preview(string file, string title)
{
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
bool isUrl = file.StartsWith("file:", StringComparison.OrdinalIgnoreCase);
var url = isUrl ? new NSUrl(file) : NSUrl.FromFilename(file);
var controller = UIDocumentInteractionController.FromUrl(url);
controller.Delegate = new MyInteractionDelegate(vc);
controller.Name = title;
controller.PresentPreview(true);
}
}
public class MyInteractionDelegate : UIDocumentInteractionControllerDelegate
{
UIViewController parent;
public MyInteractionDelegate(UIViewController controller)
{
parent = controller;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
{
return parent;
}
}

Related

How to add property from code to media type?

I use Umbraco 7.4.12 And I need to add property to media type dynamically from code and not from the UI.
What the best way to do this?
Something like this should do?
Below I am adding a textstring property to the default Image media type. I even tested it just now, and it's working :-)
There is an overload to the AddPropertyType method which allows you to add the property to a given tab/property group if needed.
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
var dataTypeService = ApplicationContext.Current.Services.DataTypeService;
var mediaType = contentTypeService.GetMediaType(1032);
if (mediaType != null && !mediaType.PropertyTypeExists("myNewPropertyAlias"))
{
var dataTypeDefinitions = dataTypeService.GetAllDataTypeDefinitions().ToArray();
var textStringDataTypeDefinition = dataTypeDefinitions.FirstOrDefault(p => p.Name.ToLower() == "textstring");
mediaType.AddPropertyType(new PropertyType(textStringDataTypeDefinition) { Name = "My New Property Name", Alias = "myNewPropertyAlias" });
contentTypeService.Save(mediaType);
}
}

Onesignal NotificationOpened doesn't work in ios app

I try to work with Onesignal Notifications in my ios app, created in Visual Studio with Xamarin. I want to make application open ViewController when user tap on notification, but it doesn't work. When user tap notification, app opens ViewController which was active when user application go to background.
Hope somebody show, where I made mistake
Here the code:
public class AppDelegate : UIApplicationDelegate
{
public static UIStoryboard Storyboard = UIStoryboard.FromName("Main", null);
public override UIWindow Window {
get;
set;
}
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
OneSignal.Current.StartInit("mykey")
.InFocusDisplaying(OSInFocusDisplayOption.None)
.HandleNotificationOpened(HandleNotificationOpened)
.EndInit();
OneSignal.Current.IdsAvailable(IdsAvailable);
return true;
}
void IdsAvailable(string userID, string pushToken)
{
GlobalUserInfo._token = userID;
}
private static void HandleNotificationOpened(OSNotificationOpenedResult result)
{
OSNotificationPayload payload = result.notification.payload;
Dictionary<string, object> additionalData = payload.additionalData;
if (additionalData != null)
{
UINavigationController NavigationController = (UINavigationController)Storyboard.InstantiateInitialViewController();
NotificationsViewController notificationsController = Storyboard.InstantiateViewController("NotificationsViewController") as NotificationsViewController;
NavigationController.PushViewController(notificationsController, true);
}
}
}
NotificationsViewController is simple list of all notification user received.
UPDATED
As I noticed, function HandleNotificationOpened does not work in iOS.
UPDATED
Error was found. I forgot, that I use OneSignal Init in other place. When I delete duplicate, HandleNotificationOpened begins work correctly.
You should find current root ViewController instead of creating a new instance. So please modify like this:
if (additionalData != null)
{
UINavigationController NavigationController = (UINavigationController)Window.RootViewController;
NotificationsViewController notificationsController = Storyboard.InstantiateViewController("NotificationsViewController") as NotificationsViewController;
NavigationController.PushViewController(notificationsController, true);
}
Moreover, if the root ViewController is a UITabBarController, please present this view controller(NotificationsViewController).

how to send custom Actionfilter to view

I have never worked with actionfilter before so i dont really understand how to do it. I have created the controller which i think will work, but now i want to my _ViewStart.cshtml to call this controller and dont know how to do it, i dont really know if my controller is right:
public class CoActionFilter : FilterAttribute, IActionFilter
{
public string CompanyFilter(ResultExecutedContext filterContext, Models.DynCss Cssdata, int id)
{
var service = ServiceFactory.Instance.CreateTemplateService();
var data = service.GetEntry(id);
var OverdriveCss = new Models.DynCss
{
GetAllTempData = data,
BGColor = Cssdata.GetAllTempData.TempBG,
HeadColor = Cssdata.GetAllTempData.TempHeader,
LayColor = Cssdata.GetAllTempData.TempLayout,
TextColor = Cssdata.GetAllTempData.TempText,
FootColor = Cssdata.GetAllTempData.TempFooter
};
string templateContent = File.ReadAllText("Content/Site.css");
return Razor.Parse(templateContent, OverdriveCss);
}
}
ps: The _Viewstart.cshtml doesnt have a controller or a model and this is why i need to use actionfilter. And i want this controller to be called inside: if (Request.IsAuthenticated)

adding custom property to webpart with a custom toolpart

I'm trying to add a custom property to my webpart as below:
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[System.ComponentModel.Category("Settings")]
[WebDisplayName("RSS List Path")]
[WebDescription("")]
public string RSSListURL
{
get
{
if (_myListURL == null)
{
_myListURL = "http://server2003dev/dev/";
}
return _myListURL;
}
set { _myListURL = value; }
}
But within the webpart I am also overriding the GetToolParts() method as below with my own custom toolpart:
public override ToolPart[] GetToolParts()
{
return new ToolPart[] { new RSSCountrySettings(), new WebPartToolPart() };
}
I need to display my custom toolpart (RSSCountrySettings) and my custom propery (RSS List Path) under the catergory Settings.
Any ideas how I do this, I able to only get one but not both to display...?
You are not using the base class's toolparts. Try this instead:
public override ToolPart[] GetToolParts()
{
var result = new List<ToolPart>() ;
var toolparts = base.GetToolParts();
result.AddRange(toolparts.ToList());
result.Add(new WebPartToolPart());
return result.ToArray();
}
The reason you need to do this is that the base class generates a toolpart for your custom property. However, you do not allow it to add that toolpart to the toolpart collection. So, you must get the base class's toolparts as a collection, then add yours in there as well. That's the danger in overriding an existing method. Check this link out for more info
You have to add CustomPropertyToolPart to toolParts list. Like this:
public override Microsoft.SharePoint.WebPartPages.ToolPart[] GetToolParts()
{
List<ToolPart> list = new List<ToolPart>();
list.AddRange(base.GetToolParts());
// adds custom controls
result.Add(new WebPartToolPart());
// adds default controls for properties marked with [WebBrowsable(true)]
list.Add(new CustomPropertyToolPart());
return list.ToArray();
}

How do you switch View Engines on the fly within an ASP.Net MVC Controller action?

I want to write a custom view engine that returns custom text (like coma delimited) does anyone know how I'd change the view engine on the fly to handle this?
I'd create a custom ActionResult. I use Json() function to return a JsonResult when I need JSON as response. I use this code to fill a ExtJS tree using JSON data.
public JsonResult Folders(string node)
{
var relativePath = (node == "root") ? "" : node;
var path = Path.Combine(BASE_PATH, relativePath);
var folder = new DirectoryInfo(path);
var subFolders = folder.GetDirectories();
var folders = new List<ExtJsTreeNode>();
foreach (var subFolder in subFolders)
{
folders.Add(new ExtJsTreeNode(subFolder.Name, subFolder.FullName.Replace(BASE_PATH, ""), "folder"));
}
return Json(folders);
}
private class ExtJsTreeNode
{
public string text { get; set; }
public string id { get; set; }
public string cls { get; set; }
public ExtJsTreeNode(string text, string id, string cls)
{
this.text = text;
this.id = id;
this.cls = cls;
}
}
A sample of a custom ActionResult here.
Your controller shouldn't know or care about this, other than which View to send the data to. The View can render in any format imaginable. I've got views that emit RSS (XML), etc. In the controller, either send it to the default view or explicitly identify the target view.
If I understood your question correctly, you want to use different views based on the parameters passed to the controller. If so, you can use this statement in the controller action:
return View("ViewName");
Otherwise, please clarify your question.

Resources