Skip to content

Commit

Permalink
Merge Dev into master (#291)
Browse files Browse the repository at this point in the history
* removed unused search plugins assets folder

* added add repository dialog

close #288

* added more categories to plugins

close #289

* bumped version for release

* removed plugins step from CI
  • Loading branch information
LivingWithHippos authored Jan 3, 2023
1 parent 2468b40 commit 80e52b5
Show file tree
Hide file tree
Showing 27 changed files with 367 additions and 110 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ jobs:
env:
ENCODED_KEYSTORE: ${{ secrets.KEYSTORE }}
run: echo "$ENCODED_KEYSTORE" | base64 --decode > /home/runner/work/unchained-android/unchained-android/app/release.pfk
- name: Copy plugins
run: cp /home/runner/work/unchained-android/unchained-android/extra_assets/plugins/*.unchained /home/runner/work/unchained-android/unchained-android/app/app/src/main/assets/search_plugins
- name: Build the app
env:
KEYSTORE: /home/runner/work/unchained-android/unchained-android/app/release.pfk
Expand All @@ -57,8 +55,6 @@ jobs:
env:
ENCODED_KEYSTORE: ${{ secrets.KEYSTORE }}
run: echo "$ENCODED_KEYSTORE" | base64 --decode > /home/runner/work/unchained-android/unchained-android/app/release.pfk
- name: Copy plugins
run: cp /home/runner/work/unchained-android/unchained-android/extra_assets/plugins/*.unchained /home/runner/work/unchained-android/unchained-android/app/app/src/main/assets/search_plugins
- name: Build the app
env:
KEYSTORE: /home/runner/work/unchained-android/unchained-android/app/release.pfk
Expand Down
5 changes: 3 additions & 2 deletions app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ android {
applicationId "com.github.livingwithhippos.unchained"
minSdk 22
targetSdk 33
versionCode 34
versionName "4.53.2-beta"
versionCode 35
versionName "4.53.4-beta"
// limit resources for a list of locales
// resConfigs "en", "it"

Expand Down Expand Up @@ -209,6 +209,7 @@ dependencies {
// retrofit
implementation deps.retrofit.runtime
implementation deps.retrofit.moshi
implementation deps.retrofit.scalars

//okhttp
implementation deps.okhttp.runtime
Expand Down
1 change: 0 additions & 1 deletion app/app/src/main/assets/search_plugins/.gitignore

This file was deleted.

74 changes: 0 additions & 74 deletions app/app/src/main/assets/search_plugins/etree.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.livingwithhippos.unchained.data.remote

import com.github.livingwithhippos.unchained.plugins.model.Plugin
import com.github.livingwithhippos.unchained.repository.model.JsonPluginRepository
import com.github.livingwithhippos.unchained.utilities.PLUGINS_PACK_LINK
import com.github.livingwithhippos.unchained.utilities.DEFAULT_PLUGINS_REPOSITORY_LINK
import okhttp3.ResponseBody
import retrofit2.Response
Expand All @@ -12,12 +11,6 @@ import retrofit2.http.Url

interface CustomDownload {

@Streaming
@GET
suspend fun getPluginsPack(
@Url packUrl: String = PLUGINS_PACK_LINK
): Response<ResponseBody>

@Streaming
@GET
suspend fun getFile(
Expand All @@ -33,4 +26,9 @@ interface CustomDownload {
suspend fun getPlugin(
@Url pluginUrl: String
): Response<Plugin>

@GET
suspend fun getString(
@Url url: String
): Response<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ interface CustomDownloadHelper {

suspend fun getFile(url: String): Response<ResponseBody>

suspend fun getPluginsPack(
packUrl: String
): Response<ResponseBody>

suspend fun getPluginsRepository(
repositoryUrl: String
): Response<JsonPluginRepository>

suspend fun getPlugin(
pluginUrl: String
): Response<Plugin>

suspend fun getAsString(
url: String
): Response<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class CustomDownloadHelperImpl @Inject constructor(private val customDownload: C
CustomDownloadHelper {
override suspend fun getFile(url: String): Response<ResponseBody> = customDownload.getFile(url)

override suspend fun getPluginsPack(packUrl: String): Response<ResponseBody> =
customDownload.getPluginsPack(packUrl)

override suspend fun getPluginsRepository(repositoryUrl: String): Response<JsonPluginRepository> =
customDownload.getPluginsRepository(repositoryUrl)

override suspend fun getPlugin(pluginUrl: String): Response<Plugin> =
customDownload.getPlugin(pluginUrl)

override suspend fun getAsString(url: String): Response<String> =
customDownload.getString(url)
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ class CustomDownloadRepository @Inject constructor(
errorMessage = "Error fetching plugin"
)
}

/**
* Generic function to retrieve url bodies as strings
*
* @param url
* @return
*/
suspend fun downloadAsString(url: String): EitherResult<UnchainedNetworkException, String> {
return eitherApiResult(
call = { customDownloadHelper.getAsString(url) },
errorMessage = "Error fetching url as a string"
)
}
}

sealed class DownloadResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class DatabasePluginRepository @Inject constructor(
return repositoryDataDao.getAllRepositories()
}

suspend fun addRepositoryUrl(url: String) {
repositoryDataDao.insert(Repository(url))
}

/**
* Get all the plugins or repository filtered by the query. If a plugin is a match the repository
* will also be returned (useful for separating results from different repositories)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class KodiRepository @Inject constructor(
@ClassicClient private val client: OkHttpClient
) : BaseRepository(protoStore) {

// todo: conflict with other Retrofit with qualifiers?
private fun provideRetrofit(baseUrl: String): Retrofit {
return Retrofit.Builder()
.client(client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import okhttp3.dnsoverhttps.DnsOverHttps
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.net.InetAddress
import javax.inject.Singleton

Expand Down Expand Up @@ -177,6 +178,7 @@ object ApiFactory {
return Retrofit.Builder()
.client(okHttpClient)
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,15 @@ class Parser(
private fun getCategory(plugin: Plugin, category: String): String? {
return when (category) {
"all" -> plugin.supportedCategories.all
"art" -> plugin.supportedCategories.art
"anime" -> plugin.supportedCategories.anime
"doujinshi" -> plugin.supportedCategories.doujinshi
"manga" -> plugin.supportedCategories.manga
"software" -> plugin.supportedCategories.software
"games" -> plugin.supportedCategories.games
"movies" -> plugin.supportedCategories.movies
"pictures" -> plugin.supportedCategories.pictures
"videos" -> plugin.supportedCategories.videos
"music" -> plugin.supportedCategories.music
"tv" -> plugin.supportedCategories.tv
"books" -> plugin.supportedCategories.books
Expand All @@ -793,8 +798,9 @@ class Parser(
* 2.1: added direct parsing mode
* 2.2: added entry class to direct parsing mode (required)
* 2.3: added optional table index to table parsers (for tables with no specific class/id)
* 2.4: added more categories
*/
const val PLUGIN_ENGINE_VERSION: Float = 2.3f
const val PLUGIN_ENGINE_VERSION: Float = 2.4f
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,24 @@ fun isCompatible(engineVersion: Double): Boolean {
data class SupportedCategories(
@Json(name = "all")
val all: String,
@Json(name = "art")
val art: String?,
@Json(name = "anime")
val anime: String?,
@Json(name = "doujinshi")
val doujinshi: String?,
@Json(name = "manga")
val manga: String?,
@Json(name = "software")
val software: String?,
@Json(name = "games")
val games: String?,
@Json(name = "movies")
val movies: String?,
@Json(name = "pictures")
val pictures: String?,
@Json(name = "videos")
val videos: String?,
@Json(name = "music")
val music: String?,
@Json(name = "tv")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.github.livingwithhippos.unchained.repository.view

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import com.github.livingwithhippos.unchained.R
import com.github.livingwithhippos.unchained.repository.viewmodel.InvalidLinkReason
import com.github.livingwithhippos.unchained.repository.viewmodel.PluginRepositoryEvent
import com.github.livingwithhippos.unchained.repository.viewmodel.RepositoryViewModel
import com.github.livingwithhippos.unchained.utilities.extension.isWebUrl
import com.github.livingwithhippos.unchained.utilities.extension.showToast
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.progressindicator.LinearProgressIndicator
import com.google.android.material.textfield.TextInputEditText
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class AddRepositoryDialogFragment : DialogFragment() {

private val viewModel: RepositoryViewModel by activityViewModels()

private lateinit var progressBar: LinearProgressIndicator

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let { activity ->

// Use the Builder class for convenient dialog construction
val builder = MaterialAlertDialogBuilder(activity)

// Get the layout inflater
val inflater = activity.layoutInflater

val view = inflater.inflate(R.layout.dialog_add_repository, null)

progressBar = view.findViewById(R.id.progressBar)

view.findViewById<Button>(R.id.bTestRepoLink).setOnClickListener {
progressBar.isIndeterminate = true
viewModel.checkRepositoryLink(
view.findViewById<TextInputEditText>(R.id.tiAdd).text.toString()
)
}

builder.setView(view)
.setNegativeButton(getString(R.string.close)) { dialog, _ ->
dialog.cancel()
}
.setPositiveButton(getString(R.string.save)) { dialog, _ ->
val url =
view.findViewById<TextInputEditText>(R.id.tiAdd).text.toString().trim()
if (url.isWebUrl()) {
viewModel.addRepository(
view.findViewById<TextInputEditText>(R.id.tiAdd).text.toString()
)
} else
context?.showToast(R.string.invalid_url)
dialog.cancel()
}
// Create the AlertDialog object and return it
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {

viewModel.pluginsRepositoryLiveData.observe(this) {
when (val result = it.peekContent()) {
is PluginRepositoryEvent.ValidRepositoryLink -> {
progressBar.isIndeterminate = false
context?.showToast(R.string.connection_successful)
}
is PluginRepositoryEvent.InvalidRepositoryLink -> {
progressBar.isIndeterminate = false
when (result.reason) {
InvalidLinkReason.ConnectionError -> context?.showToast(R.string.network_error)
InvalidLinkReason.NotAnUrl -> context?.showToast(R.string.invalid_url)
InvalidLinkReason.ParsingError -> context?.showToast(R.string.parsing_error)
}
}
else -> {
// do nothing
}
}
}

return super.onCreateView(inflater, container, savedInstanceState)
}
}
Loading

0 comments on commit 80e52b5

Please sign in to comment.