Moving to version 2.0

This commit is contained in:
Tommaso Berlose
2020-05-01 01:09:56 +02:00
parent 05a0308f8f
commit 3aecf9851a
1039 changed files with 6754 additions and 5763 deletions

View File

@ -0,0 +1,27 @@
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,66 @@
package com.tommasoberlose.anotherwidget.components
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.annotation.MenuRes
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.tommasoberlose.anotherwidget.R
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.*
import kotlinx.android.synthetic.main.bottom_sheet_menu_item.view.*
/**
* [BottomSheetDialogFragment] that uses a custom
* 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) {
private val items: ArrayList<MenuItem<T>> = ArrayList()
private var selectedRes: T? = null
private var callback: ((selectedValue: T) -> Unit)? = null
fun selectResource(res: T): BottomSheetMenu<T> {
selectedRes = res
return this
}
fun addItem(title: String, value: T): BottomSheetMenu<T> {
items.add(MenuItem(title, value))
return this
}
fun addOnSelectItemListener(callback: (selectedValue: T) -> Unit): BottomSheetMenu<T> {
this.callback = callback
return this
}
override fun show() {
val view = View.inflate(context, R.layout.bottom_sheet_menu, null)
// Header
view.header.isVisible = header != null
view.header_text.text = header ?: ""
// 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()
}
view.menu.addView(itemView)
}
setContentView(view)
super.show()
}
class MenuItem<T>(val title: String, val value: T)
}

View File

@ -0,0 +1,16 @@
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

@ -0,0 +1,9 @@
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

@ -0,0 +1,16 @@
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

@ -0,0 +1,14 @@
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

@ -0,0 +1,22 @@
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
}
}