mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Hide widget stacks feature for non-developers
This commit is contained in:
@@ -36,7 +36,6 @@ public class WidgetTest extends BaseUserInterfaceTest
|
|||||||
{
|
{
|
||||||
dragCheckmarkWidgetToHomeScreen();
|
dragCheckmarkWidgetToHomeScreen();
|
||||||
clickText("Wake up early");
|
clickText("Wake up early");
|
||||||
clickText("Save");
|
|
||||||
verifyCheckmarkWidgetIsShown();
|
verifyCheckmarkWidgetIsShown();
|
||||||
clickCheckmarkWidget();
|
clickCheckmarkWidget();
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
{
|
{
|
||||||
private HabitList habits;
|
private HabitList habits;
|
||||||
|
|
||||||
|
private Preferences preferences;
|
||||||
private WidgetPreferences widgetPrefs;
|
private WidgetPreferences widgetPrefs;
|
||||||
|
|
||||||
public static void updateAppWidget(@NonNull AppWidgetManager manager,
|
public static void updateAppWidget(@NonNull AppWidgetManager manager,
|
||||||
@@ -122,10 +123,14 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
if (context == null) throw new RuntimeException("context is null");
|
if (context == null) throw new RuntimeException("context is null");
|
||||||
if (manager == null) throw new RuntimeException("manager is null");
|
if (manager == null) throw new RuntimeException("manager is null");
|
||||||
if (widgetIds == null) throw new RuntimeException("widgetIds is null");
|
if (widgetIds == null) throw new RuntimeException("widgetIds is null");
|
||||||
context.setTheme(R.style.OpaqueWidgetTheme);
|
|
||||||
|
|
||||||
updateDependencies(context);
|
updateDependencies(context);
|
||||||
|
|
||||||
|
if(preferences.isWidgetStackEnabled()) {
|
||||||
|
context.setTheme(R.style.OpaqueWidgetTheme);
|
||||||
|
} else {
|
||||||
|
context.setTheme(R.style.TransparentWidgetTheme);
|
||||||
|
}
|
||||||
|
|
||||||
new Thread(() ->
|
new Thread(() ->
|
||||||
{
|
{
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
@@ -193,6 +198,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
|
|||||||
HabitsApplication app =
|
HabitsApplication app =
|
||||||
(HabitsApplication) context.getApplicationContext();
|
(HabitsApplication) context.getApplicationContext();
|
||||||
habits = app.getComponent().getHabitList();
|
habits = app.getComponent().getHabitList();
|
||||||
|
preferences = app.getComponent().getPreferences();
|
||||||
widgetPrefs = app.getComponent().getWidgetPreferences();
|
widgetPrefs = app.getComponent().getWidgetPreferences();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,28 +26,25 @@ import android.os.*
|
|||||||
import android.widget.*
|
import android.widget.*
|
||||||
import android.widget.AbsListView.*
|
import android.widget.AbsListView.*
|
||||||
import org.isoron.uhabits.*
|
import org.isoron.uhabits.*
|
||||||
import org.isoron.uhabits.core.models.*
|
|
||||||
import org.isoron.uhabits.core.preferences.*
|
import org.isoron.uhabits.core.preferences.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class HabitPickerDialog : Activity() {
|
class HabitPickerDialog : Activity() {
|
||||||
|
|
||||||
private var widgetId = 0
|
private var widgetId = 0
|
||||||
private lateinit var habitList: HabitList
|
private lateinit var widgetPreferences: WidgetPreferences
|
||||||
private lateinit var preferences: WidgetPreferences
|
|
||||||
private lateinit var habitIds: ArrayList<Long>
|
|
||||||
private lateinit var widgetUpdater: WidgetUpdater
|
private lateinit var widgetUpdater: WidgetUpdater
|
||||||
private lateinit var listView: ListView
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val component = (applicationContext as HabitsApplication).component
|
val component = (applicationContext as HabitsApplication).component
|
||||||
habitList = component.habitList
|
val habitList = component.habitList
|
||||||
preferences = component.widgetPreferences
|
val preferences = component.preferences
|
||||||
|
widgetPreferences = component.widgetPreferences
|
||||||
widgetUpdater = component.widgetUpdater
|
widgetUpdater = component.widgetUpdater
|
||||||
widgetId = intent.extras?.getInt(EXTRA_APPWIDGET_ID, INVALID_APPWIDGET_ID) ?: 0
|
widgetId = intent.extras?.getInt(EXTRA_APPWIDGET_ID, INVALID_APPWIDGET_ID) ?: 0
|
||||||
|
|
||||||
habitIds = ArrayList()
|
val habitIds = ArrayList<Long>()
|
||||||
val habitNames = ArrayList<String>()
|
val habitNames = ArrayList<String>()
|
||||||
for (h in habitList) {
|
for (h in habitList) {
|
||||||
if (h.isArchived) continue
|
if (h.isArchived) continue
|
||||||
@@ -56,30 +53,47 @@ class HabitPickerDialog : Activity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContentView(R.layout.widget_configure_activity)
|
setContentView(R.layout.widget_configure_activity)
|
||||||
listView = findViewById(R.id.listView) as ListView
|
val listView = findViewById<ListView>(R.id.listView)
|
||||||
|
val saveButton = findViewById<Button>(R.id.buttonSave)
|
||||||
|
|
||||||
with(listView) {
|
if(preferences.isWidgetStackEnabled) {
|
||||||
adapter = ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, habitNames)
|
with(listView) {
|
||||||
choiceMode = CHOICE_MODE_MULTIPLE
|
adapter = ArrayAdapter(context,
|
||||||
itemsCanFocus = false
|
android.R.layout.simple_list_item_multiple_choice,
|
||||||
}
|
habitNames)
|
||||||
|
choiceMode = CHOICE_MODE_MULTIPLE
|
||||||
with(findViewById(R.id.buttonSave) as Button) {
|
itemsCanFocus = false
|
||||||
setOnClickListener({
|
}
|
||||||
|
saveButton.setOnClickListener {
|
||||||
val selectedIds = mutableListOf<Long>()
|
val selectedIds = mutableListOf<Long>()
|
||||||
for (i in 0..listView.count) {
|
for (i in 0..listView.count) {
|
||||||
if (listView.isItemChecked(i)) {
|
if (listView.isItemChecked(i)) {
|
||||||
selectedIds.add(habitIds[i])
|
selectedIds.add(habitIds[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
confirm(selectedIds)
|
||||||
preferences.addWidget(widgetId, selectedIds.toLongArray())
|
}
|
||||||
widgetUpdater.updateWidgets()
|
} else {
|
||||||
setResult(Activity.RESULT_OK, Intent().apply {
|
saveButton.visibility = GONE
|
||||||
putExtra(EXTRA_APPWIDGET_ID, widgetId)
|
with(listView) {
|
||||||
})
|
adapter = ArrayAdapter(context,
|
||||||
finish()
|
android.R.layout.simple_list_item_1,
|
||||||
})
|
habitNames)
|
||||||
|
choiceMode = CHOICE_MODE_SINGLE
|
||||||
|
itemsCanFocus = false
|
||||||
|
}
|
||||||
|
listView.setOnItemClickListener { _, _, position, _ ->
|
||||||
|
confirm(listOf(habitIds[position]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun confirm(selectedIds: List<Long>) {
|
||||||
|
widgetPreferences.addWidget(widgetId, selectedIds.toLongArray())
|
||||||
|
widgetUpdater.updateWidgets()
|
||||||
|
setResult(RESULT_OK, Intent().apply {
|
||||||
|
putExtra(EXTRA_APPWIDGET_ID, widgetId)
|
||||||
|
})
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,6 +153,11 @@
|
|||||||
android:key="pref_developer"
|
android:key="pref_developer"
|
||||||
android:title="Enable developer mode"/>
|
android:title="Enable developer mode"/>
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="pref_feature_widget_stack"
|
||||||
|
android:title="Enable widget stacks"/>
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="pref_feature_sync"
|
android:key="pref_feature_sync"
|
||||||
|
|||||||
@@ -255,6 +255,11 @@ public class Preferences
|
|||||||
for (Listener l : listeners) l.onSyncFeatureChanged();
|
for (Listener l : listeners) l.onSyncFeatureChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWidgetStackEnabled()
|
||||||
|
{
|
||||||
|
return storage.getBoolean("pref_feature_widget_stack", false);
|
||||||
|
}
|
||||||
|
|
||||||
public void removeListener(Listener listener)
|
public void removeListener(Listener listener)
|
||||||
{
|
{
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
|
|||||||
Reference in New Issue
Block a user