Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find Android items #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.emergetools.hackernews

import android.app.Application
import android.content.Context
import android.util.Log
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
Expand All @@ -10,9 +11,14 @@ import com.emergetools.hackernews.data.local.BookmarkDao
import com.emergetools.hackernews.data.local.HackerNewsDatabase
import com.emergetools.hackernews.data.local.LocalCookieJar
import com.emergetools.hackernews.data.local.UserStorage
import com.emergetools.hackernews.data.remote.FeedIdResponse
import com.emergetools.hackernews.data.remote.HackerNewsBaseClient
import com.emergetools.hackernews.data.remote.HackerNewsSearchClient
import com.emergetools.hackernews.data.remote.HackerNewsWebClient
import com.emergetools.hackernews.data.remote.ItemResponse
import com.emergetools.hackernews.data.remote.PostPage
import com.emergetools.hackernews.features.stories.FeedType
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import okhttp3.OkHttpClient
import java.time.Duration
Expand Down Expand Up @@ -47,7 +53,29 @@ class HackerNewsApplication : Application() {

webClient = HackerNewsWebClient(httpClient)
baseClient = HackerNewsBaseClient(json, httpClient)

// Find if a Android item is in the feed!
runBlocking {
when (val response = baseClient.getFeedIds(FeedType.Top)) {
is FeedIdResponse.Success -> {
for (item in response.page) {
when (val item = baseClient.getItem(item)) {
is ItemResponse.Item -> {
if (item.title?.contains("Android") == true) {
Log.d("HN", "Android item! ${item.title}")
}
}
ItemResponse.NullResponse -> {
}
}
}
}
is FeedIdResponse.Error -> {
}
}
}
}

}

val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "user")
Expand Down