Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Abstract base Main Activity - Configurable project

$
0
0

Hi!

I've just started using Xamarin.Forms, but I have experience with developing android applications and about six years of C# and WPF in professional life. We've decided to replace our android application written in Java with a new one written with Xamarin. I figured out that using Xamarin.Forms will be the choice of technology. We have also decided that we want to use Xamarin.Prism with Autofac as our IoC Container. On of our desktop applications are written in WPF with Prism - so we have fairly good knowledge about the framework.

As for the Xamarin application, I've created a Shared.UI assembly which contains all shared UI logic. In my MyProduct.Android project the code looks very familiar as the boiler plate code generated by the Visual Studio scaffolding

[Activity(MainLauncher = true, LaunchMode = LaunchMode.SingleTask, Label = "MyProduct")]
public class BaseActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
FormsAppCompatActivity.ToolbarResource = Resource.Layout.Toolbar;
FormsAppCompatActivity.TabLayoutResource = Resource.Layout.Tabbar;

        base.OnCreate(bundle);

        Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new Shared.UI.Application(new DroidInitializer()));
    }
}

public class DroidInitializer : IPlatformInitializer
{
    public void RegisterTypes(IContainerRegistry containerRegistry)
    {

    }
}

I want this application to be a base product, with all the resources(styles, images etc), but as a configurable product for each of our customers.

My intention is that the boxes marked as "Customer Configuration #1 and #2" will be standalone applications, in this particular example, android applications which will inherite the style and other resources from the parent. They will live in separate solutions, so the "Product"(Shared Code, Android, iOS and UWP) will have its own solution and will be distributed in our internal NuGet feed.

My first thought was to create a "customer project" and inherite from my BaseActivity something like this:

[Activity(Label = "CustomerConfiguration1", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : BaseActivity
{
    protected override IProjectConfiguration Configure()
    {
        return new ProjectConfiguration(cfg =>
        {
            cfg.EnableSmsModule();
            cfg.UseBluetooth(bluetoothConfiguration =>
            {
                bluetoothConfiguration.HostAfterBootup();
            });
        });
    }
}

This does not work, as of now. I think it has something to do with the resource files missing..'

As a second approach, the one we are using in our desktop application, is to create Prism Modules with customer specific configuration. The bad thing about this approach is that the "product" it self need to hard reference the modules and add them to the ModulesCatalog. Its confirmed by the author of Prism, Brian Lagunas, that loading modules dynamically will not work for Prism.Xamarin.Forms

Hopefully someone understands what I'm trying to achieve.. Can anyone pinpoint me in the correct direction?

Thanks in advance!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>