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