Giter Site home page Giter Site logo

mvvmcross-androidsupport's Introduction

MvvmCross

Twitter: @MvvmCross license Build Status NuGet NuGet Pre Release MyGet OpenCollective OpenCollective CodeFactor

๐Ÿ‘€ Check out mvvmcross.com to get started with MvvmCross ๐Ÿ‘€

MvvmCross is a opinionated cross-platform MVVM framework. It enables developers to create apps using the MVVM pattern in the .NET ecosystem. We support Android, iOS, MacCatalyst, TvOS, macOS, WinUI, WPF. Using MvvmCross allows for better code sharing by allowing you to share behavior and business logic between platforms.

Among the features MvvmCross provides are:

  • ViewModel to View bindings using own customizable binding engine, which allows you to create own binding definitions for own custom views
  • ViewModel to ViewModel navigation, helps you share behavior on how and when to navigate
  • Inversion of Control through Dependency Injection and Property Injection
  • Plugin framework, which lets you plug-in cool stuff like GPS Location, Localization, Sensors, Binding Extensions and a huge selection of 3rd party community plug-ins

MvvmCross is extendable by you. We strive to let as much code be configurable and overridable, to let the developer decide how they want to use the framework. However, the framework is very usable without doing anything.


Check out the MvvmCross docs


Installation

Grab the latest MvvmCross NuGet package and install in your solution.

Install-Package MvvmCross

Make sure that both the shared core project and your application projects include the NuGet. For more details please visit the Getting Started documentation, which also provides easier ways, through Visual Studio and Xamarin Studio plugins to install and manage MvvmCross in your project.

Filing issues

We want to keep the GitHub issues list for bugs, features and other important project management tasks only. If you have questions please see the Questions & support section below.

When filing issues, please select the appropriate issue template. The best way to get your bug fixed is to be as detailed as you can be about the problem. Providing a minimal git repository with a project showing how to reproduce the problem is ideal. Here are a couple of questions you can answer before filing a bug.

  1. Did you try find your answer in the documentation
  2. Did you include a snippet of the broken code in the issue?
  3. Can you reproduce the problem in a brand new project?
  4. What are the EXACT steps to reproduce this problem?
  5. What platform(s) are you experiencing the problem on?

Remember GitHub issues support markdown. When filing bugs please make sure you check the formatting of the issue before clicking submit.

Contributing code

We are happy to receive Pull Requests and code changes. Please read CONTRIBUTING.md for more information.

Questions & support

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

Backers

Licensing

MvvmCross is licensed under the MS-PL License

  • MonoCross was the original starting point for this project, and was used as a reference under MIT
  • Tiny bits of MvvmLight are redistributed and modified under MIT
  • Messenger ideas from JonathanPeppers/XPlatUtils under Apache License Version 2.0, and from GrumpyDev/TinyMessenger under simple license of "THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY"
  • Color codes under MIT License
  • Some bits of Mvvm.Async are redistributed and modified under MIT License

Acknowledgements

  • Thanks to McCannLondon for sponsoring the initial part of this work
  • Thanks to JetBrains for a community Resharper license to use on this project

.NET Foundation

This project is supported by the .NET Foundation.

mvvmcross-androidsupport's People

Contributors

andyci avatar cheesebaron avatar dbeattie71 avatar dexyon avatar foxanna avatar geirsagberg avatar jamsoft avatar kiliman avatar kjeremy avatar lothrop avatar martijn00 avatar mattwhetton avatar nmilcoff avatar roubachof avatar sescandell avatar skycoder42 avatar slynet avatar thefex avatar tomcurran avatar vecalion avatar zleao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mvvmcross-androidsupport's Issues

Adding app compat removing Cirrious.MvvmCross.Binding.Droid

Before i install MVVM Appcompat packages via the nuget pre release channel, my code builds fine.

after i add the appcompat packages, its removing Cirrious.MvvmCross.Binding.Droid (before and after images attached).

before adding app compat (just standard mvvmcross starter )
screen shot 2015-12-10 at 16 41 07
after adding app compat libs
screen shot 2015-12-10 at 16 44 29

any ideas? these are the two build errors im getting

screen shot 2015-12-10 at 16 48 53

Views/LoginView.cs(20,27): error CS0012: The type Cirrious.MvvmCross.Binding.Droid.Views.IMvxLayoutInflaterHolder' is defined in an assembly that is not referenced. Consider adding a reference to assemblyCirrious.MvvmCross.Binding.Droid, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'

Views/LoginView.cs(20,27): error CS0012: The type Cirrious.MvvmCross.Binding.BindingContext.IMvxBindingContextOwner' is defined in an assembly that is not referenced. Consider adding a reference to assemblyCirrious.MvvmCross.Binding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'

Sample fails with NullReferenceException when rotating screen

The sample provided throws a null reference exception whenever you rotate the screen (i.e. enter save/restore state cycle).

It seems to be thrown in the RestoreLookupFromSleep method of the MvxCachingFragmentActivity as the SupportFragmentManager.Fragments is null.

The wider implication is that the save/restore state cycle does not work.

Autoregistration is too late

It is called on pause - it should be done OnCreate.
SaveInstanceState CAN be called before OnPause - therefore caching might don't work everytime.

RecyclerView Java.Lang.IllegalStateException

If items are inserted into the recycler view one by one exception is thrown:

11-20 10:14:55.330 I/mvx     (23678):   at Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerAdapter.NotifyDataSetChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0003a] in <filename unknown>:0 
11-20 10:14:55.370 I/mono-stdout(23678): mvx:Warning:201.60 Exception masked during Adapter RealNotifyDataSetChanged ArgumentException: 'jobject' must not be IntPtr.Zero.
11-20 10:14:55.370 I/mono-stdout(23678): Parameter name: jobject
11-20 10:14:55.370 I/mono-stdout(23678):      at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00010] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:563 
11-20 10:14:55.370 I/mono-stdout(23678):   at Android.Support.V7.Widget.RecyclerView+Adapter.NotifyItemRangeInserted (Int32 positionStart, Int32 itemCount) [0x0005d] in <filename unknown>:0 
11-20 10:14:55.370 I/mono-stdout(23678):   at Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerAdapter.NotifyDataSetChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0003a] in <filename unknown>:0 
Exception:

Java.Lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling

11-20 10:17:09.130 I/mvx     (23678): 335.39 Exception masked during Adapter RealNotifyDataSetChanged IllegalStateException: Exception of type 'Java.Lang.IllegalStateException' was thrown.
[0:] 
11-20 10:17:09.130 I/mvx     (23678):     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61 
11-20 10:17:09.130 I/mvx     (23678):   at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00063] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:571 
mvx:Warning:335.39 Exception masked during Adapter RealNotifyDataSetChanged IllegalStateException: Exception of type 'Java.Lang.IllegalStateException' was thrown.
11-20 10:17:09.130 I/mvx     (23678):   at Android.Support.V7.Widget.RecyclerView+Adapter.NotifyItemRangeInserted (Int32 positionStart, Int32 itemCount) [0x0005d] in <filename unknown>:0 
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/2185/53fce373/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61 
  at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00063] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:571 
  at Android.Support.V7.Widget.RecyclerView+Adapter.NotifyItemRangeInserted (Int32 positionStart, Int32 itemCount) [0x0005d] in <filename unknown>:0 
  at Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerAdapter.NotifyDataSetChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0003a] in <filename unknown>:0 

Exception is thrown when navigating back with a back stack

The issue is related to navigating back and forth to a ViewModel that takes different init params and requires a fragment to be added to a back stack.

A -> B (init 'some = 1') -> A -> B (init 'some = 2') -> A (Exception occurs here where trying to navigate back to fragment A).

Here is a demo project:
https://github.com/vecalion/MvvmCross-AndroidSupport

The issue is in the ShowFragment method of MvxCachingFragmentCompatActivity.

When fragmentReplaceMode == FragmentReplaceMode.ReplaceFragmentAndViewModel, the method makes two actions:

  1. ft.Remove(fragInfo.CachedFragment);
  2. ft.Replace(fragInfo.ContentId, fragInfo.CachedFragment, fragInfo.Tag);

According to the documentation, android will add both these actions to the backstack:

If you add multiple changes to the transaction (such as another add() or remove()) and call addToBackStack(), then all changes applied before you call commit() are added to the back stack as a single transaction and the Back button will reverse them all together.

So when navigating back from B to A, the system recreates Fragment B by it's own, which causes the issue.

As possible solution:
ft.Remove(fragInfo.CachedFragment); can be simple removed, since Replace() method does Remove() and Add() internally and there is no need to additionally call Remove()

Replace an existing fragment that was added to a container. This is essentially the same as calling remove(Fragment) for all currently added fragments that were added with the same containerViewId and then add(int, Fragment, String) with the same arguments given here.

If though there is a reason to call Remove() it can be done in a separate transaction which is not added to the back stack.

Difference between MvxAppCompatActivity vs MvxFragmentCompatActivity

I'm wondering... what's the difference between these two classes:
https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/2b24c360a7ea05ed1e57f02d5a11a72fa0477e86/Cirrious.MvvmCross.Droid.Support.AppCompat/MvxAppCompatActivity.cs
https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/2b24c360a7ea05ed1e57f02d5a11a72fa0477e86/Cirrious.MvvmCross.Droid.Support.AppCompat/MvxFragmentCompatActivity.cs

It seems to me that they do exactly the same stuff...
Maybe, one of these should be removed to avoid confusion?

Another question...
Shouldn't the MvxAppCompatActivity call the jni constructor, like in the MvxFragmentCompatActivity?

And the last one:
Shouldn't the MvxFragmentCompatActivity call the MvxAppCompatActivityHelper too, like in the MvxAppCompatActivity?

Create projects for each Xamarin Support Library

I would love to see a MvvmCross project for each Xamarin Support Library package that is out there.

Namings would be:

  • Cirrious.MvvmCross.Droid.Support.V4
  • Cirrious.MvvmCross.Droid.Support.V7.LeanBack
  • Cirrious.MvvmCross.Droid.Support.V7.Palette
  • Cirrious.MvvmCross.Droid.Support.V7.*
  • Cirrious.MvvmCross.Droid.Support.V13

Issue with MvxImageView on MvxRecylerView with a lot of items

If you have a mvxrecyclerview with a lot of items (each item has a uri to image and a text for example)

1 - Start and check that each showed image correspond with each text.
2 - Scroll to end and go to top without wait mvximageview load the images.
3 - Check that now images requested on bottom ... are showed on top.

Sorry for my english... I try to say:

On step 1 I see Image1 and text1, image2 and text2... but if I scroll to bottom and return to top without wait images end to load at botton I see imageN-1 and text1, imageN-2 and text2 etc.

I think that the problem is with async assign of image on recycler view.

Custom RecyclerView adapter overrided by existing one

Hi guys,

I have some difficulties to use my own RecyclerView adapter. The properties of my custom adapter are overrided in the Adapter setter in MvxRecyclerView.cs because in the sample code below, "existing" is never null because of the first adapter instantiated in the MvxRecyclerView constructor.

MvxRecyclerView.cs

if (value != null && existing != null)
{
     value.ItemsSource = existing.ItemsSource;
     value.ItemTemplateId = existing.ItemTemplateId;
     value.ItemClick = existing.ItemClick;
     value.ItemLongClick = existing.ItemLongClick;

     SwapAdapter((Adapter)value, false);
 }

And this is my code:

view.axml

<Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/date_filter"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="15dp"
    local:MvxBind="Visible NotLoading"
    local:MvxItemTemplate="@layout/date_filter_item" />

myAdapter.cs

public class myAdapter : MvxRecyclerAdapter
{
    public myAdapter (IEnumerable itemsSource)
    {
        this.ItemsSource = itemsSource;
    }
}

Setting adapter in myView.cs

_dateFilterRecyclerView = view.FindViewById<MvxRecyclerView>(Resource.Id.date_filter);
_dateFilterRecyclerView.Adapter = new myAdapter(myViewModel.DateFilterItems);

Did I miss something in my implementation? Or can I make this differently?

Thanks for your help and your work! ;)

Previously created ViewModels don't go through the lifecycle in cached fragments

TL;DR; VM Lifecycle is only ran when the cached fragment doesn't already have an instance of a VM. There seems to be no functionality to run it when the Vm is already created.

First, in MvxCachingFragmentCompatActivity.ShowFragment, when you have a cached fragment, you need to set the received bundle as the Arguments prop. I wasn't doing that.

Second, VM Init is only called when the fragment doesn't have one already created, in MvxFragmentExtensions.LoadViewModel(...).

If theres an instance of a VM attached to the fragment, it will be null checked to stop the execution in two places:

  1. MvxFragmentExtensions.OnCreate(...)
  2. MvxViewExtensionMethods.OnViewCreate

The current ViewModel lifecycle seems to be handled by MvxDefaultViewModelLocator, thus, a simple solutions seems to be to improve MvxDefaultViewModelLocator with a Load(IMvxViewModel vm, IMvxBundle parameterValues, IMvxBundle savedState), that skips the VM instantiation and only calls the lifecycle with the new params.

Do you have any other idea @slodge @Cheesebaron @martijn00 ?

LayoutInflater

I don't know whether this is a new issue caused by changes in MvvmCross 4.0.0.0-beta2 but when I try and show a fragment I get:

java.lang.ClassNotFoundException: Didn't find class "android.view.MvxListView" on path:

This was working fine in 3.5.1 before the fragments were moved into the support package

Expose in MvxCachingFragmentActivity

Classes implementing MvxCachingFragmentActivity would benefit if they could check the tag of the visible fragments. This is already being tracked.

Add NavigationView bindings

After comment of @vvolkgang

Was thinking about that, if it made sense to keep the current Core menu strategy (binded MenuItem) and enhance it with the new NavigationView stuff (sub menus for instance). My current position is that it doesn't, any "crossplatform" solution would be Droid first and all of the other platforms would have to adapt to that. Furthermore, you would sacrifice some "ease" of development in Droid (for instance, being able to refer to menu items in a type-safe-ish way, which is great for some L10N implementations). That being said, having the MenuVM with one or multiple MvxCommands being triggered by the platform seems to be the best compromise.

Some thoughts in Jabbr from @martijn00

This would require some good thinking on the solution, think of support for images / icons in the navigation view, with multi platform support. Maybe a multi level collection and a value converter would help, and off course bindings for the navigation viewer.

Close fragment method doesn't work properly

Close Fragment method is not implemented and won't work correctly until we change .Close method signature in main MvvmCross library.

Reason:

  1. The only information we have during .Close call is ViewModel instance.
    We need to pass custom information so we can differentiate ViewModel instances. If same Activity uses several Fragments with same ViewModel we do not know which instance of Fragment we should close.

Fragment restore crash when using non-generic MvxFragments

Application crash on fragment viewmodel restore when we use Fragments which inherits from MvxFragment (non-generic).

It looks like MvxCachingFragmentActvity is not smart enough to guess viewmodel type to restore cause in the end there is a call to Ioc.Construct(null)

Restore fragments from sleep (caching issue)

When restoring fragments from sleep and then attempting to switch the visible fragment with a fragment of the same type (using force replace), the previously shown viewmodel is populated from cache and assigned to the fragment rather than my new viewmodel.

Uncommenting out https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/master/Cirrious.MvvmCross.Droid.Support.Fragging/MvxCachingFragmentActivity.cs#L122 fixes the problem but obviously this is then no longer a caching FragmentActivity.

What I am trying to decide is how best to correct this. Should the fragment viewmodel be removed from cache before force replacing a fragment? Obviously this is not an issue if you never show the same fragment in sequence.

Improvements for showing Fragments

@martijn00 wrote this here #41:

The main problem with this change is that you use a new activity to show login. Currently the CachingFragment implementation is limited that you first need to show some ViewModel that is connected to the Hosting Activity to show other fragments.

To work around that it is possible to just use 1 Activity and for everything else use Fragments. The real solution would be to change the code of the FragmentsPresenter to allow to navigate to the correct ViewModel directly.

Let's say you start the app, depending on if you are already logged in you want to show the LoginViewModel, or the NewsViewModel(let's imagine a news app). It doesn't make sense then that you need to show MainViewModel first in order to show the NewsViewmodel.

My guess would be we need to turn the registering of fragments around. When we call ShowViewModel we should search for if it is a fragment, and if it is so, we should search for it's parent. I was thinking that could be done by adding an attribute to fragments containing it's parent.

Error binding MvxRecyclerView

I'm getting an error trying to bind an MvxRecyclerView in my app using the following XML.

    <Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerView
        android:layout_width="wrap_content"
        android:layout_height="42dp"
        android:layout_weight=".7"
        android:id="@+id/showDateSelectorListView"
        android:scrollbars="horizontal"
        android:scrollbarSize="2dp"
        local:MvxBind="ItemsSource ShowtimeDates; ItemClick ShowtimeDatePicked"
        local:MvxItemTemplate="@layout/showdateitemmvx" />

The error I receive is:

MvxBind:Error: 0.69 View type not found - cirrious.mvvmcross.droid.support.recyclerview.MvxRecyclerView

Is there some type of initialization I'm missing? I'm able to use other controls like Mvx.MvxGridView and MvxImageView without any issues.

Thanks for any help.

MvxActionBarDrawerToggle prevents using the Up carret

Having an Activity with a Drawer and content fragments, you'll need to manually handle the up carret to go back in deeper level ones. This is done by toggling _drawerToggle.DrawerIndicatorEnabled to hide the hamburguer icon and overriding OnOptionsItemSelected like this:

public override bool OnOptionsItemSelected(IMenuItem item)
{
    switch (item.ItemId)
    {
        case Android.Resource.Id.Home:
            OnBackPressed();
            return true;
    }
    return base.OnOptionsItemSelected(item);
}

Currently, the way the sample is creating MvxActionBarDrawerToggle prevents that method to be called when you tap the Up caret (back button in the Toolbar). After some researching I found this answer which quotes this part from the ActionBarDrawerToggle official documentation:

Please use ActionBarDrawerToggle(Activity, DrawerLayout, int, int) if you are setting the Toolbar as the ActionBar of your activity

The solution is then to remove this line.

MvxCachingFragmentActivityCompat.OnBackPressed crashes

I constantly get crash logs in Xamarin.Insights for MvxCachingFragmentActivityCompat.OnBackPressed.

at System.Linq.Check.Source (object) <0x00040>
at System.Linq.Enumerable.Any<Android.Support.V4.App.Fragment> (System.Collections.Generic.IEnumerable`1<Android.Support.V4.App.Fragment>) <0x00023>
at myapp.TaskExecuteActivity.OnBackPressed () <0x0003b>
at Android.App.Activity.n_OnBackPressed (intptr,intptr) <0x00037>
at (wrapper dynamic-method) object.d0e69f73-4b85-4f52-8065-8eba4d0ebb05 (intptr,intptr) <0x0003b

(TaskExecuteActivity inherits from MvxCachingFragmentActivityCompat and it does not override OnBackPressed)
It seems that this exception is raised when none of registered fragments is shown yet (in my case that's because of async REST API call) and back button is pressed.
I am implementing the bug fix now.

Fragment Cache rely on Fragment.Tag - not compatibile for ex. with ViewPager

We cannot use Fragment.Tag all the time to identify fragment (during cache/restore cycle).

We doesn't always have chance to give fragment our own "tag" - for example support ViewPager sets fragment tag to something like:
android:switcher:resourceid:indexInPager

Working on issue, adding customization of that.

Issue with MvxImageView inside MvxRecyclerView

Hello,

I have an issue with the display of MvxImageViews when they're inside a MvxRecyclerView.

I really don't know if it's related to DownloadCache plugin, MvxImageView component or MvxRecyclerView but it seems on the first display, some images don't appear but after some recycles of the RecyclerView by playing with the scroll, all images finally display.

I'm using 4.0.0-beta2 version of MvvmCross and I made a sample to reproduce the issue starting with an example found in MvvmCross-AndroidSupport.

My sample is available here : https://github.com/jbolle/MvxImgView-Issue

Thanks for your help.

Fragment Cache logic is multiplied - in Support.Fragging and Support.AppCompat

Both MvxCachingFragmentCompatActivity and MvxCachingFragmentActivity do the same thing - but the code is copy-pasted because of interface mis-match.

Supporting two code-lines (which do exactly the same thing) is unacceptable.
Do not pick this issue as I am refactoring this now. In fifteen minutes I should commit working solution to the problem.

Improve `MvxCachingFragmentActivity.RegisterFragment` to deal with Backstack and Transitions on the registry level

Giving that one already needs to manually register the fragments, this mechanism can be improved to enable devs to set transitions and if that fragment should clear the backstack.

This information should be added to the FragmentInfo config file and then used in ShowFragment.

Regarding the transitions, following this implementation, we only need something like a FragmentTransitionInfo with nullable ints for all of the possible transitions, if set, they'll be inflated when a new fragment is created.

This will reduce the code complexity required to implement something like the Home/MainActivity with a drawer.

Leanback Support (part 2)

Leanback support is still far from finished. While one's already able to pull off a leanback app (yay!), there's still stuff to do.

For example:

  • Proper bindings on most of the new fragments (at the moment you have to stuff your items into the Adapters/Presenters by hand)
  • Support for Android's presenters support
  • Caching for all new fragments

Currently I'm working on a leanback app, so I will gradually give back any emerged improvements, once they're cleaned up. And furthermore I'll refine this list...

Error on new Beta 8 AppCompat/MvxAppCompatActivity.cs

Hi :)

You forgot add
using Android.Views;
using Android.Util;
to MvvmCross.Droid.Support.V7.AppCompat/MvxAppCompatActivity.cs

And this make an error on public override View OnCreateView

I cannot fix it here to make a pull request sorry. (I cannot install anything in this computer sorry)

Sample crashes on item click in recyclerview

Start app, click one of the items in the list. BAM!

07-01 10:07:56.100 I/MonoDroid( 6896): UNHANDLED EXCEPTION:
07-01 10:07:56.102 I/MonoDroid( 6896): System.NullReferenceException: Object reference not set to an instance of an object
07-01 10:07:56.102 I/MonoDroid( 6896): at Cirrious.MvvmCross.ViewModels.MvxCommand.Execute (object) <IL 0x0000f, 0x00090>
07-01 10:07:56.102 I/MonoDroid( 6896): at Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerViewHolder.ExecuteCommandOnItem (System.Windows.Input.ICommand) [0x0002f] in c:\vcs\git\MvvmCross-AndroidSupport\Cirrious.MvvmCross.Droid.Support.RecyclerView\MvxRecyclerViewHolder.cs:76
07-01 10:07:56.102 I/MonoDroid( 6896): at Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerViewHolder.<EnsureClickOverloaded>b__0 (object,System.EventArgs) [0x00000] in c:\vcs\git\MvvmCross-AndroidSupport\Cirrious.MvvmCross.Droid.Support.RecyclerView\MvxRecyclerViewHolder.cs:47
07-01 10:07:56.102 I/MonoDroid( 6896): at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:1923
07-01 10:07:56.102 I/MonoDroid( 6896): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:1888
07-01 10:07:56.102 I/MonoDroid( 6896): at (wrapper dynamic-method) object.fabb184c-2de3-4bcd-9df3-d56f69641999 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
07-01 10:07:56.110 W/art     ( 6896): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
07-01 10:07:56.112 D/AndroidRuntime( 6896): Shutting down VM
An unhandled exception occured.

07-01 10:07:59.455 E/AndroidRuntime( 6896): FATAL EXCEPTION: main
07-01 10:07:59.455 E/AndroidRuntime( 6896): Process: com.mvvmcross.androidsupport.example, PID: 6896
07-01 10:07:59.455 E/AndroidRuntime( 6896): java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
07-01 10:07:59.455 E/AndroidRuntime( 6896): Caused by: java.lang.reflect.InvocationTargetException
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at java.lang.reflect.Method.invoke(Native Method)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at java.lang.reflect.Method.invoke(Method.java:372)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     ... 1 more
07-01 10:07:59.455 E/AndroidRuntime( 6896): Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
07-01 10:07:59.455 E/AndroidRuntime( 6896): at Cirrious.MvvmCross.ViewModels.MvxCommand.Execute (object) <IL 0x0000f, 0x00090>
07-01 10:07:59.455 E/AndroidRuntime( 6896): at Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerViewHolder.ExecuteCommandOnItem (System.Windows.Input.ICommand) [0x0002f] in c:\vcs\git\MvvmCross-AndroidSupport\Cirrious.MvvmCross.Droid.Support.RecyclerView\MvxRecyclerViewHolder.cs:76
07-01 10:07:59.455 E/AndroidRuntime( 6896): at Cirrious.MvvmCross.Droid.Support.RecyclerView.MvxRecyclerViewHolder.<EnsureClickOverloaded>b__0 (object,System.EventArgs) [0x00000] in c:\vcs\git\MvvmCross-AndroidSupport\Cirrious.MvvmCross.Droid.Support.RecyclerView\MvxRecyclerViewHolder.cs:47
07-01 10:07:59.455 E/AndroidRuntime( 6896): at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:1923
07-01 10:07:59.455 E/AndroidRuntime( 6896): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:1888
07-01 10:07:59.455 E/AndroidRuntime( 6896): at (wrapper dynamic-method) object.fabb184c-2de3-4bcd-9df3-d56f69641999 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
07-01 10:07:59.455 E/AndroidRuntime( 6896): 
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at android.view.View.performClick(View.java:4781)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at android.view.View$PerformClick.run(View.java:19873)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at android.os.Handler.handleCallback(Handler.java:739)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at android.os.Handler.dispatchMessage(Handler.java:95)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at android.os.Looper.loop(Looper.java:135)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     at android.app.ActivityThread.main(ActivityThread.java:5289)
07-01 10:07:59.455 E/AndroidRuntime( 6896):     ... 4 more
07-01 10:08:45.391 I/Process ( 6896): Sending signal. PID: 6896 SIG: 9

MvxFragment child state restore failure

I found an odd quirk that might already be fixed in your tree but I'll report it here just in case. I am using MvvmCross 3.5.1 and Fragging 3.5.1 (though I also observed this in FullFragging).

Suppose I have a fragment like so:

[MvxOwnedViewModelFragment]
public class PointOfInterestView : MvxFragment<PointOfInterestViewModel>
{
    public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {           
        var ignore = base.OnCreateView(inflater, container, savedInstanceState); //warmup
        var view = this.BindingInflate (Resource.Layout.PointOfInterestView, container, false);
        return view;
    }
}

This is presented in an activity. If I minimize the app or otherwise cause it to lose state and reload, the ViewModel will not reload; the fragment will reappear anew with no VM bound.

However, if I add this code to the class:

public override void OnSaveInstanceState (Bundle outState)
{
    base.OnSaveInstanceState (outState);
    outState.PutInt ("hack", 0);
}

It works; the previous ViewModel is correctly attached to the new Fragment when the Activity is restored.

I thought this might involve reflection but if I remove the PutInt than it goes back to the unwanted behavior.

Is this a known issue? Is there another way I should be handling this?

Customization of ViewModel Load if view model is killed and is not persistent in cache

Implementation of Support Fragging cache is simple:
a) during save state cache viewmodel in IMvxMultipleViewModelCache
b) on restore:

  • if viewmodel is in cache , restore it from cache
  • if viewmodel is not in cache, LoadViewModel using IoC request to create new ViewModel instance

If ViewModel is not in cache we should be able to customize how ViewModel should be loaded (should it keep default behavior of new IoC-created instance or something different).

Use case + why it is needed:
Activity with ViewModel "ParentViewModel" contains ViewPager and ViewPager is "binded" to IEnumerable< ChildViewModel > in ParentViewModel.
If we load new ViewModel during Activity+ViewModel kill we lose information about pager ChildViewModels (cause their viewmodels aren't synchronized with "ParentViewModel" list)

This bug exists only if during fragment restore ViewModel is not persistent in Cache.

Leanback Support

Hey guys,

I'm currently working on a FireTV/AndroidTV app and of course trying to use MvvmCross (e.g. for later development for tvOS or what else).
Is anyone already working on leanback support?
Currently I'm wondering, whether I have to implement IMvxEventSourceFragment, IMvxFragmentView etc. for each new Fragment-Type (BrowseSupportFragment, DetailSupportFragment, ...). Am I overlooking something or is this really necessary? Is there are more common class I can start with?

Fragging vs Full Fragging

Apart from some refactoring, whats the diff between Fraggin (here) and Full Fragging in the main Mvx repo?

Main features seem to be in sync, are we supposed to improve both implementations?

Call OnFragmentChanging when Back is pressed in MvxCachingFragmentActivity

In MvxCachingFragmentActivity, extenders know when a new fragment is pushed to the view but, currently no notification in place when it's popped. Although you can override OnBackPressed, theres no way for you to know the current presented fragments.

As a better solution, I would add a OnFragmentChanged(IList<string> presentedFragments) that is called at the end of the Show and OnBackPressed. This would also help dealing with #79 use cases.

Lack of JNI Constructor... Is it needed?

Both the MvxCachingFragmentActivityCompat and the MvxEventSourceAppCompatActivity are currently missing the constructor (IntPtr javaReference, JniHandleOwnership transfer)
Since, it is not totally clear to me the purpose of this constructor, I'm wondering if the lack of this JNI constructor is intentional, or it should be added...
More in general, should we always expose the JNI constructor of the base class?

https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/master/Cirrious.MvvmCross.Droid.Support.AppCompat/MvxCachingFragmentActivityCompat.cs
https://github.com/MvvmCross/MvvmCross-AndroidSupport/blob/master/Cirrious.MvvmCross.Droid.Support.AppCompat/MvxEventSourceAppCompatActivity.cs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.