Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Share button & Gradle Kotlin DSL #23

Merged
merged 4 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ It simply loads **Posts** data from API and stores it in persistence storage (i.
- [Moshi Converter](https://github.com/square/retrofit/tree/master/retrofit-converters/moshi) - A Converter which uses Moshi for serialization to and from JSON.
- [Coil-kt](https://coil-kt.github.io/coil/) - An image loading library for Android backed by Kotlin Coroutines.
- [Material Components for Android](https://github.com/material-components/material-components-android) - Modular and customizable Material Design UI components for Android.
- [Gradle Kotlin DSL](https://docs.gradle.org/current/userguide/kotlin_dsl.html) - For writing Gradle build scripts using Kotlin.


## Want [`Koin`](https://insert-koin.io/) DI Version?
Expand Down
131 changes: 0 additions & 131 deletions app/build.gradle

This file was deleted.

135 changes: 135 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* MIT License
*
* Copyright (c) 2020 Shreyas Patil
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
id("kotlin-android-extensions")
}

android {
compileSdkVersion(29)
buildToolsVersion("29.0.3")

defaultConfig {
applicationId = "dev.shreyaspatil.foodium"
minSdkVersion(21)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
annotationProcessorOptions {
arguments = hashMapOf(
"room.schemaLocation" to "$projectDir/schemas",
"room.incremental" to "true",
"room.expandProjection" to "true"
)
}
}
}

viewBinding {
isEnabled = true
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

// Kotlin
implementation(Dependencies.kotlin)

// Coroutines
implementation(Coroutines.core)
implementation(Coroutines.android)

// Android
implementation(Android.appcompat)
implementation(Android.ktx)
implementation(Android.constraintLayout)
implementation(Android.swipeRefreshLayout)

// Architecture Components
implementation(Dependencies.viewModel)
implementation(Dependencies.liveData)

// Room components
implementation(Room.runtime)
kapt(Room.compiler)
implementation(Room.ktx)

// Material Design
implementation(Dependencies.materialDesign)
implementation(Dependencies.materialDialog)

// Coil-kt
implementation(Dependencies.coil)

// Retrofit
implementation(Dependencies.retrofit)

// Moshi
implementation(Moshi.kotlin)
implementation(Moshi.retrofitConverter)
kapt(Moshi.codeGen)

// Dagger 2
implementation(Dagger.dagger)
kapt(Dagger.compiler)
implementation(Dagger.android)
implementation(Dagger.support)
kapt(Dagger.processor)

// Testing
testImplementation(Testing.core)
testImplementation(Testing.coroutines)
testImplementation(Testing.room)
testImplementation(Testing.okHttp)
testImplementation(Testing.jUnit)
androidTestImplementation(Testing.extJUnit)
androidTestImplementation(Testing.espresso)
}
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
package dev.shreyaspatil.foodium.ui.details

import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.core.app.ShareCompat
import androidx.lifecycle.Observer
import coil.api.load
import dev.shreyaspatil.foodium.R
import dev.shreyaspatil.foodium.databinding.ActivityPostDetailsBinding
import dev.shreyaspatil.foodium.model.Post
import dev.shreyaspatil.foodium.ui.base.BaseActivity
import dev.shreyaspatil.foodium.utils.viewModelOf
import kotlinx.android.synthetic.main.activity_post_details.*
Expand All @@ -37,6 +41,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
@ExperimentalCoroutinesApi
class PostDetailsActivity : BaseActivity<PostDetailsViewModel, ActivityPostDetailsBinding>() {

private lateinit var post: Post

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(mViewBinding.root)
Expand All @@ -53,6 +59,8 @@ class PostDetailsActivity : BaseActivity<PostDetailsViewModel, ActivityPostDetai
private fun initPost(postId: Int) {
mViewModel.getPost(postId).observe(this, Observer { post ->
mViewBinding.postContent.apply {
this@PostDetailsActivity.post = post

postTitle.text = post.title
postAuthor.text = post.author
postBody.text = post.body
Expand All @@ -61,8 +69,9 @@ class PostDetailsActivity : BaseActivity<PostDetailsViewModel, ActivityPostDetai
})
}

companion object {
const val POST_ID = "postId"
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.detail_menu, menu)
return true
}

override fun getViewBinding(): ActivityPostDetailsBinding =
Expand All @@ -76,8 +85,28 @@ class PostDetailsActivity : BaseActivity<PostDetailsViewModel, ActivityPostDetai
supportFinishAfterTransition()
return true
}

R.id.action_share -> {
val shareMsg = """
"${post.title}" by ${post.author} on Foodium App
""".trimIndent()

val intent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setText(shareMsg)
.intent

if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
}
return true
}
}

return super.onOptionsItemSelected(item)
}

companion object {
const val POST_ID = "postId"
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable-v24/ic_share.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/menu/detail_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_share"
android:title="Share"
app:showAsAction="always" />
</menu>
Loading