Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinnor committed Oct 18, 2020
2 parents 74d0ab0 + 9fe3130 commit 6ae1ce2
Show file tree
Hide file tree
Showing 36 changed files with 418 additions and 60 deletions.
18 changes: 18 additions & 0 deletions app/src/main/java/com/calvinnor/movieman/app/Main.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
package com.calvinnor.movieman.app

import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatDelegate
import com.calvinnor.core.application.CoreApp
import com.calvinnor.core.utils.emptyString
import com.calvinnor.data.AppDb
import com.calvinnor.data.preferences.PREFS_APP_THEME
import com.calvinnor.data.preferences.themePreferenceToAppCompatTheme
import com.calvinnor.data.util.daoModule
import com.calvinnor.data.util.webServiceModule
import org.koin.android.ext.android.inject

/**
* Android's Application class.
* Use for 3rd party library init and other setup.
*/
class Main : CoreApp() {

private val sharedPreferences: SharedPreferences by inject()

override fun onCreate() {
super.onCreate()
initialiseAppTheme()
}

private fun initialiseAppTheme() {
val themeId = sharedPreferences.getString(PREFS_APP_THEME, emptyString()) ?: emptyString()
AppCompatDelegate.setDefaultNightMode(themePreferenceToAppCompatTheme(themeId))
}

override fun getDataModules() = arrayOf(
daoModule(AppDb.getDatabase(applicationContext)),
webServiceModule
Expand Down
33 changes: 18 additions & 15 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ object Modules {
const val core = ":core"
const val data = ":data"
const val movie = ":movie"
const val settings = ":settings"

val allModules = arrayOf(app, core, data, movie)
val allModules = arrayOf(app, core, data, movie, settings)
}

object App {

const val compileSdk = 29
const val compileSdk = 30
const val targetSdk = compileSdk
const val minSdk = 21

Expand All @@ -53,19 +54,20 @@ object Versions {

// Gradle
const val gradleTools = "4.0.0"
const val dependencyUpdates = "0.28.0"
const val dependencyUpdates = "0.33.0"

// Kotlin
const val kotlinVersion = "1.3.72"
const val kotlinVersion = "1.4.10"

// AndroidX
const val appCompat = "1.1.0"
const val appCompat = "1.2.0"
const val recyclerView = "1.1.0"
const val swipeRefreshLayout = "1.1.0"
const val materialComponents = "1.1.0"
const val constraintLayout = "1.1.3"
const val materialComponents = "1.2.1"
const val constraintLayout = "2.0.2"
const val palette = "1.0.0"
const val navigationComponent = "2.3.0"
const val navigationComponent = "2.3.1"
const val preferenceKtx = "1.1.1"

// ViewModel + LiveData
const val arch_viewModelLiveData = "2.2.0"
Expand All @@ -74,7 +76,7 @@ object Versions {
const val arch_RoomCoroutines = "2.1.0-alpha04"

// Moshi
const val moshi = "1.9.3"
const val moshi = "1.11.0"
const val moshiRetrofitConverter = "2.9.0"

// Coroutines
Expand All @@ -91,26 +93,26 @@ object Versions {
const val glide = "4.11.0"

// Koin
const val koin = "2.0.1"
const val koin = "2.2.0-rc-3"

// KTX
const val ktx_Core = "1.3.0"
const val ktx_Core = "1.3.2"
const val ktx_Fragment = "1.2.5"
const val ktx_Palette = "1.0.0"
const val ktx_Collections = "1.1.0"
const val ktx_LifecycleViewModel = "2.1.0"
const val ktx_LifecycleViewModel = "2.2.0"
const val ktx_ReactiveStreams = ktx_LifecycleViewModel

// Firebase
const val plugin_Firebase = "4.3.3"
const val deps_Firebase = "17.4.4"
const val plugin_Firebase = "4.3.4"
const val deps_Firebase = "17.5.1"

// Crashlytics
const val plugin_fabricCrashlytics = "1.31.2"
const val deps_fabricCrashlytics = "2.10.1"

// Testing
const val test_JUnit = "4.13"
const val test_JUnit = "4.13.1"

// Mockito
const val mockitoKotlin = "2.1.0"
Expand All @@ -137,6 +139,7 @@ object Dependencies {
const val materialComponents =
"com.google.android.material:material:${Versions.materialComponents}"
const val palette = "androidx.palette:palette:${Versions.palette}"
const val preferenceKtx = "androidx.preference:preference-ktx:${Versions.preferenceKtx}"

// ViewModel + Lifecycle
const val arch_ViewModelLiveData =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ fun View.closeKeyboard() {
getSystemService(context, InputMethodManager::class.java)
?.hideSoftInputFromWindow(windowToken, 0)
}

fun View.focusAndOpenKeyboard() {
this.requestFocus()
getSystemService(context, InputMethodManager::class.java)
?.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package com.calvinnor.core.extensions

import android.content.Context
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment

fun Context.colorFrom(@ColorRes colorRes: Int) = ContextCompat.getColor(this, colorRes)

fun Fragment.colorFrom(@ColorRes colorRes: Int) =
ContextCompat.getColor(context as Context, colorRes)

fun Context.drawableFrom(@DrawableRes drawableId: Int) = ContextCompat.getDrawable(this, drawableId)
16 changes: 0 additions & 16 deletions core/src/main/java/com/calvinnor/core/utils/ThemeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.calvinnor.core.utils
import android.app.Activity
import android.content.res.Configuration
import android.content.res.Resources
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import androidx.fragment.app.Fragment

val Fragment.uiTheme: Theme
Expand All @@ -13,20 +11,6 @@ val Fragment.uiTheme: Theme
val Activity.uiTheme: Theme
get() = uiTheme(resources)

fun Theme.invert() = when (this) {
Theme.LIGHT -> Theme.NIGHT
Theme.NIGHT -> Theme.LIGHT
}

/**
* Returns the MODE to be used with AppCompatDelegate.
*/
val Theme.appCompatMode: Int
get() = when (this) {
Theme.NIGHT -> MODE_NIGHT_YES
Theme.LIGHT -> MODE_NIGHT_NO
}

private fun uiTheme(resources: Resources?): Theme =
when (resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)) {
Configuration.UI_MODE_NIGHT_YES -> Theme.NIGHT
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/res/drawable/ic_navigate_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@color/colorPrimaryReverse"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />

</vector>
2 changes: 1 addition & 1 deletion core/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<color name="text_hint">#80FFFFFF</color>
<color name="text_disabled">@color/text_hint</color>

<color name="window_background">#222</color>
<color name="windowBackground">#0F0F0F</color>

</resources>
2 changes: 1 addition & 1 deletion core/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<color name="text_hint">#80FFFFFF</color>
<color name="text_disabled">@color/text_hint</color>

<color name="window_background">#EEE</color>
<color name="windowBackground">#F0F0F0</color>

</resources>
1 change: 1 addition & 0 deletions core/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<dimen name="text_small">16sp</dimen>

<!-- Margins -->
<dimen name="margin_xl">32dp</dimen>
<dimen name="margin_large">16dp</dimen>
<dimen name="margin_medium">8dp</dimen>
<dimen name="margin_small">4dp</dimen>
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/window_background</item>
<item name="android:windowBackground">@color/windowBackground</item>
<item name="android:textColor">@color/text_primary</item>
</style>

<style name="NoToolbarTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/window_background</item>
<item name="android:windowBackground">@color/windowBackground</item>
<item name="android:textColor">@color/text_primary</item>
</style>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.calvinnor.data.preferences

import androidx.appcompat.app.AppCompatDelegate

@AppCompatDelegate.NightMode
fun themePreferenceToAppCompatTheme(themeId: String) = when (themeId) {
PREFS_APP_THEME_VALUE_AUTO -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
PREFS_APP_THEME_VALUE_LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
PREFS_APP_THEME_VALUE_NIGHT -> AppCompatDelegate.MODE_NIGHT_YES
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.calvinnor.data.preferences

/** App Theme **/
const val PREFS_APP_THEME = "app_theme"
const val PREFS_APP_THEME_VALUE_AUTO = "auto"
const val PREFS_APP_THEME_VALUE_NIGHT = "night"
const val PREFS_APP_THEME_VALUE_LIGHT = "light"
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
1 change: 1 addition & 0 deletions movie/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {

implementation(project(Modules.core))
implementation(project(Modules.data))
implementation(project(Modules.settings))

// TODO: Move to a Gradle script to be imported from all features

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.calvinnor.movie.details.ui

import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.view.ViewAnimationUtils
Expand Down Expand Up @@ -137,6 +139,8 @@ class MovieDetailsFragment : BaseFragment(R.layout.fragment_movie_details) {
)

groupDetails.isVisible = true

llOpenInTmdb.setOnClickListener { openMovieOnTmdb() }
}

private fun extractDarkColorAndCircularReveal(bitmap: Bitmap) {
Expand Down Expand Up @@ -183,6 +187,15 @@ class MovieDetailsFragment : BaseFragment(R.layout.fragment_movie_details) {
}
}

private fun openMovieOnTmdb() {
startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://www.themoviedb.org/movie/${navArgs.movieUiModel.id}")
)
)
}

companion object {
const val TAG = "MovieDetailsFragment"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package com.calvinnor.movie.discover.ui

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatDelegate
import androidx.navigation.findNavController
import androidx.navigation.fragment.FragmentNavigator
import androidx.navigation.fragment.findNavController
import com.calvinnor.core.ui.BaseFragment
import com.calvinnor.core.utils.*
import com.calvinnor.core.utils.showToast
import com.calvinnor.movie.R
import com.calvinnor.movie.commons.model.MovieUiModel
import com.calvinnor.movie.commons.model.MoviesSection
Expand Down Expand Up @@ -43,20 +42,13 @@ class DiscoverMoviesFragment : BaseFragment(R.layout.fragment_discover_movies),

private fun setupBottomAppBar() = bottomAppBar.run {
replaceMenu(R.menu.menu_discover)
menu.findItem(R.id.menu_toggle_theme).setIcon(
when (uiTheme) {
Theme.NIGHT -> R.drawable.ic_theme_night
Theme.LIGHT -> R.drawable.ic_theme_light
}
)
setOnMenuItemClickListener {
return@setOnMenuItemClickListener when (it.itemId) {
R.id.menu_search -> {
navigateToSearch(); true
}
R.id.menu_toggle_theme -> {
AppCompatDelegate.setDefaultNightMode(uiTheme.invert().appCompatMode)
true
R.id.menu_settings -> {
findNavController().navigate(R.id.navigateToSettings); true
}
R.id.menu_about -> {
// TODO(calvinnor): Pick up from BuildConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import androidx.appcompat.widget.SearchView
import com.calvinnor.core.domain.Result
import com.calvinnor.core.extensions.closeKeyboard
import com.calvinnor.core.extensions.focusAndOpenKeyboard
import com.calvinnor.core.extensions.observe
import com.calvinnor.core.pagination.Pagination
import com.calvinnor.core.pagination.PaginationListener
Expand Down Expand Up @@ -76,7 +77,7 @@ class SearchMoviesFragment : BaseFragment(R.layout.fragment_search_movies), Pagi
}
}

private fun focusOnSearch() = svMovies.requestFocus()
private fun focusOnSearch() = svMovies.focusAndOpenKeyboard()

private fun showError(ex: Throwable) {
// TODO
Expand Down
11 changes: 11 additions & 0 deletions movie/src/main/res/drawable/ic_menu_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@color/colorPrimaryReverse"
android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98 0,-0.34 -0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.09,-0.16 -0.26,-0.25 -0.44,-0.25 -0.06,0 -0.12,0.01 -0.17,0.03l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.06,-0.02 -0.12,-0.03 -0.18,-0.03 -0.17,0 -0.34,0.09 -0.43,0.25l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98 0,0.33 0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.09,0.16 0.26,0.25 0.44,0.25 0.06,0 0.12,-0.01 0.17,-0.03l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.06,0.02 0.12,0.03 0.18,0.03 0.17,0 0.34,-0.09 0.43,-0.25l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM17.45,11.27c0.04,0.31 0.05,0.52 0.05,0.73 0,0.21 -0.02,0.43 -0.05,0.73l-0.14,1.13 0.89,0.7 1.08,0.84 -0.7,1.21 -1.27,-0.51 -1.04,-0.42 -0.9,0.68c-0.43,0.32 -0.84,0.56 -1.25,0.73l-1.06,0.43 -0.16,1.13 -0.2,1.35h-1.4l-0.19,-1.35 -0.16,-1.13 -1.06,-0.43c-0.43,-0.18 -0.83,-0.41 -1.23,-0.71l-0.91,-0.7 -1.06,0.43 -1.27,0.51 -0.7,-1.21 1.08,-0.84 0.89,-0.7 -0.14,-1.13c-0.03,-0.31 -0.05,-0.54 -0.05,-0.74s0.02,-0.43 0.05,-0.73l0.14,-1.13 -0.89,-0.7 -1.08,-0.84 0.7,-1.21 1.27,0.51 1.04,0.42 0.9,-0.68c0.43,-0.32 0.84,-0.56 1.25,-0.73l1.06,-0.43 0.16,-1.13 0.2,-1.35h1.39l0.19,1.35 0.16,1.13 1.06,0.43c0.43,0.18 0.83,0.41 1.23,0.71l0.91,0.7 1.06,-0.43 1.27,-0.51 0.7,1.21 -1.07,0.85 -0.89,0.7 0.14,1.13zM12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z" />

</vector>
11 changes: 11 additions & 0 deletions movie/src/main/res/drawable/ic_open_in_new.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@color/colorPrimaryReverse"
android:pathData="M19,19H5V5h7V3H5c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2v-7h-2v7zM14,3v2h3.59l-9.83,9.83 1.41,1.41L19,6.41V10h2V3h-7z" />

</vector>
Loading

0 comments on commit 6ae1ce2

Please sign in to comment.