Skip to content

Commit

Permalink
Merge pull request #357 from jakepurple13/develop
Browse files Browse the repository at this point in the history
New Update!
  • Loading branch information
jakepurple13 authored Jan 4, 2022
2 parents 17e9a2d + 2881ff4 commit 568763e
Show file tree
Hide file tree
Showing 24 changed files with 976 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class AllFragment : BaseFragmentCompose() {
@ExperimentalFoundationApi
@Composable
private fun AllView(allVm: AllViewModel = viewModel(factory = factoryCreate { AllViewModel(dao, context) })) {
//TODO: MAYBE have an option to show or hide the All screen.
// maybe if possible, have it show for certain sources that the user can choose
val context = LocalContext.current

val isConnected by ReactiveNetwork.observeInternetConnectivity()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.webkit.URLUtil
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.lifecycle.LiveData
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.programmersbox.models.sourcePublish
Expand All @@ -20,6 +21,7 @@ import io.reactivex.rxkotlin.addTo
import io.reactivex.rxkotlin.subscribeBy
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.koin.android.ext.android.inject

Expand Down Expand Up @@ -85,10 +87,12 @@ abstract class BaseMainActivity : AppCompatActivity() {
}

private fun setupBottomNavBar() {
//TODO: Look into doing a recreate and if for the all_nav when showAll is changed
val navGraphIds = listOf(R.navigation.recent_nav, R.navigation.all_nav, R.navigation.setting_nav)
currentScreen.value = R.id.recent_nav
val controller = findViewById<BottomNavigationView>(R.id.navLayout2)
.also { b ->
lifecycleScope.launch { showAll.collect { runOnUiThread { b.menu.findItem(R.id.all_nav)?.isVisible = it } } }
appUpdateCheck
.filter {
AppUpdate.checkForUpdate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,15 @@ private fun GeneralSettings(
updateValue = { scope.launch { context.updatePref(SHARE_CHAPTER, it) } }
)

val showAllScreen by context.showAll.collectAsState(initial = true)

SwitchSetting(
settingTitle = { Text(stringResource(R.string.show_all_screen)) },
settingIcon = { Icon(Icons.Default.Menu, null, modifier = Modifier.fillMaxSize()) },
value = showAllScreen,
updateValue = { scope.launch { context.updatePref(SHOW_ALL, it) } }
)

customSettings?.invoke()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ val Context.shouldCheckFlow get() = dataStore.data.map { it[SHOULD_CHECK] ?: tru
val THEME_SETTING = stringPreferencesKey("theme")
val Context.themeSetting get() = dataStore.data.map { it[THEME_SETTING] ?: "System" }

val SHOW_ALL = booleanPreferencesKey("show_all")
val Context.showAll get() = dataStore.data.map { it[SHOW_ALL] ?: true }

suspend fun <T> Context.updatePref(key: Preferences.Key<T>, value: T) = dataStore.edit { it[key] = value }

@JvmInline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -287,22 +288,17 @@ fun M3CoverCard(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
GlideImage(
imageModel = imageUrl,
contentDescription = null,
contentScale = ContentScale.FillBounds,
loading = {
Image(
bitmap = AppCompatResources.getDrawable(context, placeHolder)!!.toBitmap().asImageBitmap(),
contentDescription = name
)
Image(
painter = rememberImagePainter(imageUrl) {
placeholder(AppCompatResources.getDrawable(context, placeHolder)!!)
error(AppCompatResources.getDrawable(context, error)!!)
crossfade(true)
lifecycle(LocalLifecycleOwner.current)
size(480, 360)

},
failure = {
Image(
bitmap = AppCompatResources.getDrawable(context, error)!!.toBitmap().asImageBitmap(),
contentDescription = name
)
}
contentDescription = name,
modifier = Modifier.matchParentSize()
)

Box(
Expand Down
1 change: 1 addition & 0 deletions UIViews/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<item
android:id="@+id/all_nav"
android:visible="false"
android:icon="@android:drawable/ic_menu_gallery"
android:title="@string/all" />

Expand Down
2 changes: 2 additions & 0 deletions UIViews/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
<string name="share_item">Share %s</string>
<string name="share_chapters">Share Chapter</string>

<string name="show_all_screen">Show All Screen</string>

<string name="selectDate">Select Date to be Notified At</string>
<string name="selectTime">Select Time to be Notified At</string>
<string name="notifyAtTime">Notify At…</string>
Expand Down
1 change: 1 addition & 0 deletions anime_sources/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
implementation gson
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "com.github.salomonbrys.kotson:kotson:2.5.0"
implementation "io.karn:khttp-android:0.1.2" //okhttp instead
implementation Deps.gsonutils
implementation Deps.helpfulutils
implementation Deps.rxutils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ enum class Sources(private val api: ApiService) : ApiService by api {

VIDSTREAMING(Vidstreaming), VIDEMBED(VidEmbed),

CRUNCHYROLL(CrunchyRoll),
ANIMEFLICK(AnimeFlick),

PUTLOCKERTV(PutlockerTV), PUTLOCKERANIME(PutlockerAnime), PUTLOCKERCARTOONS(PutlockerCartoons), PUTLOCKERMOVIES(PutlockerMovies),

ANIMEKISA_SUBBED(AnimeKisaSubbed), ANIMEKISA_DUBBED(AnimeKisaDubbed), ANIMEKISA_MOVIES(AnimeKisaMovies),
Expand All @@ -40,9 +43,11 @@ enum class Sources(private val api: ApiService) : ApiService by api {
WCOSTREAM,
GOGOANIME_VC,
KAWAIIFU,
ANIMEFLICK,
ANIMEKISA_SUBBED,
HDM,
WCOSTREAMCC
WCOSTREAMCC,
CRUNCHYROLL
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.programmersbox.anime_sources.anime

import androidx.compose.ui.util.fastMap
import com.programmersbox.anime_sources.ShowApi
import com.programmersbox.anime_sources.Sources
import com.programmersbox.anime_sources.toJsoup
import com.programmersbox.anime_sources.utilities.extractors
import com.programmersbox.models.ChapterModel
import com.programmersbox.models.InfoModel
import com.programmersbox.models.ItemModel
import com.programmersbox.models.Storage
import io.reactivex.Single
import org.jsoup.Jsoup
import org.jsoup.nodes.Document

object AnimeFlick : ShowApi(
baseUrl = "https://animeflick.net",
recentPath = "updates", allPath = "Anime-List"
) {
override val serviceName: String get() = "ANIMEFLICK"
override val canScroll: Boolean get() = true
override val canScrollAll: Boolean get() = true
override fun recentPage(page: Int): String = "-$page"
override fun allPage(page: Int): String = "/All/$page"

override fun getRecent(doc: Document): Single<List<ItemModel>> = Single.create { s ->
doc
.select("div.mb-4")
.select("li.slide-item")
.fastMap {
ItemModel(
title = it.select("img.img-fluid").attr("title").orEmpty(),
description = "",
imageUrl = baseUrl + it.select("img.img-fluid").attr("src"),
url = baseUrl + it.selectFirst("a")?.attr("href").orEmpty(),
source = Sources.ANIMEFLICK
)
}
.let(s::onSuccess)
}

override fun getList(doc: Document): Single<List<ItemModel>> = Single.create { s ->
doc
.select("table.table")
.select("tr")
.fastMap {
ItemModel(
title = it.select("h4.title").text().orEmpty(),
description = "",
imageUrl = baseUrl + it.select("img.d-block").attr("src"),
url = baseUrl + it.selectFirst("a")?.attr("href").orEmpty(),
source = Sources.ANIMEFLICK
)
}
.let(s::onSuccess)
}

override fun searchList(searchText: CharSequence, page: Int, list: List<ItemModel>): Single<List<ItemModel>> =
Single.create<List<ItemModel>> { s ->
Jsoup.connect("$baseUrl/search.php?search=$searchText").get()
.select(".row.mt-2")
.fastMap {
ItemModel(
title = it.selectFirst("h5 > a")?.text().orEmpty(),
description = "",
imageUrl = baseUrl + it.selectFirst("img")?.attr("src")?.replace("70x110", "225x320").orEmpty(),
url = baseUrl + it.selectFirst("a")?.attr("href").orEmpty(),
source = Sources.ANIMEFLICK
)
}
.let(s::onSuccess)
}
.onErrorResumeNext(super.searchList(searchText, page, list))

override fun getItemInfo(source: ItemModel, doc: Document): Single<InfoModel> = Single.create { emitter ->
val poster = baseUrl + doc.select("img.rounded").attr("src")
val title = doc.select("h2.title").text()
val description = doc.select("p").text()
val genres = doc.select("a[href*=\"genre-\"]").map { it.text() }
val episodes = doc.select("#collapseOne .block-space > .row > div:nth-child(2)").map {
val name = it.select("a").text()
val link = baseUrl + it.select("a").attr("href")
ChapterModel(
name,
link,
"",
source.url,
Sources.ANIMEFLICK
)
}

InfoModel(
source = Sources.ANIMEFLICK,
title = title,
url = source.url,
alternativeNames = emptyList(),
description = description,
imageUrl = poster,
genres = genres,
chapters = episodes
)
.let(emitter::onSuccess)
}

override fun getChapterInfo(chapterModel: ChapterModel): Single<List<Storage>> = Single.create { emitter ->
val data = chapterModel.url
val doc = data.toJsoup().select("iframe.embed-responsive-item").attr("src").toJsoup()
val links = doc.select("ul.list-server-items").select("li").eachAttr("data-video")
val d = links.flatMap { link ->
extractors
.filter { link.startsWith(it.mainUrl) }
.flatMap { it.getUrl(link) }
}
.distinctBy { it.link }
emitter.onSuccess(d)
}

override fun getSourceByUrl(url: String): Single<ItemModel> = Single.create { emitter ->
val doc = url.toJsoup()
ItemModel(
title = doc.select("h2.title").text(),
description = doc.select("p").text(),
imageUrl = baseUrl + doc.select("img.rounded").attr("src"),
url = url,
source = this
).let(emitter::onSuccess)
}

}

Loading

0 comments on commit 568763e

Please sign in to comment.