mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Create hidden settings for experimental features
This commit is contained in:
@@ -25,9 +25,11 @@ import android.support.v7.widget.Toolbar;
|
|||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.BuildConfig;
|
import org.isoron.uhabits.BuildConfig;
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.activities.*;
|
import org.isoron.uhabits.activities.*;
|
||||||
import org.isoron.uhabits.intents.*;
|
import org.isoron.uhabits.intents.*;
|
||||||
|
import org.isoron.uhabits.preferences.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
import butterknife.*;
|
import butterknife.*;
|
||||||
@@ -49,6 +51,11 @@ public class AboutRootView extends BaseRootView
|
|||||||
@BindView(R.id.toolbar)
|
@BindView(R.id.toolbar)
|
||||||
Toolbar toolbar;
|
Toolbar toolbar;
|
||||||
|
|
||||||
|
int developerCountdown = 10;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Preferences prefs;
|
||||||
|
|
||||||
private final IntentFactory intents;
|
private final IntentFactory intents;
|
||||||
|
|
||||||
public AboutRootView(Context context, IntentFactory intents)
|
public AboutRootView(Context context, IntentFactory intents)
|
||||||
@@ -62,6 +69,13 @@ public class AboutRootView extends BaseRootView
|
|||||||
tvVersion.setText(
|
tvVersion.setText(
|
||||||
String.format(getResources().getString(R.string.version_n),
|
String.format(getResources().getString(R.string.version_n),
|
||||||
BuildConfig.VERSION_NAME));
|
BuildConfig.VERSION_NAME));
|
||||||
|
|
||||||
|
if (context.getApplicationContext() instanceof HabitsApplication)
|
||||||
|
{
|
||||||
|
HabitsApplication app =
|
||||||
|
(HabitsApplication) context.getApplicationContext();
|
||||||
|
prefs = app.getComponent().getPreferences();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -94,11 +108,17 @@ public class AboutRootView extends BaseRootView
|
|||||||
getContext().startActivity(intent);
|
getContext().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.tvTranslate)
|
@OnClick(R.id.tvVersion)
|
||||||
public void onClickTranslate()
|
public void onClickIcon()
|
||||||
{
|
{
|
||||||
Intent intent = intents.helpTranslate(getContext());
|
developerCountdown--;
|
||||||
getContext().startActivity(intent);
|
if (developerCountdown <= 0)
|
||||||
|
{
|
||||||
|
if (prefs == null) return;
|
||||||
|
prefs.setDeveloper(true);
|
||||||
|
String text = "You are now a developer";
|
||||||
|
Toast.makeText(getContext(), text, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.tvRate)
|
@OnClick(R.id.tvRate)
|
||||||
@@ -115,6 +135,13 @@ public class AboutRootView extends BaseRootView
|
|||||||
getContext().startActivity(intent);
|
getContext().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.tvTranslate)
|
||||||
|
public void onClickTranslate()
|
||||||
|
{
|
||||||
|
Intent intent = intents.helpTranslate(getContext());
|
||||||
|
getContext().startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initToolbar()
|
protected void initToolbar()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,18 +22,25 @@ package org.isoron.uhabits.activities.settings;
|
|||||||
import android.app.backup.*;
|
import android.app.backup.*;
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
import android.support.v7.preference.*;
|
import android.support.v7.preference.*;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.activities.habits.list.*;
|
import org.isoron.uhabits.preferences.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.activities.habits.list.ListHabitsScreen.*;
|
||||||
|
|
||||||
public class SettingsFragment extends PreferenceFragmentCompat
|
public class SettingsFragment extends PreferenceFragmentCompat
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
{
|
{
|
||||||
private static int RINGTONE_REQUEST_CODE = 1;
|
private static int RINGTONE_REQUEST_CODE = 1;
|
||||||
|
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences sharedPrefs;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Preferences prefs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||||
@@ -54,13 +61,20 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.preferences);
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
setResultOnPreferenceClick("importData", ListHabitsScreen.RESULT_IMPORT_DATA);
|
setResultOnPreferenceClick("importData", RESULT_IMPORT_DATA);
|
||||||
setResultOnPreferenceClick("exportCSV", ListHabitsScreen.RESULT_EXPORT_CSV);
|
setResultOnPreferenceClick("exportCSV", RESULT_EXPORT_CSV);
|
||||||
setResultOnPreferenceClick("exportDB", ListHabitsScreen.RESULT_EXPORT_DB);
|
setResultOnPreferenceClick("exportDB", RESULT_EXPORT_DB);
|
||||||
setResultOnPreferenceClick("repairDB", ListHabitsScreen.RESULT_REPAIR_DB);
|
setResultOnPreferenceClick("repairDB", RESULT_REPAIR_DB);
|
||||||
setResultOnPreferenceClick("bugReport", ListHabitsScreen.RESULT_BUG_REPORT);
|
setResultOnPreferenceClick("bugReport", RESULT_BUG_REPORT);
|
||||||
|
|
||||||
updateRingtoneDescription();
|
updateRingtoneDescription();
|
||||||
|
|
||||||
|
Context appContext = getContext().getApplicationContext();
|
||||||
|
if(appContext instanceof HabitsApplication)
|
||||||
|
{
|
||||||
|
HabitsApplication app = (HabitsApplication) appContext;
|
||||||
|
prefs = app.getComponent().getPreferences();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -72,7 +86,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
@Override
|
@Override
|
||||||
public void onPause()
|
public void onPause()
|
||||||
{
|
{
|
||||||
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
sharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +110,16 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
public void onResume()
|
public void onResume()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
prefs = getPreferenceManager().getSharedPreferences();
|
sharedPrefs = getPreferenceManager().getSharedPreferences();
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
if(prefs != null && !prefs.isDeveloper())
|
||||||
|
{
|
||||||
|
PreferenceCategory devCategory =
|
||||||
|
(PreferenceCategory) findPreference("devCategory");
|
||||||
|
devCategory.removeAll();
|
||||||
|
devCategory.setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -110,7 +132,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
private void setResultOnPreferenceClick(String key, final int result)
|
private void setResultOnPreferenceClick(String key, final int result)
|
||||||
{
|
{
|
||||||
Preference pref = findPreference(key);
|
Preference pref = findPreference(key);
|
||||||
pref.setOnPreferenceClickListener(preference -> {
|
pref.setOnPreferenceClickListener(preference ->
|
||||||
|
{
|
||||||
getActivity().setResult(result);
|
getActivity().setResult(result);
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ public class Preferences
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDefaultOrder(HabitList.Order order)
|
||||||
|
{
|
||||||
|
prefs.edit().putString("pref_default_order", order.name()).apply();
|
||||||
|
}
|
||||||
|
|
||||||
public int getDefaultScoreSpinnerPosition()
|
public int getDefaultScoreSpinnerPosition()
|
||||||
{
|
{
|
||||||
int defaultScoreInterval = prefs.getInt("pref_score_view_interval", 1);
|
int defaultScoreInterval = prefs.getInt("pref_score_view_interval", 1);
|
||||||
@@ -85,11 +90,6 @@ public class Preferences
|
|||||||
return defaultScoreInterval;
|
return defaultScoreInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultOrder(HabitList.Order order)
|
|
||||||
{
|
|
||||||
prefs.edit().putString("pref_default_order", order.name()).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDefaultScoreSpinnerPosition(int position)
|
public void setDefaultScoreSpinnerPosition(int position)
|
||||||
{
|
{
|
||||||
prefs.edit().putInt("pref_score_view_interval", position).apply();
|
prefs.edit().putInt("pref_score_view_interval", position).apply();
|
||||||
@@ -161,6 +161,16 @@ public class Preferences
|
|||||||
PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
|
PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDeveloper()
|
||||||
|
{
|
||||||
|
return prefs.getBoolean("pref_developer", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeveloper(boolean isDeveloper)
|
||||||
|
{
|
||||||
|
prefs.edit().putBoolean("pref_developer", isDeveloper).apply();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFirstRun()
|
public boolean isFirstRun()
|
||||||
{
|
{
|
||||||
return prefs.getBoolean("pref_first_run", true);
|
return prefs.getBoolean("pref_first_run", true);
|
||||||
@@ -188,12 +198,12 @@ public class Preferences
|
|||||||
if (key.equals("pref_checkmark_reverse_order"))
|
if (key.equals("pref_checkmark_reverse_order"))
|
||||||
{
|
{
|
||||||
shouldReverseCheckmarks = null;
|
shouldReverseCheckmarks = null;
|
||||||
for(Listener l : listeners) l.onCheckmarkOrderChanged();
|
for (Listener l : listeners) l.onCheckmarkOrderChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key.equals("pref_sticky_notifications"))
|
if (key.equals("pref_sticky_notifications"))
|
||||||
{
|
{
|
||||||
for(Listener l : listeners) l.onNotificationsChanged();
|
for (Listener l : listeners) l.onNotificationsChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +225,12 @@ public class Preferences
|
|||||||
.putBoolean("pref_checkmark_reverse_order", reverse)
|
.putBoolean("pref_checkmark_reverse_order", reverse)
|
||||||
.apply();
|
.apply();
|
||||||
|
|
||||||
for(Listener l : listeners) l.onCheckmarkOrderChanged();
|
for (Listener l : listeners) l.onCheckmarkOrderChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldMakeNotificationsSticky()
|
||||||
|
{
|
||||||
|
return prefs.getBoolean("pref_sticky_notifications", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldReverseCheckmarks()
|
public boolean shouldReverseCheckmarks()
|
||||||
@@ -226,11 +241,6 @@ public class Preferences
|
|||||||
return shouldReverseCheckmarks;
|
return shouldReverseCheckmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldMakeNotificationsSticky()
|
|
||||||
{
|
|
||||||
return prefs.getBoolean("pref_sticky_notifications", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateLastAppVersion()
|
public void updateLastAppVersion()
|
||||||
{
|
{
|
||||||
prefs.edit().putInt("last_version", BuildConfig.VERSION_CODE).apply();
|
prefs.edit().putInt("last_version", BuildConfig.VERSION_CODE).apply();
|
||||||
|
|||||||
@@ -133,4 +133,15 @@
|
|||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="devCategory"
|
||||||
|
android:title="Development">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="pref_developer"
|
||||||
|
android:title="Enable developer mode"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
Reference in New Issue
Block a user