Skip to content

Commit

Permalink
Update dependencies (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva authored Oct 3, 2018
1 parent fbbe298 commit b19f0e8
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ package jahirfiquitiva.apps.blueprint.demo
import com.github.javiersantos.piracychecker.PiracyChecker
import jahirfiquitiva.libs.blueprint.models.NavigationItem
import jahirfiquitiva.libs.blueprint.ui.activities.BottomNavigationBlueprintActivity
import jahirfiquitiva.libs.blueprint.ui.activities.DrawerBlueprintActivity

/**
* You can choose between:
* - DrawerBlueprintActivity
* - BottomNavigationBlueprintActivity
*/
class MainActivity : BottomNavigationBlueprintActivity() {
class MainActivity : DrawerBlueprintActivity() {
/**
* These things here have the default values. You can delete the ones you don't want to change
* and/or modify the ones you want to.
Expand Down
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ ext.versions = [
targetSdk : 28,
buildTools : '28.0.3',
// Versions:
versionCode: 130,
versionName: '1.3.0',
versionCode: 131,
versionName: '1.3.1',
// Gradle Plugins
gradle : '3.2.0',
kotlin : '1.2.71',
libs : '2.1',
// Dependencies
kuper : '1.4.9',
kuper : '1.5.0',
counterFab : '1.1.0',
fuel : '1.15.0',
oneSignal : '3.10.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ import jahirfiquitiva.libs.blueprint.models.NavigationItem
import jahirfiquitiva.libs.blueprint.quest.IconRequest
import jahirfiquitiva.libs.blueprint.quest.events.SendRequestCallback
import jahirfiquitiva.libs.blueprint.ui.fragments.ApplyFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.EmptyFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.HomeFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.IconsFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.RequestsFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.WallpapersFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.dialogs.FiltersBottomSheet
import jahirfiquitiva.libs.frames.helpers.extensions.mdDialog
import jahirfiquitiva.libs.frames.helpers.extensions.showChanges
Expand All @@ -77,7 +75,6 @@ import jahirfiquitiva.libs.kext.extensions.primaryColor
import jahirfiquitiva.libs.kext.extensions.setItemVisibility
import jahirfiquitiva.libs.kext.extensions.stringArray
import jahirfiquitiva.libs.kext.extensions.tint
import jahirfiquitiva.libs.kext.ui.fragments.adapters.FragmentsPagerAdapter
import jahirfiquitiva.libs.kext.ui.layouts.FixedElevationAppBarLayout
import jahirfiquitiva.libs.kext.ui.widgets.CustomSearchView
import jahirfiquitiva.libs.kuper.ui.widgets.PseudoViewPager
Expand Down Expand Up @@ -106,6 +103,7 @@ abstract class BaseBlueprintActivity : BaseFramesActivity<BPKonfigs>() {
private var searchView: CustomSearchView? = null

private val pager: PseudoViewPager? by bind(R.id.pager)
private var pagerAdapter: BlueprintSectionsAdapter? = null

internal val isIconsPicker: Boolean
get() = (pickerKey == ICONS_PICKER || pickerKey == IMAGE_PICKER || pickerKey == ICONS_APPLIER)
Expand Down Expand Up @@ -160,29 +158,13 @@ abstract class BaseBlueprintActivity : BaseFramesActivity<BPKonfigs>() {
}

private fun initFragments() {
val fragmentsAdapter = FragmentsPagerAdapter(supportFragmentManager)
val defFragment = EmptyFragment()
loop@ for (item in getNavigationItems()) {
when (item.id) {
DEFAULT_HOME_SECTION_ID ->
fragmentsAdapter.addFragment(if (isIconsPicker) defFragment else HomeFragment())
DEFAULT_ICONS_SECTION_ID ->
fragmentsAdapter.addFragment(IconsFragment.create(pickerKey))
DEFAULT_WALLPAPERS_SECTION_ID ->
fragmentsAdapter.addFragment(
if (isIconsPicker) defFragment else
WallpapersFragment.create(getLicenseChecker() != null))
DEFAULT_APPLY_SECTION_ID ->
fragmentsAdapter.addFragment(
if (isIconsPicker) defFragment else ApplyFragment())
DEFAULT_REQUEST_SECTION_ID ->
fragmentsAdapter.addFragment(
if (isIconsPicker) defFragment else RequestsFragment.create(debug()))
else -> continue@loop
}
}
pager?.offscreenPageLimit = fragmentsAdapter.count
pager?.adapter = fragmentsAdapter
pagerAdapter = BlueprintSectionsAdapter(
supportFragmentManager,
pickerKey,
getLicenseChecker() != null,
debug(),
getNavigationItems())
pager?.adapter = pagerAdapter
}

private fun initFAB() {
Expand Down Expand Up @@ -313,8 +295,7 @@ abstract class BaseBlueprintActivity : BaseFramesActivity<BPKonfigs>() {
override fun onResume() {
super.onResume()
invalidateOptionsMenu()
((pager?.adapter as? FragmentsPagerAdapter)?.get(currentSectionPosition) as? HomeFragment)
?.scrollToTop()
(pagerAdapter?.get(currentSectionPosition) as? HomeFragment)?.scrollToTop()
}

override fun onPause() {
Expand Down Expand Up @@ -519,13 +500,11 @@ abstract class BaseBlueprintActivity : BaseFramesActivity<BPKonfigs>() {
}

private fun applyIconFilters() {
((pager?.adapter as? FragmentsPagerAdapter)?.get(
currentSectionPosition) as? IconsFragment)?.applyFilters(activeFilters)
(pagerAdapter?.get(currentSectionPosition) as? IconsFragment)?.applyFilters(activeFilters)
}

private fun scrollToTop() {
val activeFragment =
(pager?.adapter as? FragmentsPagerAdapter)?.get(currentSectionPosition)
val activeFragment = pagerAdapter?.get(currentSectionPosition)
(activeFragment as? HomeFragment)?.scrollToTop()
(activeFragment as? IconsFragment)?.scrollToTop()
(activeFragment as? BaseFramesFragment<*, *>)?.scrollToTop()
Expand All @@ -534,35 +513,27 @@ abstract class BaseBlueprintActivity : BaseFramesActivity<BPKonfigs>() {
}

private fun doSearch(search: String = "", closed: Boolean = false) {
val activeFragment =
(pager?.adapter as? FragmentsPagerAdapter)?.get(currentSectionPosition)
val activeFragment = pagerAdapter?.get(currentSectionPosition)
(activeFragment as? IconsFragment)?.doSearch(search, closed)
(activeFragment as? BaseFramesFragment<*, *>)?.applyFilter(search, closed)
(activeFragment as? ApplyFragment)?.applyFilter(search, closed)
(activeFragment as? RequestsFragment)?.applyFilter(search, closed)
}

private fun refreshWallpapers() {
((pager?.adapter as? FragmentsPagerAdapter)?.get(currentSectionPosition)
as? BaseFramesFragment<*, *>)?.reloadData(1)
(pagerAdapter?.get(currentSectionPosition) as? BaseFramesFragment<*, *>)?.reloadData(1)
}

private fun refreshRequests() {
((pager?.adapter as? FragmentsPagerAdapter)?.get(
currentSectionPosition) as? RequestsFragment)
?.refresh()
(pagerAdapter?.get(currentSectionPosition) as? RequestsFragment)?.refresh()
}

private fun toggleSelectAll() {
((pager?.adapter as? FragmentsPagerAdapter)?.get(
currentSectionPosition) as? RequestsFragment)
?.toggleSelectAll()
(pagerAdapter?.get(currentSectionPosition) as? RequestsFragment)?.toggleSelectAll()
}

internal fun deselectAll() {
((pager?.adapter as? FragmentsPagerAdapter)?.get(
currentSectionPosition) as? RequestsFragment)
?.deselectAll()
(pagerAdapter?.get(currentSectionPosition) as? RequestsFragment)?.deselectAll()
}

internal fun launchHelpActivity() {
Expand All @@ -574,8 +545,7 @@ abstract class BaseBlueprintActivity : BaseFramesActivity<BPKonfigs>() {
}

internal fun postToFab(post: (CounterFab) -> Unit) {
val currentFragment =
(pager?.adapter as? FragmentsPagerAdapter)?.get(currentSectionPosition)
val currentFragment = pagerAdapter?.get(currentSectionPosition)
when (currentFragment) {
is RequestsFragment, is IconsFragment -> fab?.let { post(it) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2018.
*
* Licensed under the CreativeCommons Attribution-ShareAlike
* 4.0 International License. You may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jahirfiquitiva.libs.blueprint.ui.activities

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import jahirfiquitiva.libs.blueprint.helpers.utils.DEFAULT_APPLY_SECTION_ID
import jahirfiquitiva.libs.blueprint.helpers.utils.DEFAULT_HOME_SECTION_ID
import jahirfiquitiva.libs.blueprint.helpers.utils.DEFAULT_ICONS_SECTION_ID
import jahirfiquitiva.libs.blueprint.helpers.utils.DEFAULT_REQUEST_SECTION_ID
import jahirfiquitiva.libs.blueprint.helpers.utils.DEFAULT_WALLPAPERS_SECTION_ID
import jahirfiquitiva.libs.blueprint.models.NavigationItem
import jahirfiquitiva.libs.blueprint.ui.fragments.ApplyFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.EmptyFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.HomeFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.IconsFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.RequestsFragment
import jahirfiquitiva.libs.blueprint.ui.fragments.WallpapersFragment
import jahirfiquitiva.libs.frames.helpers.utils.ICONS_APPLIER
import jahirfiquitiva.libs.frames.helpers.utils.ICONS_PICKER
import jahirfiquitiva.libs.frames.helpers.utils.IMAGE_PICKER
import jahirfiquitiva.libs.kext.ui.fragments.adapters.DynamicFragmentsPagerAdapter

internal class BlueprintSectionsAdapter(
manager: FragmentManager,
private val pickerKey: Int,
private val withChecker: Boolean,
private val withDebug: Boolean,
private val navItems: Array<NavigationItem>
) :
DynamicFragmentsPagerAdapter(manager) {

private val isIconsPicker: Boolean by lazy {
(pickerKey == ICONS_PICKER || pickerKey == IMAGE_PICKER || pickerKey == ICONS_APPLIER)
}

override fun createItem(position: Int): Fragment {
val defFragment = EmptyFragment()
val idForPosition = try {
navItems[position].id
} catch (e: Exception) {
DEFAULT_HOME_SECTION_ID
}
return when (idForPosition) {
DEFAULT_HOME_SECTION_ID -> if (isIconsPicker) defFragment else HomeFragment()
DEFAULT_ICONS_SECTION_ID -> IconsFragment.create(pickerKey)
DEFAULT_WALLPAPERS_SECTION_ID ->
if (isIconsPicker) defFragment else WallpapersFragment.create(withChecker)
DEFAULT_APPLY_SECTION_ID -> if (isIconsPicker) defFragment else ApplyFragment()
DEFAULT_REQUEST_SECTION_ID ->
if (isIconsPicker) defFragment else RequestsFragment.create(withDebug)
else -> defFragment
}
}

override fun getCount(): Int = navItems.size
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class BottomNavigationBlueprintActivity : BaseBlueprintActivity() {
}

override fun navigateToItem(item: NavigationItem, fromClick: Boolean, force: Boolean): Boolean {
if (!fromClick) bottomBar?.setCurrentItem(item.id, false)
if (!fromClick) bottomBar?.setCurrentItem(getNavigationItems().indexOf(item), false)
if (!hasBottomNavigation()) {
bottomBar?.hideBottomNavigation()
bottomBar?.gone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ abstract class DrawerBlueprintActivity : BaseBlueprintActivity(),

override fun navigateToItem(item: NavigationItem, fromClick: Boolean, force: Boolean): Boolean {
if (isIconsPicker) lockDrawer()
val itemId = getMenuIdForItemId(item.id)
val correctItem = itemId != R.id.nav_templates && itemId != R.id.nav_about &&
itemId != R.id.nav_settings && itemId != R.id.nav_help
navView?.menu?.findItem(itemId)?.isChecked = correctItem
return super.navigateToItem(item, fromClick, force)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ca.allanwang.kau.utils.dpToPx
import ca.allanwang.kau.utils.setPaddingBottom
import com.bumptech.glide.Glide
import com.pluscubed.recyclerfastscroll.RecyclerFastScroller
import jahirfiquitiva.libs.archhelpers.extensions.lazyViewModel
import jahirfiquitiva.libs.archhelpers.extensions.getViewModel
import jahirfiquitiva.libs.archhelpers.ui.fragments.ViewModelFragment
import jahirfiquitiva.libs.blueprint.R
import jahirfiquitiva.libs.blueprint.helpers.extensions.executeLauncherIntent
Expand All @@ -45,27 +45,27 @@ import jahirfiquitiva.libs.kuper.helpers.extensions.isAppInstalled
internal class ApplyFragment : ViewModelFragment<Launcher>() {

private var recyclerView: EmptyViewRecyclerView? = null
private val launchersViewModel: LaunchersViewModel by lazyViewModel()
private var launchersViewModel: LaunchersViewModel? = null

private val adapter: LaunchersAdapter by lazy {
LaunchersAdapter(context?.let { Glide.with(it) }) { onItemClicked(it, false) }
}

override fun registerObservers() {
launchersViewModel.observe(this) { setAdapterItems(it) }
override fun initViewModels() {
launchersViewModel = getViewModel()
}

override fun loadDataFromViewModel() {
context { launchersViewModel.loadData(it) }
override fun registerObservers() {
launchersViewModel?.observe(this) { setAdapterItems(it) }
}

override fun unregisterObservers() {
launchersViewModel.destroy(this)
override fun loadDataFromViewModel() {
context { launchersViewModel?.loadData(it) }
}

override fun onResume() {
super.onResume()
launchersViewModel.getData()?.let { setAdapterItems(it) }
launchersViewModel?.getData()?.let { setAdapterItems(it) }
}

override fun initUI(content: View) {
Expand Down Expand Up @@ -102,13 +102,13 @@ internal class ApplyFragment : ViewModelFragment<Launcher>() {
if (filter.hasContent()) {
recyclerView?.setEmptyImage(R.drawable.no_results)
recyclerView?.setEmptyText(R.string.search_no_results)
setAdapterItems(ArrayList(launchersViewModel.getData().orEmpty()).jfilter {
setAdapterItems(ArrayList(launchersViewModel?.getData().orEmpty()).jfilter {
it.name.contains(filter, true)
})
} else {
recyclerView?.setEmptyImage(R.drawable.empty_section)
recyclerView?.setEmptyText(R.string.empty_section)
setAdapterItems(ArrayList(launchersViewModel.getData().orEmpty()))
setAdapterItems(ArrayList(launchersViewModel?.getData().orEmpty()))
}
if (!closed)
scrollToTop()
Expand Down
Loading

0 comments on commit b19f0e8

Please sign in to comment.