mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-21 13:19:02 +00:00
[#13] First version of SettingsActivity
This commit is contained in:
parent
237b66cb6b
commit
d1ceb6d6b9
9 changed files with 104 additions and 188 deletions
|
|
@ -34,7 +34,9 @@
|
|||
</activity>
|
||||
<activity
|
||||
android:name=".prefs.PrefsActivity"
|
||||
android:label="@string/PS_param_title">
|
||||
android:theme="@style/AppThemeWithActionBar"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:label="@string/PS_settings_title">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
<!-- Prefs -->
|
||||
<string name="PS_param_title">Params</string>
|
||||
<string name="PS_settings_title">Settings</string>
|
||||
<string name="PS_param_summary">Server config</string>
|
||||
<string name="SP_address">ServerAdress</string>
|
||||
<string name="SP_address_title">Server Address</string>
|
||||
|
|
@ -30,6 +31,8 @@
|
|||
<string name="SP_userID_title">User ID</string>
|
||||
<string name="SP_userID_summary">Your User ID</string>
|
||||
<string name="SP_APIToken">APIToken</string>
|
||||
<string name="SP_username">Username</string>
|
||||
<string name="SP_email">E-mail</string>
|
||||
<string name="SP_APIToken_title">API Token</string>
|
||||
<string name="SP_APIToken_summary">Your API Token</string>
|
||||
<string name="PS_contact_title">Contact me</string>
|
||||
|
|
|
|||
33
Habitica/res/xml/activity_preferences.xml
Normal file
33
Habitica/res/xml/activity_preferences.xml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/PS_contact_title" >
|
||||
|
||||
<PreferenceCategory android:title="Account Details">
|
||||
|
||||
<EditTextPreference
|
||||
android:key="@string/SP_username"
|
||||
android:title="Login Name"
|
||||
android:summary="Login Name" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="@string/SP_email"
|
||||
android:title="E-mail"
|
||||
android:summary="E-mail" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="@string/SP_userID"
|
||||
android:title="@string/SP_userID_title"
|
||||
android:summary="@string/SP_userID_summary"/>
|
||||
|
||||
<EditTextPreference
|
||||
android:key="@string/SP_APIToken"
|
||||
android:title="@string/SP_APIToken_title"
|
||||
android:summary="@string/SP_APIToken_summary"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<Preference android:title="LOGOUT"
|
||||
android:key="logout"
|
||||
android:summary="Logout your account"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/PS_param_title">
|
||||
<com.habitrpg.android.habitica.prefs.CustomListPreference
|
||||
android:key="@string/SP_address"
|
||||
android:title="@string/SP_address_title"
|
||||
android:dialogTitle="@string/SP_address_title"
|
||||
android:entries="@array/prefs_items_array"
|
||||
android:entryValues="@array/prefs_items_values"
|
||||
android:summary="@string/SP_address_summary"
|
||||
android:defaultValue="@string/SP_address_default"
|
||||
android:descendantFocusability="afterDescendants"/>
|
||||
|
||||
<EditTextPreference
|
||||
android:key="@string/SP_userID"
|
||||
android:title="@string/SP_userID_title"
|
||||
android:summary="@string/SP_userID_summary"/>
|
||||
<EditTextPreference
|
||||
android:key="@string/SP_APIToken"
|
||||
android:title="@string/SP_APIToken_title"
|
||||
android:summary="@string/SP_APIToken_summary"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/PS_contact_title" >
|
||||
<Preference
|
||||
android:icon="@drawable/ic_action_twitter"
|
||||
android:title="@string/SP_open_twitter"
|
||||
android:summary="@string/SP_open_twitter_summary">
|
||||
<intent android:action="android.intent.action.VIEW"
|
||||
android:data="https://twitter.com/MagicMicky" />
|
||||
|
||||
</Preference>
|
||||
<Preference
|
||||
android:title="@string/SP_licences"
|
||||
android:summary="@string/SP_licences_summary">
|
||||
<intent android:action="android.intent.action.VIEW"
|
||||
android:data="https://dl.dropboxusercontent.com/u/9280157/HabitRPGNotice.html"/>
|
||||
</Preference>
|
||||
</PreferenceScreen>
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<preference-headers
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<header android:fragment="com.habitrpg.android.habitica.prefs.PrefsActivity$PrefsFragment"
|
||||
android:title="@string/PS_param_title"
|
||||
android:icon="@drawable/ic_action_computer"
|
||||
android:summary="@string/PS_param_summary">
|
||||
<extra android:name="pref-resource" android:value="app_prefs_cat1" />
|
||||
</header>
|
||||
|
||||
<header
|
||||
android:icon="@drawable/ic_action_twitter"
|
||||
android:title="@string/SP_open_twitter"
|
||||
android:summary="@string/SP_open_twitter_summary">
|
||||
<intent android:action="android.intent.action.VIEW"
|
||||
android:data="http://twitter.com/MagicMicky" />
|
||||
</header>
|
||||
<header
|
||||
android:title="@string/SP_licences"
|
||||
android:summary="@string/SP_licences_summary">
|
||||
<intent android:action="android.intent.action.VIEW"
|
||||
android:data="https://dl.dropboxusercontent.com/u/9280157/HabitRPGNotice.html"/>
|
||||
</header>
|
||||
</preference-headers>
|
||||
|
|
@ -1,40 +1,27 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Transformation;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.AccessToken;
|
||||
import com.facebook.CallbackManager;
|
||||
import com.facebook.FacebookCallback;
|
||||
import com.facebook.FacebookException;
|
||||
import com.facebook.FacebookSdk;
|
||||
import com.facebook.login.LoginResult;
|
||||
import com.facebook.login.widget.LoginButton;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
|
|
@ -125,7 +112,6 @@ public class LoginActivity extends AppCompatActivity
|
|||
mApiHelper = new APIHelper(this,hc);
|
||||
|
||||
this.isRegistering = false;
|
||||
|
||||
}
|
||||
|
||||
private void resetLayout() {
|
||||
|
|
@ -178,7 +164,6 @@ public class LoginActivity extends AppCompatActivity
|
|||
public static void expand(final View v) {
|
||||
v.setVisibility(View.VISIBLE);
|
||||
}
|
||||
//
|
||||
|
||||
public static void collapse(final View v) {
|
||||
v.setVisibility(View.GONE);
|
||||
|
|
@ -189,18 +174,7 @@ public class LoginActivity extends AppCompatActivity
|
|||
finish();
|
||||
|
||||
}
|
||||
private void saveTokens(String api, String user) throws Exception {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
boolean ans = editor.putString(getString(R.string.SP_APIToken), api)
|
||||
.putString(getString(R.string.SP_userID), user)
|
||||
.putString(getString(R.string.SP_address),getString(R.string.SP_address_default))
|
||||
.commit();
|
||||
if(!ans) {
|
||||
throw new Exception("PB_string_commit");
|
||||
}
|
||||
|
||||
}
|
||||
private void toggleRegistering() {
|
||||
this.isRegistering = !this.isRegistering;
|
||||
MenuItem menuItem = menu.findItem(R.id.action_toggleRegistering);
|
||||
|
|
@ -301,6 +275,18 @@ public class LoginActivity extends AppCompatActivity
|
|||
this.startMainActivity();
|
||||
}
|
||||
|
||||
private void saveTokens(String api, String user) throws Exception {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
boolean ans = editor.putString(getString(R.string.SP_APIToken), api)
|
||||
.putString(getString(R.string.SP_userID), user)
|
||||
.putString(getString(R.string.SP_address),getString(R.string.SP_address_default))
|
||||
.commit();
|
||||
if(!ans) {
|
||||
throw new Exception("PB_string_commit");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@ package com.habitrpg.android.habitica;
|
|||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
|
@ -145,6 +147,23 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
this.tagsHelper = new TagsHelper();
|
||||
}
|
||||
|
||||
private void saveLoginInformation(){
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
boolean ans = editor.putString(getString(R.string.SP_username), User.getAuthentication().getLocalAuthentication().getUsername())
|
||||
.putString(getString(R.string.SP_email), User.getAuthentication().getLocalAuthentication().getEmail())
|
||||
.commit();
|
||||
try{
|
||||
if(!ans) {
|
||||
throw new Exception("Shared Preferences Username and Email error");
|
||||
}
|
||||
}catch (Exception e){
|
||||
Log.e("SHARED PREFERENCES", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -612,6 +631,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
updateHeader();
|
||||
updateSidebar();
|
||||
displayDeathDialogIfNeeded();
|
||||
saveLoginInformation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,110 +1,52 @@
|
|||
package com.habitrpg.android.habitica.prefs;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.MenuItem;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.habitrpg.android.habitica.HostConfig;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
public class PrefsActivity extends PreferenceActivity {
|
||||
protected Method mLoadHeaders = null;
|
||||
protected Method mHasHeaders = null;
|
||||
|
||||
/**
|
||||
* Checks to see if using new v11+ way of handling PrefsFragments.
|
||||
*
|
||||
* @return Returns false pre-v11, else checks to see if using headers.
|
||||
*/
|
||||
public boolean isNewV11Prefs() {
|
||||
if (mHasHeaders != null && mLoadHeaders != null) {
|
||||
try {
|
||||
return (Boolean) mHasHeaders.invoke(this);
|
||||
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException ignored) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onCreate(Bundle aSavedState) {
|
||||
//onBuildHeaders() will be called during super.onCreate()
|
||||
try {
|
||||
mLoadHeaders = getClass().getMethod("loadHeadersFromResource", int.class, List.class);
|
||||
mHasHeaders = getClass().getMethod("hasHeaders");
|
||||
} catch (NoSuchMethodException e) {
|
||||
}
|
||||
super.onCreate(aSavedState);
|
||||
if (!isNewV11Prefs()) {
|
||||
addPreferencesFromResource(R.xml.app_prefs_cat1);
|
||||
addPreferencesFromResource(R.xml.app_prefs_cat2);
|
||||
this.findPreference(this.getString(R.string.SP_last_seen_version)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
//ChangeLogDialog _ChangelogDialog = new ChangeLogDialog(PrefsActivity.this);
|
||||
//_ChangelogDialog.show( getSupportFragmentManager());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
public class PrefsActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
} else {
|
||||
if (this.getActionBar() != null) {
|
||||
this.getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBuildHeaders(List<Header> aTarget) {
|
||||
try {
|
||||
mLoadHeaders.invoke(this, new Object[]{R.xml.pref_headers, aTarget});
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (InvocationTargetException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
static public class PrefsFragment extends PreferenceFragment {
|
||||
public static class SettingsFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle aSavedState) {
|
||||
super.onCreate(aSavedState);
|
||||
Context anAct = getActivity().getApplicationContext();
|
||||
int thePrefRes = anAct.getResources().getIdentifier(getArguments().getString("pref-resource"),
|
||||
"xml", anAct.getPackageName());
|
||||
addPreferencesFromResource(thePrefRes);
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.activity_preferences);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayUseLogoEnabled(false);
|
||||
}
|
||||
|
||||
// Display the fragment as the main content
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
|
||||
public static HostConfig fromContext(Context ctx) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
HostConfig config;
|
||||
|
|
@ -127,9 +69,5 @@ public class PrefsActivity extends PreferenceActivity {
|
|||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue