Skip to content

Commit

Permalink
Merge branch 'main' into view-binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Abrynos committed Feb 18, 2023
2 parents 56718ec + d4723da commit f6f9c35
Show file tree
Hide file tree
Showing 30 changed files with 256 additions and 85 deletions.
4 changes: 3 additions & 1 deletion .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/scopes/default_copyright_scope.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/scopes/xml.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Shopping list
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/Abrynos/ShoppingList/CI/main?label=Build&logo=github)
![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/Abrynos/ShoppingList/ci.yml?branch=main&label=Build&logo=github)
![GitHub release version](https://img.shields.io/github/v/release/Abrynos/ShoppingList?label=Stable&logo=github)
[![F-Droid release version](https://img.shields.io/f-droid/v/pl.edu.pjwstk.s999844.shoppinglist?label=F-Droid&logo=fdroid)](https://f-droid.org/packages/pl.edu.pjwstk.s999844.shoppinglist/)
[![Localization](https://badges.crowdin.net/abrynosshoppinglist/localized.svg)](https://crowdin.com/project/abrynosshoppinglist)
Expand Down
18 changes: 9 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ android {
applicationId "pl.edu.pjwstk.s999844.shoppinglist"
minSdkVersion 25
targetSdkVersion 33
versionCode 15
versionName "v1.13.0"
versionCode 16
versionName "v1.14.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -49,6 +49,7 @@ android {
arguments["room.incremental"] = "true"
}
}
signingConfig signingConfigs.debug
}
applicationVariants.all {
variant -> variant.resValue "string", "versionName", variant.versionName
Expand Down Expand Up @@ -96,23 +97,22 @@ android {
dependencies {
implementation "androidx.lifecycle:lifecycle-process:2.5.1"

def androidx_navigation_version = "2.5.2"
def androidx_navigation_version = "2.5.3"
implementation "androidx.navigation:navigation-fragment-ktx:$androidx_navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$androidx_navigation_version"

def room_version = "2.4.3"
def room_version = "2.5.0"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation fileTree(include: ["*.jar"], dir: "libs")

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:1.9.0"
implementation "androidx.appcompat:appcompat:1.5.1"
implementation "com.google.android.material:material:1.6.1"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "com.google.android.material:material:1.8.0"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"

testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
androidTestImplementation "androidx.test.ext:junit:1.1.5"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
}

16 changes: 8 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
android:supportsRtl="true"
android:theme="@style/Theme.ShoppingList">
<activity
android:name=".AddItemActivity"
android:name=".activities.AddItemActivity"
android:exported="true"
android:parentActivityName=".MainActivity"
android:parentActivityName=".activities.MainActivity"
android:windowSoftInputMode="stateAlwaysVisible">
<intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="@string/shareScheme"
android:host="@string/shareHost"
android:pathPrefix="@string/sharePath"
android:scheme="@string/shareScheme" />
android:pathPrefix="@string/sharePath" />
</intent-filter>
</activity>
<activity
android:name=".OptionsActivity"
android:parentActivityName=".MainActivity" />
android:name=".activities.OptionsActivity"
android:parentActivityName=".activities.MainActivity" />
<activity
android:name=".MainActivity"
android:name=".activities.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* _____ _ _ _ _ _
* / ___| | (_) | | (_) | |
* \ `--.| |__ ___ _ __ _ __ _ _ __ __ _| | _ ___| |_
* `--. \ '_ \ / _ \| '_ \| '_ \| | '_ \ / _` | | | / __| __|
* /\__/ / | | | (_) | |_) | |_) | | | | | (_| | |___| \__ \ |_
* \____/|_| |_|\___/| .__/| .__/|_|_| |_|\__, \_____/_|___/\__|
* | | | | __/ |
* |_| |_| |___/
*
* Copyright (C) 2021-2022 Sebastian Göls
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License only
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package pl.edu.pjwstk.s999844.shoppinglist

import android.content.Intent
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultCaller
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts


class BetterActivityResult<Input, Result> private constructor(caller: ActivityResultCaller, contract: ActivityResultContract<Input, Result>, private var onActivityResult: OnActivityResult<Result>?) {
fun interface OnActivityResult<O> {
fun onActivityResult(result: O)
}

private val launcher: ActivityResultLauncher<Input>

init {
launcher = caller.registerForActivityResult(contract) { result: Result -> callOnActivityResult(result) }
}

fun setOnActivityResult(onActivityResult: OnActivityResult<Result>?) {
this.onActivityResult = onActivityResult
}


fun launch(input: Input, onActivityResult: OnActivityResult<Result>? = this.onActivityResult) {
if (onActivityResult != null) {
this.onActivityResult = onActivityResult
}
launcher.launch(input)
}

private fun callOnActivityResult(result: Result) {
if (onActivityResult != null) {
onActivityResult!!.onActivityResult(result)
}
}

companion object {
fun <Input, Result> registerForActivityResult(caller: ActivityResultCaller, contract: ActivityResultContract<Input, Result>, onActivityResult: OnActivityResult<Result>?): BetterActivityResult<Input, Result> {
return BetterActivityResult(caller, contract, onActivityResult)
}

fun <Input, Result> registerForActivityResult(caller: ActivityResultCaller, contract: ActivityResultContract<Input, Result>): BetterActivityResult<Input, Result> {
return registerForActivityResult(caller, contract, null)
}

fun registerActivityForResult(caller: ActivityResultCaller): BetterActivityResult<Intent, ActivityResult> {
return registerForActivityResult(caller, ActivityResultContracts.StartActivityForResult())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package pl.edu.pjwstk.s999844.shoppinglist

import android.view.LayoutInflater
import androidx.viewbinding.ViewBinding
import pl.edu.pjwstk.s999844.shoppinglist.activities.AbstractShoppingActivity


inline fun <T : ViewBinding> AbstractShoppingActivity.viewBinding(crossinline bindingInflater: (LayoutInflater) -> T) = lazy(LazyThreadSafetyMode.NONE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package pl.edu.pjwstk.s999844.shoppinglist
package pl.edu.pjwstk.s999844.shoppinglist.activities

import android.content.Intent
import android.os.Bundle
import androidx.activity.result.ActivityResult
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import pl.edu.pjwstk.s999844.shoppinglist.BetterActivityResult
import pl.edu.pjwstk.s999844.shoppinglist.settings.Settings


abstract class AbstractShoppingActivity : AppCompatActivity() {
protected val settings: Settings by lazy { Settings(this) }

Expand All @@ -47,4 +51,6 @@ abstract class AbstractShoppingActivity : AppCompatActivity() {
}

protected fun setDark(dark: Boolean) = AppCompatDelegate.setDefaultNightMode(if (dark) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO)

protected val activityLauncher: BetterActivityResult<Intent, ActivityResult> = BetterActivityResult.registerActivityForResult(this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package pl.edu.pjwstk.s999844.shoppinglist
package pl.edu.pjwstk.s999844.shoppinglist.activities

import android.content.Context
import android.content.Intent
Expand All @@ -35,10 +35,12 @@ import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import com.google.android.material.snackbar.Snackbar
import pl.edu.pjwstk.s999844.shoppinglist.R
import pl.edu.pjwstk.s999844.shoppinglist.dal.ShoppingListDao
import pl.edu.pjwstk.s999844.shoppinglist.dal.ShoppingListDatabase
import pl.edu.pjwstk.s999844.shoppinglist.databinding.ActivityAddItemBinding
import pl.edu.pjwstk.s999844.shoppinglist.models.RequiredItem
import pl.edu.pjwstk.s999844.shoppinglist.viewBinding
import java.util.*

class AddItemActivity : AbstractShoppingActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package pl.edu.pjwstk.s999844.shoppinglist
package pl.edu.pjwstk.s999844.shoppinglist.activities

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.Menu
Expand All @@ -35,11 +34,13 @@ import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import pl.edu.pjwstk.s999844.shoppinglist.R
import pl.edu.pjwstk.s999844.shoppinglist.adapters.ShoppingListAdapter
import pl.edu.pjwstk.s999844.shoppinglist.dal.ShoppingListDao
import pl.edu.pjwstk.s999844.shoppinglist.dal.ShoppingListDatabase
import pl.edu.pjwstk.s999844.shoppinglist.databinding.ActivityMainBinding
import pl.edu.pjwstk.s999844.shoppinglist.models.RequiredItem
import pl.edu.pjwstk.s999844.shoppinglist.viewBinding

class MainActivity : AbstractShoppingActivity() {
private val binding by viewBinding(ActivityMainBinding::inflate)
Expand All @@ -64,7 +65,6 @@ class MainActivity : AbstractShoppingActivity() {
supportActionBar?.setDisplayUseLogoEnabled(true)
}


override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
Expand All @@ -73,17 +73,17 @@ class MainActivity : AbstractShoppingActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.actionBarMenuOptionsEntry -> {
openActivity(OptionsActivity::class.java)
activityLauncher.launch(Intent(baseContext, OptionsActivity::class.java)) {
recreate()
}
return true
}
}
return super.onOptionsItemSelected(item)
}

@Suppress("UNUSED_PARAMETER")
fun onClickFloatingButton(view: View) = openActivity(AddItemActivity::class.java)

private fun <T : Activity> openActivity(clazz: Class<T>) = startActivity(Intent(baseContext, clazz))
fun onClickFloatingButton(view: View) = startActivity(Intent(baseContext, AddItemActivity::class.java))

private fun changeItemCallback(item: RequiredItem, change: Int) {
val dbItem: RequiredItem = shoppingListDao.findById(item.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package pl.edu.pjwstk.s999844.shoppinglist
package pl.edu.pjwstk.s999844.shoppinglist.activities

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.widget.Spinner
import pl.edu.pjwstk.s999844.shoppinglist.BuildConfig
import pl.edu.pjwstk.s999844.shoppinglist.R
import pl.edu.pjwstk.s999844.shoppinglist.adapters.DescriptiveSettingSpinnerAdapter
import pl.edu.pjwstk.s999844.shoppinglist.adapters.SpinnerItemSelectedListener
import pl.edu.pjwstk.s999844.shoppinglist.databinding.ActivityOptionsBinding
import pl.edu.pjwstk.s999844.shoppinglist.settings.Settings
import pl.edu.pjwstk.s999844.shoppinglist.viewBinding

class OptionsActivity : AbstractShoppingActivity() {
companion object {
private const val RELEASES_PAGE_LINK = "https://github.com/Abrynos/ShoppingList/releases/"
private const val RELEASES_PAGE_LINK = "https://github.com/Abrynos/ShoppingList/releases"

private const val CURRENT_RELEASE_LINK = RELEASES_PAGE_LINK + "tag/" + BuildConfig.VERSION_NAME
private const val LATEST_RELEASE_LINK = RELEASES_PAGE_LINK + "latest"
private const val CURRENT_RELEASE_LINK = "$RELEASES_PAGE_LINK/tag/${BuildConfig.VERSION_NAME}"
private const val LATEST_RELEASE_LINK = "$RELEASES_PAGE_LINK/latest"

private val CURRENT_RELEASE_URI: Uri = Uri.parse(CURRENT_RELEASE_LINK)
private val LATEST_RELEASE_URI: Uri = Uri.parse(LATEST_RELEASE_LINK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ import pl.edu.pjwstk.s999844.shoppinglist.R

class Settings(context: Context) {
companion object {
private const val ACCENT_NAME = "accentColor"
private val ACCENT_DEFAULT: AccentColor = AccentColor.Blue

private const val IS_DARK_THEME_NAME = "darkTheme"
private const val IS_DARK_THEME_DEFAULT = true

private const val ORDER_NAME = "listOrder"
private val ORDER_DEFAULT: Order = Order.Unordered

private const val ACCENT_NAME = "accentColor"
private val ACCENT_DEFAULT: AccentColor = AccentColor.Blue
}

private val sharedPreferences: SharedPreferences = context.getSharedPreferences("SETTINGS", MODE_PRIVATE)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_add_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AddItemActivity">
tools:context=".activities.AddItemActivity">

<!-- we are ignoring the MissingConstraints warning, because the used styles set default values -->

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".activities.MainActivity">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/mainListRecyclerView"
Expand Down
Loading

0 comments on commit f6f9c35

Please sign in to comment.