Skip to content

Commit

Permalink
Stop using MaterialDrawer (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Jul 6, 2018
1 parent a47ca67 commit cc99934
Show file tree
Hide file tree
Showing 17 changed files with 429 additions and 238 deletions.
2 changes: 2 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
public *;
}

-keep class android.support.design.widget.NavigationView { *; }

-keep public class android.app.ActivityTransitionCoordinator
-keep class jahirfiquitiva.libs.frames.** { *; }
-keep class jahirfiquitiva.libs.kuper.** { *; }
Expand Down
35 changes: 16 additions & 19 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
*/
ext.versions = [
// Projects
minSdk : 16,
targetSdk : 27,
buildTools : '27.0.3',
minSdk : 16,
targetSdk : 27,
buildTools : '27.0.3',
// Versions:
versionCode : 124,
versionName : '1.2.4',
versionCode: 124,
versionName: '1.2.4',
// Gradle Plugins
gradle : '3.1.3',
kotlin : '1.2.51',
libs : '2.1',
gradle : '3.1.3',
kotlin : '1.2.51',
libs : '2.1',
// Dependencies
kuper : '1.4.2',
materialDrawer: '6.0.8',
counterFab : '1.0.3',
fuel : '1.13.0',
oneSignal : '3.8.3'
kuper : '1.4.2',
counterFab : '1.0.3',
fuel : '1.13.0',
oneSignal : '3.8.3'
]

ext.gradlePlugins = [
Expand All @@ -41,13 +40,11 @@ ext.gradlePlugins = [

ext.libraries = [
// Kuper
kuper : 'com.jahirfiquitiva:Kuper:' + versions.kuper + '@aar',
// Material Drawer
materialDrawer: 'com.mikepenz:materialdrawer:' + versions.materialDrawer + '@aar',
kuper : 'com.jahirfiquitiva:Kuper:' + versions.kuper + '@aar',
// CounterFab
counterFab : 'com.github.andremion:counterfab:' + versions.counterFab,
counterFab: 'com.github.andremion:counterfab:' + versions.counterFab,
// Fuel
fuel : 'com.github.kittinunf.fuel:fuel-android:' + versions.fuel,
fuel : 'com.github.kittinunf.fuel:fuel-android:' + versions.fuel,
// OneSignal
oneSignal : 'com.onesignal:OneSignal:' + versions.oneSignal
oneSignal : 'com.onesignal:OneSignal:' + versions.oneSignal
]
14 changes: 0 additions & 14 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ dependencies {
exclude module: 'transition'
exclude module: 'mediarouter-v7'
exclude module: 'support-media-compat'
exclude module: 'support-v4'
}
// Navigation
api(libraries.materialDrawer) {
transitive = true
exclude group: 'com.android.support'
exclude module: 'constraint'
exclude module: 'transition'
exclude module: 'mediarouter-v7'
exclude module: 'support-media-compat'
exclude module: 'support-v4'
}
// Fuel
api libraries.fuel
Expand All @@ -102,9 +91,6 @@ configurations {
all*.exclude module: 'transition'
all*.exclude module: 'mediarouter-v7'
all*.exclude module: 'support-media-compat'
all*.exclude module: 'support-v4'
// all*.exclude module: 'iconics-core'
// all*.exclude module: 'fastadapter-extensions-expandable'
all*.exclude group: 'com.google.code'
}

Expand Down
2 changes: 2 additions & 0 deletions library/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
public *;
}

-keep class android.support.design.widget.NavigationView { *; }

-keep public class android.app.ActivityTransitionCoordinator
-keep class jahirfiquitiva.libs.frames.** { *; }
-keep class jahirfiquitiva.libs.kuper.** { *; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@
*/
package jahirfiquitiva.libs.blueprint.helpers.extensions

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.TypedArray
import android.os.Build
import android.support.annotation.AttrRes
import android.support.design.widget.FloatingActionButton
import android.support.v4.app.Fragment
import android.view.View
import ca.allanwang.kau.utils.dpToPx
import ca.allanwang.kau.utils.setPaddingTop
import jahirfiquitiva.libs.blueprint.R
import jahirfiquitiva.libs.blueprint.helpers.utils.BPKonfigs
import jahirfiquitiva.libs.kext.extensions.bind
import jahirfiquitiva.libs.kext.extensions.ctxt
import jahirfiquitiva.libs.kext.extensions.getStatusBarHeight
import jahirfiquitiva.libs.kext.ui.activities.ThemedActivity
import java.util.concurrent.TimeUnit
import kotlin.math.roundToInt

@Suppress("DEPRECATION", "UNCHECKED_CAST")
internal val Fragment.configs: BPKonfigs
Expand Down Expand Up @@ -52,6 +62,64 @@ fun Context.millisToText(millis: Long): String {
}
}

@SuppressLint("PrivateResource")
internal fun Context.setOptimalDrawerHeaderHeight(headerView: View) {
val ratio = 9.0 / 16.0
val defaultHeaderMinHeight = resources.getDimensionPixelSize(R.dimen.nav_header_height)
val statusBarHeight = getStatusBarHeight(true)
var height = getOptimalDrawerWidth() * ratio

if (Build.VERSION.SDK_INT < 19) {
val tempHeight = height - statusBarHeight
if (tempHeight > (defaultHeaderMinHeight - 8.dpToPx)) {
height = tempHeight
}
}

if (Build.VERSION.SDK_INT >= 21) {
headerView.setPaddingTop(headerView.paddingTop + statusBarHeight)
if ((height - statusBarHeight) <= defaultHeaderMinHeight) {
height = (defaultHeaderMinHeight + statusBarHeight).toDouble()
}
}

val finalHeight =
(if (Build.VERSION.SDK_INT >= 19) (height - statusBarHeight) else height).roundToInt()
headerView.post {
val params = headerView.layoutParams
params?.height = finalHeight
headerView.layoutParams = params

val headerBg: View? by headerView.bind(R.id.nav_header)
val bgParams = headerBg?.layoutParams
bgParams?.height = finalHeight
headerBg?.layoutParams = bgParams
}
}

@SuppressLint("PrivateResource")
internal fun Context.getOptimalDrawerWidth(): Int {
var actionBarHeight: Int = getThemeAttributeDimensionSize(R.attr.actionBarSize)
if (actionBarHeight == 0) {
actionBarHeight =
resources.getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material)
}

val possibleMinDrawerWidth = resources.displayMetrics.widthPixels - actionBarHeight
val maxDrawerWidth = resources.getDimensionPixelSize(R.dimen.nav_drawer_width)
return Math.min(possibleMinDrawerWidth, maxDrawerWidth)
}

internal fun Context.getThemeAttributeDimensionSize(@AttrRes attr: Int): Int {
var a: TypedArray? = null
try {
a = theme.obtainStyledAttributes(intArrayOf(attr))
return a?.getDimensionPixelSize(0, 0) ?: 0
} finally {
a?.recycle()
}
}

private fun Long.toWeeks() = TimeUnit.MILLISECONDS.toDays(this) / 7
private fun Long.toMonths() = toWeeks() / 4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ abstract class BaseBlueprintActivity : BaseFramesActivity<BPKonfigs>() {
abstract fun hasBottomNavigation(): Boolean
open fun debug(): Boolean = false

private val coordinatorLayout: CoordinatorLayout? by bind(R.id.mainCoordinatorLayout)
private val appbarLayout: FixedElevationAppBarLayout? by bind(R.id.appbar)
internal val coordinatorLayout: CoordinatorLayout? by bind(R.id.mainCoordinatorLayout)
internal val appbarLayout: FixedElevationAppBarLayout? by bind(R.id.appbar)

private val iconsFilters: ArrayList<Filter> = ArrayList()
private val activeFilters: ArrayList<Filter> = ArrayList()
Expand Down Expand Up @@ -130,7 +130,8 @@ abstract class BaseBlueprintActivity : BaseFramesActivity<BPKonfigs>() {
@SuppressLint("MissingSuperCall")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_blueprint)
setContentView(
if (hasBottomNavigation()) R.layout.activity_blueprint else R.layout.activity_w_drawer)
toolbar?.bindToActivity(this, false)
toolbar?.enableScroll(true)
initCurrentSectionId()
Expand Down
Loading

0 comments on commit cc99934

Please sign in to comment.