kandi background
Explore Kits

mosby | Intent library for modern Android apps | Model View Controller library

 by   sockeqwe Java Version: 3.1.1 License: Apache-2.0

 by   sockeqwe Java Version: 3.1.1 License: Apache-2.0

Download this library from

kandi X-RAY | mosby Summary

mosby is a Java library typically used in Architecture, Model View Controller applications. mosby has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub, Maven.
A Model-View-Presenter and Model-View-Intent library for Android apps.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • mosby has a highly active ecosystem.
  • It has 5452 star(s) with 854 fork(s). There are 217 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 24 open issues and 239 have been closed. On average issues are closed in 40 days. There are 4 open pull requests and 0 closed requests.
  • It has a positive sentiment in the developer community.
  • The latest version of mosby is 3.1.1
mosby Support
Best in #Model View Controller
Average in #Model View Controller
mosby Support
Best in #Model View Controller
Average in #Model View Controller

quality kandi Quality

  • mosby has 0 bugs and 0 code smells.
mosby Quality
Best in #Model View Controller
Average in #Model View Controller
mosby Quality
Best in #Model View Controller
Average in #Model View Controller

securitySecurity

  • mosby has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • mosby code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
mosby Security
Best in #Model View Controller
Average in #Model View Controller
mosby Security
Best in #Model View Controller
Average in #Model View Controller

license License

  • mosby 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.
mosby License
Best in #Model View Controller
Average in #Model View Controller
mosby License
Best in #Model View Controller
Average in #Model View Controller

buildReuse

  • mosby releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • It has 22789 lines of code, 2234 functions and 568 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
mosby Reuse
Best in #Model View Controller
Average in #Model View Controller
mosby Reuse
Best in #Model View Controller
Average in #Model View Controller
Top functions reviewed by kandi - BETA

kandi has reviewed mosby and discovered the below as its top functions. This is intended to give you an instant insight into mosby implemented functionality, and help decide if they suit your requirements.

  • Reduce the current state to the previous state .
    • Tries to restore view state after process destruction .
      • Setup the item touch helper .
        • Generates a list of mails .
          • Bind an intent to the selected items .
            • Returns the labels for the mails .
              • Loads countries .
                • Shows the content to the loading view .
                  • Method triggered when a send button is clicked .
                    • Default demo .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      mosby Key Features

                      A Model-View-Presenter / Model-View-Intent library for modern Android apps

                      Dependency

                      copy iconCopydownload iconDownload
                      dependencies {
                      
                        compile 'com.hannesdorfmann.mosby3:mvi:3.1.1' // Model-View-Intent
                        // or
                        compile 'com.hannesdorfmann.mosby3:mvp:3.1.1' // Plain MVP
                        // or
                        compile 'com.hannesdorfmann.mosby3:viewstate:3.1.1' // MVP + ViewState support
                      }
                      

                      License

                      copy iconCopydownload iconDownload
                      Copyright 2015 Hannes Dorfmann
                      
                      Licensed under the Apache License, Version 2.0 (the "License");
                      you may not use this file except in compliance with the License.
                      You may obtain a copy of the License at
                      
                         http://www.apache.org/licenses/LICENSE-2.0
                      
                      Unless required by applicable law or agreed to in writing, software
                      distributed under the License is distributed on an "AS IS" BASIS,
                      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                      See the License for the specific language governing permissions and
                      limitations under the License.
                      

                      OnErrorNotImplementedException using RxJava2 and Retrofit2 Mosby MVI

                      copy iconCopydownload iconDownload
                          val resp0 = getMapResponse()
                          resp0.subscribe { size = it.totalCount }
                      
                      fun getItemsFormResponses(): Observable<List<Item>> {
                        return getMapResponse().map { resp0 ->
                          val size = resp0.totalCount
                      
                          val list = mutableListOf<Observable<List<Item>>>()
                          var accum = 0
                          do {
                            list.add(getMapResponse(accum).map { it.items })
                            accum++
                          } while (list.size*200 < size)
                          return Observable.merge(list)
                        }
                      }
                      
                          val resp0 = getMapResponse()
                          resp0.subscribe { size = it.totalCount }
                      
                      fun getItemsFormResponses(): Observable<List<Item>> {
                        return getMapResponse().map { resp0 ->
                          val size = resp0.totalCount
                      
                          val list = mutableListOf<Observable<List<Item>>>()
                          var accum = 0
                          do {
                            list.add(getMapResponse(accum).map { it.items })
                            accum++
                          } while (list.size*200 < size)
                          return Observable.merge(list)
                        }
                      }
                      
                      getMapResponse()
                                  .subscribe ( 
                                           { size = it.totalCount },
                                           {/* Do something with the error*/}
                                  )
                      

                      How to parse core data's data to struct

                      copy iconCopydownload iconDownload
                      extension StructUser {
                         init(record: User) {
                           // initialize all properties, ie:
                           self.city = record.city
                           // etc.
                         } 
                      }
                      
                      let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "User")
                      let managedObjectUsers = try! context.fetch(fetchRequest) as! [User]
                      let codableUsers = managedObjectUsers.map { StructUser.init(record: $0) }
                      
                      extension StructUser {
                         init(record: User) {
                           // initialize all properties, ie:
                           self.city = record.city
                           // etc.
                         } 
                      }
                      
                      let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "User")
                      let managedObjectUsers = try! context.fetch(fetchRequest) as! [User]
                      let codableUsers = managedObjectUsers.map { StructUser.init(record: $0) }
                      

                      array of pointer game not sure how to move pointers to back

                      copy iconCopydownload iconDownload
                      int count = (boomnum-2)%(length);
                      
                          count=(count+boomnum-1)%(length);
                          length=length-1;
                      
                          length=length-1;
                          count=(count+boomnum-1)%(length);
                      
                      Remy 13 Hadley
                      
                      for (int i = 0; i<30; i++) {
                      
                      while(length > 1) {
                      
                      count=(count+boomnum-1)%(length);
                      
                      int count = (boomnum-2)%(length);
                      
                          count=(count+boomnum-1)%(length);
                          length=length-1;
                      
                          length=length-1;
                          count=(count+boomnum-1)%(length);
                      
                      Remy 13 Hadley
                      
                      for (int i = 0; i<30; i++) {
                      
                      while(length > 1) {
                      
                      count=(count+boomnum-1)%(length);
                      
                      int count = (boomnum-2)%(length);
                      
                          count=(count+boomnum-1)%(length);
                          length=length-1;
                      
                          length=length-1;
                          count=(count+boomnum-1)%(length);
                      
                      Remy 13 Hadley
                      
                      for (int i = 0; i<30; i++) {
                      
                      while(length > 1) {
                      
                      count=(count+boomnum-1)%(length);
                      
                      int count = (boomnum-2)%(length);
                      
                          count=(count+boomnum-1)%(length);
                          length=length-1;
                      
                          length=length-1;
                          count=(count+boomnum-1)%(length);
                      
                      Remy 13 Hadley
                      
                      for (int i = 0; i<30; i++) {
                      
                      while(length > 1) {
                      
                      count=(count+boomnum-1)%(length);
                      
                      int count = (boomnum-2)%(length);
                      
                          count=(count+boomnum-1)%(length);
                          length=length-1;
                      
                          length=length-1;
                          count=(count+boomnum-1)%(length);
                      
                      Remy 13 Hadley
                      
                      for (int i = 0; i<30; i++) {
                      
                      while(length > 1) {
                      
                      count=(count+boomnum-1)%(length);
                      
                      int count = (boomnum-2)%(length);
                      
                          count=(count+boomnum-1)%(length);
                          length=length-1;
                      
                          length=length-1;
                          count=(count+boomnum-1)%(length);
                      
                      Remy 13 Hadley
                      
                      for (int i = 0; i<30; i++) {
                      
                      while(length > 1) {
                      
                      count=(count+boomnum-1)%(length);
                      
                      int count = (boomnum-2)%(length);
                      
                          count=(count+boomnum-1)%(length);
                          length=length-1;
                      
                          length=length-1;
                          count=(count+boomnum-1)%(length);
                      
                      Remy 13 Hadley
                      
                      for (int i = 0; i<30; i++) {
                      
                      while(length > 1) {
                      
                      count=(count+boomnum-1)%(length);
                      

                      Why does print statements sometimes require indents while in some cases indenting print ruins the code?

                      copy iconCopydownload iconDownload
                      for i, name in enumerate(cast):
                          cast[i] = name + " " + str(heights[i])
                      print(cast)
                      
                      for i, name in enumerate(cast):
                          cast[i] = name + " " + str(heights[i])
                          print(cast)
                      
                      for i, name in enumerate(cast):
                          cast[i] = name + " " + str(heights[i])
                      print(cast)
                      
                      for i, name in enumerate(cast):
                          cast[i] = name + " " + str(heights[i])
                          print(cast)
                      

                      Realm , RXJava project does not recognise my intent. Activities have Name_ in manifest trying to understand why

                      copy iconCopydownload iconDownload
                      javaCompileOptions {
                              annotationProcessorOptions {
                                  arguments = [
                                          'androidManifestFile': 'app\\build\\intermediates\\merged_manifests\\debug\\AndroidManifest.xml'
                                  ]
                              }
                          }
                      

                      Iterating through array and shift elements to the end of the array

                      copy iconCopydownload iconDownload
                      int size = 31;
                      int inc = 10;
                      
                      for (int i = 0; i < size; i++)
                      {
                          int t = ((i + 1) * inc) % (size - i);
                          int *tmp = *(names + t);
                          printf("%d\n", t);
                      
                          for (int j = t; j < (size - 1); j++)
                          {
                              *(names + j) = *(names + j + 1);
                          }
                      
                          *(names + size - 1) = tmp;
                      }
                      
                      void element_to_last (int *a, int elem_idx, int sz)
                      {
                          if (elem_idx > sz - 1) {    /* valdate index in range */
                              fprintf (stderr, "error: index %d out of range for size %d\n",
                                      elem_idx, sz);
                              return;
                          }
                      
                          int i = elem_idx,   /* declare, initialize i, tmp */
                              tmp = *(a + i);
                      
                          if (elem_idx == sz - 1)     /* elem_idx is last index */
                              return;     /* no-swap */
                      
                          for (; i < sz - 1; i++)     /* loop shifting elements down */
                              *(a + i) = *(a + i + 1);
                      
                          *(a + i) = tmp;     /* set last to tmp */
                      }
                      
                      #include <stdio.h>
                      
                      #ifndef WRAP
                       #define WRAP 10
                      #endif
                      
                      void element_to_last (int *a, int elem_idx, int sz)
                      {
                          if (elem_idx > sz - 1) {    /* valdate index in range */
                              fprintf (stderr, "error: index %d out of range for size %d\n",
                                      elem_idx, sz);
                              return;
                          }
                      
                          int i = elem_idx,   /* declare, initialize i, tmp */
                              tmp = *(a + i);
                      
                          if (elem_idx == sz - 1) {   /* elem_idx is last index */
                      #ifdef DEBUG
                              fprintf (stderr, " index %d (%d) is last index %d - no swap.\n",
                                      elem_idx, tmp, sz - 1);
                      #endif
                              return;     /* no-swap */
                          }
                      
                      #ifdef DEBUG
                          printf (" index %d (%d) to end %d\n", elem_idx, tmp, sz - 1);
                      #endif
                      
                          for (; i < sz - 1; i++)     /* loop shifting elements down */
                              *(a + i) = *(a + i + 1);
                      
                          *(a + i) = tmp;     /* set last to tmp */
                      }
                      
                      void prn_array (int *a, int sz, int wrap)
                      {
                          for (int i = 0; i < sz; i++) {
                              if (i && i % wrap == 0)
                                  putchar ('\n');
                              printf (" %2d", *(a + i));
                          }
                          putchar ('\n');
                      }
                      
                      int main (void) {
                      
                          int a[] = {0,1,2,3,4,5,6,7,8,9},    /* original array order */
                              sz = sizeof a/sizeof *a,        /* nelem in original */
                              n = sz,                         /* n tracks remaining size */
                              loser[] = {2,0,7,3,2,3,2,1,1},  /* order of losing indexes */
                              lsz = sizeof loser/sizeof *loser;   /* nelem in loser array */
                      
                          puts ("before:");
                          prn_array (a, sz, WRAP);
                      
                          puts ("\nelimination\n(remove indexes 2,0,7,3,2,3,2,1,1):");
                          for (int i = 0; i < lsz; i++) {
                              element_to_last (a, loser[i], n > 0 ? n-- : n);
                              prn_array (a, sz, WRAP);
                          }
                      
                          puts ("\nafter:");
                          prn_array (a, sz, WRAP);
                      }
                      
                      $ ./bin/array_rotate
                      before:
                        0  1  2  3  4  5  6  7  8  9
                      
                      elimination
                      (remove indexes 2,0,7,3,2,3,2,1,1):
                        0  1  3  4  5  6  7  8  9  2
                        1  3  4  5  6  7  8  9  0  2
                        1  3  4  5  6  7  8  9  0  2
                        1  3  4  6  7  8  5  9  0  2
                        1  3  6  7  8  4  5  9  0  2
                        1  3  6  8  7  4  5  9  0  2
                        1  3  8  6  7  4  5  9  0  2
                        1  8  3  6  7  4  5  9  0  2
                        1  8  3  6  7  4  5  9  0  2
                      
                      after:
                        1  8  3  6  7  4  5  9  0  2
                      
                      $ ./bin/array_rotate
                      before:
                        0  1  2  3  4  5  6  7  8  9
                      
                      elimination
                      (remove indexes 2,0,7,3,2,3,2,1,1):
                       index 2 (2) to end 9
                        0  1  3  4  5  6  7  8  9  2
                       index 0 (0) to end 8
                        1  3  4  5  6  7  8  9  0  2
                       index 7 (9) is last index 7 - no swap.
                        1  3  4  5  6  7  8  9  0  2
                       index 3 (5) to end 6
                        1  3  4  6  7  8  5  9  0  2
                       index 2 (4) to end 5
                        1  3  6  7  8  4  5  9  0  2
                       index 3 (7) to end 4
                        1  3  6  8  7  4  5  9  0  2
                       index 2 (6) to end 3
                        1  3  8  6  7  4  5  9  0  2
                       index 1 (3) to end 2
                        1  8  3  6  7  4  5  9  0  2
                       index 1 (8) is last index 1 - no swap.
                        1  8  3  6  7  4  5  9  0  2
                      
                      after:
                        1  8  3  6  7  4  5  9  0  2
                      
                      void element_to_last (int *a, int elem_idx, int sz)
                      {
                          if (elem_idx > sz - 1) {    /* valdate index in range */
                              fprintf (stderr, "error: index %d out of range for size %d\n",
                                      elem_idx, sz);
                              return;
                          }
                      
                          int i = elem_idx,   /* declare, initialize i, tmp */
                              tmp = *(a + i);
                      
                          if (elem_idx == sz - 1)     /* elem_idx is last index */
                              return;     /* no-swap */
                      
                          for (; i < sz - 1; i++)     /* loop shifting elements down */
                              *(a + i) = *(a + i + 1);
                      
                          *(a + i) = tmp;     /* set last to tmp */
                      }
                      
                      #include <stdio.h>
                      
                      #ifndef WRAP
                       #define WRAP 10
                      #endif
                      
                      void element_to_last (int *a, int elem_idx, int sz)
                      {
                          if (elem_idx > sz - 1) {    /* valdate index in range */
                              fprintf (stderr, "error: index %d out of range for size %d\n",
                                      elem_idx, sz);
                              return;
                          }
                      
                          int i = elem_idx,   /* declare, initialize i, tmp */
                              tmp = *(a + i);
                      
                          if (elem_idx == sz - 1) {   /* elem_idx is last index */
                      #ifdef DEBUG
                              fprintf (stderr, " index %d (%d) is last index %d - no swap.\n",
                                      elem_idx, tmp, sz - 1);
                      #endif
                              return;     /* no-swap */
                          }
                      
                      #ifdef DEBUG
                          printf (" index %d (%d) to end %d\n", elem_idx, tmp, sz - 1);
                      #endif
                      
                          for (; i < sz - 1; i++)     /* loop shifting elements down */
                              *(a + i) = *(a + i + 1);
                      
                          *(a + i) = tmp;     /* set last to tmp */
                      }
                      
                      void prn_array (int *a, int sz, int wrap)
                      {
                          for (int i = 0; i < sz; i++) {
                              if (i && i % wrap == 0)
                                  putchar ('\n');
                              printf (" %2d", *(a + i));
                          }
                          putchar ('\n');
                      }
                      
                      int main (void) {
                      
                          int a[] = {0,1,2,3,4,5,6,7,8,9},    /* original array order */
                              sz = sizeof a/sizeof *a,        /* nelem in original */
                              n = sz,                         /* n tracks remaining size */
                              loser[] = {2,0,7,3,2,3,2,1,1},  /* order of losing indexes */
                              lsz = sizeof loser/sizeof *loser;   /* nelem in loser array */
                      
                          puts ("before:");
                          prn_array (a, sz, WRAP);
                      
                          puts ("\nelimination\n(remove indexes 2,0,7,3,2,3,2,1,1):");
                          for (int i = 0; i < lsz; i++) {
                              element_to_last (a, loser[i], n > 0 ? n-- : n);
                              prn_array (a, sz, WRAP);
                          }
                      
                          puts ("\nafter:");
                          prn_array (a, sz, WRAP);
                      }
                      
                      $ ./bin/array_rotate
                      before:
                        0  1  2  3  4  5  6  7  8  9
                      
                      elimination
                      (remove indexes 2,0,7,3,2,3,2,1,1):
                        0  1  3  4  5  6  7  8  9  2
                        1  3  4  5  6  7  8  9  0  2
                        1  3  4  5  6  7  8  9  0  2
                        1  3  4  6  7  8  5  9  0  2
                        1  3  6  7  8  4  5  9  0  2
                        1  3  6  8  7  4  5  9  0  2
                        1  3  8  6  7  4  5  9  0  2
                        1  8  3  6  7  4  5  9  0  2
                        1  8  3  6  7  4  5  9  0  2
                      
                      after:
                        1  8  3  6  7  4  5  9  0  2
                      
                      $ ./bin/array_rotate
                      before:
                        0  1  2  3  4  5  6  7  8  9
                      
                      elimination
                      (remove indexes 2,0,7,3,2,3,2,1,1):
                       index 2 (2) to end 9
                        0  1  3  4  5  6  7  8  9  2
                       index 0 (0) to end 8
                        1  3  4  5  6  7  8  9  0  2
                       index 7 (9) is last index 7 - no swap.
                        1  3  4  5  6  7  8  9  0  2
                       index 3 (5) to end 6
                        1  3  4  6  7  8  5  9  0  2
                       index 2 (4) to end 5
                        1  3  6  7  8  4  5  9  0  2
                       index 3 (7) to end 4
                        1  3  6  8  7  4  5  9  0  2
                       index 2 (6) to end 3
                        1  3  8  6  7  4  5  9  0  2
                       index 1 (3) to end 2
                        1  8  3  6  7  4  5  9  0  2
                       index 1 (8) is last index 1 - no swap.
                        1  8  3  6  7  4  5  9  0  2
                      
                      after:
                        1  8  3  6  7  4  5  9  0  2
                      
                      void element_to_last (int *a, int elem_idx, int sz)
                      {
                          if (elem_idx > sz - 1) {    /* valdate index in range */
                              fprintf (stderr, "error: index %d out of range for size %d\n",
                                      elem_idx, sz);
                              return;
                          }
                      
                          int i = elem_idx,   /* declare, initialize i, tmp */
                              tmp = *(a + i);
                      
                          if (elem_idx == sz - 1)     /* elem_idx is last index */
                              return;     /* no-swap */
                      
                          for (; i < sz - 1; i++)     /* loop shifting elements down */
                              *(a + i) = *(a + i + 1);
                      
                          *(a + i) = tmp;     /* set last to tmp */
                      }
                      
                      #include <stdio.h>
                      
                      #ifndef WRAP
                       #define WRAP 10
                      #endif
                      
                      void element_to_last (int *a, int elem_idx, int sz)
                      {
                          if (elem_idx > sz - 1) {    /* valdate index in range */
                              fprintf (stderr, "error: index %d out of range for size %d\n",
                                      elem_idx, sz);
                              return;
                          }
                      
                          int i = elem_idx,   /* declare, initialize i, tmp */
                              tmp = *(a + i);
                      
                          if (elem_idx == sz - 1) {   /* elem_idx is last index */
                      #ifdef DEBUG
                              fprintf (stderr, " index %d (%d) is last index %d - no swap.\n",
                                      elem_idx, tmp, sz - 1);
                      #endif
                              return;     /* no-swap */
                          }
                      
                      #ifdef DEBUG
                          printf (" index %d (%d) to end %d\n", elem_idx, tmp, sz - 1);
                      #endif
                      
                          for (; i < sz - 1; i++)     /* loop shifting elements down */
                              *(a + i) = *(a + i + 1);
                      
                          *(a + i) = tmp;     /* set last to tmp */
                      }
                      
                      void prn_array (int *a, int sz, int wrap)
                      {
                          for (int i = 0; i < sz; i++) {
                              if (i && i % wrap == 0)
                                  putchar ('\n');
                              printf (" %2d", *(a + i));
                          }
                          putchar ('\n');
                      }
                      
                      int main (void) {
                      
                          int a[] = {0,1,2,3,4,5,6,7,8,9},    /* original array order */
                              sz = sizeof a/sizeof *a,        /* nelem in original */
                              n = sz,                         /* n tracks remaining size */
                              loser[] = {2,0,7,3,2,3,2,1,1},  /* order of losing indexes */
                              lsz = sizeof loser/sizeof *loser;   /* nelem in loser array */
                      
                          puts ("before:");
                          prn_array (a, sz, WRAP);
                      
                          puts ("\nelimination\n(remove indexes 2,0,7,3,2,3,2,1,1):");
                          for (int i = 0; i < lsz; i++) {
                              element_to_last (a, loser[i], n > 0 ? n-- : n);
                              prn_array (a, sz, WRAP);
                          }
                      
                          puts ("\nafter:");
                          prn_array (a, sz, WRAP);
                      }
                      
                      $ ./bin/array_rotate
                      before:
                        0  1  2  3  4  5  6  7  8  9
                      
                      elimination
                      (remove indexes 2,0,7,3,2,3,2,1,1):
                        0  1  3  4  5  6  7  8  9  2
                        1  3  4  5  6  7  8  9  0  2
                        1  3  4  5  6  7  8  9  0  2
                        1  3  4  6  7  8  5  9  0  2
                        1  3  6  7  8  4  5  9  0  2
                        1  3  6  8  7  4  5  9  0  2
                        1  3  8  6  7  4  5  9  0  2
                        1  8  3  6  7  4  5  9  0  2
                        1  8  3  6  7  4  5  9  0  2
                      
                      after:
                        1  8  3  6  7  4  5  9  0  2
                      
                      $ ./bin/array_rotate
                      before:
                        0  1  2  3  4  5  6  7  8  9
                      
                      elimination
                      (remove indexes 2,0,7,3,2,3,2,1,1):
                       index 2 (2) to end 9
                        0  1  3  4  5  6  7  8  9  2
                       index 0 (0) to end 8
                        1  3  4  5  6  7  8  9  0  2
                       index 7 (9) is last index 7 - no swap.
                        1  3  4  5  6  7  8  9  0  2
                       index 3 (5) to end 6
                        1  3  4  6  7  8  5  9  0  2
                       index 2 (4) to end 5
                        1  3  6  7  8  4  5  9  0  2
                       index 3 (7) to end 4
                        1  3  6  8  7  4  5  9  0  2
                       index 2 (6) to end 3
                        1  3  8  6  7  4  5  9  0  2
                       index 1 (3) to end 2
                        1  8  3  6  7  4  5  9  0  2
                       index 1 (8) is last index 1 - no swap.
                        1  8  3  6  7  4  5  9  0  2
                      
                      after:
                        1  8  3  6  7  4  5  9  0  2
                      
                      void element_to_last (int *a, int elem_idx, int sz)
                      {
                          if (elem_idx > sz - 1) {    /* valdate index in range */
                              fprintf (stderr, "error: index %d out of range for size %d\n",
                                      elem_idx, sz);
                              return;
                          }
                      
                          int i = elem_idx,   /* declare, initialize i, tmp */
                              tmp = *(a + i);
                      
                          if (elem_idx == sz - 1)     /* elem_idx is last index */
                              return;     /* no-swap */
                      
                          for (; i < sz - 1; i++)     /* loop shifting elements down */
                              *(a + i) = *(a + i + 1);
                      
                          *(a + i) = tmp;     /* set last to tmp */
                      }
                      
                      #include <stdio.h>
                      
                      #ifndef WRAP
                       #define WRAP 10
                      #endif
                      
                      void element_to_last (int *a, int elem_idx, int sz)
                      {
                          if (elem_idx > sz - 1) {    /* valdate index in range */
                              fprintf (stderr, "error: index %d out of range for size %d\n",
                                      elem_idx, sz);
                              return;
                          }
                      
                          int i = elem_idx,   /* declare, initialize i, tmp */
                              tmp = *(a + i);
                      
                          if (elem_idx == sz - 1) {   /* elem_idx is last index */
                      #ifdef DEBUG
                              fprintf (stderr, " index %d (%d) is last index %d - no swap.\n",
                                      elem_idx, tmp, sz - 1);
                      #endif
                              return;     /* no-swap */
                          }
                      
                      #ifdef DEBUG
                          printf (" index %d (%d) to end %d\n", elem_idx, tmp, sz - 1);
                      #endif
                      
                          for (; i < sz - 1; i++)     /* loop shifting elements down */
                              *(a + i) = *(a + i + 1);
                      
                          *(a + i) = tmp;     /* set last to tmp */
                      }
                      
                      void prn_array (int *a, int sz, int wrap)
                      {
                          for (int i = 0; i < sz; i++) {
                              if (i && i % wrap == 0)
                                  putchar ('\n');
                              printf (" %2d", *(a + i));
                          }
                          putchar ('\n');
                      }
                      
                      int main (void) {
                      
                          int a[] = {0,1,2,3,4,5,6,7,8,9},    /* original array order */
                              sz = sizeof a/sizeof *a,        /* nelem in original */
                              n = sz,                         /* n tracks remaining size */
                              loser[] = {2,0,7,3,2,3,2,1,1},  /* order of losing indexes */
                              lsz = sizeof loser/sizeof *loser;   /* nelem in loser array */
                      
                          puts ("before:");
                          prn_array (a, sz, WRAP);
                      
                          puts ("\nelimination\n(remove indexes 2,0,7,3,2,3,2,1,1):");
                          for (int i = 0; i < lsz; i++) {
                              element_to_last (a, loser[i], n > 0 ? n-- : n);
                              prn_array (a, sz, WRAP);
                          }
                      
                          puts ("\nafter:");
                          prn_array (a, sz, WRAP);
                      }
                      
                      $ ./bin/array_rotate
                      before:
                        0  1  2  3  4  5  6  7  8  9
                      
                      elimination
                      (remove indexes 2,0,7,3,2,3,2,1,1):
                        0  1  3  4  5  6  7  8  9  2
                        1  3  4  5  6  7  8  9  0  2
                        1  3  4  5  6  7  8  9  0  2
                        1  3  4  6  7  8  5  9  0  2
                        1  3  6  7  8  4  5  9  0  2
                        1  3  6  8  7  4  5  9  0  2
                        1  3  8  6  7  4  5  9  0  2
                        1  8  3  6  7  4  5  9  0  2
                        1  8  3  6  7  4  5  9  0  2
                      
                      after:
                        1  8  3  6  7  4  5  9  0  2
                      
                      $ ./bin/array_rotate
                      before:
                        0  1  2  3  4  5  6  7  8  9
                      
                      elimination
                      (remove indexes 2,0,7,3,2,3,2,1,1):
                       index 2 (2) to end 9
                        0  1  3  4  5  6  7  8  9  2
                       index 0 (0) to end 8
                        1  3  4  5  6  7  8  9  0  2
                       index 7 (9) is last index 7 - no swap.
                        1  3  4  5  6  7  8  9  0  2
                       index 3 (5) to end 6
                        1  3  4  6  7  8  5  9  0  2
                       index 2 (4) to end 5
                        1  3  6  7  8  4  5  9  0  2
                       index 3 (7) to end 4
                        1  3  6  8  7  4  5  9  0  2
                       index 2 (6) to end 3
                        1  3  8  6  7  4  5  9  0  2
                       index 1 (3) to end 2
                        1  8  3  6  7  4  5  9  0  2
                       index 1 (8) is last index 1 - no swap.
                        1  8  3  6  7  4  5  9  0  2
                      
                      after:
                        1  8  3  6  7  4  5  9  0  2
                      

                      how to use Mockito when in kotin to mock method call and return mock value?

                      copy iconCopydownload iconDownload
                      public abstract class BaseUseCase {
                      
                      protected abstract Observable buildUseCaseObservable();
                      
                      @SuppressWarnings("unchecked")
                      public Observable retrieveUseCaseObservable(){
                                  return  this.buildUseCaseObservable()
                                  .subscribeOn(Schedulers.io())
                                  .observeOn(AndroidSchedulers.mainThread());
                      }
                      
                          import org.junit.Before
                      import org.junit.Test
                      import org.junit.runner.RunWith
                      import org.mockito.ArgumentMatchers.any
                      import org.mockito.BDDMockito
                      import org.mockito.BDDMockito.given
                      import org.mockito.Mock
                      import org.mockito.MockitoAnnotations
                      import org.mockito.runners.MockitoJUnitRunner
                      
                      
                      @RunWith(MockitoJUnitRunner::class)
                      class WeatherDetailsPresenterTest {
                      
                          @Mock
                          lateinit var usecase: GetCurrentWithForcastedWeatherUsecase
                      
                          @Mock
                          lateinit var view: WeatherDetailsView
                      
                          lateinit var presenter: WeatherDetailsPresenter
                      
                          @Before
                          fun setUp() {
                              MockitoAnnotations.initMocks(this)
                              RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
                              presenter = WeatherDetailsPresenter(usecase)
                              presenter.attachView(view)
                      
                          }
                      
                          @Test
                          fun testCurrentWeatherScreenAppears() {
                      
                              //arrange
                              given(usecase.retrieveUseCaseObservable()).willReturn(Observable.just(Pair(CurrentWeatherModel(), ForecastedWeatherModel())))
                      
                              //act
                              presenter.presentCurrentAndForcastedWeather("canada")
                      
                              //assert
                              BDDMockito.verify(view, BDDMockito.times(1)).showCurrentWeather(any(CurrentWeatherModel::class.java)?:CurrentWeatherModel())
                          }
                      }
                      
                      fun presentCurrentAndForcastedWeather(country: String?) {
                          getCurrentWeatherWithForecastUsecase.takeUnless { country?.isBlank() == true }?.apply {
                              this.countyName = country
                              retrieveUseCaseObservable().subscribe(object : DefaultSubscriber<Pair<CurrentWeatherModel, ForecastedWeatherModel>>() {
                                  override fun onSubscribe(d: Disposable) {
                                      super.onSubscribe(d)
                                      showLoading(true)
                                  }
                      
                                  override fun onNext(t: Pair<CurrentWeatherModel, ForecastedWeatherModel>) {
                                      super.onNext(t)
                                      view?.showCurrentWeather(t.first)
                                      view?.showForcastWeather(t.second)
                                  }
                      
                                  override fun onError(e: Throwable) {
                                      super.onError(e)
                                      showError { this@WeatherDetailsPresenter.presentCurrentAndForcastedWeather(country) }
                                  }
                      
                                  override fun onComplete() {
                                      super.onComplete()
                                      showLoading(false)
                                  }
                              })
                          } ?: run { view?.showCountryUnavailable() }
                      }
                      
                      public abstract class BaseUseCase {
                      
                      protected abstract Observable buildUseCaseObservable();
                      
                      @SuppressWarnings("unchecked")
                      public Observable retrieveUseCaseObservable(){
                                  return  this.buildUseCaseObservable()
                                  .subscribeOn(Schedulers.io())
                                  .observeOn(AndroidSchedulers.mainThread());
                      }
                      
                          import org.junit.Before
                      import org.junit.Test
                      import org.junit.runner.RunWith
                      import org.mockito.ArgumentMatchers.any
                      import org.mockito.BDDMockito
                      import org.mockito.BDDMockito.given
                      import org.mockito.Mock
                      import org.mockito.MockitoAnnotations
                      import org.mockito.runners.MockitoJUnitRunner
                      
                      
                      @RunWith(MockitoJUnitRunner::class)
                      class WeatherDetailsPresenterTest {
                      
                          @Mock
                          lateinit var usecase: GetCurrentWithForcastedWeatherUsecase
                      
                          @Mock
                          lateinit var view: WeatherDetailsView
                      
                          lateinit var presenter: WeatherDetailsPresenter
                      
                          @Before
                          fun setUp() {
                              MockitoAnnotations.initMocks(this)
                              RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
                              presenter = WeatherDetailsPresenter(usecase)
                              presenter.attachView(view)
                      
                          }
                      
                          @Test
                          fun testCurrentWeatherScreenAppears() {
                      
                              //arrange
                              given(usecase.retrieveUseCaseObservable()).willReturn(Observable.just(Pair(CurrentWeatherModel(), ForecastedWeatherModel())))
                      
                              //act
                              presenter.presentCurrentAndForcastedWeather("canada")
                      
                              //assert
                              BDDMockito.verify(view, BDDMockito.times(1)).showCurrentWeather(any(CurrentWeatherModel::class.java)?:CurrentWeatherModel())
                          }
                      }
                      
                      fun presentCurrentAndForcastedWeather(country: String?) {
                          getCurrentWeatherWithForecastUsecase.takeUnless { country?.isBlank() == true }?.apply {
                              this.countyName = country
                              retrieveUseCaseObservable().subscribe(object : DefaultSubscriber<Pair<CurrentWeatherModel, ForecastedWeatherModel>>() {
                                  override fun onSubscribe(d: Disposable) {
                                      super.onSubscribe(d)
                                      showLoading(true)
                                  }
                      
                                  override fun onNext(t: Pair<CurrentWeatherModel, ForecastedWeatherModel>) {
                                      super.onNext(t)
                                      view?.showCurrentWeather(t.first)
                                      view?.showForcastWeather(t.second)
                                  }
                      
                                  override fun onError(e: Throwable) {
                                      super.onError(e)
                                      showError { this@WeatherDetailsPresenter.presentCurrentAndForcastedWeather(country) }
                                  }
                      
                                  override fun onComplete() {
                                      super.onComplete()
                                      showLoading(false)
                                  }
                              })
                          } ?: run { view?.showCountryUnavailable() }
                      }
                      
                      public abstract class BaseUseCase {
                      
                      protected abstract Observable buildUseCaseObservable();
                      
                      @SuppressWarnings("unchecked")
                      public Observable retrieveUseCaseObservable(){
                                  return  this.buildUseCaseObservable()
                                  .subscribeOn(Schedulers.io())
                                  .observeOn(AndroidSchedulers.mainThread());
                      }
                      
                          import org.junit.Before
                      import org.junit.Test
                      import org.junit.runner.RunWith
                      import org.mockito.ArgumentMatchers.any
                      import org.mockito.BDDMockito
                      import org.mockito.BDDMockito.given
                      import org.mockito.Mock
                      import org.mockito.MockitoAnnotations
                      import org.mockito.runners.MockitoJUnitRunner
                      
                      
                      @RunWith(MockitoJUnitRunner::class)
                      class WeatherDetailsPresenterTest {
                      
                          @Mock
                          lateinit var usecase: GetCurrentWithForcastedWeatherUsecase
                      
                          @Mock
                          lateinit var view: WeatherDetailsView
                      
                          lateinit var presenter: WeatherDetailsPresenter
                      
                          @Before
                          fun setUp() {
                              MockitoAnnotations.initMocks(this)
                              RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
                              presenter = WeatherDetailsPresenter(usecase)
                              presenter.attachView(view)
                      
                          }
                      
                          @Test
                          fun testCurrentWeatherScreenAppears() {
                      
                              //arrange
                              given(usecase.retrieveUseCaseObservable()).willReturn(Observable.just(Pair(CurrentWeatherModel(), ForecastedWeatherModel())))
                      
                              //act
                              presenter.presentCurrentAndForcastedWeather("canada")
                      
                              //assert
                              BDDMockito.verify(view, BDDMockito.times(1)).showCurrentWeather(any(CurrentWeatherModel::class.java)?:CurrentWeatherModel())
                          }
                      }
                      
                      fun presentCurrentAndForcastedWeather(country: String?) {
                          getCurrentWeatherWithForecastUsecase.takeUnless { country?.isBlank() == true }?.apply {
                              this.countyName = country
                              retrieveUseCaseObservable().subscribe(object : DefaultSubscriber<Pair<CurrentWeatherModel, ForecastedWeatherModel>>() {
                                  override fun onSubscribe(d: Disposable) {
                                      super.onSubscribe(d)
                                      showLoading(true)
                                  }
                      
                                  override fun onNext(t: Pair<CurrentWeatherModel, ForecastedWeatherModel>) {
                                      super.onNext(t)
                                      view?.showCurrentWeather(t.first)
                                      view?.showForcastWeather(t.second)
                                  }
                      
                                  override fun onError(e: Throwable) {
                                      super.onError(e)
                                      showError { this@WeatherDetailsPresenter.presentCurrentAndForcastedWeather(country) }
                                  }
                      
                                  override fun onComplete() {
                                      super.onComplete()
                                      showLoading(false)
                                  }
                              })
                          } ?: run { view?.showCountryUnavailable() }
                      }
                      

                      Dagger: A binding with matching key exists in component

                      copy iconCopydownload iconDownload
                      @ContributesAndroidInjector
                      fun downloadsFragment(): DownloadsFragment
                      
                      @Component(modules = [AndroidSupportInjectionModule::class, /* ... */])
                      interface AppComponent { /* ... */ }
                      
                      @ContributesAndroidInjector
                      fun downloadsFragment(): DownloadsFragment
                      
                      @Component(modules = [AndroidSupportInjectionModule::class, /* ... */])
                      interface AppComponent { /* ... */ }
                      

                      Single time events in MVI architecture

                      copy iconCopydownload iconDownload
                      enum ViewState {
                         // The user can type typing text
                         IDLING,
                      
                         // The app is saving the note
                         PROCESSING,
                      
                         // After having saved (PROCESSING) the note, CLEARED means, show a new empty note  
                         CLEARED
                      }
                      
                      Observable.just( ViewState(error = true, ...), new ViewState( error = false, ... )
                      
                      enum ViewState {
                         // The user can type typing text
                         IDLING,
                      
                         // The app is saving the note
                         PROCESSING,
                      
                         // After having saved (PROCESSING) the note, CLEARED means, show a new empty note  
                         CLEARED
                      }
                      
                      Observable.just( ViewState(error = true, ...), new ViewState( error = false, ... )
                      

                      TOAD invalid identifier error ORA-00904

                      copy iconCopydownload iconDownload
                      `EMP_NAME (OYKUN_TEMPORAL_VARCHAR('1/1/2007','12/31/2017','Ted Mosby')),
                      
                      OYKUN_NAME_TYPE(OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Ted Mosby')),
                      
                      INSERT INTO OYKUN_EMPLOYEE (EMPNO,EMP_NAME,EMP_ADDRESS,EMP_BIRTH_DATE,EMP_DEPARTMENT,EMP_MANAGER,EMP_SALARY) VALUES 
                      (100,
                      OYKUN_NAME_TYPE(OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Ted Mosby')),
                      OYKUN_ADDRESS_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Manhattan,New York')),
                      '20/5/1982',
                      OYKUN_DEPARTMENT_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Architect')),
                      OYKUN_MANAGER_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Walter White')),
                      OYKUN_SALARY_TYPE (OYKUN_TEMPORAL_NUMBER('1/1/2007','31/12/2017',2500))
                      );
                      
                      `EMP_NAME (OYKUN_TEMPORAL_VARCHAR('1/1/2007','12/31/2017','Ted Mosby')),
                      
                      OYKUN_NAME_TYPE(OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Ted Mosby')),
                      
                      INSERT INTO OYKUN_EMPLOYEE (EMPNO,EMP_NAME,EMP_ADDRESS,EMP_BIRTH_DATE,EMP_DEPARTMENT,EMP_MANAGER,EMP_SALARY) VALUES 
                      (100,
                      OYKUN_NAME_TYPE(OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Ted Mosby')),
                      OYKUN_ADDRESS_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Manhattan,New York')),
                      '20/5/1982',
                      OYKUN_DEPARTMENT_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Architect')),
                      OYKUN_MANAGER_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Walter White')),
                      OYKUN_SALARY_TYPE (OYKUN_TEMPORAL_NUMBER('1/1/2007','31/12/2017',2500))
                      );
                      
                      `EMP_NAME (OYKUN_TEMPORAL_VARCHAR('1/1/2007','12/31/2017','Ted Mosby')),
                      
                      OYKUN_NAME_TYPE(OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Ted Mosby')),
                      
                      INSERT INTO OYKUN_EMPLOYEE (EMPNO,EMP_NAME,EMP_ADDRESS,EMP_BIRTH_DATE,EMP_DEPARTMENT,EMP_MANAGER,EMP_SALARY) VALUES 
                      (100,
                      OYKUN_NAME_TYPE(OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Ted Mosby')),
                      OYKUN_ADDRESS_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Manhattan,New York')),
                      '20/5/1982',
                      OYKUN_DEPARTMENT_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Architect')),
                      OYKUN_MANAGER_TYPE (OYKUN_TEMPORAL_VARCHAR('1/1/2007','31/12/2017','Walter White')),
                      OYKUN_SALARY_TYPE (OYKUN_TEMPORAL_NUMBER('1/1/2007','31/12/2017',2500))
                      );
                      

                      Community Discussions

                      Trending Discussions on mosby
                      • OnErrorNotImplementedException using RxJava2 and Retrofit2 Mosby MVI
                      • How to parse core data's data to struct
                      • array of pointer game not sure how to move pointers to back
                      • Why does print statements sometimes require indents while in some cases indenting print ruins the code?
                      • Realm , RXJava project does not recognise my intent. Activities have Name_ in manifest trying to understand why
                      • Iterating through array and shift elements to the end of the array
                      • java.lang.NoSuchMethodError: com.squareup.kotlinpoet.PropertySpec$Companion.varBuilder
                      • how to use Mockito when in kotin to mock method call and return mock value?
                      • MVP pattern Android duplicated methods in presenters
                      • Failure to build a commit in gitlab(gradle)
                      Trending Discussions on mosby

                      QUESTION

                      OnErrorNotImplementedException using RxJava2 and Retrofit2 Mosby MVI

                      Asked 2019-Sep-26 at 13:41

                      I'm getting a OnErrorNotImplementedException thrown and the app crashes, despite handling the error downstream(?).

                      Exception

                      E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-1
                      Process: pl.netlandgroup.smartsab, PID: 9920
                      io.reactivex.exceptions.OnErrorNotImplementedException: HTTP 401 Unauthorized
                          at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
                          at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
                          at io.reactivex.internal.observers.LambdaObserver.onError(LambdaObserver.java:74)
                          at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onError(ObservableDoOnEach.java:119)
                          at io.reactivex.internal.operators.observable.ObservableDoOnEach$DoOnEachObserver.onError(ObservableDoOnEach.java:119)
                          at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeOnObserver.onError(ObservableSubscribeOn.java:63)
                          at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:56)
                          at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:37)
                          at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:43)
                          at io.reactivex.Observable.subscribe(Observable.java:10838)
                          at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
                          at io.reactivex.Observable.subscribe(Observable.java:10838)
                          at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
                          at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
                          at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
                          at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
                          at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                          at java.lang.Thread.run(Thread.java:761)
                       Caused by: retrofit2.adapter.rxjava2.HttpException: HTTP 401 Unauthorized
                          at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:54)
                          at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:37) 
                          at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:43) 
                          at io.reactivex.Observable.subscribe(Observable.java:10838) 
                          at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34) 
                          at io.reactivex.Observable.subscribe(Observable.java:10838) 
                          at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96) 
                          at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452) 
                          at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61) 
                          at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52) 
                          at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                          at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272) 
                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                          at java.lang.Thread.run(Thread.java:761) 
                      

                      Retrofit Repository:

                      class RetrofitRepository (retrofit: Retrofit) {
                      
                          val apiService: ApiService = retrofit.create(ApiService::class.java)
                          var size: Int = 0
                      
                          fun getMapResponse(pageIndex: Int = 0): Observable<MapResponse> {
                              return apiService.getMapResponse(pageIndex = pageIndex)
                                      .doOnError { Log.d("error", it.message) }
                                      .doOnNext { Log.d("currThread", Thread.currentThread().name) }
                      
                          }
                      
                          fun getItemsFormResponses(): Observable<List<Item>> {
                              val list = mutableListOf<Observable<List<Item>>>()
                              val resp0 = getMapResponse()
                              resp0.subscribe { size = it.totalCount }
                              var accum = 0
                              do {
                                  list.add(getMapResponse(accum).map { it.items })
                                  accum++
                              } while (list.size*200 < size)
                              return Observable.merge(list)
                          }
                      }
                      

                      This results are observed by Interactor:

                      class MapInteractor @Inject constructor(private val repository: RetrofitRepository) {
                      
                          fun getMapItems(): Observable<MapViewState> {
                              return repository.getItemsFormResponses()
                                      .map {
                                          if(it.isEmpty()) {
                                              return@map MapViewState.EmptyResult()
                                          } else {
                                              val mapItems = it.map { it.toMapItem() }
                                              return@map MapViewState.MapResult(mapItems)
                                          }
                                      }
                                      .doOnNext { Log.d("currThread", Thread.currentThread().name) }
                                      .startWith(MapViewState.Loading())
                                      .onErrorReturn { MapViewState.Error(it) }
                          }
                      }
                      

                      The onErrorReturn { MapViewState.Error(it) } emits correctly (right before the app crash I can see the correct thing rendered on screen). How can I avoid this exception while still maintaining the MVI architecture?

                      EDIT

                      The answer provided by dimsuz was the correct solution, although to achieve the merging and returning one Observable with all items it had to be modified to this:

                      fun getMapItems(): Observable<List<Item>> {
                          return getMapResponse().map {
                              val size = it.totalCount
                              val list = mutableListOf<Observable<List<Item>>>()
                              var accum = 0
                              do {
                                  list.add(getMapResponse(accum++).map { it.items })
                              } while (list.size*200 < size)
                              return@map list.zip { it.flatten() }
                          }.mergeAll()
                      }
                      

                      ANSWER

                      Answered 2017-Jul-05 at 16:42

                      I believe the error is thrown in getItemsFromResponse() along the lines of:

                          val resp0 = getMapResponse()
                          resp0.subscribe { size = it.totalCount }
                      

                      Here you subscribe, but do not handle the error case. Actually this code is incorrect, because you break the Rx chain in two independent pieces, you shouldn't do that.

                      What you should do is something like this:

                      fun getItemsFormResponses(): Observable<List<Item>> {
                        return getMapResponse().map { resp0 ->
                          val size = resp0.totalCount
                      
                          val list = mutableListOf<Observable<List<Item>>>()
                          var accum = 0
                          do {
                            list.add(getMapResponse(accum).map { it.items })
                            accum++
                          } while (list.size*200 < size)
                          return Observable.merge(list)
                        }
                      }
                      

                      I.e. extract size by extending the chain with an operator, rather then breaking it with subscribe().

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

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

                      Vulnerabilities

                      No vulnerabilities reported

                      Install mosby

                      You can download it from GitHub, Maven.
                      You can use mosby like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the mosby component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

                      Support

                      See the project website. For Model-View-Intent check out this blog post series.

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Explore Related Topics

                      Share this Page

                      share link
                      Consider Popular Model View Controller Libraries
                      Try Top Libraries by sockeqwe
                      Compare Model View Controller Libraries with Highest Support
                      Compare Model View Controller Libraries with Highest Quality
                      Compare Model View Controller Libraries with Highest Security
                      Compare Model View Controller Libraries with Permissive License
                      Compare Model View Controller Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.