Skip to content

Commit

Permalink
Develop (#35)
Browse files Browse the repository at this point in the history
* feat: add copyright to all the files
fix: alert dialog dsl

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: add documentation for edit-text extensions
feat: add ontextchange extension
refactor: simplfy textwatcher dsl

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: add documentation for remaining files

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* refactor: use only one variable to get string from resource

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* fix: add missing comments
refactor: improve code quality

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: implement dsl markers

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: refactor documentation
refactor: remove redundant parenthesis
feat: add more extensions
feat: implement detekt for code quality

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: add missing docs
fix: unsafe cast

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* fix: too generic exception warning

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* chore: update gradle dependencies
feat: migrate to androidx

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* refactor: androidx imports

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* fix: incorrect import of constraint layout

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: update alert dialog
refactor: remove copyrights

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: add updated copyrights

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: add gson extensions
feat: add view pager extensions
feat: add shared preferences extensions

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* doc: update copyrights

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* feat: add develop branch for travis

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>

* fix: missing null check

* refactor: use expression body functions

Signed-off-by: BirjuVachhani <brvachhani@gmail.com>
  • Loading branch information
BirjuVachhani committed Feb 2, 2019
1 parent 5d8b5ae commit eb52078
Show file tree
Hide file tree
Showing 23 changed files with 521 additions and 219 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ before_install:
- chmod +x gradlew
branches:
only:
- master
- master
- develop
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(':bext')
}
23 changes: 13 additions & 10 deletions app/src/main/java/com/birjuvachhani/baseextensions/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2018 BirjuVachhani
* </p>
* Copyright 2019 BirjuVachhani (https://github.com/BirjuVachhani)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* </p>
* http://www.apache.org/licenses/LICENSE-2.0
* </p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
Expand All @@ -17,10 +17,10 @@
package com.birjuvachhani.baseextensions

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.bext.alertDialog
import com.bext.toast
import kotlinx.android.synthetic.main.activity_main.*

/**
* Main Activity class to handle handle MainActivity UI
Expand All @@ -31,24 +31,27 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnShowDialog.setOnClickListener {
displayDialog()
}
}

/**
* This will be executed on the button click in main activity
*
* */
fun displayDialog(v: View) {
private fun displayDialog() {
alertDialog {
title = "Tips"
message = "This is the awesome form of kotlin DSL."
positiveButton {
text = from(R.string.positive)
text = R.string.positive
onClick {
toast("Cool")
}
}
negativeButton {
text = from(R.string.negative)
text = R.string.negative
onClick {
toast("Whatever")
}
Expand Down
37 changes: 10 additions & 27 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2018 BirjuVachhani
~ </p>
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~ </p>
~ http://www.apache.org/licenses/LICENSE-2.0
~ </p>
~ 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.
-->

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:text="Show Dialog"
android:onClick="displayDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:id="@+id/btnShowDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Dialog" />

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 3 additions & 2 deletions bext/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ android {

dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:appcompat-v7:28.0.0'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.0"
api 'androidx.appcompat:appcompat:1.1.0-alpha01'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.20"
api 'com.google.code.gson:gson:2.8.5'
}
repositories {
mavenCentral()
Expand Down
21 changes: 4 additions & 17 deletions bext/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<!--
~ Copyright 2018 BirjuVachhani
~ </p>
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~ </p>
~ http://www.apache.org/licenses/LICENSE-2.0
~ </p>
~ 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bext">

<manifest
package="com.bext"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
52 changes: 30 additions & 22 deletions bext/src/main/java/com/bext/ActivityExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2018 BirjuVachhani
* </p>
* Copyright 2019 BirjuVachhani (https://github.com/BirjuVachhani)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* </p>
* http://www.apache.org/licenses/LICENSE-2.0
* </p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
Expand All @@ -19,24 +19,23 @@ package com.bext
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Handler
import android.support.v4.app.FragmentTransaction
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction

/**
* Created by Birju Vachhani on 13/11/18.
*/

/**
* Extension function to hide soft keyboard
* Extension function to hide soft keyboard for activity
* */
fun Activity.hideKeyboard() = Handler().post {
(getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager)
?.hideSoftInputFromWindow(
this.findViewById<View>(android.R.id.content).windowToken, 0
)
fun Activity.hideKeyboard() = postHandler {
getService<InputMethodManager>(Context.INPUT_METHOD_SERVICE)?.hideSoftInputFromWindow(
this.findViewById<View>(android.R.id.content).windowToken, 0
)
}

/**
Expand All @@ -45,11 +44,8 @@ fun Activity.hideKeyboard() = Handler().post {
* to perform action on to the [Intent] which will be used to start Activity
* T takes name of the destination [Activity]
* */
inline fun <reified T : Activity> Activity.navigateTo(func: Intent.() -> Unit = {}) {
val intent = Intent(this, T::class.java)
intent.func()
this.startActivity(intent)
}
inline fun <reified T : Activity> Activity.navigateTo(func: Intent.() -> Unit = {}) =
this.startActivity(Intent(this, T::class.java).apply(func))

/**
* Extension function to start/launch new [Activity] without passing any data
Expand All @@ -64,6 +60,18 @@ inline fun <reified T : Activity> Activity.navigateTo() =
* used to process [FragmentTransaction]
* */
fun AppCompatActivity.transact(func: FragmentTransaction.() -> Unit) =
this.supportFragmentManager.beginTransaction().apply {
func()
}.commit()
this.supportFragmentManager.beginTransaction().apply(func).commit()

/**
* Extension function to start/launch new [Activity] for result without passing any data
* */
inline fun <reified T : Activity> Activity.navigateForResultTo(requestCode: Int) =
this.startActivityForResult(Intent(this, T::class.java), requestCode)

/**
* Extension function to start/launch new [Activity] for result
* @param func is a lambda function with [Intent]'s receiver which provides a lambda block
* to perform action on to the [Intent] which will be used to start Activity
* */
inline fun <reified T : Activity> Activity.navigateForResultTo(requestCode: Int, func: Intent.() -> Unit = {}) =
this.startActivityForResult(Intent(this, T::class.java).apply(func), requestCode)
Loading

0 comments on commit eb52078

Please sign in to comment.