architecture-components-samples | Samples for Android Architecture Components | Architecture library

 by   android Kotlin Version: Current License: Apache-2.0

kandi X-RAY | architecture-components-samples Summary

kandi X-RAY | architecture-components-samples Summary

architecture-components-samples is a Kotlin library typically used in Architecture applications. architecture-components-samples has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

Android Architecture Components samples.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              architecture-components-samples has a medium active ecosystem.
              It has 22841 star(s) with 8338 fork(s). There are 891 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 148 open issues and 537 have been closed. On average issues are closed in 284 days. There are 42 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of architecture-components-samples is current.

            kandi-Quality Quality

              architecture-components-samples has 0 bugs and 0 code smells.

            kandi-Security Security

              architecture-components-samples has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              architecture-components-samples code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              architecture-components-samples is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              architecture-components-samples releases are not available. You will need to build from source code and install.
              Installation instructions are not available. Examples and code snippets are available.
              It has 19559 lines of code, 959 functions and 511 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of architecture-components-samples
            Get all kandi verified functions for this library.

            architecture-components-samples Key Features

            No Key Features are available at this moment for architecture-components-samples.

            architecture-components-samples Examples and Code Snippets

            No Code Snippets are available at this moment for architecture-components-samples.

            Community Discussions

            QUESTION

            How to handle result of paging data in compose and implement header and footer load states?
            Asked 2022-Mar-30 at 09:13

            In View system there are official examples how to implement loading states and adding header and footer item to the list:

            https://developer.android.com/topic/libraries/architecture/paging/load-state

            https://github.com/android/architecture-components-samples/blob/main/PagingWithNetworkSample/app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/ui/RedditActivity.kt

            I didn't really found anything similar for Jetpack Compose

            Only how to show items

            https://developer.android.com/jetpack/compose/lists#large-datasets

            But how can we implement load states in Compose?

            ...

            ANSWER

            Answered 2022-Mar-30 at 09:13

            We are doing something like this, it works well:

            Source https://stackoverflow.com/questions/71674153

            QUESTION

            Android clear backstack after reselecting Bottom Navigation tab
            Asked 2022-Feb-23 at 18:37

            Using the newest Navigation Component with the BottomNavigationView, the NavController now saves and restores the states of tabs by default:

            As part of this change, the NavigationUI methods of onNavDestinationSelected(), BottomNavigationView.setupWithNavController() and NavigationView.setupWithNavController() now automatically save and restore the state of popped destinations, enabling support for multiple back stacks without any code changes. When using Navigation with Fragments, this is the recommended way to integrate with multiple back stacks.

            This is great! Now switching tabs gives you the last viewed stack.

            But, if the user reselects a tab, say they've gone Home -> Detail Page A -> Detail Page B, then they select the Home tab expecting to go back to the default view, they still see Detail Page B.

            It seems like part of the discussion was to handle the "reselecting a tab" behavior as mentioned in the issue tracker, but I can't figure out the recommended way for implementing this.

            All that's included in the NavigationAdvancedSample is:

            ...

            ANSWER

            Answered 2021-Aug-14 at 00:04

            BottomNavigationView has its own method for handling reselection via setOnItemReselectedListener() (or, when using an earlier version of the Material Design Library, the now deprecated setOnNavigationItemReselectedListener()).

            bottomNavigationView.setupWithNavController does not set this listener (as there is no Material specification for exactly what reselecting a tab should do), so you need to set it yourself:

            Source https://stackoverflow.com/questions/68777836

            QUESTION

            How can I correctly use custom PagingSource with PagingDataAdapter, on local data?
            Asked 2022-Jan-26 at 11:16

            The Problem

            I have locally-generated data that I need to display in a RecyclerView. I tried to use a custom PagingSource with PagingDataAdapter to reduce the amount of data in memory, but I get visual effects when I invalidate the data, for example if I insert or delete one item:

            • when the visible items belong to 2 different "pages", many unchanged items flash as if they had been modified
            • if all the visible items belong to the same page, everything is fine. Only the inserted / deleted item shows an animation.

            I took an example application referenced by Google's doc (PagingSample) to test the concept. The original with Room does not show artefacts, but my modified version with custom PagingSource does.

            The code generated and used by Room is too complicated to see any difference that would explain the issue.

            My data must be locally-generated, I can't use Room as a work-around to display them.

            My question

            How can I properly define a PagingSource for my local data, and use it with PagingDataAdapter without visual glitches?

            Optionally, how can I know when data is discarded (so I can discard my local data as well)?

            Code excerpts and details

            The full example project is hosted here: https://github.com/blueglyph/PagingSampleModified

            Here is the data:

            ...

            ANSWER

            Answered 2022-Jan-26 at 11:16

            I finally found out a possible solution, though I'm not sure it will work if the Paging-3 library is updated. I don't know yet if the behaviour explained above is due to bugs / limitations in the Paging-3 components or if that's just a bad explanation in the reference documentation, or something I missed entirely.

            I. Work-around for the glitch issue.

            1. In PagingConfig, we must have enablePlaceholders = true or it simply won't work correctly. With false I'm observing the scrollbar jumping on each load operation when scrolling up/down, and inserting items at the end will make all items glitch on the display, then the list will jump all the way to the top.

            2. The logic in getRefreshKey and load, as shown in Google's guide and reference documentation, is naive and will not work with custom data. I had to modify them as follows (modifications have been pushed in the github example):

            Source https://stackoverflow.com/questions/70801968

            QUESTION

            What is this implemention? Android
            Asked 2021-Dec-02 at 16:33

            I've downloaded a repository from github and in the dependencies I've founded this

            ...

            ANSWER

            Answered 2021-Dec-02 at 16:33

            This is a way (with ExtraPropertiesExtension) to keep build.gradle files as clean as possible with an external file like a version.gradle file in which there are all dependencies and their version.

            Source https://stackoverflow.com/questions/70202775

            QUESTION

            Android BottomNavigationView recreating Fragments each time with Navigation Component
            Asked 2021-Nov-15 at 21:28

            I'm using a BottomNavigationView to switch between a Home and Meetings fragment. Each time I switch between them, each Fragment is recreated. I'm using a SharedViewModel between them for a shared "meetingID" variable, but that's being destroyed and recreated along with the Fragments (aggravatingly so). I'm using Jetpack Navigation Component; I almost completely copied the Google example here. It's still not working, however.

            Here's a look at my onCreate and onSupportNavigateUp:

            ...

            ANSWER

            Answered 2021-Nov-15 at 21:28

            @ianhanniballake was onto the right idea!

            I was foolishly using the LoginFragment as my home destination to awkwardly do some conditional logic. A quick refactor, and with HomeFragment set as the actual home destination, it now works. Thanks, @ianhanniballake.

            Source https://stackoverflow.com/questions/69980239

            QUESTION

            How to achieve a modern Android Navigation implementation
            Asked 2021-Nov-13 at 21:40

            I would like to implement a navigation logic based in the Android Navigation Component in it's more updated version (2.4.0-beta02) but I'm facing some kind of issues (or non expected behaviors) related with the Android lifeycle.

            My main problem is that each time you change a tab, fragments are totally recreated which means that onCreate() method it's called every time the tab is changed. I understand that for performance reasons, fragments call onDestroyView() method each time you left the tab associated with it and then when you came back to that tab onCreateView() method will be called. Actually I don't know if my implementation of the Navigation Component and it's behavior it's correct or not and I would like to know how correctly implement it.

            My actual implementation looks like this:

            Gradle file:

            ...

            ANSWER

            Answered 2021-Nov-13 at 19:05

            The Navigation Component calls onDestroy() method each time a tab it's changed so it's the normal behaviour.

            Source https://stackoverflow.com/questions/69956577

            QUESTION

            How can I implement Paging library 2 Boundary Callback using Coroutines?
            Asked 2021-Sep-01 at 18:01

            I want to implement my custom PagedList.BoundaryCallback with coroutines, liveData and repository pattern using Paging Library 2, but I couldn't find a good example of integration of these libraries.

            Even in Android official samples, they use enqueue and callbacks to perform the API request with paging 2...

            I read this Medium post also but it use a coroutines scope inside the boundary callback and I think that is not a good practice.

            Is there any way to achieve it? Or should I migrate to Paging 3?

            ...

            ANSWER

            Answered 2021-Sep-01 at 15:38

            This solution works for me:

            1. I injected a CoroutinesDispatcherProvider in my Repository:

            Source https://stackoverflow.com/questions/68986397

            QUESTION

            How to UnitTest kotlin-flow version of networkBoundResource?
            Asked 2021-Aug-29 at 10:07

            I want to UnitTest my AuthRepository which is using this "flow-version" of NetworkBoundResource (find the code for that below)

            My current UnitTest is green when writing it like this:

            ...

            ANSWER

            Answered 2021-Aug-29 at 10:07
            Update

            While trying to implement further tests, the number of problems increased. In the end I did a rewrite of networkBoundResource that turned out a lot better than the one circulating on SO. The according question and answer together with code can befound here:

            Kotlin Flow: emitAll is never collected

            Original Answer

            Thanks to @aSemy, I was forced to dig deeper. It turned out to be a series of errors I had. None of them very big, but annoying to find out. Here they are:

            1. Breakpoints with coroutines

            While debugging and setting breakpoints, you should make sure to set the thread suspension to "All". This can be easily done by right-clicking on a breakpoint, choose the radio button "All" and click "Make default". Every breakpoint from then on will have the right setting.

            2. Catch flow exceptions correctly

            At some point I realized that I have the .catch function setup, but that I do not get any exceptions or any helpful hint out of it. This is because I ignored the exception param coming into this function. Changing the code to

            Source https://stackoverflow.com/questions/68874174

            QUESTION

            Confused by example on the Android Developer Website
            Asked 2021-Jun-04 at 20:44

            While working on my android app, I found this example on the android developer site. Specifically, I don't understand the interface UserDataSource ( in /observability) and its corresponding localUserDataSource implementation class (in /observability/persistence). This doesn't look like a repository to me, but it contains an instance to a DAO like a repository would.

            1. Does this approach/pattern have a name?
            2. Are there advantages and disadvantages to doing this over a repository? (It seems like its a lot of redundant code, but I don't know what I'm doing yet)
            3. Should I have a repository in addition to this?

            I think I'm being confused by the different ways of doing things, and seeing a different approach to what I was expecting made me wonder what I really needed (or what is correct, more extensible, etc.). Thank you so much for any light you can shine on this for me.

            ...

            ANSWER

            Answered 2021-Jun-04 at 20:42
            1. Does this approach/pattern have a name?

            The project that you linked is structured using the recommended app architecture described in the official Android docs:

            1. Are there advantages and disadvantages to doing this over a repository? (It seems like its a lot of redundant code, but I don't know what I'm doing yet)
            2. Should I have a repository in addition to this?

            In order to clarify, UserDataSource is not a repository, it is a data source. In that project, UserDataSource is used by a repository: UserRepository. As per official docs:

            You can consider repositories to be mediators between different data sources.

            Therefore the recommended way is to have both a repository and data sources. The advantage is also described in the official docs:

            Even though the repository module looks unnecessary, it serves an important purpose: it abstracts the data sources from the rest of the app. Now, our UserProfileViewModel doesn't know how the data is fetched, so we can provide the view model with data obtained from several different data-fetching implementations.

            Source https://stackoverflow.com/questions/67293794

            QUESTION

            RecyclerView with StaggeredGridLayoutManager in ViewPager, arranges items automatically when going back to fragment
            Asked 2021-Jun-03 at 09:28

            I am using Navigation component in my App, using google Advanced Sample(here). my problem is when going back to a fragment, the scrolling position does not lost but it rearranges items and moves highest visible items so that top of those item align to top of recyclerview. please see this:

            before going to next fragment:

            and after back to fragment:

            this problem is matter because some times clicked item goes down and not seen until scroll down. how to prevent this behavior?

            please consider:

            • this problem exist if using navigation component to change fragment. if start fragment using supportFragmentManager.beginTransaction() or start another activity and then go to this fragment it is OK. but if I navigate to another fragment using navigation component this problem is exist.(maybe because of recreating fragment)

            • also this problem exist if using fragment in ViewPager. i.e recyclerView is in a fragment that handle with ViewPagerAdapter and viewPager is in HomeFragment that opened with Navigation component. if recyclerView is in HomeFragment there is no problem.

            • no problem with LinearLayoutManager. only with StaggeredGridLayoutManager.

            • there is not difference if using ViewPager2 and also FragmentStatePagerAdapter

            • I try to prevent recreate of fragment(by this solution) but not solved.

            UPDATE: you can clone project with this problem from here

            ...

            ANSWER

            Answered 2021-Jan-05 at 13:46

            The Navigation Component behavior is normal when you navigate from one fragment to another. I mean, onDestroyView() method from the previous fragment is executed, so it means that your view is destroyed, but not the fragment. Remembering that fragment has two lifecycles one for the fragment and another one for the view, There was a video about it.

            Also, there were issues registered in issue tracker in order to avoid this behavior in some cases and the GitHub issues:

            The problem is that when you have fragment that is heavy to recreate, is easier to do not destroy it and just add one fragment. So, when you go back it is not recreated. But, for this behavior is not part of navigation component.

            Solutions

            • The easiest solution is to not use navigation component and work with the tradicional way, as you can see this works perfectly in you use case.

            • You can use the traditional way just for this use case, and use the navigation component for other cases.

            • You can inflate this view in an activity. So you are adding un activity

            • But if the previous tree options is not possible. You can try the following:

              • If you are using viewModel, you can use SaveState. Basically, it can save the data from your fragment, it is like a map data structure, so you can save positions from your list or recycler view. When go back to this fragment, get the position from this saveState object and use scrollToPosition method in order to add the real position.
              • Recycler view have methods for restore positions. You can see the uses cases for that, because first you need the data and then add the real position, for more details you can visit this link. This configuration for recycler view is useful also when you lose memory and you need to recreate the recycler view with asynchronous data.

            Finally, if you want to understand more about how fragment works with navigation component, you can see this link

            Source https://stackoverflow.com/questions/65539771

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install architecture-components-samples

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/android/architecture-components-samples.git

          • CLI

            gh repo clone android/architecture-components-samples

          • sshUrl

            git@github.com:android/architecture-components-samples.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link