Skip to content

Commit

Permalink
* Migration to AndroidX libraries (#2)
Browse files Browse the repository at this point in the history
* Updated kotlin plugins
* Publish gradle script changed
* Updated sample app code using view binding feature
* Updated maven plugin setup
* Set latest SDK support to Version 30
* Updated style attributes for sliderType
  • Loading branch information
BhavnikDesai authored Sep 1, 2021
1 parent 8524871 commit fd0699f
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 149 deletions.
26 changes: 13 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
compileSdkVersion 30
defaultConfig {
applicationId "com.example.minavigationdrawer"
minSdkVersion 21
targetSdkVersion 27
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation project(':midrawer')
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.minavigationdrawer

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -18,7 +18,7 @@ class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
val appContext = androidx.test.platform.app.InstrumentationRegistry.getTargetContext()
assertEquals("com.example.harsh.minavigationdrawer", appContext.packageName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package com.example.minavigationdrawer
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.support.v4.view.GravityCompat
import android.support.v7.app.AppCompatActivity
import androidx.core.view.GravityCompat
import androidx.appcompat.app.AppCompatActivity
import android.util.Log
import android.view.MenuItem
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
import com.example.minavigationdrawer.databinding.ActivityMainBinding
import com.mindinventory.midrawer.MIDrawerView
import com.mindinventory.midrawer.MIDrawerView.Companion.MI_TYPE_DOOR_IN
import com.mindinventory.midrawer.MIDrawerView.Companion.MI_TYPE_DOOR_OUT
Expand All @@ -20,27 +19,29 @@ class MIDrawerActivity : AppCompatActivity(), View.OnClickListener {

val TAG = "MIDrawerActivity"
private var slideType = 0
private lateinit var activityMainBinding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
activityMainBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(activityMainBinding.root)

// Set color for the container's content as transparent
drawer_layout.setScrimColor(Color.TRANSPARENT)
activityMainBinding.drawerLayout.setScrimColor(Color.TRANSPARENT)

nav_scroll.setOnClickListener(this)
nav_slide.setOnClickListener(this)
nav_doorIn.setOnClickListener(this)
nav_doorOut.setOnClickListener(this)
activityMainBinding.navScroll.setOnClickListener(this)
activityMainBinding.navSlide.setOnClickListener(this)
activityMainBinding.navDoorIn.setOnClickListener(this)
activityMainBinding.navDoorOut.setOnClickListener(this)

setSupportActionBar(toolbar)
setSupportActionBar(activityMainBinding.includeToolbar.toolbar)

val actionbar = supportActionBar
actionbar?.setDisplayHomeAsUpEnabled(true)
actionbar?.setHomeAsUpIndicator(R.drawable.ic_action_name)

// Implement the drawer listener
drawer_layout.setMIDrawerListener(object : MIDrawerView.MIDrawerEvents {
activityMainBinding.drawerLayout.setMIDrawerListener(object : MIDrawerView.MIDrawerEvents {
override fun onDrawerOpened(drawerView: View) {
super.onDrawerOpened(drawerView)
Log.d(TAG, "Drawer Opened")
Expand All @@ -54,8 +55,8 @@ class MIDrawerActivity : AppCompatActivity(), View.OnClickListener {
}

override fun onBackPressed() {
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
drawer_layout.closeDrawer(GravityCompat.START)
if (activityMainBinding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
activityMainBinding.drawerLayout.closeDrawer(GravityCompat.START)
} else {
super.onBackPressed()
}
Expand All @@ -64,22 +65,22 @@ class MIDrawerActivity : AppCompatActivity(), View.OnClickListener {
override fun onClick(v: View) {
when (v.id) {
R.id.nav_scroll -> {
avoidDoubleClicks(nav_scroll)
avoidDoubleClicks(activityMainBinding.navScroll)
slideType = MI_TYPE_SLIDE_WITH_CONTENT
updateSliderTypeEvents()
}
R.id.nav_slide -> {
avoidDoubleClicks(nav_slide)
avoidDoubleClicks(activityMainBinding.navSlide)
slideType = MI_TYPE_SLIDE
updateSliderTypeEvents()
}
R.id.nav_doorIn -> {
avoidDoubleClicks(nav_doorIn)
avoidDoubleClicks(activityMainBinding.navDoorIn)
slideType = MI_TYPE_DOOR_IN
updateSliderTypeEvents()
}
R.id.nav_doorOut -> {
avoidDoubleClicks(nav_doorIn)
avoidDoubleClicks(activityMainBinding.navDoorIn)
slideType = MI_TYPE_DOOR_OUT
updateSliderTypeEvents()
}
Expand All @@ -89,7 +90,7 @@ class MIDrawerActivity : AppCompatActivity(), View.OnClickListener {
private fun updateSliderTypeEvents() {
if (handler == null) {
handler = Handler()
drawer_layout.closeDrawer(GravityCompat.START)
activityMainBinding.drawerLayout.closeDrawer(GravityCompat.START)
handler?.postDelayed(runnable, 500)
}
}
Expand All @@ -98,26 +99,26 @@ class MIDrawerActivity : AppCompatActivity(), View.OnClickListener {
var runnable: Runnable = Runnable {
when (slideType) {
MI_TYPE_SLIDE_WITH_CONTENT -> {
toolbar.title = this@MIDrawerActivity.resources.getString(R.string.scroll)
activityMainBinding.includeToolbar.toolbar.title = this@MIDrawerActivity.resources.getString(R.string.scroll)
}
MI_TYPE_SLIDE -> {
toolbar.title = this@MIDrawerActivity.resources.getString(R.string.slide)
activityMainBinding.includeToolbar.toolbar.title = this@MIDrawerActivity.resources.getString(R.string.slide)
}
MI_TYPE_DOOR_IN -> {
toolbar.title = this@MIDrawerActivity.resources.getString(R.string.doorIn)
activityMainBinding.includeToolbar.toolbar.title = this@MIDrawerActivity.resources.getString(R.string.doorIn)
}
MI_TYPE_DOOR_OUT -> {
toolbar.title = this@MIDrawerActivity.resources.getString(R.string.doorOut)
activityMainBinding.includeToolbar.toolbar.title = this@MIDrawerActivity.resources.getString(R.string.doorOut)
}
}
drawer_layout.setSliderType(slideType)
activityMainBinding.drawerLayout.setSliderType(slideType)
handler = null
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
drawer_layout.openDrawer(GravityCompat.START)
activityMainBinding.drawerLayout.openDrawer(GravityCompat.START)
return true
}
}
Expand Down
26 changes: 13 additions & 13 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mindinventory.midrawer.MIDrawerView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.mindinventory.midrawer.MIDrawerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_gradient"
android:fitsSystemWindows="true"
app:sliderType="doorIn"
app:sliderType="scroll"
tools:openDrawer="start">

<include
android:id="@+id/include_toolbar"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<android.support.design.widget.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
Expand All @@ -39,9 +39,9 @@
android:drawableTint="@android:color/white"
android:gravity="center_vertical"
android:padding="20dp"
android:textStyle="bold"
android:text="@string/scroll"
android:textColor="@android:color/white" />
android:textColor="@android:color/white"
android:textStyle="bold" />

<View
android:layout_width="match_parent"
Expand All @@ -59,9 +59,9 @@
android:drawableTint="@android:color/white"
android:gravity="center_vertical"
android:padding="20dp"
android:textStyle="bold"
android:text="@string/slide"
android:textColor="@android:color/white" />
android:textColor="@android:color/white"
android:textStyle="bold" />

<View
android:layout_width="match_parent"
Expand All @@ -79,9 +79,9 @@
android:drawableTint="@android:color/white"
android:gravity="center_vertical"
android:padding="20dp"
android:textStyle="bold"
android:text="@string/doorIn"
android:textColor="@android:color/white" />
android:textColor="@android:color/white"
android:textStyle="bold" />

<View
android:layout_width="match_parent"
Expand All @@ -99,9 +99,9 @@
android:drawableTint="@android:color/white"
android:gravity="center_vertical"
android:padding="20dp"
android:textStyle="bold"
android:text="@string/doorOut"
android:textColor="@android:color/white" />
android:textColor="@android:color/white"
android:textStyle="bold" />

<View
android:layout_width="match_parent"
Expand All @@ -112,6 +112,6 @@

</LinearLayout>

</android.support.design.widget.NavigationView>
</com.google.android.material.navigation.NavigationView>

</com.mindinventory.midrawer.MIDrawerView>
13 changes: 7 additions & 6 deletions app/src/main/res/layout/app_bar_main.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="@string/doorIn"
app:title="@string/scroll"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>
</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_main" />

</android.support.design.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -13,4 +13,4 @@
android:src="@drawable/mind"
android:scaleType="centerCrop"/>

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
7 changes: 6 additions & 1 deletion app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MIDrawerView">
<attr name="sliderType" format="integer" />
<attr name="sliderType" format="integer" >
<enum name="scroll" value="1"/>
<enum name="doorIn" value="2"/>
<enum name="doorOut" value="3"/>
<enum name="slide" value="4"/>
</attr>
</declare-styleable>
</resources>
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.31'
ext.kotlin_version = '1.5.21'
repositories {
google()
jcenter()
// jcenter()
// mavenCentral()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "com.android.tools.build:gradle:7.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// classpath("com.github.dcendents:android-maven-gradle-plugin:2.1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -21,6 +25,7 @@ allprojects {
google()
jcenter()
maven { url 'https://jitpack.io' }
mavenCentral()
}
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sat Apr 21 15:47:16 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Empty file modified gradlew
100644 → 100755
Empty file.
Loading

0 comments on commit fd0699f

Please sign in to comment.