Browse Source

Settings fix

pull/61/merge
Ezerous 6 years ago
parent
commit
268b446b03
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  3. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java
  4. 46
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  5. 3
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  6. 46
      app/src/main/res/xml/app_preferences_guest.xml
  7. 0
      app/src/main/res/xml/app_preferences_user.xml

2
app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java

@ -46,7 +46,7 @@ public class LoginActivity extends BaseActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
PreferenceManager.setDefaultValues(this, R.xml.app_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.app_preferences_user, false);
//Variables initialization //Variables initialization
inputUsername = findViewById(R.id.username); inputUsername = findViewById(R.id.username);

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -58,7 +58,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
redirectToActivityFromIntent(intentFilter); redirectToActivityFromIntent(intentFilter);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
PreferenceManager.setDefaultValues(this, R.xml.app_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.app_preferences_user, false);
if (sessionManager.isLoginScreenDefault()) { if (sessionManager.isLoginScreenDefault()) {
//Go to login //Go to login

3
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java

@ -42,8 +42,7 @@ public class SettingsActivity extends BaseActivity {
protected void onResume() { protected void onResume() {
drawer.setSelection(SETTINGS_ID); drawer.setSelection(SETTINGS_ID);
super.onResume(); super.onResume();
if (preferenceFragment != null) { if (preferenceFragment != null)
preferenceFragment.updateUserLoginState(sessionManager.isLoggedIn()); preferenceFragment.updateUserLoginState(sessionManager.isLoggedIn());
} }
} }
}

46
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java

@ -22,9 +22,12 @@ import gr.thmmy.mthmmy.base.BaseApplication;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB; import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_TAB;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.POSTING_APP_SIGNATURE_ENABLE_KEY;
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
private enum PREFS_TYPE {
NOT_SET, USER, GUEST
}
public static final String ARG_IS_LOGGED_IN = "selectedRingtoneKey"; public static final String ARG_IS_LOGGED_IN = "selectedRingtoneKey";
//Preferences xml keys //Preferences xml keys
@ -40,6 +43,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
private SharedPreferences settingsFile; private SharedPreferences settingsFile;
private PREFS_TYPE prefs_type = PREFS_TYPE.NOT_SET;
private boolean isLoggedIn = false; private boolean isLoggedIn = false;
private ArrayList<String> defaultHomeTabEntries = new ArrayList<>(); private ArrayList<String> defaultHomeTabEntries = new ArrayList<>();
private ArrayList<String> defaultHomeTabValues = new ArrayList<>(); private ArrayList<String> defaultHomeTabValues = new ArrayList<>();
@ -85,8 +89,17 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
@Override @Override
public void onCreatePreferences(Bundle bundle, String rootKey) { public void onCreatePreferences(Bundle bundle, String rootKey) {
// Load the Preferences from the XML file isLoggedIn = BaseApplication.getInstance().getSessionManager().isLoggedIn(); //Ensures it stays updated
addPreferencesFromResource(R.xml.app_preferences); // Add the Preferences from the XML file if needed
if(isLoggedIn&&(prefs_type==PREFS_TYPE.GUEST||prefs_type==PREFS_TYPE.NOT_SET)){
prefs_type = PREFS_TYPE.USER;
addPreferencesFromResource(R.xml.app_preferences_user);
}
else if(!isLoggedIn&&(prefs_type==PREFS_TYPE.USER||prefs_type==PREFS_TYPE.NOT_SET)){
prefs_type = PREFS_TYPE.GUEST;
addPreferencesFromResource(R.xml.app_preferences_guest);
}
} }
@Override @Override
@ -152,25 +165,34 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
} }
private void updatePreferenceVisibility(){ private void updatePreferenceVisibility(){
findPreference(POSTING_CATEGORY).setVisible(isLoggedIn); boolean updateHomeTabs=false;
findPreference(POSTING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn); if(isLoggedIn&& prefs_type==PREFS_TYPE.GUEST) {
//findPreference(UPLOADING_CATEGORY).setVisible(isLoggedIn); prefs_type = PREFS_TYPE.USER;
//findPreference(UPLOADING_APP_SIGNATURE_ENABLE_KEY).setVisible(isLoggedIn); setPreferencesFromResource(R.xml.app_preferences_user, getPreferenceScreen().getKey());
if(!defaultHomeTabEntries.contains("Unread")){
if (!isLoggedIn && defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.remove("Unread");
defaultHomeTabValues.remove("2");
} else if (isLoggedIn && !defaultHomeTabEntries.contains("Unread")) {
defaultHomeTabEntries.add("Unread"); defaultHomeTabEntries.add("Unread");
defaultHomeTabValues.add("2"); defaultHomeTabValues.add("2");
updateHomeTabs=true;
}
}
else if(!isLoggedIn&&prefs_type==PREFS_TYPE.USER){
prefs_type = PREFS_TYPE.GUEST;
setPreferencesFromResource(R.xml.app_preferences_guest,getPreferenceScreen().getKey());
if(defaultHomeTabEntries.contains("Unread")){
defaultHomeTabEntries.remove("Unread");
defaultHomeTabValues.remove("2");
updateHomeTabs=true;
}
} }
if(updateHomeTabs){
CharSequence[] tmpCs = defaultHomeTabEntries.toArray(new CharSequence[defaultHomeTabEntries.size()]); CharSequence[] tmpCs = defaultHomeTabEntries.toArray(new CharSequence[defaultHomeTabEntries.size()]);
((ListPreference) findPreference(DEFAULT_HOME_TAB)).setEntries(tmpCs); ((ListPreference) findPreference(DEFAULT_HOME_TAB)).setEntries(tmpCs);
tmpCs = defaultHomeTabValues.toArray(new CharSequence[defaultHomeTabValues.size()]); tmpCs = defaultHomeTabValues.toArray(new CharSequence[defaultHomeTabValues.size()]);
((ListPreference) findPreference(DEFAULT_HOME_TAB)).setEntryValues(tmpCs); ((ListPreference) findPreference(DEFAULT_HOME_TAB)).setEntryValues(tmpCs);
} }
}
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

3
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -56,7 +56,6 @@ import gr.thmmy.mthmmy.model.ThmmyFile;
import gr.thmmy.mthmmy.services.DownloadHelper; import gr.thmmy.mthmmy.services.DownloadHelper;
import gr.thmmy.mthmmy.session.SessionManager; import gr.thmmy.mthmmy.session.SessionManager;
import gr.thmmy.mthmmy.utils.FileUtils; import gr.thmmy.mthmmy.utils.FileUtils;
import gr.thmmy.mthmmy.utils.LaunchType;
import gr.thmmy.mthmmy.viewmodel.BaseViewModel; import gr.thmmy.mthmmy.viewmodel.BaseViewModel;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import ru.noties.markwon.LinkResolverDef; import ru.noties.markwon.LinkResolverDef;
@ -74,8 +73,6 @@ import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DEFAULT_HOME_
import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR; import static gr.thmmy.mthmmy.services.DownloadHelper.SAVE_DIR;
import static gr.thmmy.mthmmy.session.SessionManager.SUCCESS; import static gr.thmmy.mthmmy.session.SessionManager.SUCCESS;
import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType; import static gr.thmmy.mthmmy.utils.FileUtils.getMimeType;
import static gr.thmmy.mthmmy.utils.LaunchType.LAUNCH_TYPE.FIRST_LAUNCH_EVER;
import static gr.thmmy.mthmmy.utils.LaunchType.LAUNCH_TYPE.INDETERMINATE;
public abstract class BaseActivity extends AppCompatActivity { public abstract class BaseActivity extends AppCompatActivity {
// Client & Cookies // Client & Cookies

46
app/src/main/res/xml/app_preferences_guest.xml

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceCategory android:title="@string/pref_category_app">
<android.support.v7.preference.ListPreference
android:defaultValue="0"
android:dialogTitle="@string/pref_app_main_default_tab_dialog_title"
android:entries="@array/pref_app_main_default_tab_entries"
android:entryValues="@array/pref_app_main_default_tab_values"
android:key="pref_app_main_default_tab_key"
android:title="@string/pref_title_app_main_default_tab"
android:summary="@string/pref_summary_app_main_default_tab" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory android:title="@string/pref_category_notifications">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_notification_vibration_enable_key"
android:title="@string/pref_title_notification_vibration_enable" />
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_notification_led_enable_key"
android:title="@string/pref_title_notification_led_enable"
android:summary="@string/pref_summary_notification_led_enable" />
<Preference
android:key="pref_notifications_select_sound_key"
android:title="@string/pref_title_notifications_sound"
android:summary="@string/pref_summary_notifications_sound" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
android:key="pref_category_privacy_key"
android:title="@string/pref_category_privacy">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/pref_privacy_crashlytics_enable_key"
android:title="@string/pref_title_privacy_crashlytics_enable"
android:summary="@string/pref_summary_privacy_crashlytics_enable" />
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/pref_privacy_analytics_enable_key"
android:title="@string/pref_title_privacy_analytics_enable"
android:summary="@string/pref_summary_privacy_analytics_enable" />
</android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>

0
app/src/main/res/xml/app_preferences.xml → app/src/main/res/xml/app_preferences_user.xml

Loading…
Cancel
Save