Release v2.0.1

This commit is contained in:
Tommaso Berlose
2020-05-03 17:54:35 +02:00
parent 3aecf9851a
commit 9a978ac8d3
135 changed files with 2368 additions and 1221 deletions

View File

@ -1,27 +0,0 @@
package com.tommasoberlose.anotherwidget.components
import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import com.chibatching.kotpref.Kotpref
import com.tommasoberlose.anotherwidget.global.Preferences
import io.realm.Realm
import io.realm.RealmConfiguration
class AWApplication : Application() {
override fun onCreate() {
super.onCreate()
// Preferences
Kotpref.init(this)
// Dark theme
AppCompatDelegate.setDefaultNightMode(Preferences.darkThemePreference)
// Realm
Realm.init(this)
val config = RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.build()
Realm.setDefaultConfiguration(config)
}
}

View File

@ -0,0 +1,55 @@
package com.tommasoberlose.anotherwidget.components
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.view.View
import android.widget.GridLayout
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.view.*
import kotlinx.android.synthetic.main.color_picker_menu_item.view.*
class BottomSheetColorPicker(
context: Context,
private val colors: IntArray = intArrayOf(),
private val selected: Int? = null,
private val header: String? = null,
private val onColorSelected: ((selectedValue: Int) -> Unit)? = null
) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
override fun show() {
val view = View.inflate(context, R.layout.bottom_sheet_menu_hor, null)
// Header
view.header.isVisible = header != null
view.header_text.text = header ?: ""
// Menu
for (@ColorInt color: Int in colors) {
val itemView = View.inflate(context, R.layout.color_picker_menu_item, null)
itemView.color.setCardBackgroundColor(ColorStateList.valueOf(color))
itemView.check.setColorFilter(ContextCompat.getColor(context,
if (color.isColorDark()) android.R.color.white else android.R.color.black
), android.graphics.PorterDuff.Mode.MULTIPLY)
itemView.check.isVisible = selected == color
itemView.color.setOnClickListener {
onColorSelected?.invoke(color)
this.dismiss()
}
view.menu.addView(itemView, GridLayout.LayoutParams(
GridLayout.spec(GridLayout.UNDEFINED, 1f),
GridLayout.spec(GridLayout.UNDEFINED, 1f)
)
)
}
setContentView(view)
super.show()
}
}

View File

@ -4,11 +4,14 @@ import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.annotation.MenuRes
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.card.MaterialCardView
import com.tommasoberlose.anotherwidget.R
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.*
import kotlinx.android.synthetic.main.bottom_sheet_menu_item.view.*
@ -18,18 +21,24 @@ import kotlinx.android.synthetic.main.bottom_sheet_menu_item.view.*
* theme which sets a rounded background to the dialog
* and doesn't dim the navigation bar
*/
open class BottomSheetMenu<T>(context: Context, private val header: String? = null) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
open class BottomSheetMenu<T>(context: Context, private val header: String? = null, private val isMultiSelection: Boolean = false) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
private val items: ArrayList<MenuItem<T>> = ArrayList()
private var selectedRes: T? = null
private var selectedRes: ArrayList<T> = ArrayList()
private var callback: ((selectedValue: T) -> Unit)? = null
private var multipleSelectionCallback: ((selectedValues: ArrayList<T>) -> Unit)? = null
fun selectResource(res: T): BottomSheetMenu<T> {
selectedRes = res
fun setSelectedValue(res: T): BottomSheetMenu<T> {
selectedRes = ArrayList(listOf(res))
return this
}
fun addItem(title: String, value: T): BottomSheetMenu<T> {
fun setSelectedValues(res: List<T>): BottomSheetMenu<T> {
selectedRes = ArrayList(res)
return this
}
fun addItem(title: String, value: T? = null): BottomSheetMenu<T> {
items.add(MenuItem(title, value))
return this
}
@ -39,6 +48,11 @@ open class BottomSheetMenu<T>(context: Context, private val header: String? = nu
return this
}
fun addOnMultipleSelectItemListener(multipleSelectionCallback: (selectedValues: ArrayList<T>) -> Unit): BottomSheetMenu<T> {
this.multipleSelectionCallback = multipleSelectionCallback
return this
}
override fun show() {
val view = View.inflate(context, R.layout.bottom_sheet_menu, null)
@ -48,19 +62,52 @@ open class BottomSheetMenu<T>(context: Context, private val header: String? = nu
// Menu
for (item in items) {
val itemView = View.inflate(context, R.layout.bottom_sheet_menu_item, null)
itemView.label.text = item.title
itemView.isSelected = item.value == selectedRes
itemView.setOnClickListener {
callback?.invoke(item.value)
this.dismiss()
if (item.value != null) {
val itemView = View.inflate(context, R.layout.bottom_sheet_menu_item, null)
itemView.label.text = item.title
if (isMultiSelection) {
itemView.icon_check.isVisible = selectedRes.contains(item.value)
itemView.label.setTextColor(
if (selectedRes.contains(item.value)) ContextCompat.getColor(
context,
R.color.colorPrimaryText
) else ContextCompat.getColor(context, R.color.colorSecondaryText)
)
} else {
itemView.isSelected = selectedRes.contains(item.value)
}
itemView.setOnClickListener {
if (!isMultiSelection) {
callback?.invoke(item.value)
this.dismiss()
} else {
if (selectedRes.contains(item.value)) {
selectedRes.remove(item.value)
} else {
selectedRes.add(item.value)
}
multipleSelectionCallback?.invoke(selectedRes)
itemView.icon_check.isVisible = selectedRes.contains(item.value)
itemView.label.setTextColor(
if (selectedRes.contains(item.value)) ContextCompat.getColor(
context,
R.color.colorPrimaryText
) else ContextCompat.getColor(context, R.color.colorSecondaryText)
)
}
}
view.menu.addView(itemView)
} else {
val itemView = View.inflate(context, R.layout.bottom_sheet_menu_divider, null)
itemView.label.text = item.title
view.menu.addView(itemView)
}
view.menu.addView(itemView)
}
setContentView(view)
super.show()
}
class MenuItem<T>(val title: String, val value: T)
class MenuItem<T>(val title: String, val value: T? = null)
}

View File

@ -1,16 +0,0 @@
package com.tommasoberlose.anotherwidget.components
/**
* Created by tommaso on 08/10/17.
*/
class CalendarSelector(id: Int, name: String?, account_name: String?) {
var id: Int = 0
var name: String = ""
var account_name: String = ""
init {
this.id = id
this.name = name?: ""
this.account_name = account_name?: ""
}
}

View File

@ -1,9 +0,0 @@
package com.tommasoberlose.anotherwidget.components.events
import android.content.pm.ApplicationInfo
/**
* Created by tommaso on 15/10/17.
*/
class AppInfoSavedEvent(val app: ApplicationInfo) {
}

View File

@ -1,16 +0,0 @@
package com.tommasoberlose.anotherwidget.components.events
import android.content.pm.ApplicationInfo
/**
* Created by tommaso on 15/10/17.
*/
class ApplicationListEvent(apps: List<ApplicationInfo>, filtered: Boolean) {
var apps: List<ApplicationInfo> = ArrayList()
var filtered: Boolean = false
init {
this.apps = apps
this.filtered = filtered
}
}

View File

@ -1,14 +0,0 @@
package com.tommasoberlose.anotherwidget.components.events
import android.location.Address
/**
* Created by tommaso on 14/10/17.
*/
class CustomLocationEvent(addresses: ArrayList<Address>) {
var addresses: ArrayList<Address> = ArrayList()
init {
this.addresses = addresses
}
}

View File

@ -1,22 +0,0 @@
package com.tommasoberlose.anotherwidget.components.events
import io.realm.RealmObject
import java.util.Date
/**
* Created by tommaso on 05/10/17.
*/
open class Event(var id: Long = 0,
var eventID: Long = 0,
var title: String = "",
var startDate: Long = 0,
var endDate: Long = 0,
var calendarID: Int = 0,
var allDay: Boolean = false,
var address: String = "") : RealmObject(){
override fun toString(): String {
return "Event:\nID: " + id + "\nTITLE: " + title + "\nSTART DATE: " + Date(startDate) + "\nEND DATE: " + Date(endDate) + "\nCAL DAY: " + calendarID + "\nADDRESS: " + address
}
}