Skip to content

Instantly share code, notes, and snippets.

View wangerekaharun's full-sized avatar

Harun Wangereka wangerekaharun

View GitHub Profile
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28])
class ExchangeRatesRepositoryImplTest : KoinTest {
private val mockWebServer = MockWebServer()
lateinit var repo: ExchangeRateRepository
private val api: ExchangeRateAPI by inject()
@get:Rule
// Adapter Class
package ke.co.appslab.letafood.adapters;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
2021-01-30 22:59:19.254 29158-29158/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.usehover.debug, PID: 29158
java.lang.RuntimeException: StrictMode ThreadPolicy violation
at android.os.StrictMode$AndroidBlockGuardPolicy.onThreadPolicyViolation(StrictMode.java:1774)
at android.os.StrictMode$AndroidBlockGuardPolicy.lambda$handleViolationWithTimingAttempt$0$StrictMode$AndroidBlockGuardPolicy(StrictMode.java:1693)
at android.os.-$$Lambda$StrictMode$AndroidBlockGuardPolicy$9nBulCQKaMajrWr41SB7f7YRT1I.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7562)
import com.android254.droidconKE2020.feedback.ui.viewmodels.EventFeedbackViewModel
import com.android254.droidconKE2020.repository.Data
import com.android254.droidconKE2020.repository.feedback.EventFeedbackRepository
import com.android254.droidconKE2020.test_utils.BaseViewModelTest
import com.jraska.livedata.test
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import org.junit.Before
import org.junit.Test
androidx.test.espresso.AmbiguousViewMatcherException: '(with id is <com.safeboda.debug:id/user_name>)' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params={(0,0)(fillxfill) ty=BASE_APPLICATION wanim=0x10302fe
fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED DRAWS_SYSTEM_BAR_BACKGROUNDS
pfl=FORCE_DRAW_STATUS_BAR_BACKGROUND}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=1794, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false,
> Task :app:lintVitalRelease
/home/harun/AndroidStudioProjects/droidconKE2020App/features/sessions/src/main/res/layout/fragment_sessions.xml:38: Error: @+id/toolbar2 is not a sibling in the same ConstraintLayout [NotSibling]
app:layout_constraintTop_toBottomOf="@+id/toolbar2"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/harun/AndroidStudioProjects/droidconKE2020App/features/sessions/src/main/res/layout/fragment_sessions.xml:55: Error: @+id/toolbar2 is not a sibling in the same ConstraintLayout [NotSibling]
app:layout_constraintTop_toBottomOf="@+id/toolbar2" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Explanation for issues of type "NotSibling":
Layout constraints in a given ConstraintLayout or RelativeLayout should
@wangerekaharun
wangerekaharun / PostsRepo.kt
Created November 13, 2020 08:54
Getting a list of posts and for each post looping through it to get a subcirbers count.
suspend fun getPostWithSubscribers(): NetworkResult<List<PostsUIModel>> {
return try {
val response = api.loadPosts().body()!!.posts
val postModel = mutableListOf<PostsUIModel>()
response.onEach { post ->
post.url.toUri().host?.let { siteUrl ->
val site = api.loadSubscribersCount(siteUrl)
postModel.add(post.toPostUIModel(site.body()!!.subscribersCount))
}
}
@OptIn(ExperimentalPagingApi::class)
class RedditRemoteMediator(
private val redditService: RedditService,
private val redditDatabase: RedditDatabase
) : RemoteMediator<Int, RedditPost>() {
override suspend fun load(
loadType: LoadType,
state: PagingState<Int, RedditPost>
): MediatorResult {
return try {
package ke.co.appslab.bring.ui.views.fragments
import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity.RESULT_CANCELED
import android.app.Activity.RESULT_OK
import android.content.Intent
import android.content.IntentSender
import android.content.pm.PackageManager
import android.net.Uri