Skip to content

Commit

Permalink
Merge pull request #133 from jakepurple13/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jakepurple13 authored Jul 19, 2021
2 parents 2f6ab57 + 1f2a387 commit fd2fd0d
Show file tree
Hide file tree
Showing 68 changed files with 847 additions and 386 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Models/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
buildToolsVersion buildVersion

defaultConfig {
minSdkVersion 23
targetSdkVersion 30
minSdkVersion minimumSdk
targetSdkVersion targetSdk
versionCode 1
versionName "1.0"

Expand Down
12 changes: 5 additions & 7 deletions UIViews/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
buildToolsVersion buildVersion

defaultConfig {
minSdkVersion 23
targetSdkVersion 30
minSdkVersion minimumSdk
targetSdkVersion targetSdk
versionCode 1
versionName "1.0"

Expand Down Expand Up @@ -44,16 +44,13 @@ dependencies {
implementation appCompat
implementation material
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation preference
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.firebaseui:firebase-ui-auth:7.1.1'
implementation 'com.google.firebase:firebase-firestore-ktx:23.0.2'
implementation 'com.google.firebase:firebase-database-ktx:20.0.0'

implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.2.2'
implementation "androidx.browser:browser:1.3.0"
Expand All @@ -66,6 +63,7 @@ dependencies {

implementation project(':Models')
implementation project(':favoritesdatabase')
implementation project(':sharedutils')

implementation constraintlayout
implementation swiperefresh
Expand All @@ -86,7 +84,7 @@ dependencies {

implementation recyclerview
implementation 'androidx.palette:palette-ktx:1.0.0'
implementation 'com.airbnb.android:lottie:3.7.1'
implementation 'com.airbnb.android:lottie:3.7.2'
implementation "androidx.room:room-runtime:2.3.0"
implementation 'com.github.anzaizai:EasySwipeMenuLayout:1.1.4'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import com.programmersbox.helpfulutils.visible
import com.programmersbox.models.ApiService
import com.programmersbox.models.ItemModel
import com.programmersbox.models.sourcePublish
import com.programmersbox.sharedutils.FirebaseDb
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.uiviews.databinding.FragmentAllBinding
import com.programmersbox.uiviews.utils.EndlessScrollingListener
import com.programmersbox.uiviews.utils.FirebaseDb
import com.programmersbox.uiviews.utils.MainLogo
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.Flowables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import androidx.lifecycle.LiveData
import androidx.navigation.NavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.programmersbox.models.sourcePublish
import com.programmersbox.uiviews.utils.AppUpdate
import com.programmersbox.uiviews.utils.appUpdateCheck
import com.programmersbox.sharedutils.AppUpdate
import com.programmersbox.sharedutils.appUpdateCheck
import com.programmersbox.uiviews.utils.currentService
import com.programmersbox.uiviews.utils.setupWithNavController
import io.reactivex.Single
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import com.programmersbox.favoritesdatabase.ItemDao
import com.programmersbox.helpfulutils.layoutInflater
import com.programmersbox.models.ChapterModel
import com.programmersbox.models.SwatchInfo
import com.programmersbox.sharedutils.FirebaseDb
import com.programmersbox.uiviews.databinding.ChapterItemBinding
import com.programmersbox.uiviews.utils.FirebaseDb
import io.reactivex.Completable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ import com.programmersbox.models.ChapterModel
import com.programmersbox.models.InfoModel
import com.programmersbox.models.SwatchInfo
import com.programmersbox.rxutils.invoke
import com.programmersbox.sharedutils.FirebaseDb
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.thirdpartyutils.changeTint
import com.programmersbox.thirdpartyutils.check
import com.programmersbox.thirdpartyutils.getPalette
import com.programmersbox.thirdpartyutils.into
import com.programmersbox.uiviews.databinding.DetailsFragmentBinding
import com.programmersbox.uiviews.utils.ChromeCustomTabTransformationMethod
import com.programmersbox.uiviews.utils.FirebaseDb
import com.programmersbox.uiviews.utils.MainLogo
import com.programmersbox.uiviews.utils.openInCustomChromeBrowser
import io.reactivex.Completable
import io.reactivex.android.schedulers.AndroidSchedulers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import com.programmersbox.helpfulutils.visible
import com.programmersbox.models.ApiService
import com.programmersbox.rxutils.behaviorDelegate
import com.programmersbox.rxutils.toLatestFlowable
import com.programmersbox.sharedutils.FirebaseDb
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.uiviews.databinding.FavoriteItemBinding
import com.programmersbox.uiviews.databinding.FragmentFavoriteBinding
import com.programmersbox.uiviews.utils.AutoFitGridLayoutManager
import com.programmersbox.uiviews.utils.FirebaseDb
import com.programmersbox.uiviews.utils.MainLogo
import com.programmersbox.uiviews.utils.toolTipText
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.programmersbox.models.ApiService
import com.programmersbox.models.ChapterModel
import com.programmersbox.uiviews.utils.AppUpdate
import com.programmersbox.uiviews.utils.MainLogo
import com.programmersbox.sharedutils.AppUpdate
import com.programmersbox.sharedutils.MainLogo

interface GenericInfo {

Expand All @@ -16,6 +16,7 @@ interface GenericInfo {
fun createLayoutManager(context: Context): RecyclerView.LayoutManager
fun chapterOnClick(model: ChapterModel, allChapters: List<ChapterModel>, context: Context)
fun sourceList(): List<ApiService>
fun searchList(): List<ApiService> = sourceList()
fun toSource(s: String): ApiService?
fun customPreferences(preferenceScreen: SettingsDsl) = Unit
fun downloadChapter(chapterModel: ChapterModel, title: String)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package com.programmersbox.uiviews

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import androidx.navigation.findNavController
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
import com.jakewharton.rxbinding2.widget.textChanges
import com.programmersbox.dragswipe.DragSwipeAdapter
import com.programmersbox.dragswipe.DragSwipeDiffUtil
import com.programmersbox.helpfulutils.layoutInflater
import com.programmersbox.helpfulutils.runOnUIThread
import com.programmersbox.models.ItemModel
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.uiviews.databinding.FragmentGlobalSearchBinding
import com.programmersbox.uiviews.databinding.SearchItemBinding
import com.programmersbox.uiviews.utils.toolTipText
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.util.concurrent.TimeUnit

class GlobalSearchFragment : BaseFragment() {

override val layoutId: Int get() = R.layout.fragment_global_search

private val disposable: CompositeDisposable = CompositeDisposable()

private val info: GenericInfo by inject()

private val adapter by lazy { SearchAdapter() }

private lateinit var binding: FragmentGlobalSearchBinding

override fun viewCreated(view: View, savedInstanceState: Bundle?) {

binding = FragmentGlobalSearchBinding.bind(view)

binding.scrollToTop.setOnClickListener {
lifecycleScope.launch {
activity?.runOnUiThread { binding.searchList.smoothScrollToPosition(0) }
delay(500)
activity?.runOnUiThread { binding.searchList.scrollToPosition(0) }
}
}

binding.searchList.apply {
adapter = this@GlobalSearchFragment.adapter
setItemViewCacheSize(20)
setHasFixedSize(true)
}

ReactiveNetwork.observeInternetConnectivity()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
binding.offlineView.visibility = if (it) View.GONE else View.VISIBLE
binding.searchRefresh.visibility = if (it) View.VISIBLE else View.GONE
}
.addTo(disposable)

binding.searchRefresh.isEnabled = false

binding.searchInfo
.textChanges()
.doOnNext { activity?.runOnUiThread { binding.searchRefresh.isRefreshing = true } }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.debounce(1000, TimeUnit.MILLISECONDS)
.flatMap { s ->
Observable.combineLatest(
info.searchList()
.map {
it
.searchList(s, list = emptyList())
.timeout(5, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.onErrorReturnItem(emptyList())
.toObservable()
}
) { (it as Array<List<ItemModel>>).toList().flatten().sortedBy(ItemModel::title) }
}
.onErrorReturnItem(emptyList())
.subscribe {
adapter.setData(it)
binding.searchLayout.suffixText = "${it.size}"
binding.searchRefresh.isRefreshing = false
}
.addTo(disposable)
}

private fun DragSwipeAdapter<ItemModel, *>.setData(newList: List<ItemModel>) {
val diffCallback = object : DragSwipeDiffUtil<ItemModel>(dataList, newList) {
override fun areContentsTheSame(oldItem: ItemModel, newItem: ItemModel): Boolean = oldItem.url == newItem.url
override fun areItemsTheSame(oldItem: ItemModel, newItem: ItemModel): Boolean = oldItem.url === newItem.url
}
val diffResult = DiffUtil.calculateDiff(diffCallback)
dataList.clear()
dataList.addAll(newList)
runOnUIThread { diffResult.dispatchUpdatesTo(this) }
}

override fun onDestroy() {
super.onDestroy()
disposable.dispose()
}

inner class SearchAdapter : DragSwipeAdapter<ItemModel, SearchHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchHolder =
SearchHolder(SearchItemBinding.inflate(requireContext().layoutInflater, parent, false))

override fun SearchHolder.onBind(item: ItemModel, position: Int) = bind(item)
}

class SearchHolder(private val binding: SearchItemBinding) : RecyclerView.ViewHolder(binding.root), KoinComponent {

private val logo: MainLogo by inject()

fun bind(info: ItemModel) {
binding.show = info
binding.root.toolTipText(info.title)
Glide.with(itemView.context)
.asBitmap()
.load(info.imageUrl)
.fallback(logo.logoId)
.placeholder(logo.logoId)
.error(logo.logoId)
.fitCenter()
.transform(RoundedCorners(15))
.into(binding.galleryListCover)

binding.root.setOnClickListener {
binding.root.findNavController()
.navigate(GlobalSearchFragmentDirections.actionGlobalSearchFragmentToDetailsFragment(info))
}
binding.executePendingBindings()
}

}

companion object {
@JvmStatic
fun newInstance() = GlobalSearchFragment()
}
}
4 changes: 4 additions & 0 deletions UIViews/src/main/java/com/programmersbox/uiviews/OtakuApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import com.programmersbox.helpfulutils.NotificationChannelImportance
import com.programmersbox.helpfulutils.createNotificationChannel
import com.programmersbox.helpfulutils.createNotificationGroup
import com.programmersbox.loggingutils.Loged
import com.programmersbox.sharedutils.FirebaseUIStyle
import com.programmersbox.uiviews.utils.shouldCheck
import io.reactivex.plugins.RxJavaPlugins
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.loadKoinModules
import org.koin.core.context.startKoin
import org.koin.dsl.module
import java.util.concurrent.TimeUnit

abstract class OtakuApp : Application() {
Expand Down Expand Up @@ -44,6 +47,7 @@ abstract class OtakuApp : Application() {
startKoin {
androidLogger()
androidContext(this@OtakuApp)
loadKoinModules(module { single { FirebaseUIStyle(R.style.Theme_OtakuWorldBase) } })
}

onCreated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import com.programmersbox.helpfulutils.gone
import com.programmersbox.helpfulutils.visible
import com.programmersbox.models.ApiService
import com.programmersbox.models.sourcePublish
import com.programmersbox.sharedutils.FirebaseDb
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.uiviews.databinding.FragmentRecentBinding
import com.programmersbox.uiviews.utils.EndlessScrollingListener
import com.programmersbox.uiviews.utils.FirebaseDb
import com.programmersbox.uiviews.utils.MainLogo
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.Flowables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import com.programmersbox.helpfulutils.notificationManager
import com.programmersbox.helpfulutils.requestPermissions
import com.programmersbox.loggingutils.Loged
import com.programmersbox.models.sourcePublish
import com.programmersbox.sharedutils.AppUpdate
import com.programmersbox.sharedutils.FirebaseAuthentication
import com.programmersbox.sharedutils.MainLogo
import com.programmersbox.sharedutils.appUpdateCheck
import com.programmersbox.thirdpartyutils.into
import com.programmersbox.thirdpartyutils.openInCustomChromeBrowser
import com.programmersbox.uiviews.utils.*
Expand Down Expand Up @@ -147,7 +151,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
findPreference<Preference>("view_source")?.let { p ->
p.setOnPreferenceClickListener {
requireContext().openInCustomChromeBrowser(sourcePublish.value!!.baseUrl) {
setStartAnimations(requireContext(), R.anim.fui_slide_in_right, R.anim.fui_slide_out_left)
setStartAnimations(requireContext(), R.anim.slide_in_right, R.anim.slide_out_left)
}
true
}
Expand All @@ -158,6 +162,11 @@ class SettingsFragment : PreferenceFragmentCompat() {
true
}

findPreference<Preference>("view_global_search")?.setOnPreferenceClickListener {
findNavController().navigate(SettingsFragmentDirections.actionSettingsFragmentToGlobalSearchFragment())
true
}

findPreference<ListPreference>("theme_setting")?.let { p ->
p.setDefaultValue("system")
p.setOnPreferenceChangeListener { _, newValue ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import com.programmersbox.helpfulutils.notificationManager
import com.programmersbox.loggingutils.Loged
import com.programmersbox.loggingutils.fd
import com.programmersbox.models.InfoModel
import com.programmersbox.sharedutils.AppUpdate
import com.programmersbox.sharedutils.FirebaseDb
import com.programmersbox.uiviews.utils.*
import io.reactivex.Single
import kotlinx.coroutines.GlobalScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ val updateCheckPublishEnd = BehaviorSubject.create<Long>()

var Context.batteryAlertPercent: Int by sharedPrefNotNullDelegate(20)

val appUpdateCheck = BehaviorSubject.create<AppUpdate.AppUpdates>()

@JvmInline
value class MainLogo(val logoId: Int)

@JvmInline
value class NotificationLogo(val notificationId: Int)

Expand Down
Loading

0 comments on commit fd2fd0d

Please sign in to comment.