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.content.Context
|
||||
import android.text.format.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
object AlarmHelper {
|
||||
@ -11,9 +12,12 @@ object AlarmHelper {
|
||||
return if (
|
||||
alarm != null
|
||||
&& 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 {
|
||||
""
|
||||
}
|
||||
|
@ -109,7 +109,6 @@ object CalendarHelper {
|
||||
}
|
||||
})
|
||||
eventList.reverse()
|
||||
Log.d("ciao", "list: $eventList")
|
||||
eventRepository.saveEvents(
|
||||
eventList
|
||||
)
|
||||
|
@ -30,7 +30,6 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var adapter: SlimAdapter
|
||||
private lateinit var viewModel: ChooseApplicationViewModel
|
||||
private val pm by lazy { packageManager }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -63,11 +62,11 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
}
|
||||
.register<ResolveInfo>(R.layout.application_info_layout) { item, injector ->
|
||||
injector
|
||||
.text(R.id.text, item.loadLabel(pm))
|
||||
.text(R.id.text, item.loadLabel(viewModel.pm))
|
||||
.with<ImageView>(R.id.icon) {
|
||||
Glide
|
||||
.with(this)
|
||||
.load(item.loadIcon(pm))
|
||||
.load(item.loadIcon(viewModel.pm))
|
||||
.centerCrop()
|
||||
.into(it)
|
||||
}
|
||||
@ -88,49 +87,47 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
|
||||
private fun subscribeUi(binding: ActivityChooseApplicationBinding, viewModel: ChooseApplicationViewModel) {
|
||||
binding.viewModel = viewModel
|
||||
|
||||
viewModel.appList.observe(this, Observer {
|
||||
adapter.updateData(listOf("Default") + it)
|
||||
updateList(list = it)
|
||||
loader.visibility = View.INVISIBLE
|
||||
})
|
||||
|
||||
viewModel.searchInput.observe(this, Observer { search ->
|
||||
loader.visibility = View.VISIBLE
|
||||
filterJob?.cancel()
|
||||
filterJob = lifecycleScope.launch(Dispatchers.IO) {
|
||||
updateList(search = search)
|
||||
})
|
||||
}
|
||||
|
||||
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)
|
||||
val list = if (search == null || search == "") {
|
||||
viewModel.appList.value!!
|
||||
val filteredList: List<ResolveInfo> = if (search == null || search == "") {
|
||||
list
|
||||
} else {
|
||||
viewModel.appList.value!!.filter {
|
||||
it.loadLabel(pm).contains(search, true)
|
||||
list.filter {
|
||||
it.loadLabel(viewModel.pm).contains(search, true)
|
||||
}
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
adapter.updateData(listOf("Default") + list)
|
||||
adapter.updateData(listOf("Default") + filteredList)
|
||||
loader.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
// viewModel.filterSettingsApp.observe(this, Observer {
|
||||
// action_filter.alpha = if (it) 1f else 0.5f
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupListener() {
|
||||
action_back.setOnClickListener {
|
||||
onBackPressed()
|
||||
}
|
||||
|
||||
// action_filter.setOnClickListener {
|
||||
// viewModel.toggleFilter()
|
||||
// }
|
||||
}
|
||||
|
||||
private fun saveApp(app: ResolveInfo) {
|
||||
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)
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
|
@ -3,20 +3,33 @@ package com.tommasoberlose.anotherwidget.ui.viewmodels
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.ResolveInfo
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.liveData
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class ChooseApplicationViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
val appList: LiveData<List<ResolveInfo>> = liveData {
|
||||
val mainIntent = Intent(Intent.ACTION_MAIN, null).apply {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}
|
||||
val app = application.packageManager.queryIntentActivities( mainIntent, 0)
|
||||
emit(app)
|
||||
}
|
||||
val pm: PackageManager by lazy { application.packageManager }
|
||||
val appList: MutableLiveData<List<ResolveInfo>> = 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
|
||||
listOf<Pair<TextView, Float>>(
|
||||
v.empty_date to Preferences.textMainSize,
|
||||
v.divider1 to Preferences.textSecondSize,
|
||||
v.divider1 to Preferences.textMainSize,
|
||||
v.temp to Preferences.textMainSize,
|
||||
v.next_event to Preferences.textMainSize,
|
||||
v.next_event_difference_time to Preferences.textMainSize,
|
||||
|
@ -3,7 +3,8 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:padding="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:id="@+id/main_layout">
|
||||
<TextClock
|
||||
android:id="@+id/time"
|
||||
|
@ -3,7 +3,7 @@
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
featureSplit="tasksintegration"
|
||||
package="com.tommasoberlose.anotherwidget"
|
||||
android:versionCode="56"
|
||||
android:versionCode="58"
|
||||
android:versionName="2.0.4" >
|
||||
|
||||
<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
|
||||
path.0=classes.dex
|
||||
renamed.0=classes.dex
|
||||
|
Binary file not shown.
@ -4,7 +4,7 @@
|
||||
featureSplit="tasksintegration"
|
||||
package="com.tommasoberlose.anotherwidget"
|
||||
android:targetSandboxVersion="2"
|
||||
android:versionCode="56"
|
||||
android:versionCode="58"
|
||||
android:versionName="2.0.4" >
|
||||
|
||||
<uses-sdk
|
||||
|
@ -3,7 +3,7 @@
|
||||
3 xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
4 featureSplit="tasksintegration"
|
||||
5 package="com.tommasoberlose.anotherwidget"
|
||||
6 android:versionCode="56"
|
||||
6 android:versionCode="58"
|
||||
7 android:versionName="2.0.4" >
|
||||
8
|
||||
9 <uses-sdk
|
||||
|
@ -3,7 +3,7 @@
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
featureSplit="tasksintegration"
|
||||
package="com.tommasoberlose.anotherwidget"
|
||||
android:versionCode="56"
|
||||
android:versionCode="58"
|
||||
android:versionName="2.0.4" >
|
||||
|
||||
<uses-sdk
|
||||
|
@ -3,7 +3,7 @@
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
featureSplit="tasksintegration"
|
||||
package="com.tommasoberlose.anotherwidget"
|
||||
android:versionCode="56"
|
||||
android:versionCode="58"
|
||||
android:versionName="2.0.4" >
|
||||
|
||||
<uses-sdk android:targetSdkVersion="29" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user