Hide widget stacks feature for non-developers

pull/619/head^2
Alinson S. Xavier 6 years ago
parent 8341956a90
commit caed1aef79

@ -36,7 +36,6 @@ public class WidgetTest extends BaseUserInterfaceTest
{
dragCheckmarkWidgetToHomeScreen();
clickText("Wake up early");
clickText("Save");
verifyCheckmarkWidgetIsShown();
clickCheckmarkWidget();

@ -38,6 +38,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
{
private HabitList habits;
private Preferences preferences;
private WidgetPreferences widgetPrefs;
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 (manager == null) throw new RuntimeException("manager is null");
if (widgetIds == null) throw new RuntimeException("widgetIds is null");
context.setTheme(R.style.OpaqueWidgetTheme);
updateDependencies(context);
if(preferences.isWidgetStackEnabled()) {
context.setTheme(R.style.OpaqueWidgetTheme);
} else {
context.setTheme(R.style.TransparentWidgetTheme);
}
new Thread(() ->
{
Looper.prepare();
@ -193,6 +198,7 @@ public abstract class BaseWidgetProvider extends AppWidgetProvider
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
habits = app.getComponent().getHabitList();
preferences = app.getComponent().getPreferences();
widgetPrefs = app.getComponent().getWidgetPreferences();
}
}

@ -26,28 +26,25 @@ import android.os.*
import android.widget.*
import android.widget.AbsListView.*
import org.isoron.uhabits.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.core.preferences.*
import java.util.*
class HabitPickerDialog : Activity() {
private var widgetId = 0
private lateinit var habitList: HabitList
private lateinit var preferences: WidgetPreferences
private lateinit var habitIds: ArrayList<Long>
private lateinit var widgetPreferences: WidgetPreferences
private lateinit var widgetUpdater: WidgetUpdater
private lateinit var listView: ListView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val component = (applicationContext as HabitsApplication).component
habitList = component.habitList
preferences = component.widgetPreferences
val habitList = component.habitList
val preferences = component.preferences
widgetPreferences = component.widgetPreferences
widgetUpdater = component.widgetUpdater
widgetId = intent.extras?.getInt(EXTRA_APPWIDGET_ID, INVALID_APPWIDGET_ID) ?: 0
habitIds = ArrayList()
val habitIds = ArrayList<Long>()
val habitNames = ArrayList<String>()
for (h in habitList) {
if (h.isArchived) continue
@ -56,30 +53,47 @@ class HabitPickerDialog : 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) {
adapter = ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, habitNames)
choiceMode = CHOICE_MODE_MULTIPLE
itemsCanFocus = false
}
with(findViewById(R.id.buttonSave) as Button) {
setOnClickListener({
if(preferences.isWidgetStackEnabled) {
with(listView) {
adapter = ArrayAdapter(context,
android.R.layout.simple_list_item_multiple_choice,
habitNames)
choiceMode = CHOICE_MODE_MULTIPLE
itemsCanFocus = false
}
saveButton.setOnClickListener {
val selectedIds = mutableListOf<Long>()
for (i in 0..listView.count) {
if (listView.isItemChecked(i)) {
selectedIds.add(habitIds[i])
}
}
preferences.addWidget(widgetId, selectedIds.toLongArray())
widgetUpdater.updateWidgets()
setResult(Activity.RESULT_OK, Intent().apply {
putExtra(EXTRA_APPWIDGET_ID, widgetId)
})
finish()
})
confirm(selectedIds)
}
} else {
saveButton.visibility = GONE
with(listView) {
adapter = ArrayAdapter(context,
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:title="Enable developer mode"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_feature_widget_stack"
android:title="Enable widget stacks"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_feature_sync"

@ -255,6 +255,11 @@ public class Preferences
for (Listener l : listeners) l.onSyncFeatureChanged();
}
public boolean isWidgetStackEnabled()
{
return storage.getBoolean("pref_feature_widget_stack", false);
}
public void removeListener(Listener listener)
{
listeners.remove(listener);

Loading…
Cancel
Save