Skip to content

Commit

Permalink
Start implementing search for F-Droid
Browse files Browse the repository at this point in the history
  • Loading branch information
rumboalla committed Jul 23, 2023
1 parent 6dcc685 commit 8856164
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/src/main/java/com/apkupdater/data/fdroid/FdroidUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ fun FdroidUpdate.toAppUpdate() = AppUpdate(
apk.versionName,
apk.versionCode,
FdroidSource,
app.icon.toUri(),
if(app.icon.isEmpty())
"https://f-droid.org/assets/ic_repo_app_default.png".toUri()
else
"https://f-droid.org/repo/icons-640/${app.icon}".toUri(),
"https://f-droid.org/repo/${apk.apkName}"
)
6 changes: 3 additions & 3 deletions app/src/main/java/com/apkupdater/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.apkupdater.di
import android.content.Context
import androidx.work.WorkManager
import com.apkupdater.BuildConfig
import com.google.gson.GsonBuilder
import com.kryptoprefs.preferences.KryptoBuilder
import com.apkupdater.R
import com.apkupdater.prefs.Prefs
import com.apkupdater.repository.ApkMirrorRepository
Expand All @@ -21,6 +19,8 @@ import com.apkupdater.viewmodel.MainViewModel
import com.apkupdater.viewmodel.SearchViewModel
import com.apkupdater.viewmodel.SettingsViewModel
import com.apkupdater.viewmodel.UpdatesViewModel
import com.google.gson.GsonBuilder
import com.kryptoprefs.preferences.KryptoBuilder
import okhttp3.Cache
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand Down Expand Up @@ -113,6 +113,6 @@ val mainModule = module {

viewModel { SettingsViewModel(get(), get(), WorkManager.getInstance(get())) }

viewModel { parameters -> SearchViewModel(parameters.get(), get()) }
viewModel { parameters -> SearchViewModel(parameters.get(), get(), get()) }

}
21 changes: 20 additions & 1 deletion app/src/main/java/com/apkupdater/repository/FdroidRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,26 @@ class FdroidRepository(
emit(updates)
}.catch {
emit(emptyList())
Log.e("FdroidRepository", "Error", it)
Log.e("FdroidRepository", "Error looking for updates.", it)
}

suspend fun search(text: String) = flow {
val response = service.getJar()
val data = jarToJson(response.byteStream())
val updates = data.apps
.asSequence()
.filter { it.name.contains(text) }
.map { FdroidUpdate(data.packages[it.packageName]!![0], it) }
.filter { it.apk.minSdkVersion <= api }
.filter { filterArch(it) }
.filter { filterAlpha(it) }
.filter { filterBeta(it) }
.map { it.toAppUpdate() }
.toList()
emit(Result.success(updates))
}.catch {
emit(Result.failure(it))
Log.e("FdroidRepository", "Error searching.", it)
}

private fun filterAlpha(update: FdroidUpdate) = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ fun SearchImage(app: AppUpdate, onInstall: (String) -> Unit = {}) = Box {
{ onInstall(app.link) },
Modifier.align(Alignment.TopEnd).padding(4.dp)
)
SourceIcon(app.source, Modifier.align(Alignment.TopStart).padding(4.dp))
}

@Composable
Expand Down

0 comments on commit 8856164

Please sign in to comment.