Fix choose application order
This commit is contained in:
parent
864978e5d3
commit
faaa21eef7
@ -3,6 +3,7 @@ package com.tommasoberlose.anotherwidget.helpers
|
|||||||
import android.app.AlarmManager
|
import android.app.AlarmManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.text.format.DateFormat
|
import android.text.format.DateFormat
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object AlarmHelper {
|
object AlarmHelper {
|
||||||
@ -11,9 +12,12 @@ object AlarmHelper {
|
|||||||
return if (
|
return if (
|
||||||
alarm != null
|
alarm != null
|
||||||
&& alarm.triggerTime - Calendar.getInstance().timeInMillis > 2 * 60 * 1000
|
&& alarm.triggerTime - Calendar.getInstance().timeInMillis > 2 * 60 * 1000
|
||||||
&& alarm.triggerTime - Calendar.getInstance().timeInMillis < 24 * 60 * 60 * 1000
|
&& alarm.triggerTime - Calendar.getInstance().timeInMillis < 12 * 60 * 60 * 1000
|
||||||
) {
|
) {
|
||||||
DateFormat.getTimeFormat(context).format(Date(alarm.triggerTime))
|
"%s %s".format(
|
||||||
|
SimpleDateFormat("EEE", Locale.getDefault()).format(alarm.triggerTime),
|
||||||
|
DateFormat.getTimeFormat(context).format(Date(alarm.triggerTime))
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,6 @@ object CalendarHelper {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
eventList.reverse()
|
eventList.reverse()
|
||||||
Log.d("ciao", "list: $eventList")
|
|
||||||
eventRepository.saveEvents(
|
eventRepository.saveEvents(
|
||||||
eventList
|
eventList
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,6 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private lateinit var adapter: SlimAdapter
|
private lateinit var adapter: SlimAdapter
|
||||||
private lateinit var viewModel: ChooseApplicationViewModel
|
private lateinit var viewModel: ChooseApplicationViewModel
|
||||||
private val pm by lazy { packageManager }
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -63,11 +62,11 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
.register<ResolveInfo>(R.layout.application_info_layout) { item, injector ->
|
.register<ResolveInfo>(R.layout.application_info_layout) { item, injector ->
|
||||||
injector
|
injector
|
||||||
.text(R.id.text, item.loadLabel(pm))
|
.text(R.id.text, item.loadLabel(viewModel.pm))
|
||||||
.with<ImageView>(R.id.icon) {
|
.with<ImageView>(R.id.icon) {
|
||||||
Glide
|
Glide
|
||||||
.with(this)
|
.with(this)
|
||||||
.load(item.loadIcon(pm))
|
.load(item.loadIcon(viewModel.pm))
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.into(it)
|
.into(it)
|
||||||
}
|
}
|
||||||
@ -88,49 +87,47 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun subscribeUi(binding: ActivityChooseApplicationBinding, viewModel: ChooseApplicationViewModel) {
|
private fun subscribeUi(binding: ActivityChooseApplicationBinding, viewModel: ChooseApplicationViewModel) {
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
|
||||||
viewModel.appList.observe(this, Observer {
|
viewModel.appList.observe(this, Observer {
|
||||||
adapter.updateData(listOf("Default") + it)
|
updateList(list = it)
|
||||||
loader.visibility = View.INVISIBLE
|
loader.visibility = View.INVISIBLE
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.searchInput.observe(this, Observer { search ->
|
viewModel.searchInput.observe(this, Observer { search ->
|
||||||
loader.visibility = View.VISIBLE
|
updateList(search = search)
|
||||||
filterJob?.cancel()
|
})
|
||||||
filterJob = lifecycleScope.launch(Dispatchers.IO) {
|
}
|
||||||
|
|
||||||
|
private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) {
|
||||||
|
loader.visibility = View.VISIBLE
|
||||||
|
filterJob?.cancel()
|
||||||
|
filterJob = lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
if (list != null && list.isNotEmpty()) {
|
||||||
delay(200)
|
delay(200)
|
||||||
val list = if (search == null || search == "") {
|
val filteredList: List<ResolveInfo> = if (search == null || search == "") {
|
||||||
viewModel.appList.value!!
|
list
|
||||||
} else {
|
} else {
|
||||||
viewModel.appList.value!!.filter {
|
list.filter {
|
||||||
it.loadLabel(pm).contains(search, true)
|
it.loadLabel(viewModel.pm).contains(search, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
adapter.updateData(listOf("Default") + list)
|
adapter.updateData(listOf("Default") + filteredList)
|
||||||
loader.visibility = View.INVISIBLE
|
loader.visibility = View.INVISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
// viewModel.filterSettingsApp.observe(this, Observer {
|
|
||||||
// action_filter.alpha = if (it) 1f else 0.5f
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupListener() {
|
private fun setupListener() {
|
||||||
action_back.setOnClickListener {
|
action_back.setOnClickListener {
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
// action_filter.setOnClickListener {
|
|
||||||
// viewModel.toggleFilter()
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveApp(app: ResolveInfo) {
|
private fun saveApp(app: ResolveInfo) {
|
||||||
val resultIntent = Intent()
|
val resultIntent = Intent()
|
||||||
resultIntent.putExtra(Constants.RESULT_APP_NAME, app.loadLabel(pm))
|
resultIntent.putExtra(Constants.RESULT_APP_NAME, app.loadLabel(viewModel.pm))
|
||||||
resultIntent.putExtra(Constants.RESULT_APP_PACKAGE, app.activityInfo.packageName)
|
resultIntent.putExtra(Constants.RESULT_APP_PACKAGE, app.activityInfo.packageName)
|
||||||
setResult(Activity.RESULT_OK, resultIntent)
|
setResult(Activity.RESULT_OK, resultIntent)
|
||||||
finish()
|
finish()
|
||||||
|
@ -3,20 +3,33 @@ package com.tommasoberlose.anotherwidget.ui.viewmodels
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.content.pm.ResolveInfo
|
import android.content.pm.ResolveInfo
|
||||||
import androidx.lifecycle.AndroidViewModel
|
import android.util.Log
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.*
|
||||||
import androidx.lifecycle.MutableLiveData
|
import kotlinx.coroutines.Dispatchers
|
||||||
import androidx.lifecycle.liveData
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class ChooseApplicationViewModel(application: Application) : AndroidViewModel(application) {
|
class ChooseApplicationViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
|
|
||||||
val appList: LiveData<List<ResolveInfo>> = liveData {
|
val pm: PackageManager by lazy { application.packageManager }
|
||||||
val mainIntent = Intent(Intent.ACTION_MAIN, null).apply {
|
val appList: MutableLiveData<List<ResolveInfo>> = MutableLiveData()
|
||||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
|
||||||
}
|
|
||||||
val app = application.packageManager.queryIntentActivities( mainIntent, 0)
|
|
||||||
emit(app)
|
|
||||||
}
|
|
||||||
val searchInput: MutableLiveData<String> = MutableLiveData("")
|
val searchInput: MutableLiveData<String> = MutableLiveData("")
|
||||||
|
|
||||||
|
init {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
val mainIntent = Intent(Intent.ACTION_MAIN, null).apply {
|
||||||
|
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
}
|
||||||
|
|
||||||
|
val app = application.packageManager.queryIntentActivities(mainIntent, 0)
|
||||||
|
val sortedApp = app.sortedWith(Comparator { app1: ResolveInfo, app2: ResolveInfo ->
|
||||||
|
app1.loadLabel(pm).toString().compareTo(app2.loadLabel(pm).toString())
|
||||||
|
})
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
appList.postValue(sortedApp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -336,7 +336,7 @@ class MainWidget : AppWidgetProvider() {
|
|||||||
// Text Size
|
// Text Size
|
||||||
listOf<Pair<TextView, Float>>(
|
listOf<Pair<TextView, Float>>(
|
||||||
v.empty_date to Preferences.textMainSize,
|
v.empty_date to Preferences.textMainSize,
|
||||||
v.divider1 to Preferences.textSecondSize,
|
v.divider1 to Preferences.textMainSize,
|
||||||
v.temp to Preferences.textMainSize,
|
v.temp to Preferences.textMainSize,
|
||||||
v.next_event to Preferences.textMainSize,
|
v.next_event to Preferences.textMainSize,
|
||||||
v.next_event_difference_time to Preferences.textMainSize,
|
v.next_event_difference_time to Preferences.textMainSize,
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:padding="8dp"
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingRight="8dp"
|
||||||
android:id="@+id/main_layout">
|
android:id="@+id/main_layout">
|
||||||
<TextClock
|
<TextClock
|
||||||
android:id="@+id/time"
|
android:id="@+id/time"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||||
featureSplit="tasksintegration"
|
featureSplit="tasksintegration"
|
||||||
package="com.tommasoberlose.anotherwidget"
|
package="com.tommasoberlose.anotherwidget"
|
||||||
android:versionCode="56"
|
android:versionCode="58"
|
||||||
android:versionName="2.0.4" >
|
android:versionName="2.0.4" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#Mon May 04 02:19:12 CEST 2020
|
#Mon May 04 11:34:58 CEST 2020
|
||||||
base.0=/Users/tommaso/Documents/MyCode/another-widget/tasksintegration/build/intermediates/dex/debug/mergeProjectDexDebug/out/classes.dex
|
base.0=/Users/tommaso/Documents/MyCode/another-widget/tasksintegration/build/intermediates/dex/debug/mergeProjectDexDebug/out/classes.dex
|
||||||
path.0=classes.dex
|
path.0=classes.dex
|
||||||
renamed.0=classes.dex
|
renamed.0=classes.dex
|
||||||
|
Binary file not shown.
@ -4,7 +4,7 @@
|
|||||||
featureSplit="tasksintegration"
|
featureSplit="tasksintegration"
|
||||||
package="com.tommasoberlose.anotherwidget"
|
package="com.tommasoberlose.anotherwidget"
|
||||||
android:targetSandboxVersion="2"
|
android:targetSandboxVersion="2"
|
||||||
android:versionCode="56"
|
android:versionCode="58"
|
||||||
android:versionName="2.0.4" >
|
android:versionName="2.0.4" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
3 xmlns:dist="http://schemas.android.com/apk/distribution"
|
3 xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||||
4 featureSplit="tasksintegration"
|
4 featureSplit="tasksintegration"
|
||||||
5 package="com.tommasoberlose.anotherwidget"
|
5 package="com.tommasoberlose.anotherwidget"
|
||||||
6 android:versionCode="56"
|
6 android:versionCode="58"
|
||||||
7 android:versionName="2.0.4" >
|
7 android:versionName="2.0.4" >
|
||||||
8
|
8
|
||||||
9 <uses-sdk
|
9 <uses-sdk
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||||
featureSplit="tasksintegration"
|
featureSplit="tasksintegration"
|
||||||
package="com.tommasoberlose.anotherwidget"
|
package="com.tommasoberlose.anotherwidget"
|
||||||
android:versionCode="56"
|
android:versionCode="58"
|
||||||
android:versionName="2.0.4" >
|
android:versionName="2.0.4" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||||
featureSplit="tasksintegration"
|
featureSplit="tasksintegration"
|
||||||
package="com.tommasoberlose.anotherwidget"
|
package="com.tommasoberlose.anotherwidget"
|
||||||
android:versionCode="56"
|
android:versionCode="58"
|
||||||
android:versionName="2.0.4" >
|
android:versionName="2.0.4" >
|
||||||
|
|
||||||
<uses-sdk android:targetSdkVersion="29" />
|
<uses-sdk android:targetSdkVersion="29" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user