mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-13 17:51:57 +00:00
Merge branch 'develop' of github.com:HabitRPG/habitrpg-android into sidebar
Conflicts: Habitica/src/com/habitrpg/android/habitica/AvatarActivityBase.java Habitica/src/com/habitrpg/android/habitica/MainActivity.java Habitica/src/com/habitrpg/android/habitica/userpicture/UserPicture.java
This commit is contained in:
commit
d56237e726
64 changed files with 1065 additions and 981 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.habitrpg.android.habitica"
|
package="com.habitrpg.android.habitica"
|
||||||
android:versionCode="8"
|
android:versionCode="9"
|
||||||
android:versionName="0.0.8"
|
android:versionName="0.0.9"
|
||||||
android:screenOrientation="portrait" >
|
android:screenOrientation="portrait" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
|
|
||||||
0
Habitica/assets/migrations/Habitica/2.sql
Normal file
0
Habitica/assets/migrations/Habitica/2.sql
Normal file
|
|
@ -51,10 +51,10 @@ dependencies {
|
||||||
}
|
}
|
||||||
compile 'com.mikepenz:google-material-typeface:2.2.0.1@aar'
|
compile 'com.mikepenz:google-material-typeface:2.2.0.1@aar'
|
||||||
|
|
||||||
compile 'com.android.support:appcompat-v7:23.0.1'
|
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||||
compile 'com.android.support:design:23.0.1'
|
compile 'com.android.support:design:23.1.1'
|
||||||
compile 'com.android.support:gridlayout-v7:23.0.1'
|
compile 'com.android.support:gridlayout-v7:23.1.1'
|
||||||
compile 'com.android.support:recyclerview-v7:23.0.1'
|
compile 'com.android.support:recyclerview-v7:23.1.1'
|
||||||
|
|
||||||
// Image Loading/Caching
|
// Image Loading/Caching
|
||||||
compile 'com.squareup.picasso:picasso:2.5.2'
|
compile 'com.squareup.picasso:picasso:2.5.2'
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,13 @@
|
||||||
<string name="internal_error_api">There seems to be a problem with the server. Try again later.</string>
|
<string name="internal_error_api">There seems to be a problem with the server. Try again later.</string>
|
||||||
<string name="network_up">Your internet connection just got back!</string>
|
<string name="network_up">Your internet connection just got back!</string>
|
||||||
|
|
||||||
|
<string name="authentication_error_title">Authentication Error</string>
|
||||||
|
<string name="authentication_error_body">Your Username and/or Password was incorrect.</string>
|
||||||
|
|
||||||
|
<string name="login_validation_error_title">Validation Error</string>
|
||||||
|
<string name="login_validation_error_fieldsmissing">You have to fill out all fields.</string>
|
||||||
|
<string name="login_validation_error_invalid_email">Invalid email address.</string>
|
||||||
|
|
||||||
<string name="checklist.title.add">Add checklist</string>
|
<string name="checklist.title.add">Add checklist</string>
|
||||||
<string name="checklist.title.edit">Edit checklist</string>
|
<string name="checklist.title.edit">Edit checklist</string>
|
||||||
<string name="checklist.item.hint">Add item…</string>
|
<string name="checklist.item.hint">Add item…</string>
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import com.raizlabs.android.dbflow.structure.ModelAdapter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import retrofit.Callback;
|
import retrofit.Callback;
|
||||||
|
|
@ -49,115 +48,122 @@ import retrofit.converter.GsonConverter;
|
||||||
public class APIHelper implements ErrorHandler, Profiler {
|
public class APIHelper implements ErrorHandler, Profiler {
|
||||||
|
|
||||||
private static final String TAG = "ApiHelper";
|
private static final String TAG = "ApiHelper";
|
||||||
// I think we don't need the APIHelper anymore we could just use ApiService
|
// I think we don't need the APIHelper anymore we could just use ApiService
|
||||||
public final ApiService apiService;
|
public final ApiService apiService;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
//private OnHabitsAPIResult mResultListener;
|
|
||||||
//private HostConfig mConfig;
|
|
||||||
public APIHelper(Context c, final HostConfig cfg) {
|
|
||||||
this.mContext = c;
|
|
||||||
|
|
||||||
RequestInterceptor requestInterceptor = new RequestInterceptor() {
|
//private OnHabitsAPIResult mResultListener;
|
||||||
@Override
|
//private HostConfig mConfig;
|
||||||
public void intercept(RequestInterceptor.RequestFacade request) {
|
public APIHelper(Context c, final HostConfig cfg) {
|
||||||
request.addHeader("x-api-key", cfg.getApi());
|
this.mContext = c;
|
||||||
request.addHeader("x-api-user", cfg.getUser());
|
|
||||||
|
RequestInterceptor requestInterceptor = new RequestInterceptor() {
|
||||||
|
@Override
|
||||||
|
public void intercept(RequestInterceptor.RequestFacade request) {
|
||||||
|
request.addHeader("x-api-key", cfg.getApi());
|
||||||
|
request.addHeader("x-api-user", cfg.getUser());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Type taskTagClassListType = new TypeToken<List<TaskTag>>() {}.getType();
|
Type taskTagClassListType = new TypeToken<List<TaskTag>>() {
|
||||||
|
}.getType();
|
||||||
|
|
||||||
|
|
||||||
//Exclusion stratety needed for DBFlow https://github.com/Raizlabs/DBFlow/issues/121
|
//Exclusion stratety needed for DBFlow https://github.com/Raizlabs/DBFlow/issues/121
|
||||||
Gson gson = new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.setExclusionStrategies(new ExclusionStrategy() {
|
.setExclusionStrategies(new ExclusionStrategy() {
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldSkipField(FieldAttributes f) {
|
public boolean shouldSkipField(FieldAttributes f) {
|
||||||
return f.getDeclaredClass().equals(ModelAdapter.class);
|
return f.getDeclaredClass().equals(ModelAdapter.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldSkipClass(Class<?> clazz) {
|
public boolean shouldSkipClass(Class<?> clazz) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.registerTypeAdapter(taskTagClassListType, new TagsAdapter())
|
.registerTypeAdapter(taskTagClassListType, new TagsAdapter())
|
||||||
.registerTypeAdapter(Boolean.class, booleanAsIntAdapter)
|
.registerTypeAdapter(Boolean.class, booleanAsIntAdapter)
|
||||||
.registerTypeAdapter(boolean.class, booleanAsIntAdapter)
|
.registerTypeAdapter(boolean.class, booleanAsIntAdapter)
|
||||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
|
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
Server server = new Server(cfg.getAddress());
|
Server server = new Server(cfg.getAddress());
|
||||||
|
|
||||||
RestAdapter adapter = new RestAdapter.Builder()
|
RestAdapter adapter = new RestAdapter.Builder()
|
||||||
.setEndpoint(server.toString())
|
.setEndpoint(server.toString())
|
||||||
.setErrorHandler(this)
|
.setErrorHandler(this)
|
||||||
.setProfiler(this)
|
.setProfiler(this)
|
||||||
.setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
|
.setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
|
||||||
.setRequestInterceptor(requestInterceptor)
|
.setRequestInterceptor(requestInterceptor)
|
||||||
.setConverter(new GsonConverter(gson))
|
.setConverter(new GsonConverter(gson))
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
this.apiService = adapter.create(ApiService.class);
|
this.apiService = adapter.create(ApiService.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final TypeAdapter<Boolean> booleanAsIntAdapter = new TypeAdapter<Boolean>() {
|
private static final TypeAdapter<Boolean> booleanAsIntAdapter = new TypeAdapter<Boolean>() {
|
||||||
@Override public void write(JsonWriter out, Boolean value) throws IOException {
|
@Override
|
||||||
if (value == null) {
|
public void write(JsonWriter out, Boolean value) throws IOException {
|
||||||
out.nullValue();
|
if (value == null) {
|
||||||
} else {
|
out.nullValue();
|
||||||
out.value(value);
|
} else {
|
||||||
}
|
out.value(value);
|
||||||
}
|
}
|
||||||
@Override public Boolean read(JsonReader in) throws IOException {
|
}
|
||||||
JsonToken peek = in.peek();
|
|
||||||
switch (peek) {
|
@Override
|
||||||
case BOOLEAN:
|
public Boolean read(JsonReader in) throws IOException {
|
||||||
return in.nextBoolean();
|
JsonToken peek = in.peek();
|
||||||
case NULL:
|
switch (peek) {
|
||||||
in.nextNull();
|
case BOOLEAN:
|
||||||
return null;
|
return in.nextBoolean();
|
||||||
case NUMBER:
|
case NULL:
|
||||||
return in.nextInt() != 0;
|
in.nextNull();
|
||||||
case STRING:
|
return null;
|
||||||
return Boolean.parseBoolean(in.nextString());
|
case NUMBER:
|
||||||
default:
|
return in.nextInt() != 0;
|
||||||
throw new IllegalStateException("Expected BOOLEAN or NUMBER but was " + peek);
|
case STRING:
|
||||||
}
|
return Boolean.parseBoolean(in.nextString());
|
||||||
}
|
default:
|
||||||
};
|
throw new IllegalStateException("Expected BOOLEAN or NUMBER but was " + peek);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public void createNewTask(Task item, Callback cb) {
|
public void createNewTask(Task item, Callback cb) {
|
||||||
this.apiService.createItem(item, cb);
|
this.apiService.createItem(item, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void retrieveUser(HabitRPGUserCallback callback) {
|
public void retrieveUser(HabitRPGUserCallback callback) {
|
||||||
this.apiService.getUser(callback);
|
this.apiService.getUser(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTaskDirection(String id, TaskDirection direction, TaskScoringCallback callback) {
|
public void updateTaskDirection(String id, TaskDirection direction, TaskScoringCallback callback) {
|
||||||
this.apiService.postTaskDirection(id, direction.toString(), callback);
|
this.apiService.postTaskDirection(id, direction.toString(), callback);
|
||||||
}
|
}
|
||||||
public void registerUser(View btnClicked, String username, String email, String password, String confirmPassword) {
|
|
||||||
|
|
||||||
// ATAskRegisterUser reg = new ATAskRegisterUser(mResultListener,mConfig,btnClicked);
|
public void registerUser(View btnClicked, String username, String email, String password, String confirmPassword) {
|
||||||
// String[] params = {username,email,password,confirmPassword};
|
|
||||||
// reg.execute(params);
|
|
||||||
|
|
||||||
}
|
// ATAskRegisterUser reg = new ATAskRegisterUser(mResultListener,mConfig,btnClicked);
|
||||||
public void connectUser(String username, String password, Callback<UserAuthResponse> callback) {
|
// String[] params = {username,email,password,confirmPassword};
|
||||||
// ATaskConnectUser con = new ATaskConnectUser(mResultListener,mConfig,btnClicked);
|
// reg.execute(params);
|
||||||
// String[] params = {username,password};
|
|
||||||
// con.execute(params);
|
}
|
||||||
|
|
||||||
|
public void connectUser(String username, String password, Callback<UserAuthResponse> callback) {
|
||||||
|
// ATaskConnectUser con = new ATaskConnectUser(mResultListener,mConfig,btnClicked);
|
||||||
|
// String[] params = {username,password};
|
||||||
|
// con.execute(params);
|
||||||
UserAuth auth = new UserAuth();
|
UserAuth auth = new UserAuth();
|
||||||
auth.setUsername(username);
|
auth.setUsername(username);
|
||||||
auth.setPassword(password);
|
auth.setPassword(password);
|
||||||
this.apiService.connectLocal(auth, callback);
|
this.apiService.connectLocal(auth, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectSocial(String userId, String accessToken, Callback<UserAuthResponse> callback) {
|
public void connectSocial(String userId, String accessToken, Callback<UserAuthResponse> callback) {
|
||||||
UserAuthSocial auth = new UserAuthSocial();
|
UserAuthSocial auth = new UserAuthSocial();
|
||||||
|
|
@ -170,37 +176,45 @@ public class APIHelper implements ErrorHandler, Profiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteTask(Task item, TaskDeletionCallback cb) {
|
public void deleteTask(Task item, TaskDeletionCallback cb) {
|
||||||
this.apiService.deleteTask(item.getId(), cb);
|
this.apiService.deleteTask(item.getId(), cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTask(Task item, Callback cb) {
|
public void updateTask(Task item, Callback cb) {
|
||||||
this.apiService.updateTask(item.getId(), item, cb);
|
this.apiService.updateTask(item.getId(), item, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Throwable handleError(RetrofitError cause) {
|
public Throwable handleError(RetrofitError cause) {
|
||||||
final Activity activity = (Activity) this.mContext;
|
final Activity activity = (Activity) this.mContext;
|
||||||
|
|
||||||
if (cause.getKind().equals(RetrofitError.Kind.NETWORK)) {
|
if (cause.getKind().equals(RetrofitError.Kind.NETWORK)) {
|
||||||
//It also handles timeouts
|
//It also handles timeouts
|
||||||
showConnectionProblemDialog(activity, R.string.network_error_no_network_body);
|
showConnectionProblemDialog(activity, R.string.network_error_no_network_body);
|
||||||
}else{
|
return cause;
|
||||||
/*
|
} else if (cause.getKind().equals(RetrofitError.Kind.HTTP)) {
|
||||||
* CONVERSION An exception was thrown while (de)serializing a body.
|
int status = cause.getResponse().getStatus();
|
||||||
* HTTP A non-200 HTTP status code was received from the server e.g. 502, 503, etc...
|
if (status == 401) {
|
||||||
* UNEXPECTED An internal error occurred while attempting to execute a request.
|
showConnectionProblemDialog(activity, R.string.authentication_error_title, R.string.authentication_error_body);
|
||||||
*/
|
return cause;
|
||||||
showConnectionProblemDialog(activity,R.string.internal_error_api);
|
} else if (status >= 500 && status < 600) {
|
||||||
}
|
showConnectionProblemDialog(activity,R.string.internal_error_api);
|
||||||
|
return cause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showConnectionProblemDialog(activity, R.string.internal_error_api);
|
||||||
|
|
||||||
return cause;
|
return cause;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showConnectionProblemDialog(final Activity activity, final int resourceMessageString){
|
private void showConnectionProblemDialog(final Activity activity, final int resourceMessageString) {
|
||||||
|
showConnectionProblemDialog(activity, R.string.network_error_title, resourceMessageString);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showConnectionProblemDialog(final Activity activity, final int resourceTitleString, final int resourceMessageString){
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
new AlertDialog.Builder(activity)
|
new AlertDialog.Builder(activity)
|
||||||
.setTitle(R.string.network_error_title)
|
.setTitle(resourceTitleString)
|
||||||
.setMessage(resourceMessageString)
|
.setMessage(resourceMessageString)
|
||||||
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ public class AboutActivity extends AppCompatActivity {
|
||||||
|
|
||||||
return new AboutFragment();
|
return new AboutFragment();
|
||||||
case 1:
|
case 1:
|
||||||
Fragment tab1 = new LibsBuilder()
|
return new LibsBuilder()
|
||||||
//Pass the fields of your application to the lib so it can find all external lib information
|
//Pass the fields of your application to the lib so it can find all external lib information
|
||||||
.withFields(R.string.class.getFields())
|
.withFields(R.string.class.getFields())
|
||||||
.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
|
.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
|
||||||
|
|
@ -117,8 +117,6 @@ public class AboutActivity extends AppCompatActivity {
|
||||||
.withAboutVersionShownName(true)
|
.withAboutVersionShownName(true)
|
||||||
.withAnimations(true)
|
.withAnimations(true)
|
||||||
.fragment();
|
.fragment();
|
||||||
|
|
||||||
return tab1;
|
|
||||||
case 2:
|
case 2:
|
||||||
PaperboyBuilder builder = new PaperboyBuilder(AboutActivity.this)
|
PaperboyBuilder builder = new PaperboyBuilder(AboutActivity.this)
|
||||||
.setViewType(ViewTypes.HEADER)
|
.setViewType(ViewTypes.HEADER)
|
||||||
|
|
@ -140,9 +138,9 @@ public class AboutActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getPageTitle(int position) {
|
public CharSequence getPageTitle(int position) {
|
||||||
if (position == 0){
|
if (position == 0) {
|
||||||
return getString(R.string.about_title);
|
return getString(R.string.about_title);
|
||||||
}else if(position == 1){
|
} else if (position == 1) {
|
||||||
return getString(R.string.about_libraries);
|
return getString(R.string.about_libraries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,18 +98,12 @@ public abstract class AvatarActivityBase extends InstabugAppCompatActivity {
|
||||||
viewPager.setBackgroundColor(getResources().getColor(R.color.white));
|
viewPager.setBackgroundColor(getResources().getColor(R.color.white));
|
||||||
|
|
||||||
avatarInHeader = new AvatarWithBarsViewModel(this, avatar_with_bars);
|
avatarInHeader = new AvatarWithBarsViewModel(this, avatar_with_bars);
|
||||||
|
|
||||||
accountHeader = MainDrawerBuilder.CreateDefaultAccountHeader(this).build();
|
accountHeader = MainDrawerBuilder.CreateDefaultAccountHeader(this).build();
|
||||||
drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar, accountHeader)
|
drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar, accountHeader)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// titleTextView = new TextView(this);
|
|
||||||
// titleTextView.setTextAppearance(this, android.R.style.TextAppearance_Material_Widget_ActionBar_Title_Inverse);
|
|
||||||
// titleTextView.setPadding(0,16,0,0);
|
|
||||||
// toolbar.addView(titleTextView);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTitle(String text){
|
protected void setTitle(String text) {
|
||||||
toolbar.setTitle(text);
|
toolbar.setTitle(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,7 @@ public class ContentCache {
|
||||||
final QuestContent quest = new Select().from(QuestContent.class).where(Condition.column("key").eq(key)).querySingle();
|
final QuestContent quest = new Select().from(QuestContent.class).where(Condition.column("key").eq(key)).querySingle();
|
||||||
|
|
||||||
if (quest != null) {
|
if (quest != null) {
|
||||||
QuestBoss boss = new Select().from(QuestBoss.class).where(Condition.column("key").eq(key)).querySingle();
|
quest.boss = new Select().from(QuestBoss.class).where(Condition.column("key").eq(key)).querySingle();
|
||||||
quest.boss = boss;
|
|
||||||
|
|
||||||
cb.GotQuest(quest);
|
cb.GotQuest(quest);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import com.raizlabs.android.dbflow.sql.language.Select;
|
||||||
import org.solovyev.android.checkout.ActivityCheckout;
|
import org.solovyev.android.checkout.ActivityCheckout;
|
||||||
import org.solovyev.android.checkout.BillingRequests;
|
import org.solovyev.android.checkout.BillingRequests;
|
||||||
import org.solovyev.android.checkout.Checkout;
|
import org.solovyev.android.checkout.Checkout;
|
||||||
import org.solovyev.android.checkout.Inventory;
|
|
||||||
import org.solovyev.android.checkout.ProductTypes;
|
import org.solovyev.android.checkout.ProductTypes;
|
||||||
import org.solovyev.android.checkout.Purchase;
|
import org.solovyev.android.checkout.Purchase;
|
||||||
import org.solovyev.android.checkout.RequestListener;
|
import org.solovyev.android.checkout.RequestListener;
|
||||||
|
|
@ -71,7 +70,7 @@ public class GemPurchaseActivity extends AppCompatActivity {
|
||||||
actionBar.setHomeButtonEnabled(false);
|
actionBar.setHomeButtonEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
actionBar.setTitle("Purchase Gems 2");
|
actionBar.setTitle("Purchase Gems");
|
||||||
}
|
}
|
||||||
|
|
||||||
accountHeader = MainDrawerBuilder.CreateDefaultAccountHeader(this).build();
|
accountHeader = MainDrawerBuilder.CreateDefaultAccountHeader(this).build();
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import org.solovyev.android.checkout.RequestListener;
|
||||||
import com.facebook.FacebookSdk;
|
import com.facebook.FacebookSdk;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.security.Security;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -69,13 +68,12 @@ public class HabiticaApplication extends Application {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getDatabasePath(String name) {
|
public File getDatabasePath(String name) {
|
||||||
return new File(getExternalFilesDir(null), "HabiticaDatabase/"+name);
|
return new File(getExternalFilesDir(null), "HabiticaDatabase/" + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For better performance billing class should be used as singleton
|
* For better performance billing class should be used as singleton
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
|
@ -20,8 +19,6 @@ import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
|
@ -159,11 +156,19 @@ public class LoginActivity extends AppCompatActivity
|
||||||
email = String.valueOf(mEmail.getText());
|
email = String.valueOf(mEmail.getText());
|
||||||
password = String.valueOf(mPasswordET.getText());
|
password = String.valueOf(mPasswordET.getText());
|
||||||
cpassword = String.valueOf(mConfirmPassword.getText());
|
cpassword = String.valueOf(mConfirmPassword.getText());
|
||||||
|
if (username.length() == 0 || password.length() == 0 || email.length() == 0 || cpassword.length() == 0) {
|
||||||
|
showValidationError(R.string.login_validation_error_fieldsmissing);
|
||||||
|
return;
|
||||||
|
}
|
||||||
mApiHelper.registerUser(v,username,email,password,cpassword);
|
mApiHelper.registerUser(v,username,email,password,cpassword);
|
||||||
} else {
|
} else {
|
||||||
String username,password;
|
String username,password;
|
||||||
username = String.valueOf(mUsernameET.getText());
|
username = String.valueOf(mUsernameET.getText());
|
||||||
password = String.valueOf(mPasswordET.getText());
|
password = String.valueOf(mPasswordET.getText());
|
||||||
|
if (username.length() == 0 || password.length() == 0) {
|
||||||
|
showValidationError(R.string.login_validation_error_fieldsmissing);
|
||||||
|
return;
|
||||||
|
}
|
||||||
mApiHelper.connectUser(username,password, LoginActivity.this);
|
mApiHelper.connectUser(username,password, LoginActivity.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -304,7 +309,7 @@ public class LoginActivity extends AppCompatActivity
|
||||||
@Override
|
@Override
|
||||||
public void onUserReceived(HabitRPGUser user) {
|
public void onUserReceived(HabitRPGUser user) {
|
||||||
try {
|
try {
|
||||||
saveTokens(mTmpApiToken,mTmpUserToken);
|
saveTokens(mTmpApiToken, mTmpUserToken);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -316,4 +321,17 @@ public class LoginActivity extends AppCompatActivity
|
||||||
mProgressBar.setVisibility(View.GONE);
|
mProgressBar.setVisibility(View.GONE);
|
||||||
showSnackbar(getString(R.string.unknown_error));
|
showSnackbar(getString(R.string.unknown_error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showValidationError(int resourceMessageString) {
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
|
new android.support.v7.app.AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.login_validation_error_title)
|
||||||
|
.setMessage(resourceMessageString)
|
||||||
|
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setIcon(R.drawable.ic_warning_black)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,10 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
||||||
import com.mikepenz.materialdrawer.Drawer;
|
import com.mikepenz.materialdrawer.Drawer;
|
||||||
import com.mikepenz.materialdrawer.DrawerBuilder;
|
import com.mikepenz.materialdrawer.DrawerBuilder;
|
||||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
|
||||||
import com.mikepenz.materialdrawer.model.SectionDrawerItem;
|
import com.mikepenz.materialdrawer.model.SectionDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.model.SwitchDrawerItem;
|
import com.mikepenz.materialdrawer.model.SwitchDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener;
|
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener;
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
|
||||||
import com.raizlabs.android.dbflow.runtime.FlowContentObserver;
|
import com.raizlabs.android.dbflow.runtime.FlowContentObserver;
|
||||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||||
|
|
@ -585,7 +583,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModelStateChanged(Class<? extends Model> aClass, BaseModel.Action action, String s, String s1) {
|
public void onModelStateChanged(Class<? extends Model> aClass, BaseModel.Action action, String s, String s1) {
|
||||||
if(aClass != HabitRPGUser.class)
|
if (aClass != HabitRPGUser.class)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ public class PartyActivity extends AvatarActivityBase implements AppBarLayout.On
|
||||||
|
|
||||||
mAPIHelper = new APIHelper(this, hostConfig);
|
mAPIHelper = new APIHelper(this, hostConfig);
|
||||||
|
|
||||||
if(User == null)
|
if (User == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
updateUserAvatars();
|
updateUserAvatars();
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
package com.habitrpg.android.habitica;
|
package com.habitrpg.android.habitica;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -106,8 +105,8 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O
|
||||||
this.task = task;
|
this.task = task;
|
||||||
this.populate(task);
|
this.populate(task);
|
||||||
setTitle(task);
|
setTitle(task);
|
||||||
} else{
|
} else {
|
||||||
setTitle((Task)null);
|
setTitle((Task) null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +118,7 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O
|
||||||
String title = "";
|
String title = "";
|
||||||
|
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
title = getResources().getString(R.string.action_edit)+ " " + task.getText();
|
title = getResources().getString(R.string.action_edit) + " " + task.getText();
|
||||||
} else {
|
} else {
|
||||||
switch (taskType) {
|
switch (taskType) {
|
||||||
case "todo":
|
case "todo":
|
||||||
|
|
@ -273,7 +272,7 @@ public class TaskFormActivity extends AppCompatActivity implements AdapterView.O
|
||||||
if (this.dailyFrequencySpinner.getSelectedItemPosition() == 0) {
|
if (this.dailyFrequencySpinner.getSelectedItemPosition() == 0) {
|
||||||
task.setFrequency("weekly");
|
task.setFrequency("weekly");
|
||||||
Days repeat = task.getRepeat();
|
Days repeat = task.getRepeat();
|
||||||
if(repeat == null){
|
if (repeat == null) {
|
||||||
repeat = new Days();
|
repeat = new Days();
|
||||||
task.setRepeat(repeat);
|
task.setRepeat(repeat);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ public class TavernActivity extends AppCompatActivity {
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEvent(ToggledInnStateEvent evt){
|
public void onEvent(ToggledInnStateEvent evt) {
|
||||||
avatarInHeader.updateData(User);
|
avatarInHeader.updateData(User);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,9 @@ public class HabitRPGUserCallback implements Callback<HabitRPGUser> {
|
||||||
private final OnUserReceived mCallback;
|
private final OnUserReceived mCallback;
|
||||||
|
|
||||||
public HabitRPGUserCallback(OnUserReceived callback) {
|
public HabitRPGUserCallback(OnUserReceived callback) {
|
||||||
this.mCallback = callback;
|
this.mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success(HabitRPGUser habitRPGUser, Response response) {
|
public void success(HabitRPGUser habitRPGUser, Response response) {
|
||||||
Log.d("db", "saving");
|
Log.d("db", "saving");
|
||||||
|
|
@ -37,7 +38,8 @@ public class HabitRPGUserCallback implements Callback<HabitRPGUser> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnUserReceived {
|
public interface OnUserReceived {
|
||||||
public void onUserReceived(HabitRPGUser user);
|
void onUserReceived(HabitRPGUser user);
|
||||||
public void onUserFail();
|
|
||||||
|
void onUserFail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import retrofit.client.Response;
|
||||||
/**
|
/**
|
||||||
* Created by magicmicky on 02/04/15.
|
* Created by magicmicky on 02/04/15.
|
||||||
*/
|
*/
|
||||||
public class TaskDeletionCallback implements Callback<Void> {
|
public class TaskDeletionCallback implements Callback<Void> {
|
||||||
private final OnTaskDeleted callback;
|
private final OnTaskDeleted callback;
|
||||||
private final Task taskToDelete;
|
private final Task taskToDelete;
|
||||||
|
|
||||||
|
|
@ -20,6 +20,7 @@ public class TaskDeletionCallback implements Callback<Void> {
|
||||||
this.callback = cb;
|
this.callback = cb;
|
||||||
this.taskToDelete = taskToDelete;
|
this.taskToDelete = taskToDelete;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success(Void aVoid, Response response) {
|
public void success(Void aVoid, Response response) {
|
||||||
callback.onTaskDeleted(taskToDelete);
|
callback.onTaskDeleted(taskToDelete);
|
||||||
|
|
@ -36,5 +37,7 @@ public class TaskDeletionCallback implements Callback<Void> {
|
||||||
|
|
||||||
public interface OnTaskDeleted {
|
public interface OnTaskDeleted {
|
||||||
public void onTaskDeleted(Task deleted);
|
public void onTaskDeleted(Task deleted);
|
||||||
|
|
||||||
public void onTaskDeletionFail();
|
public void onTaskDeletionFail();
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package com.habitrpg.android.habitica.callbacks;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirectionData;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||||
|
|
@ -19,10 +18,12 @@ import retrofit.client.Response;
|
||||||
public class TaskScoringCallback implements Callback<TaskDirectionData> {
|
public class TaskScoringCallback implements Callback<TaskDirectionData> {
|
||||||
private final OnTaskScored mCallback;
|
private final OnTaskScored mCallback;
|
||||||
private final String taskId;
|
private final String taskId;
|
||||||
|
|
||||||
public TaskScoringCallback(OnTaskScored callback, String taskId) {
|
public TaskScoringCallback(OnTaskScored callback, String taskId) {
|
||||||
this.mCallback= callback;
|
this.mCallback = callback;
|
||||||
this.taskId = taskId;
|
this.taskId = taskId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success(TaskDirectionData taskDirectionData, Response response) {
|
public void success(TaskDirectionData taskDirectionData, Response response) {
|
||||||
Task task = new Select().from(Task.class).where(Condition.column("id").eq(taskId)).querySingle();
|
Task task = new Select().from(Task.class).where(Condition.column("id").eq(taskId)).querySingle();
|
||||||
|
|
@ -35,13 +36,14 @@ public class TaskScoringCallback implements Callback<TaskDirectionData> {
|
||||||
@Override
|
@Override
|
||||||
public void failure(RetrofitError error) {
|
public void failure(RetrofitError error) {
|
||||||
Crashlytics.logException(error);
|
Crashlytics.logException(error);
|
||||||
|
|
||||||
this.mCallback.onTaskScoringFailed();
|
this.mCallback.onTaskScoringFailed();
|
||||||
Log.w("TaskScoring", "Task scoring failed " + error.getMessage());
|
Log.w("TaskScoring", "Task scoring failed " + error.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnTaskScored {
|
public interface OnTaskScored {
|
||||||
public void onTaskDataReceived(TaskDirectionData data);
|
void onTaskDataReceived(TaskDirectionData data);
|
||||||
public void onTaskScoringFailed();
|
|
||||||
|
void onTaskScoringFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package com.habitrpg.android.habitica.callbacks;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.habitrpg.android.habitica.events.TaskCreatedEvent;
|
|
||||||
import com.habitrpg.android.habitica.events.TaskUpdatedEvent;
|
import com.habitrpg.android.habitica.events.TaskUpdatedEvent;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
public class TaskCreatedEvent {
|
public class TaskCreatedEvent {
|
||||||
public Task task;
|
public Task task;
|
||||||
|
|
||||||
public TaskCreatedEvent(Task t){
|
public TaskCreatedEvent(Task t) {
|
||||||
task = t;
|
task = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
public class TaskUpdatedEvent {
|
public class TaskUpdatedEvent {
|
||||||
public Task task;
|
public Task task;
|
||||||
|
|
||||||
public TaskUpdatedEvent(Task t){
|
public TaskUpdatedEvent(Task t) {
|
||||||
task = t;
|
task = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@ package com.habitrpg.android.habitica.events.commands;
|
||||||
* Created by Negue on 11.07.2015.
|
* Created by Negue on 11.07.2015.
|
||||||
*/
|
*/
|
||||||
public class AddNewTaskCommand {
|
public class AddNewTaskCommand {
|
||||||
public String ClassType ;
|
public String ClassType;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ public abstract class ChatMessageCommandBase {
|
||||||
public String groupId;
|
public String groupId;
|
||||||
public ChatMessage chatMessage;
|
public ChatMessage chatMessage;
|
||||||
|
|
||||||
public ChatMessageCommandBase(String groupId, ChatMessage chatMessage){
|
public ChatMessageCommandBase(String groupId, ChatMessage chatMessage) {
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
this.chatMessage = chatMessage;
|
this.chatMessage = chatMessage;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ package com.habitrpg.android.habitica.events.commands;
|
||||||
public class CreateTagCommand {
|
public class CreateTagCommand {
|
||||||
public String tagName;
|
public String tagName;
|
||||||
|
|
||||||
public CreateTagCommand(String tagName){
|
public CreateTagCommand(String tagName) {
|
||||||
this.tagName = tagName;
|
this.tagName = tagName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ public class SendNewGroupMessageCommand {
|
||||||
public String Message;
|
public String Message;
|
||||||
public String TargetGroupId;
|
public String TargetGroupId;
|
||||||
|
|
||||||
public SendNewGroupMessageCommand(String targetGroupId, String message){
|
public SendNewGroupMessageCommand(String targetGroupId, String message) {
|
||||||
TargetGroupId = targetGroupId;
|
TargetGroupId = targetGroupId;
|
||||||
Message = message;
|
Message = message;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
||||||
/**
|
/**
|
||||||
* Created by Negue on 02.09.2015.
|
* Created by Negue on 02.09.2015.
|
||||||
*/
|
*/
|
||||||
public class ToggleLikeMessageCommand extends ChatMessageCommandBase {
|
public class ToggleLikeMessageCommand extends ChatMessageCommandBase {
|
||||||
public ToggleLikeMessageCommand(String groupId, ChatMessage chatMessage) {
|
public ToggleLikeMessageCommand(String groupId, ChatMessage chatMessage) {
|
||||||
super(groupId, chatMessage);
|
super(groupId, chatMessage);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public class TagsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTags(List<String> tagsId) {
|
public void setTags(List<String> tagsId) {
|
||||||
this.tagsId= tagsId;
|
this.tagsId = tagsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTags(String tags) {
|
public void addTags(String tags) {
|
||||||
|
|
@ -34,7 +34,7 @@ public class TagsHelper {
|
||||||
|
|
||||||
public List<Task> filter(List<Task> tasks) {
|
public List<Task> filter(List<Task> tasks) {
|
||||||
List<Task> filtered = new ArrayList<Task>();
|
List<Task> filtered = new ArrayList<Task>();
|
||||||
for(Task t : tasks) {
|
for (Task t : tasks) {
|
||||||
if (t.containsAllTagIds(this.tagsId)) {
|
if (t.containsAllTagIds(this.tagsId)) {
|
||||||
filtered.add(t);
|
filtered.add(t);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.habitrpg.android.habitica.prefs;
|
package com.habitrpg.android.habitica.prefs;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import android.app.AlertDialog.Builder;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
|
|
@ -20,13 +19,13 @@ import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.app.AlertDialog.Builder;
|
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.R;
|
import com.habitrpg.android.habitica.R;
|
||||||
|
|
||||||
public class CustomListPreference extends ListPreference
|
import java.util.ArrayList;
|
||||||
{
|
|
||||||
private CustomListPreferenceAdapter customListPreferenceAdapter = null;
|
public class CustomListPreference extends ListPreference {
|
||||||
|
private CustomListPreferenceAdapter customListPreferenceAdapter = null;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private CharSequence[] entries;
|
private CharSequence[] entries;
|
||||||
|
|
@ -34,10 +33,10 @@ public class CustomListPreference extends ListPreference
|
||||||
private ArrayList<RadioButton> rButtonList;
|
private ArrayList<RadioButton> rButtonList;
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
private SharedPreferences.Editor editor;
|
private SharedPreferences.Editor editor;
|
||||||
private String value="";
|
private String value = "";
|
||||||
private EditText text;
|
private EditText text;
|
||||||
public CustomListPreference(Context context, AttributeSet attrs)
|
|
||||||
{
|
public CustomListPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
|
|
@ -47,123 +46,108 @@ public class CustomListPreference extends ListPreference
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPrepareDialogBuilder(Builder builder)
|
protected void onPrepareDialogBuilder(Builder builder) {
|
||||||
{
|
|
||||||
entries = getEntries();
|
entries = getEntries();
|
||||||
entryValues = getEntryValues();
|
entryValues = getEntryValues();
|
||||||
|
|
||||||
if (entries == null || entryValues == null || entries.length != entryValues.length )
|
if (entries == null || entryValues == null || entries.length != entryValues.length) {
|
||||||
{
|
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"ListPreference requires an entries array and an entryValues array which are both the same length");
|
"ListPreference requires an entries array and an entryValues array which are both the same length");
|
||||||
}
|
}
|
||||||
|
|
||||||
customListPreferenceAdapter = new CustomListPreferenceAdapter(mContext);
|
customListPreferenceAdapter = new CustomListPreferenceAdapter(mContext);
|
||||||
builder.setAdapter(customListPreferenceAdapter, new DialogInterface.OnClickListener()
|
builder.setAdapter(customListPreferenceAdapter, new DialogInterface.OnClickListener() {
|
||||||
{
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
public void onClick(DialogInterface dialog, int which)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setPositiveButton("OK", new OnClickListener() {
|
builder.setPositiveButton("OK", new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface arg0, int arg1) {
|
public void onClick(DialogInterface arg0, int arg1) {
|
||||||
if(value != null && value.equals("custom")) {
|
if (value != null && value.equals("custom")) {
|
||||||
Log.d("commiting","custom value");
|
Log.d("commiting", "custom value");
|
||||||
value=text.getText().toString();
|
value = text.getText().toString();
|
||||||
}
|
}
|
||||||
if(value == null || !value.startsWith("http")) {
|
if (value == null || !value.startsWith("http")) {
|
||||||
Log.v("Commiting", "changing values to default");
|
Log.v("Commiting", "changing values to default");
|
||||||
value = mContext.getString(R.string.SP_address_default);
|
value = mContext.getString(R.string.SP_address_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("Commiting", "putting string: " + value);
|
Log.d("Commiting", "putting string: " + value);
|
||||||
editor.putString(mContext.getString(R.string.SP_address), value);
|
editor.putString(mContext.getString(R.string.SP_address), value);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
arg0.dismiss();
|
arg0.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CustomListPreferenceAdapter extends BaseAdapter
|
private class CustomListPreferenceAdapter extends BaseAdapter {
|
||||||
{
|
public CustomListPreferenceAdapter(Context context) {
|
||||||
public CustomListPreferenceAdapter(Context context)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount()
|
public int getCount() {
|
||||||
{
|
|
||||||
return entries.length;
|
return entries.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getItem(int position)
|
public Object getItem(int position) {
|
||||||
{
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getItemId(int position)
|
public long getItemId(int position) {
|
||||||
{
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getView(final int position, View convertView, ViewGroup parent)
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
{
|
|
||||||
View row = convertView;
|
View row = convertView;
|
||||||
|
|
||||||
if(row == null)
|
if (row == null) {
|
||||||
{
|
|
||||||
// do whatever you need here, for me I wanted the last item to be greyed out and unclickable
|
// do whatever you need here, for me I wanted the last item to be greyed out and unclickable
|
||||||
if(position < 2)
|
if (position < 2) {
|
||||||
{
|
|
||||||
NormalHolder holder = null;
|
NormalHolder holder = null;
|
||||||
|
|
||||||
row = mInflater.inflate(R.layout.normal_list_preference_row, parent, false);
|
row = mInflater.inflate(R.layout.normal_list_preference_row, parent, false);
|
||||||
if(prefs.getString(mContext.getString(R.string.SP_address), "0").equals(entryValues[position])) {
|
if (prefs.getString(mContext.getString(R.string.SP_address), "0").equals(entryValues[position])) {
|
||||||
holder = new NormalHolder(row, position,true);
|
holder = new NormalHolder(row, position, true);
|
||||||
Log.v("Prefs", entryValues[position] + " already exists at position " + position);
|
Log.v("Prefs", entryValues[position] + " already exists at position " + position);
|
||||||
value=entryValues[position].toString();
|
value = entryValues[position].toString();
|
||||||
} else {
|
} else {
|
||||||
holder = new NormalHolder(row, position,false);
|
holder = new NormalHolder(row, position, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
row.setTag(holder);
|
row.setTag(holder);
|
||||||
// row.setClickable(true);
|
// row.setClickable(true);
|
||||||
row.setOnClickListener(new View.OnClickListener()
|
row.setOnClickListener(new View.OnClickListener() {
|
||||||
{
|
public void onClick(View v) {
|
||||||
public void onClick(View v)
|
if (!rButtonList.get(position).isChecked()) {
|
||||||
{
|
for (RadioButton rb : rButtonList) {
|
||||||
if(!rButtonList.get(position).isChecked()) {
|
if (rb.getId() == position) {
|
||||||
for(RadioButton rb : rButtonList)
|
Log.d("row.OnClickListener - " + position, "isChecked");
|
||||||
{
|
if (!rb.isChecked())
|
||||||
if(rb.getId() == position) {
|
rb.setChecked(true);
|
||||||
Log.d("row.OnClickListener - " + position, "isChecked");
|
}
|
||||||
if(!rb.isChecked())
|
}
|
||||||
rb.setChecked(true);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
row = mInflater.inflate(R.layout.custom_list_preference_row, parent, false);
|
row = mInflater.inflate(R.layout.custom_list_preference_row, parent, false);
|
||||||
String fromPref = prefs.getString(mContext.getString(R.string.SP_address), "0");
|
String fromPref = prefs.getString(mContext.getString(R.string.SP_address), "0");
|
||||||
boolean flag=false;
|
boolean flag = false;
|
||||||
for(CharSequence entry : entryValues) {
|
for (CharSequence entry : entryValues) {
|
||||||
if(entry.toString().equals(fromPref)) {
|
if (entry.toString().equals(fromPref)) {
|
||||||
Log.v("ListPref", entry.toString() + " already exists");
|
Log.v("ListPref", entry.toString() + " already exists");
|
||||||
flag=true;
|
flag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CustomHolder holder;
|
CustomHolder holder;
|
||||||
if(!flag && fromPref != null && !fromPref.equals("")) {
|
if (!flag && fromPref != null && !fromPref.equals("")) {
|
||||||
holder = new CustomHolder(row, position, fromPref, true);
|
holder = new CustomHolder(row, position, fromPref, true);
|
||||||
value = "custom";
|
value = "custom";
|
||||||
} else {
|
} else {
|
||||||
holder = new CustomHolder(row, position, "", false);
|
holder = new CustomHolder(row, position, "", false);
|
||||||
|
|
||||||
}
|
}
|
||||||
row.setTag(holder);
|
row.setTag(holder);
|
||||||
|
|
@ -172,87 +156,77 @@ public class CustomListPreference extends ListPreference
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
class NormalHolder
|
|
||||||
{
|
|
||||||
private TextView text = null;
|
|
||||||
private RadioButton rButton = null;
|
|
||||||
|
|
||||||
NormalHolder(View row, int position, boolean isCheked)
|
class NormalHolder {
|
||||||
{
|
private TextView text = null;
|
||||||
text = (TextView)row.findViewById(R.id.custom_list_view_row_text_view);
|
|
||||||
text.setText(entries[position]);
|
|
||||||
rButton = (RadioButton)row.findViewById(R.id.custom_list_view_row_radio_button);
|
|
||||||
rButton.setId(position);
|
|
||||||
rButton.setChecked(isCheked);
|
|
||||||
|
|
||||||
// also need to do something to check your preference and set the right button as checked
|
|
||||||
|
|
||||||
rButtonList.add(rButton);
|
|
||||||
rButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
|
||||||
{
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
|
||||||
{
|
|
||||||
if(isChecked)
|
|
||||||
{
|
|
||||||
for(RadioButton rb : rButtonList)
|
|
||||||
{
|
|
||||||
if(rb.getId() != buttonView.getId())
|
|
||||||
rb.setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = buttonView.getId();
|
|
||||||
value = entryValues[index].toString();
|
|
||||||
Log.v("NormalHolder.onCheckedChanged", "putting string" + value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
class CustomHolder
|
|
||||||
{
|
|
||||||
private RadioButton rButton = null;
|
private RadioButton rButton = null;
|
||||||
|
|
||||||
CustomHolder(View row, int position, String pref, boolean checked)
|
NormalHolder(View row, int position, boolean isCheked) {
|
||||||
{
|
text = (TextView) row.findViewById(R.id.custom_list_view_row_text_view);
|
||||||
rButton = (RadioButton)row.findViewById(R.id.custom_list_view_row_radio_button);
|
text.setText(entries[position]);
|
||||||
|
rButton = (RadioButton) row.findViewById(R.id.custom_list_view_row_radio_button);
|
||||||
|
rButton.setId(position);
|
||||||
|
rButton.setChecked(isCheked);
|
||||||
|
|
||||||
|
// also need to do something to check your preference and set the right button as checked
|
||||||
|
|
||||||
|
rButtonList.add(rButton);
|
||||||
|
rButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
if (isChecked) {
|
||||||
|
for (RadioButton rb : rButtonList) {
|
||||||
|
if (rb.getId() != buttonView.getId())
|
||||||
|
rb.setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = buttonView.getId();
|
||||||
|
value = entryValues[index].toString();
|
||||||
|
Log.v("NormalHolder.onCheckedChanged", "putting string" + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomHolder {
|
||||||
|
private RadioButton rButton = null;
|
||||||
|
|
||||||
|
CustomHolder(View row, int position, String pref, boolean checked) {
|
||||||
|
rButton = (RadioButton) row.findViewById(R.id.custom_list_view_row_radio_button);
|
||||||
rButton.setId(position);
|
rButton.setId(position);
|
||||||
rButton.setChecked(checked);
|
rButton.setChecked(checked);
|
||||||
|
|
||||||
text = (EditText)row.findViewById(R.id.ET_prefs_customText);
|
text = (EditText) row.findViewById(R.id.ET_prefs_customText);
|
||||||
text.setText(pref);
|
text.setText(pref);
|
||||||
text.setOnFocusChangeListener(new OnFocusChangeListener() {
|
text.setOnFocusChangeListener(new OnFocusChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFocusChange(View v, boolean hasFocus) {
|
public void onFocusChange(View v, boolean hasFocus) {
|
||||||
if(hasFocus) {
|
if (hasFocus) {
|
||||||
if(!rButton.isChecked())
|
if (!rButton.isChecked())
|
||||||
rButton.setChecked(true);
|
rButton.setChecked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||||
rButtonList.add(rButton);
|
rButtonList.add(rButton);
|
||||||
|
|
||||||
// also need to do something to check your preference and set the right button as checked
|
// also need to do something to check your preference and set the right button as checked
|
||||||
|
|
||||||
rButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
rButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
{
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
if (isChecked) {
|
||||||
{
|
for (RadioButton rb : rButtonList) {
|
||||||
if(isChecked)
|
if (rb != buttonView)
|
||||||
{
|
|
||||||
for(RadioButton rb : rButtonList)
|
|
||||||
{
|
|
||||||
if(rb != buttonView)
|
|
||||||
rb.setChecked(false);
|
rb.setChecked(false);
|
||||||
}
|
}
|
||||||
if(!text.hasFocus())
|
if (!text.hasFocus())
|
||||||
text.requestFocus();
|
text.requestFocus();
|
||||||
value = String.valueOf("custom");
|
value = String.valueOf("custom");
|
||||||
Log.v("CustomHolder.onCheckedChanged","putting string" + value);
|
Log.v("CustomHolder.onCheckedChanged", "putting string" + value);
|
||||||
} else {
|
} else {
|
||||||
if(text.hasFocus())
|
if (text.hasFocus())
|
||||||
text.clearFocus();
|
text.clearFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,5 @@
|
||||||
package com.habitrpg.android.habitica.prefs;
|
package com.habitrpg.android.habitica.prefs;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.HostConfig;
|
|
||||||
import com.habitrpg.android.habitica.R;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
@ -19,30 +12,39 @@ import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
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 {
|
public class PrefsActivity extends PreferenceActivity {
|
||||||
protected Method mLoadHeaders = null;
|
protected Method mLoadHeaders = null;
|
||||||
protected Method mHasHeaders = null;
|
protected Method mHasHeaders = null;
|
||||||
/**
|
|
||||||
|
/**
|
||||||
* Checks to see if using new v11+ way of handling PrefsFragments.
|
* Checks to see if using new v11+ way of handling PrefsFragments.
|
||||||
|
*
|
||||||
* @return Returns false pre-v11, else checks to see if using headers.
|
* @return Returns false pre-v11, else checks to see if using headers.
|
||||||
*/
|
*/
|
||||||
public boolean isNewV11Prefs() {
|
public boolean isNewV11Prefs() {
|
||||||
if (mHasHeaders!=null && mLoadHeaders!=null) {
|
if (mHasHeaders != null && mLoadHeaders != null) {
|
||||||
try {
|
try {
|
||||||
return (Boolean)mHasHeaders.invoke(this);
|
return (Boolean) mHasHeaders.invoke(this);
|
||||||
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException ignored) {
|
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle aSavedState) {
|
public void onCreate(Bundle aSavedState) {
|
||||||
//onBuildHeaders() will be called during super.onCreate()
|
//onBuildHeaders() will be called during super.onCreate()
|
||||||
try {
|
try {
|
||||||
mLoadHeaders = getClass().getMethod("loadHeadersFromResource", int.class, List.class );
|
mLoadHeaders = getClass().getMethod("loadHeadersFromResource", int.class, List.class);
|
||||||
mHasHeaders = getClass().getMethod("hasHeaders");
|
mHasHeaders = getClass().getMethod("hasHeaders");
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
}
|
}
|
||||||
|
|
@ -59,11 +61,11 @@ public class PrefsActivity extends PreferenceActivity {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(this.getActionBar() != null) {
|
if (this.getActionBar() != null) {
|
||||||
this.getActionBar().setDisplayHomeAsUpEnabled(true);
|
this.getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -74,11 +76,11 @@ public class PrefsActivity extends PreferenceActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onBuildHeaders(List<Header> aTarget) {
|
public void onBuildHeaders(List<Header> aTarget) {
|
||||||
try {
|
try {
|
||||||
mLoadHeaders.invoke(this,new Object[]{R.xml.pref_headers,aTarget});
|
mLoadHeaders.invoke(this, new Object[]{R.xml.pref_headers, aTarget});
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -92,39 +94,39 @@ public class PrefsActivity extends PreferenceActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
static public class PrefsFragment extends PreferenceFragment {
|
static public class PrefsFragment extends PreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle aSavedState) {
|
public void onCreate(Bundle aSavedState) {
|
||||||
super.onCreate(aSavedState);
|
super.onCreate(aSavedState);
|
||||||
Context anAct = getActivity().getApplicationContext();
|
Context anAct = getActivity().getApplicationContext();
|
||||||
int thePrefRes = anAct.getResources().getIdentifier(getArguments().getString("pref-resource"),
|
int thePrefRes = anAct.getResources().getIdentifier(getArguments().getString("pref-resource"),
|
||||||
"xml",anAct.getPackageName());
|
"xml", anAct.getPackageName());
|
||||||
addPreferencesFromResource(thePrefRes);
|
addPreferencesFromResource(thePrefRes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static HostConfig fromContext(Context ctx) {
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
|
||||||
HostConfig config;
|
|
||||||
String httpPort = "80";
|
|
||||||
String address = prefs.getString(ctx.getString(R.string.SP_address), ctx.getString(R.string.SP_address_default));
|
|
||||||
if(address.contains("http://habitrpg.com")) {
|
|
||||||
address = "https://habitrpg.com";
|
|
||||||
prefs.edit().putString(ctx.getString(R.string.SP_address), address).commit();
|
|
||||||
} else if (address.contains("http://beta.habitrpg.com")) {
|
|
||||||
address = "https://beta.habitrpg.com/";
|
|
||||||
prefs.edit().putString(ctx.getString(R.string.SP_address), address).commit();
|
|
||||||
|
|
||||||
}
|
public static HostConfig fromContext(Context ctx) {
|
||||||
if(address==null || address=="" || address.length()<2) {
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
config=null;
|
HostConfig config;
|
||||||
}
|
String httpPort = "80";
|
||||||
else {
|
String address = prefs.getString(ctx.getString(R.string.SP_address), ctx.getString(R.string.SP_address_default));
|
||||||
String api=prefs.getString(ctx.getString(R.string.SP_APIToken), null);
|
if (address.contains("http://habitrpg.com")) {
|
||||||
String userID=prefs.getString(ctx.getString(R.string.SP_userID), null);
|
address = "https://habitrpg.com";
|
||||||
config = new HostConfig(address, httpPort, api, userID);
|
prefs.edit().putString(ctx.getString(R.string.SP_address), address).commit();
|
||||||
}
|
} else if (address.contains("http://beta.habitrpg.com")) {
|
||||||
return config;
|
address = "https://beta.habitrpg.com/";
|
||||||
}
|
prefs.edit().putString(ctx.getString(R.string.SP_address), address).commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (address == null || address == "" || address.length() < 2) {
|
||||||
|
config = null;
|
||||||
|
} else {
|
||||||
|
String api = prefs.getString(ctx.getString(R.string.SP_APIToken), null);
|
||||||
|
String userID = prefs.getString(ctx.getString(R.string.SP_userID), null);
|
||||||
|
config = new HostConfig(address, httpPort, api, userID);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,6 @@ package com.habitrpg.android.habitica.prefs.scanner;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
|
|
@ -34,22 +27,29 @@ import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>A utility class which helps ease integration with Barcode Scanner via {@link Intent}s. This is a simple
|
* <p>A utility class which helps ease integration with Barcode Scanner via {@link Intent}s. This is a simple
|
||||||
* way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the
|
* way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the
|
||||||
* project's source code.</p>
|
* project's source code.</p>
|
||||||
*
|
* <p/>
|
||||||
* <h2>Initiating a barcode scan</h2>
|
* <h2>Initiating a barcode scan</h2>
|
||||||
*
|
* <p/>
|
||||||
* <p>To integrate, create an instance of {@code IntentIntegrator} and call {@link #initiateScan()} and wait
|
* <p>To integrate, create an instance of {@code IntentIntegrator} and call {@link #initiateScan()} and wait
|
||||||
* for the result in your app.</p>
|
* for the result in your app.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>It does require that the Barcode Scanner (or work-alike) application is installed. The
|
* <p>It does require that the Barcode Scanner (or work-alike) application is installed. The
|
||||||
* {@link #initiateScan()} method will prompt the user to download the application, if needed.</p>
|
* {@link #initiateScan()} method will prompt the user to download the application, if needed.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>There are a few steps to using this integration. First, your {@link Activity} must implement
|
* <p>There are a few steps to using this integration. First, your {@link Activity} must implement
|
||||||
* the method {@link Activity#onActivityResult(int, int, Intent)} and include a line of code like this:</p>
|
* the method {@link Activity#onActivityResult(int, int, Intent)} and include a line of code like this:</p>
|
||||||
*
|
* <p/>
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
* public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
* public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
* IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
* IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
||||||
|
|
@ -60,41 +60,41 @@ import android.util.Log;
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
* }</pre>
|
* }</pre>
|
||||||
*
|
* <p/>
|
||||||
* <p>This is where you will handle a scan result.</p>
|
* <p>This is where you will handle a scan result.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Second, just call this in response to a user action somewhere to begin the scan process:</p>
|
* <p>Second, just call this in response to a user action somewhere to begin the scan process:</p>
|
||||||
*
|
* <p/>
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
* IntentIntegrator integrator = new IntentIntegrator(yourActivity);
|
* IntentIntegrator integrator = new IntentIntegrator(yourActivity);
|
||||||
* integrator.initiateScan();
|
* integrator.initiateScan();
|
||||||
* }</pre>
|
* }</pre>
|
||||||
*
|
* <p/>
|
||||||
* <p>Note that {@link #initiateScan()} returns an {@link AlertDialog} which is non-null if the
|
* <p>Note that {@link #initiateScan()} returns an {@link AlertDialog} which is non-null if the
|
||||||
* user was prompted to download the application. This lets the calling app potentially manage the dialog.
|
* user was prompted to download the application. This lets the calling app potentially manage the dialog.
|
||||||
* In particular, ideally, the app dismisses the dialog if it's still active in its {@link Activity#onPause()}
|
* In particular, ideally, the app dismisses the dialog if it's still active in its {@link Activity#onPause()}
|
||||||
* method.</p>
|
* method.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>You can use {@link #setTitle(String)} to customize the title of this download prompt dialog (or, use
|
* <p>You can use {@link #setTitle(String)} to customize the title of this download prompt dialog (or, use
|
||||||
* {@link #setTitleByID(int)} to set the title by string resource ID.) Likewise, the prompt message, and
|
* {@link #setTitleByID(int)} to set the title by string resource ID.) Likewise, the prompt message, and
|
||||||
* yes/no button labels can be changed.</p>
|
* yes/no button labels can be changed.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Finally, you can use {@link #addExtra(String, Object)} to add more parameters to the Intent used
|
* <p>Finally, you can use {@link #addExtra(String, Object)} to add more parameters to the Intent used
|
||||||
* to invoke the scanner. This can be used to set additional options not directly exposed by this
|
* to invoke the scanner. This can be used to set additional options not directly exposed by this
|
||||||
* simplified API.</p>
|
* simplified API.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>By default, this will only allow applications that are known to respond to this intent correctly
|
* <p>By default, this will only allow applications that are known to respond to this intent correctly
|
||||||
* do so. The apps that are allowed to response can be set with {@link #setTargetApplications(List)}.
|
* do so. The apps that are allowed to response can be set with {@link #setTargetApplications(List)}.
|
||||||
* For example, set to {@link #TARGET_BARCODE_SCANNER_ONLY} to only target the Barcode Scanner app itself.</p>
|
* For example, set to {@link #TARGET_BARCODE_SCANNER_ONLY} to only target the Barcode Scanner app itself.</p>
|
||||||
*
|
* <p/>
|
||||||
* <h2>Sharing text via barcode</h2>
|
* <h2>Sharing text via barcode</h2>
|
||||||
*
|
* <p/>
|
||||||
* <p>To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(CharSequence)}.</p>
|
* <p>To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(CharSequence)}.</p>
|
||||||
*
|
* <p/>
|
||||||
* <p>Some code, particularly download integration, was contributed from the Anobiit application.</p>
|
* <p>Some code, particularly download integration, was contributed from the Anobiit application.</p>
|
||||||
*
|
* <p/>
|
||||||
* <h2>Enabling experimental barcode formats</h2>
|
* <h2>Enabling experimental barcode formats</h2>
|
||||||
*
|
* <p/>
|
||||||
* <p>Some formats are not enabled by default even when scanning with {@link #ALL_CODE_TYPES}, such as
|
* <p>Some formats are not enabled by default even when scanning with {@link #ALL_CODE_TYPES}, such as
|
||||||
* PDF417. Use {@link #initiateScan(java.util.Collection)} with
|
* PDF417. Use {@link #initiateScan(java.util.Collection)} with
|
||||||
* a collection containing the names of formats to scan for explicitly, like "PDF_417", to use such
|
* a collection containing the names of formats to scan for explicitly, like "PDF_417", to use such
|
||||||
|
|
@ -108,312 +108,314 @@ import android.util.Log;
|
||||||
*/
|
*/
|
||||||
public class IntentIntegrator {
|
public class IntentIntegrator {
|
||||||
|
|
||||||
public static final int REQUEST_CODE = 0x0000c0de; // Only use bottom 16 bits
|
public static final int REQUEST_CODE = 0x0000c0de; // Only use bottom 16 bits
|
||||||
private static final String TAG = IntentIntegrator.class.getSimpleName();
|
private static final String TAG = IntentIntegrator.class.getSimpleName();
|
||||||
|
|
||||||
public static final String DEFAULT_TITLE = "Install Barcode Scanner?";
|
public static final String DEFAULT_TITLE = "Install Barcode Scanner?";
|
||||||
public static final String DEFAULT_MESSAGE =
|
public static final String DEFAULT_MESSAGE =
|
||||||
"This application requires Barcode Scanner. Would you like to install it?";
|
"This application requires Barcode Scanner. Would you like to install it?";
|
||||||
public static final String DEFAULT_YES = "Yes";
|
public static final String DEFAULT_YES = "Yes";
|
||||||
public static final String DEFAULT_NO = "No";
|
public static final String DEFAULT_NO = "No";
|
||||||
|
|
||||||
private static final String BS_PACKAGE = "com.google.zxing.client.android";
|
private static final String BS_PACKAGE = "com.google.zxing.client.android";
|
||||||
private static final String BSPLUS_PACKAGE = "com.srowen.bs.android";
|
private static final String BSPLUS_PACKAGE = "com.srowen.bs.android";
|
||||||
|
|
||||||
// supported barcode formats
|
// supported barcode formats
|
||||||
public static final Collection<String> PRODUCT_CODE_TYPES = list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "RSS_14");
|
public static final Collection<String> PRODUCT_CODE_TYPES = list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "RSS_14");
|
||||||
public static final Collection<String> ONE_D_CODE_TYPES =
|
public static final Collection<String> ONE_D_CODE_TYPES =
|
||||||
list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "CODE_39", "CODE_93", "CODE_128",
|
list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "CODE_39", "CODE_93", "CODE_128",
|
||||||
"ITF", "RSS_14", "RSS_EXPANDED");
|
"ITF", "RSS_14", "RSS_EXPANDED");
|
||||||
public static final Collection<String> QR_CODE_TYPES = Collections.singleton("QR_CODE");
|
public static final Collection<String> QR_CODE_TYPES = Collections.singleton("QR_CODE");
|
||||||
public static final Collection<String> DATA_MATRIX_TYPES = Collections.singleton("DATA_MATRIX");
|
public static final Collection<String> DATA_MATRIX_TYPES = Collections.singleton("DATA_MATRIX");
|
||||||
|
|
||||||
public static final Collection<String> ALL_CODE_TYPES = null;
|
public static final Collection<String> ALL_CODE_TYPES = null;
|
||||||
|
|
||||||
public static final List<String> TARGET_BARCODE_SCANNER_ONLY = Collections.singletonList(BS_PACKAGE);
|
|
||||||
public static final List<String> TARGET_ALL_KNOWN = list(
|
|
||||||
BS_PACKAGE, // Barcode Scanner
|
|
||||||
BSPLUS_PACKAGE, // Barcode Scanner+
|
|
||||||
BSPLUS_PACKAGE + ".simple" // Barcode Scanner+ Simple
|
|
||||||
// What else supports this intent?
|
|
||||||
);
|
|
||||||
|
|
||||||
private final Activity activity;
|
|
||||||
private String title;
|
|
||||||
private String message;
|
|
||||||
private String buttonYes;
|
|
||||||
private String buttonNo;
|
|
||||||
private List<String> targetApplications;
|
|
||||||
private final Map<String,Object> moreExtras;
|
|
||||||
|
|
||||||
public IntentIntegrator(Activity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
title = DEFAULT_TITLE;
|
|
||||||
message = DEFAULT_MESSAGE;
|
|
||||||
buttonYes = DEFAULT_YES;
|
|
||||||
buttonNo = DEFAULT_NO;
|
|
||||||
targetApplications = TARGET_ALL_KNOWN;
|
|
||||||
moreExtras = new HashMap<String,Object>(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitleByID(int titleID) {
|
public static final List<String> TARGET_BARCODE_SCANNER_ONLY = Collections.singletonList(BS_PACKAGE);
|
||||||
title = activity.getString(titleID);
|
public static final List<String> TARGET_ALL_KNOWN = list(
|
||||||
}
|
BS_PACKAGE, // Barcode Scanner
|
||||||
|
BSPLUS_PACKAGE, // Barcode Scanner+
|
||||||
|
BSPLUS_PACKAGE + ".simple" // Barcode Scanner+ Simple
|
||||||
|
// What else supports this intent?
|
||||||
|
);
|
||||||
|
|
||||||
public String getMessage() {
|
private final Activity activity;
|
||||||
return message;
|
private String title;
|
||||||
}
|
private String message;
|
||||||
|
private String buttonYes;
|
||||||
|
private String buttonNo;
|
||||||
|
private List<String> targetApplications;
|
||||||
|
private final Map<String, Object> moreExtras;
|
||||||
|
|
||||||
public void setMessage(String message) {
|
public IntentIntegrator(Activity activity) {
|
||||||
this.message = message;
|
this.activity = activity;
|
||||||
}
|
title = DEFAULT_TITLE;
|
||||||
|
message = DEFAULT_MESSAGE;
|
||||||
public void setMessageByID(int messageID) {
|
buttonYes = DEFAULT_YES;
|
||||||
message = activity.getString(messageID);
|
buttonNo = DEFAULT_NO;
|
||||||
}
|
targetApplications = TARGET_ALL_KNOWN;
|
||||||
|
moreExtras = new HashMap<String, Object>(3);
|
||||||
public String getButtonYes() {
|
|
||||||
return buttonYes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setButtonYes(String buttonYes) {
|
|
||||||
this.buttonYes = buttonYes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setButtonYesByID(int buttonYesID) {
|
|
||||||
buttonYes = activity.getString(buttonYesID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getButtonNo() {
|
|
||||||
return buttonNo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setButtonNo(String buttonNo) {
|
|
||||||
this.buttonNo = buttonNo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setButtonNoByID(int buttonNoID) {
|
|
||||||
buttonNo = activity.getString(buttonNoID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<String> getTargetApplications() {
|
|
||||||
return targetApplications;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void setTargetApplications(List<String> targetApplications) {
|
|
||||||
if (targetApplications.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("No target applications");
|
|
||||||
}
|
}
|
||||||
this.targetApplications = targetApplications;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSingleTargetApplication(String targetApplication) {
|
|
||||||
this.targetApplications = Collections.singletonList(targetApplication);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String,?> getMoreExtras() {
|
public String getTitle() {
|
||||||
return moreExtras;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void addExtra(String key, Object value) {
|
public void setTitle(String title) {
|
||||||
moreExtras.put(key, value);
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void setTitleByID(int titleID) {
|
||||||
* Initiates a scan for all known barcode types.
|
title = activity.getString(titleID);
|
||||||
*/
|
}
|
||||||
public final AlertDialog initiateScan() {
|
|
||||||
return initiateScan(ALL_CODE_TYPES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public String getMessage() {
|
||||||
* Initiates a scan only for a certain set of barcode types, given as strings corresponding
|
return message;
|
||||||
* to their names in ZXing's {@code BarcodeFormat} class like "UPC_A". You can supply constants
|
}
|
||||||
* like {@link #PRODUCT_CODE_TYPES} for example.
|
|
||||||
*
|
|
||||||
* @return the {@link AlertDialog} that was shown to the user prompting them to download the app
|
|
||||||
* if a prompt was needed, or null otherwise
|
|
||||||
*/
|
|
||||||
public final AlertDialog initiateScan(Collection<String> desiredBarcodeFormats) {
|
|
||||||
Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");
|
|
||||||
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
|
|
||||||
|
|
||||||
// check which types of codes to scan for
|
public void setMessage(String message) {
|
||||||
if (desiredBarcodeFormats != null) {
|
this.message = message;
|
||||||
// set the desired barcode types
|
}
|
||||||
StringBuilder joinedByComma = new StringBuilder();
|
|
||||||
for (String format : desiredBarcodeFormats) {
|
public void setMessageByID(int messageID) {
|
||||||
if (joinedByComma.length() > 0) {
|
message = activity.getString(messageID);
|
||||||
joinedByComma.append(',');
|
}
|
||||||
|
|
||||||
|
public String getButtonYes() {
|
||||||
|
return buttonYes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setButtonYes(String buttonYes) {
|
||||||
|
this.buttonYes = buttonYes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setButtonYesByID(int buttonYesID) {
|
||||||
|
buttonYes = activity.getString(buttonYesID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getButtonNo() {
|
||||||
|
return buttonNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setButtonNo(String buttonNo) {
|
||||||
|
this.buttonNo = buttonNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setButtonNoByID(int buttonNoID) {
|
||||||
|
buttonNo = activity.getString(buttonNoID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<String> getTargetApplications() {
|
||||||
|
return targetApplications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setTargetApplications(List<String> targetApplications) {
|
||||||
|
if (targetApplications.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("No target applications");
|
||||||
}
|
}
|
||||||
joinedByComma.append(format);
|
this.targetApplications = targetApplications;
|
||||||
}
|
|
||||||
intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetAppPackage = findTargetAppPackage(intentScan);
|
public void setSingleTargetApplication(String targetApplication) {
|
||||||
if (targetAppPackage == null) {
|
this.targetApplications = Collections.singletonList(targetApplication);
|
||||||
return showDownloadDialog();
|
|
||||||
}
|
}
|
||||||
intentScan.setPackage(targetAppPackage);
|
|
||||||
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
|
||||||
attachMoreExtras(intentScan);
|
|
||||||
startActivityForResult(intentScan, REQUEST_CODE);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public Map<String, ?> getMoreExtras() {
|
||||||
* Start an activity.<br>
|
return moreExtras;
|
||||||
* This method is defined to allow different methods of activity starting for
|
}
|
||||||
* newer versions of Android and for compatibility library.
|
|
||||||
*
|
public final void addExtra(String key, Object value) {
|
||||||
* @param intent Intent to start.
|
moreExtras.put(key, value);
|
||||||
* @param code Request code for the activity
|
}
|
||||||
* @see android.app.Activity#startActivityForResult(Intent, int)
|
|
||||||
* @see android.app.Fragment#startActivityForResult(Intent, int)
|
/**
|
||||||
*/
|
* Initiates a scan for all known barcode types.
|
||||||
protected void startActivityForResult(Intent intent, int code) {
|
*/
|
||||||
activity.startActivityForResult(intent, code);
|
public final AlertDialog initiateScan() {
|
||||||
}
|
return initiateScan(ALL_CODE_TYPES);
|
||||||
|
}
|
||||||
private String findTargetAppPackage(Intent intent) {
|
|
||||||
PackageManager pm = activity.getPackageManager();
|
/**
|
||||||
List<ResolveInfo> availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
* Initiates a scan only for a certain set of barcode types, given as strings corresponding
|
||||||
if (availableApps != null) {
|
* to their names in ZXing's {@code BarcodeFormat} class like "UPC_A". You can supply constants
|
||||||
for (ResolveInfo availableApp : availableApps) {
|
* like {@link #PRODUCT_CODE_TYPES} for example.
|
||||||
String packageName = availableApp.activityInfo.packageName;
|
*
|
||||||
if (targetApplications.contains(packageName)) {
|
* @return the {@link AlertDialog} that was shown to the user prompting them to download the app
|
||||||
return packageName;
|
* if a prompt was needed, or null otherwise
|
||||||
|
*/
|
||||||
|
public final AlertDialog initiateScan(Collection<String> desiredBarcodeFormats) {
|
||||||
|
Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");
|
||||||
|
intentScan.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
|
||||||
|
// check which types of codes to scan for
|
||||||
|
if (desiredBarcodeFormats != null) {
|
||||||
|
// set the desired barcode types
|
||||||
|
StringBuilder joinedByComma = new StringBuilder();
|
||||||
|
for (String format : desiredBarcodeFormats) {
|
||||||
|
if (joinedByComma.length() > 0) {
|
||||||
|
joinedByComma.append(',');
|
||||||
|
}
|
||||||
|
joinedByComma.append(format);
|
||||||
|
}
|
||||||
|
intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AlertDialog showDownloadDialog() {
|
String targetAppPackage = findTargetAppPackage(intentScan);
|
||||||
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
|
if (targetAppPackage == null) {
|
||||||
downloadDialog.setTitle(title);
|
return showDownloadDialog();
|
||||||
downloadDialog.setMessage(message);
|
|
||||||
downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
String packageName = targetApplications.get(0);
|
|
||||||
Uri uri = Uri.parse("market://details?id=" + packageName);
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
|
||||||
try {
|
|
||||||
activity.startActivity(intent);
|
|
||||||
} catch (ActivityNotFoundException anfe) {
|
|
||||||
// Hmm, market is not installed
|
|
||||||
Log.w(TAG, "Google Play is not installed; cannot install " + packageName);
|
|
||||||
}
|
}
|
||||||
}
|
intentScan.setPackage(targetAppPackage);
|
||||||
});
|
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
downloadDialog.setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
|
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||||
@Override
|
attachMoreExtras(intentScan);
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {}
|
startActivityForResult(intentScan, REQUEST_CODE);
|
||||||
});
|
return null;
|
||||||
return downloadDialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Call this from your {@link Activity}'s
|
|
||||||
* {@link Activity#onActivityResult(int, int, Intent)} method.</p>
|
|
||||||
*
|
|
||||||
* @return null if the event handled here was not related to this class, or
|
|
||||||
* else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
|
|
||||||
* the fields will be null.
|
|
||||||
*/
|
|
||||||
public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
||||||
if (requestCode == REQUEST_CODE) {
|
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
|
||||||
String contents = intent.getStringExtra("SCAN_RESULT");
|
|
||||||
String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
|
|
||||||
byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
|
|
||||||
int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
|
|
||||||
Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
|
|
||||||
String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
|
|
||||||
return new IntentResult(contents,
|
|
||||||
formatName,
|
|
||||||
rawBytes,
|
|
||||||
orientation,
|
|
||||||
errorCorrectionLevel);
|
|
||||||
}
|
|
||||||
return new IntentResult();
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* Start an activity.<br>
|
||||||
* Defaults to type "TEXT_TYPE".
|
* This method is defined to allow different methods of activity starting for
|
||||||
* @see #shareText(CharSequence, CharSequence)
|
* newer versions of Android and for compatibility library.
|
||||||
*/
|
*
|
||||||
public final AlertDialog shareText(CharSequence text) {
|
* @param intent Intent to start.
|
||||||
return shareText(text, "TEXT_TYPE");
|
* @param code Request code for the activity
|
||||||
}
|
* @see android.app.Activity#startActivityForResult(Intent, int)
|
||||||
|
* @see android.app.Fragment#startActivityForResult(Intent, int)
|
||||||
/**
|
*/
|
||||||
* Shares the given text by encoding it as a barcode, such that another user can
|
protected void startActivityForResult(Intent intent, int code) {
|
||||||
* scan the text off the screen of the device.
|
activity.startActivityForResult(intent, code);
|
||||||
*
|
|
||||||
* @param text the text string to encode as a barcode
|
|
||||||
* @param type type of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
|
|
||||||
* @return the {@link AlertDialog} that was shown to the user prompting them to download the app
|
|
||||||
* if a prompt was needed, or null otherwise
|
|
||||||
*/
|
|
||||||
public final AlertDialog shareText(CharSequence text, CharSequence type) {
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
||||||
intent.setAction(BS_PACKAGE + ".ENCODE");
|
|
||||||
intent.putExtra("ENCODE_TYPE", type);
|
|
||||||
intent.putExtra("ENCODE_DATA", text);
|
|
||||||
String targetAppPackage = findTargetAppPackage(intent);
|
|
||||||
if (targetAppPackage == null) {
|
|
||||||
return showDownloadDialog();
|
|
||||||
}
|
}
|
||||||
intent.setPackage(targetAppPackage);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
|
||||||
attachMoreExtras(intent);
|
|
||||||
activity.startActivity(intent);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<String> list(String... values) {
|
|
||||||
return Collections.unmodifiableList(Arrays.asList(values));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void attachMoreExtras(Intent intent) {
|
private String findTargetAppPackage(Intent intent) {
|
||||||
for (Map.Entry<String,Object> entry : moreExtras.entrySet()) {
|
PackageManager pm = activity.getPackageManager();
|
||||||
String key = entry.getKey();
|
List<ResolveInfo> availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
Object value = entry.getValue();
|
if (availableApps != null) {
|
||||||
// Kind of hacky
|
for (ResolveInfo availableApp : availableApps) {
|
||||||
if (value instanceof Integer) {
|
String packageName = availableApp.activityInfo.packageName;
|
||||||
intent.putExtra(key, (Integer) value);
|
if (targetApplications.contains(packageName)) {
|
||||||
} else if (value instanceof Long) {
|
return packageName;
|
||||||
intent.putExtra(key, (Long) value);
|
}
|
||||||
} else if (value instanceof Boolean) {
|
}
|
||||||
intent.putExtra(key, (Boolean) value);
|
}
|
||||||
} else if (value instanceof Double) {
|
return null;
|
||||||
intent.putExtra(key, (Double) value);
|
}
|
||||||
} else if (value instanceof Float) {
|
|
||||||
intent.putExtra(key, (Float) value);
|
private AlertDialog showDownloadDialog() {
|
||||||
} else if (value instanceof Bundle) {
|
AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
|
||||||
intent.putExtra(key, (Bundle) value);
|
downloadDialog.setTitle(title);
|
||||||
} else {
|
downloadDialog.setMessage(message);
|
||||||
intent.putExtra(key, value.toString());
|
downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
|
||||||
}
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
String packageName = targetApplications.get(0);
|
||||||
|
Uri uri = Uri.parse("market://details?id=" + packageName);
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
try {
|
||||||
|
activity.startActivity(intent);
|
||||||
|
} catch (ActivityNotFoundException anfe) {
|
||||||
|
// Hmm, market is not installed
|
||||||
|
Log.w(TAG, "Google Play is not installed; cannot install " + packageName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
downloadDialog.setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return downloadDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Call this from your {@link Activity}'s
|
||||||
|
* {@link Activity#onActivityResult(int, int, Intent)} method.</p>
|
||||||
|
*
|
||||||
|
* @return null if the event handled here was not related to this class, or
|
||||||
|
* else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
|
||||||
|
* the fields will be null.
|
||||||
|
*/
|
||||||
|
public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
|
if (requestCode == REQUEST_CODE) {
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
String contents = intent.getStringExtra("SCAN_RESULT");
|
||||||
|
String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
|
||||||
|
byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
|
||||||
|
int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
|
||||||
|
Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
|
||||||
|
String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
|
||||||
|
return new IntentResult(contents,
|
||||||
|
formatName,
|
||||||
|
rawBytes,
|
||||||
|
orientation,
|
||||||
|
errorCorrectionLevel);
|
||||||
|
}
|
||||||
|
return new IntentResult();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defaults to type "TEXT_TYPE".
|
||||||
|
*
|
||||||
|
* @see #shareText(CharSequence, CharSequence)
|
||||||
|
*/
|
||||||
|
public final AlertDialog shareText(CharSequence text) {
|
||||||
|
return shareText(text, "TEXT_TYPE");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shares the given text by encoding it as a barcode, such that another user can
|
||||||
|
* scan the text off the screen of the device.
|
||||||
|
*
|
||||||
|
* @param text the text string to encode as a barcode
|
||||||
|
* @param type type of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
|
||||||
|
* @return the {@link AlertDialog} that was shown to the user prompting them to download the app
|
||||||
|
* if a prompt was needed, or null otherwise
|
||||||
|
*/
|
||||||
|
public final AlertDialog shareText(CharSequence text, CharSequence type) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
intent.setAction(BS_PACKAGE + ".ENCODE");
|
||||||
|
intent.putExtra("ENCODE_TYPE", type);
|
||||||
|
intent.putExtra("ENCODE_DATA", text);
|
||||||
|
String targetAppPackage = findTargetAppPackage(intent);
|
||||||
|
if (targetAppPackage == null) {
|
||||||
|
return showDownloadDialog();
|
||||||
|
}
|
||||||
|
intent.setPackage(targetAppPackage);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||||
|
attachMoreExtras(intent);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> list(String... values) {
|
||||||
|
return Collections.unmodifiableList(Arrays.asList(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void attachMoreExtras(Intent intent) {
|
||||||
|
for (Map.Entry<String, Object> entry : moreExtras.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
// Kind of hacky
|
||||||
|
if (value instanceof Integer) {
|
||||||
|
intent.putExtra(key, (Integer) value);
|
||||||
|
} else if (value instanceof Long) {
|
||||||
|
intent.putExtra(key, (Long) value);
|
||||||
|
} else if (value instanceof Boolean) {
|
||||||
|
intent.putExtra(key, (Boolean) value);
|
||||||
|
} else if (value instanceof Double) {
|
||||||
|
intent.putExtra(key, (Double) value);
|
||||||
|
} else if (value instanceof Float) {
|
||||||
|
intent.putExtra(key, (Float) value);
|
||||||
|
} else if (value instanceof Bundle) {
|
||||||
|
intent.putExtra(key, (Bundle) value);
|
||||||
|
} else {
|
||||||
|
intent.putExtra(key, value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -22,73 +22,73 @@ package com.habitrpg.android.habitica.prefs.scanner;
|
||||||
*/
|
*/
|
||||||
public final class IntentResult {
|
public final class IntentResult {
|
||||||
|
|
||||||
private final String contents;
|
private final String contents;
|
||||||
private final String formatName;
|
private final String formatName;
|
||||||
private final byte[] rawBytes;
|
private final byte[] rawBytes;
|
||||||
private final Integer orientation;
|
private final Integer orientation;
|
||||||
private final String errorCorrectionLevel;
|
private final String errorCorrectionLevel;
|
||||||
|
|
||||||
IntentResult() {
|
IntentResult() {
|
||||||
this(null, null, null, null, null);
|
this(null, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
IntentResult(String contents,
|
IntentResult(String contents,
|
||||||
String formatName,
|
String formatName,
|
||||||
byte[] rawBytes,
|
byte[] rawBytes,
|
||||||
Integer orientation,
|
Integer orientation,
|
||||||
String errorCorrectionLevel) {
|
String errorCorrectionLevel) {
|
||||||
this.contents = contents;
|
this.contents = contents;
|
||||||
this.formatName = formatName;
|
this.formatName = formatName;
|
||||||
this.rawBytes = rawBytes;
|
this.rawBytes = rawBytes;
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
this.errorCorrectionLevel = errorCorrectionLevel;
|
this.errorCorrectionLevel = errorCorrectionLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return raw content of barcode
|
* @return raw content of barcode
|
||||||
*/
|
*/
|
||||||
public String getContents() {
|
public String getContents() {
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names.
|
* @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names.
|
||||||
*/
|
*/
|
||||||
public String getFormatName() {
|
public String getFormatName() {
|
||||||
return formatName;
|
return formatName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return raw bytes of the barcode content, if applicable, or null otherwise
|
* @return raw bytes of the barcode content, if applicable, or null otherwise
|
||||||
*/
|
*/
|
||||||
public byte[] getRawBytes() {
|
public byte[] getRawBytes() {
|
||||||
return rawBytes;
|
return rawBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return rotation of the image, in degrees, which resulted in a successful scan. May be null.
|
* @return rotation of the image, in degrees, which resulted in a successful scan. May be null.
|
||||||
*/
|
*/
|
||||||
public Integer getOrientation() {
|
public Integer getOrientation() {
|
||||||
return orientation;
|
return orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return name of the error correction level used in the barcode, if applicable
|
* @return name of the error correction level used in the barcode, if applicable
|
||||||
*/
|
*/
|
||||||
public String getErrorCorrectionLevel() {
|
public String getErrorCorrectionLevel() {
|
||||||
return errorCorrectionLevel;
|
return errorCorrectionLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder dialogText = new StringBuilder(100);
|
StringBuilder dialogText = new StringBuilder(100);
|
||||||
dialogText.append("Format: ").append(formatName).append('\n');
|
dialogText.append("Format: ").append(formatName).append('\n');
|
||||||
dialogText.append("Contents: ").append(contents).append('\n');
|
dialogText.append("Contents: ").append(contents).append('\n');
|
||||||
int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
|
int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
|
||||||
dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n");
|
dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n");
|
||||||
dialogText.append("Orientation: ").append(orientation).append('\n');
|
dialogText.append("Orientation: ").append(orientation).append('\n');
|
||||||
dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n');
|
dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n');
|
||||||
return dialogText.toString();
|
return dialogText.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,12 @@ public class AvatarWithBarsViewModel {
|
||||||
|
|
||||||
private TextView lvlText, goldText, silverText, gemsText;
|
private TextView lvlText, goldText, silverText, gemsText;
|
||||||
|
|
||||||
public AvatarWithBarsViewModel(Context context, View v){
|
public AvatarWithBarsViewModel(Context context, View v) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
res = context.getResources();
|
res = context.getResources();
|
||||||
|
|
||||||
if(v == null)
|
if (v == null) {
|
||||||
{
|
|
||||||
Log.w("AvatarWithBarsViewModel", "View is null");
|
Log.w("AvatarWithBarsViewModel", "View is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -62,8 +61,7 @@ public class AvatarWithBarsViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||||
public void updateData(HabitRPGUser user)
|
public void updateData(HabitRPGUser user) {
|
||||||
{
|
|
||||||
Stats stats = user.getStats();
|
Stats stats = user.getStats();
|
||||||
char classShort;
|
char classShort;
|
||||||
String userClass = "";
|
String userClass = "";
|
||||||
|
|
@ -74,14 +72,14 @@ public class AvatarWithBarsViewModel {
|
||||||
setValueBar(mpBar, stats.getMp().floatValue(), stats.getMaxMP(), context.getString(R.string.MP_default), context.getResources().getColor(R.color.mpColor), R.drawable.ic_header_magic);
|
setValueBar(mpBar, stats.getMp().floatValue(), stats.getMaxMP(), context.getString(R.string.MP_default), context.getResources().getColor(R.color.mpColor), R.drawable.ic_header_magic);
|
||||||
new UserPicture(user, this.context).setPictureOn(image);
|
new UserPicture(user, this.context).setPictureOn(image);
|
||||||
|
|
||||||
if(user.getStats().get_class()!=null) {
|
if (user.getStats().get_class() != null) {
|
||||||
userClass+=user.getStats().get_class().name();
|
userClass += user.getStats().get_class().name();
|
||||||
}
|
}
|
||||||
lvlText.setText("Lvl" + user.getStats().getLvl() + " " + userClass);
|
lvlText.setText("Lvl" + user.getStats().getLvl() + " " + userClass);
|
||||||
Drawable drawable;
|
Drawable drawable;
|
||||||
switch(stats.get_class()) {
|
switch (stats.get_class()) {
|
||||||
case warrior:
|
case warrior:
|
||||||
drawable = ResourcesCompat.getDrawable(res, R.drawable.ic_header_warrior, null);
|
drawable = ResourcesCompat.getDrawable(res, R.drawable.ic_header_warrior, null);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case rogue:
|
case rogue:
|
||||||
|
|
@ -106,18 +104,16 @@ public class AvatarWithBarsViewModel {
|
||||||
|
|
||||||
// binding.setClassShort(classShort);
|
// binding.setClassShort(classShort);
|
||||||
|
|
||||||
goldText.setText(gp+"");
|
goldText.setText(gp + "");
|
||||||
silverText.setText(sp+"");
|
silverText.setText(sp + "");
|
||||||
|
|
||||||
Double gems = new Double(user.getBalance()*4);
|
Double gems = new Double(user.getBalance() * 4);
|
||||||
gemsText.setText(gems.intValue()+"");
|
gemsText.setText(gems.intValue() + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHpBarData(ValueBarBinding valueBar, Stats stats, Context ctx)
|
public static void setHpBarData(ValueBarBinding valueBar, Stats stats, Context ctx) {
|
||||||
{
|
|
||||||
int maxHP = stats.getMaxHealth();
|
int maxHP = stats.getMaxHealth();
|
||||||
if(maxHP == 0)
|
if (maxHP == 0) {
|
||||||
{
|
|
||||||
maxHP = 50;
|
maxHP = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,17 +122,13 @@ public class AvatarWithBarsViewModel {
|
||||||
|
|
||||||
// Layout_Weight don't accepts 0.7/0.3 to have 70% filled instead it shows the 30% , so I had to switch the values
|
// Layout_Weight don't accepts 0.7/0.3 to have 70% filled instead it shows the 30% , so I had to switch the values
|
||||||
// but on a 1.0/0.0 which switches to 0.0/1.0 it shows the blank part full size...
|
// but on a 1.0/0.0 which switches to 0.0/1.0 it shows the blank part full size...
|
||||||
private static void setValueBar(ValueBarBinding valueBar, float value, float valueMax, String description, int color, int icon)
|
private static void setValueBar(ValueBarBinding valueBar, float value, float valueMax, String description, int color, int icon) {
|
||||||
{
|
|
||||||
double percent = Math.min(1, value / valueMax);
|
double percent = Math.min(1, value / valueMax);
|
||||||
|
|
||||||
if(percent == 1)
|
if (percent == 1) {
|
||||||
{
|
|
||||||
valueBar.setWeightToShow(1);
|
valueBar.setWeightToShow(1);
|
||||||
valueBar.setWeightToHide(0);
|
valueBar.setWeightToHide(0);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
valueBar.setWeightToShow((float) percent);
|
valueBar.setWeightToShow((float) percent);
|
||||||
valueBar.setWeightToHide((float) (1 - percent));
|
valueBar.setWeightToHide((float) (1 - percent));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,13 @@
|
||||||
package com.habitrpg.android.habitica.ui;
|
package com.habitrpg.android.habitica.ui;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.R;
|
import com.habitrpg.android.habitica.R;
|
||||||
import com.habitrpg.android.habitica.events.commands.CreateTagCommand;
|
import com.habitrpg.android.habitica.events.commands.CreateTagCommand;
|
||||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||||
import com.mikepenz.materialdrawer.model.BaseDrawerItem;
|
|
||||||
import com.mikepenz.materialdrawer.model.BasePrimaryDrawerItem;
|
import com.mikepenz.materialdrawer.model.BasePrimaryDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.model.utils.ViewHolderFactory;
|
import com.mikepenz.materialdrawer.model.utils.ViewHolderFactory;
|
||||||
|
|
||||||
|
|
@ -42,22 +38,6 @@ public class EditTextDrawer extends BasePrimaryDrawerItem<EditTextDrawer> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
|
||||||
public View convertView(LayoutInflater inflater, View convertView, ViewGroup parent) {
|
|
||||||
Context ctx = parent.getContext();
|
|
||||||
|
|
||||||
//get the viewHolder
|
|
||||||
ViewHolder viewHolder;
|
|
||||||
if (convertView == null) {
|
|
||||||
convertView = inflater.inflate(getLayoutRes(), parent, false);
|
|
||||||
viewHolder = new ViewHolder(convertView);
|
|
||||||
convertView.setTag(viewHolder);
|
|
||||||
} else {
|
|
||||||
viewHolder = (ViewHolder) convertView.getTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertView;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ViewHolderFactory getFactory() {
|
public ViewHolderFactory getFactory() {
|
||||||
|
|
@ -93,7 +73,7 @@ public class EditTextDrawer extends BasePrimaryDrawerItem<EditTextDrawer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if(editText.getText().equals(""))
|
if (editText.getText().equals(""))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EventBus.getDefault().post(new CreateTagCommand(editText.getText().toString()));
|
EventBus.getDefault().post(new CreateTagCommand(editText.getText().toString()));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.AboutActivity;
|
import com.habitrpg.android.habitica.AboutActivity;
|
||||||
import com.habitrpg.android.habitica.GemPurchaseActivity;
|
import com.habitrpg.android.habitica.GemPurchaseActivity;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import com.habitrpg.android.habitica.events.commands.ToggleLikeMessageCommand;
|
||||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
||||||
import com.mikepenz.iconics.Iconics;
|
|
||||||
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
|
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
|
||||||
|
import com.mikepenz.iconics.Iconics;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IReceiveNewEntries{
|
public interface IReceiveNewEntries {
|
||||||
void GotAdditionalItems(List<Task> items);
|
void GotAdditionalItems(List<Task> items);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,63 +20,71 @@ import java.util.Map;
|
||||||
public class TagAdapter extends BaseAdapter {
|
public class TagAdapter extends BaseAdapter {
|
||||||
|
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Map<String, String> mTags;
|
private Map<String, String> mTags;
|
||||||
private String[] mKeySet;
|
private String[] mKeySet;
|
||||||
public TagAdapter(Context c) {
|
|
||||||
this(c, new HashMap<String, String>());
|
|
||||||
}
|
|
||||||
public TagAdapter(Context c, Map<String, String> tags) {
|
|
||||||
this.mContext = c;
|
|
||||||
this.mTags = tags;
|
|
||||||
if(this.mTags!=null)
|
|
||||||
this.mKeySet = this.mTags.keySet().toArray(new String[mTags.size()]);
|
|
||||||
else {
|
|
||||||
mKeySet = new String[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return mTags.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public TagAdapter(Context c) {
|
||||||
public String getItem(int i) {
|
this(c, new HashMap<String, String>());
|
||||||
|
}
|
||||||
|
|
||||||
return mTags.get(mKeySet[i]);
|
public TagAdapter(Context c, Map<String, String> tags) {
|
||||||
}
|
this.mContext = c;
|
||||||
@Override
|
this.mTags = tags;
|
||||||
public boolean isEnabled(int position) {
|
if (this.mTags != null)
|
||||||
|
this.mKeySet = this.mTags.keySet().toArray(new String[mTags.size()]);
|
||||||
|
else {
|
||||||
|
mKeySet = new String[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return super.isEnabled(position);
|
@Override
|
||||||
}
|
public int getCount() {
|
||||||
@Override
|
return mTags.size();
|
||||||
public long getItemId(int i) {
|
}
|
||||||
return i;
|
|
||||||
}
|
@Override
|
||||||
|
public String getItem(int i) {
|
||||||
|
|
||||||
|
return mTags.get(mKeySet[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int position) {
|
||||||
|
|
||||||
|
return super.isEnabled(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int i) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTagId(int i) {
|
||||||
|
return mKeySet[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int i, View convertView, ViewGroup parent) {
|
||||||
|
String tag = getItem(i);
|
||||||
|
TextView tv = (TextView) LayoutInflater.from(mContext).inflate(R.layout.drawer_list_item, parent, false);
|
||||||
|
tv.setText(tag);
|
||||||
|
convertView = tv;
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTags(Map<String, String> tags) {
|
||||||
|
this.mTags.clear();
|
||||||
|
if (tags != null)
|
||||||
|
this.mTags.putAll(tags);
|
||||||
|
this.mKeySet = this.mTags.keySet().toArray(new String[mTags.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
public String getTagId(int i) {
|
|
||||||
return mKeySet[i];
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public View getView(int i, View convertView, ViewGroup parent) {
|
|
||||||
String tag = getItem(i);
|
|
||||||
TextView tv = (TextView)LayoutInflater.from(mContext).inflate(R.layout.drawer_list_item, parent, false);
|
|
||||||
tv.setText(tag);
|
|
||||||
convertView = tv;
|
|
||||||
return convertView;
|
|
||||||
}
|
|
||||||
public void updateTags(Map<String, String> tags) {
|
|
||||||
this.mTags.clear();
|
|
||||||
if(tags!=null)
|
|
||||||
this.mTags.putAll(tags);
|
|
||||||
this.mKeySet = this.mTags.keySet().toArray(new String[mTags.size()]);
|
|
||||||
}
|
|
||||||
//TODO: Nooooooooooo! this is kinda ugly to do it like that.
|
//TODO: Nooooooooooo! this is kinda ugly to do it like that.
|
||||||
public void updateTags(List<Tag> tags) {
|
public void updateTags(List<Tag> tags) {
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
for(Tag tag : tags) {
|
for (Tag tag : tags) {
|
||||||
map.put(tag.getId(),tag.getName());
|
map.put(tag.getId(), tag.getName());
|
||||||
}
|
}
|
||||||
this.updateTags(map);
|
this.updateTags(map);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,31 +23,33 @@ public class AboutFragment extends Fragment {
|
||||||
private String twitterLink = "https://twitter.com/habitica";
|
private String twitterLink = "https://twitter.com/habitica";
|
||||||
|
|
||||||
@OnClick(R.id.sourceCodeLink)
|
@OnClick(R.id.sourceCodeLink)
|
||||||
public void openSourceCodePageByLabel(){
|
public void openSourceCodePageByLabel() {
|
||||||
openBrowserLink(androidSourceCodeLink);
|
openBrowserLink(androidSourceCodeLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.twitter)
|
@OnClick(R.id.twitter)
|
||||||
public void openTwitterPage(){
|
public void openTwitterPage() {
|
||||||
openBrowserLink(twitterLink);
|
openBrowserLink(twitterLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.sourceCodeButton)
|
@OnClick(R.id.sourceCodeButton)
|
||||||
public void openSourceCodePageByButton(){
|
public void openSourceCodePageByButton() {
|
||||||
openBrowserLink(androidSourceCodeLink);
|
openBrowserLink(androidSourceCodeLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.reportBug)
|
@OnClick(R.id.reportBug)
|
||||||
public void sendBugReport(){ sendEmail("[Android] Bugreport"); }
|
public void sendBugReport() {
|
||||||
|
sendEmail("[Android] Bugreport");
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick(R.id.sendFeedback)
|
@OnClick(R.id.sendFeedback)
|
||||||
public void sendFeedback(){
|
public void sendFeedback() {
|
||||||
sendEmail("[Android] Feedback");
|
sendEmail("[Android] Feedback");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@OnClick(R.id.googlePlayStoreButton)
|
@OnClick(R.id.googlePlayStoreButton)
|
||||||
public void openGooglePlay(){
|
public void openGooglePlay() {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setData(Uri.parse("market://details?id=com.habitrpg.android.habitica"));
|
intent.setData(Uri.parse("market://details?id=com.habitrpg.android.habitica"));
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
@ -72,7 +74,7 @@ public class AboutFragment extends Fragment {
|
||||||
ButterKnife.inject(this, view);
|
ButterKnife.inject(this, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openBrowserLink(String url){
|
private void openBrowserLink(String url) {
|
||||||
Uri uriUrl = Uri.parse(url);
|
Uri uriUrl = Uri.parse(url);
|
||||||
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
|
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
|
||||||
startActivity(launchBrowser);
|
startActivity(launchBrowser);
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ public class ChatListFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||||
private String userId;
|
private String userId;
|
||||||
private boolean isTavern;
|
private boolean isTavern;
|
||||||
|
|
||||||
public ChatListFragment(Context ctx, String groupId, APIHelper apiHelper, HabitRPGUser user, boolean isTavern){
|
public ChatListFragment(Context ctx, String groupId, APIHelper apiHelper, HabitRPGUser user, boolean isTavern) {
|
||||||
|
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
|
|
@ -105,7 +105,7 @@ public class ChatListFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRefreshEnabled(boolean enable) {
|
public void setRefreshEnabled(boolean enable) {
|
||||||
if(swipeRefreshLayout != null){
|
if (swipeRefreshLayout != null) {
|
||||||
swipeRefreshLayout.setEnabled(enable);
|
swipeRefreshLayout.setEnabled(enable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +127,7 @@ public class ChatListFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||||
for (int i = chatMessages.size() - 1; i >= 0; i--) {
|
for (int i = chatMessages.size() - 1; i >= 0; i--) {
|
||||||
ChatMessage msg = chatMessages.get(i);
|
ChatMessage msg = chatMessages.get(i);
|
||||||
|
|
||||||
if(msg.flagCount >= 2){
|
if (msg.flagCount >= 2) {
|
||||||
chatMessages.remove(msg);
|
chatMessages.remove(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +145,7 @@ public class ChatListFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void showSnackbar(String msg, boolean negative){
|
private void showSnackbar(String msg, boolean negative) {
|
||||||
Snackbar snackbar = Snackbar.make(mRecyclerView, msg, Snackbar.LENGTH_LONG);
|
Snackbar snackbar = Snackbar.make(mRecyclerView, msg, Snackbar.LENGTH_LONG);
|
||||||
|
|
||||||
if (negative) {
|
if (negative) {
|
||||||
|
|
@ -158,7 +158,7 @@ public class ChatListFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEvent(final FlagChatMessageCommand cmd){
|
public void onEvent(final FlagChatMessageCommand cmd) {
|
||||||
apiHelper.apiService.flagMessage(cmd.groupId, cmd.chatMessage.id, new Callback<Void>() {
|
apiHelper.apiService.flagMessage(cmd.groupId, cmd.chatMessage.id, new Callback<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(Void aVoid, Response response) {
|
public void success(Void aVoid, Response response) {
|
||||||
|
|
@ -172,7 +172,7 @@ public class ChatListFragment extends Fragment implements SwipeRefreshLayout.OnR
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEvent(final ToggleLikeMessageCommand cmd){
|
public void onEvent(final ToggleLikeMessageCommand cmd) {
|
||||||
apiHelper.apiService.likeMessage(cmd.groupId, cmd.chatMessage.id, new Callback<List<Void>>() {
|
apiHelper.apiService.likeMessage(cmd.groupId, cmd.chatMessage.id, new Callback<List<Void>>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(List<Void> aVoid, Response response) {
|
public void success(List<Void> aVoid, Response response) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.habitrpg.android.habitica.ui.fragments;
|
package com.habitrpg.android.habitica.ui.fragments;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
import android.app.DatePickerDialog;
|
import android.app.DatePickerDialog;
|
||||||
import android.app.DatePickerDialog.OnDateSetListener;
|
import android.app.DatePickerDialog.OnDateSetListener;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
|
@ -11,28 +9,30 @@ import android.content.DialogInterface.OnDismissListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
public class DatePickerFragment extends DialogFragment {
|
public class DatePickerFragment extends DialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
// Use the current time as the default values for the picker
|
// Use the current time as the default values for the picker
|
||||||
final Calendar c = Calendar.getInstance();
|
final Calendar c = Calendar.getInstance();
|
||||||
int year = c.get(Calendar.YEAR);
|
int year = c.get(Calendar.YEAR);
|
||||||
int month = c.get(Calendar.MONTH);
|
int month = c.get(Calendar.MONTH);
|
||||||
int day = c.get(Calendar.DAY_OF_MONTH);
|
int day = c.get(Calendar.DAY_OF_MONTH);
|
||||||
// Create a new instance of TimePickerDialog and return it
|
// Create a new instance of TimePickerDialog and return it
|
||||||
Dialog d = new DatePickerDialog(getActivity(), (OnDateSetListener) getTargetFragment(), year, month, day);
|
Dialog d = new DatePickerDialog(getActivity(), (OnDateSetListener) getTargetFragment(), year, month, day);
|
||||||
d.setOnDismissListener(new OnDismissListener() {
|
d.setOnDismissListener(new OnDismissListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
d.setOnCancelListener(new OnCancelListener() {
|
d.setOnCancelListener(new OnCancelListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.R;
|
import com.habitrpg.android.habitica.R;
|
||||||
import com.habitrpg.android.habitica.databinding.FragmentPartyInfoBinding;
|
import com.habitrpg.android.habitica.databinding.FragmentPartyInfoBinding;
|
||||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.QuestContent;
|
import com.magicmicky.habitrpgwrapper.lib.models.QuestContent;
|
||||||
|
|
||||||
|
|
@ -37,20 +36,20 @@ public class PartyInformationFragment extends Fragment {
|
||||||
|
|
||||||
viewBinding = DataBindingUtil.bind(view);
|
viewBinding = DataBindingUtil.bind(view);
|
||||||
|
|
||||||
if(group != null){
|
if (group != null) {
|
||||||
setGroup(group);
|
setGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGroup(Group group){
|
public void setGroup(Group group) {
|
||||||
if (viewBinding != null) {
|
if (viewBinding != null) {
|
||||||
viewBinding.setParty(group);
|
viewBinding.setParty(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQuestContent(QuestContent quest){
|
public void setQuestContent(QuestContent quest) {
|
||||||
if (viewBinding != null) {
|
if (viewBinding != null) {
|
||||||
viewBinding.setQuest(quest);
|
viewBinding.setQuest(quest);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public class PartyMemberListFragment extends Fragment {
|
||||||
|
|
||||||
private PartyMemberRecyclerViewAdapter viewAdapter;
|
private PartyMemberRecyclerViewAdapter viewAdapter;
|
||||||
|
|
||||||
public PartyMemberListFragment(Context ctx, Group group){
|
public PartyMemberListFragment(Context ctx, Group group) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
|
|
||||||
|
|
@ -60,12 +60,12 @@ public class PartyMemberListFragment extends Fragment {
|
||||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||||
mRecyclerView.setAdapter(viewAdapter);
|
mRecyclerView.setAdapter(viewAdapter);
|
||||||
|
|
||||||
if(group != null){
|
if (group != null) {
|
||||||
setMemberList(group.members);
|
setMemberList(group.members);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMemberList(ArrayList<HabitRPGUser> members){
|
public void setMemberList(ArrayList<HabitRPGUser> members) {
|
||||||
viewAdapter.setMemberList(members);
|
viewAdapter.setMemberList(members);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class DataBindingUtils {
|
||||||
|
|
||||||
@BindingAdapter("bind:imageName")
|
@BindingAdapter("bind:imageName")
|
||||||
public static void loadImage(ImageView view, String imageName) {
|
public static void loadImage(ImageView view, String imageName) {
|
||||||
if(view.getVisibility() == View.VISIBLE) {
|
if (view.getVisibility() == View.VISIBLE) {
|
||||||
Picasso.with(view.getContext())
|
Picasso.with(view.getContext())
|
||||||
.load("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + imageName + ".png")
|
.load("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + imageName + ".png")
|
||||||
.into(view);
|
.into(view);
|
||||||
|
|
@ -73,7 +73,7 @@ public class DataBindingUtils {
|
||||||
|
|
||||||
@BindingAdapter("app:layout_weight")
|
@BindingAdapter("app:layout_weight")
|
||||||
public static void setLayoutWeight(View view, float weight) {
|
public static void setLayoutWeight(View view, float weight) {
|
||||||
LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams)view.getLayoutParams();
|
LinearLayout.LayoutParams layout = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||||
|
|
||||||
layout.weight = weight;
|
layout.weight = weight;
|
||||||
|
|
||||||
|
|
@ -82,7 +82,7 @@ public class DataBindingUtils {
|
||||||
|
|
||||||
@BindingAdapter("app:layout_weight_anim")
|
@BindingAdapter("app:layout_weight_anim")
|
||||||
public static void setLayoutWeightAnim(View view, float weight) {
|
public static void setLayoutWeightAnim(View view, float weight) {
|
||||||
if(weight == 0.0f || weight == 1.0f){
|
if (weight == 0.0f || weight == 1.0f) {
|
||||||
setLayoutWeight(view, weight);
|
setLayoutWeight(view, weight);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +97,7 @@ public class DataBindingUtils {
|
||||||
public static void setRoundedBackground(View view, int color) {
|
public static void setRoundedBackground(View view, int color) {
|
||||||
Drawable drawable = view.getResources().getDrawable(R.drawable.layout_rounded_bg);
|
Drawable drawable = view.getResources().getDrawable(R.drawable.layout_rounded_bg);
|
||||||
drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
|
drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
|
||||||
if(Build.VERSION.SDK_INT < 16) {
|
if (Build.VERSION.SDK_INT < 16) {
|
||||||
view.setBackgroundDrawable(drawable);
|
view.setBackgroundDrawable(drawable);
|
||||||
} else {
|
} else {
|
||||||
view.setBackground(drawable);
|
view.setBackground(drawable);
|
||||||
|
|
@ -106,7 +106,7 @@ public class DataBindingUtils {
|
||||||
|
|
||||||
@BindingAdapter("app:rounded_background_int")
|
@BindingAdapter("app:rounded_background_int")
|
||||||
public static void setRoundedBackgroundInt(View view, int color) {
|
public static void setRoundedBackgroundInt(View view, int color) {
|
||||||
if(color != 0){
|
if (color != 0) {
|
||||||
setRoundedBackground(view, view.getResources().getColor(color));
|
setRoundedBackground(view, view.getResources().getColor(color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -122,7 +122,7 @@ public class DataBindingUtils {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.targetWeight = targetWeight;
|
this.targetWeight = targetWeight;
|
||||||
|
|
||||||
layoutParams = (LinearLayout.LayoutParams)view.getLayoutParams();
|
layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||||
initializeWeight = layoutParams.weight;
|
initializeWeight = layoutParams.weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ public abstract class Debounce {
|
||||||
this.checkDelay = checkDelay;
|
this.checkDelay = checkDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hit(){
|
public void hit() {
|
||||||
lastHit = System.currentTimeMillis();
|
lastHit = System.currentTimeMillis();
|
||||||
if(this.timer != null){
|
if (this.timer != null) {
|
||||||
this.timer.cancel();
|
this.timer.cancel();
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
}
|
}
|
||||||
|
|
@ -28,8 +28,8 @@ public abstract class Debounce {
|
||||||
this.timer.schedule(new DebounceTask(this), 0, checkDelay);
|
this.timer.schedule(new DebounceTask(this), 0, checkDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkExecute(){
|
private void checkExecute() {
|
||||||
if((System.currentTimeMillis() - lastHit) > debounceDelay){
|
if ((System.currentTimeMillis() - lastHit) > debounceDelay) {
|
||||||
this.timer.cancel();
|
this.timer.cancel();
|
||||||
this.timer = null;
|
this.timer = null;
|
||||||
execute();
|
execute();
|
||||||
|
|
|
||||||
|
|
@ -15,34 +15,36 @@ public class BitmapUtils {
|
||||||
} else {
|
} else {
|
||||||
path = Environment.getDownloadCacheDirectory().getAbsolutePath();
|
path = Environment.getDownloadCacheDirectory().getAbsolutePath();
|
||||||
}
|
}
|
||||||
return path+"/HabiticaImageCache";
|
return path + "/HabiticaImageCache";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap loadFromFile(String filename) {
|
public static Bitmap loadFromFile(String filename) {
|
||||||
try {
|
try {
|
||||||
filename = getSavePath() +"/"+ filename;
|
filename = getSavePath() + "/" + filename;
|
||||||
|
|
||||||
File f = new File(filename);
|
File f = new File(filename);
|
||||||
if (!f.exists()) { return null; }
|
if (!f.exists()) {
|
||||||
Bitmap tmp = BitmapFactory.decodeFile(filename);
|
return null;
|
||||||
return tmp;
|
}
|
||||||
|
return BitmapFactory.decodeFile(filename);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveToFile(String filename,Bitmap bmp) {
|
public static void saveToFile(String filename, Bitmap bmp) {
|
||||||
try {
|
try {
|
||||||
File myDir = new File(getSavePath());
|
File myDir = new File(getSavePath());
|
||||||
boolean res = myDir.mkdirs();
|
boolean res = myDir.mkdirs();
|
||||||
|
|
||||||
filename = getSavePath() +"/"+ filename;
|
filename = getSavePath() + "/" + filename;
|
||||||
|
|
||||||
FileOutputStream out = new FileOutputStream(filename);
|
FileOutputStream out = new FileOutputStream(filename);
|
||||||
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
|
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
} catch(Exception e) {}
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasSDCard() {
|
public static boolean hasSDCard() {
|
||||||
|
|
|
||||||
|
|
@ -53,12 +53,12 @@ public class UserPicture {
|
||||||
this.hasPetMount = hasPetMount;
|
this.hasPetMount = hasPetMount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTask(){
|
public void removeTask() {
|
||||||
numOfTasks.decrementAndGet();
|
numOfTasks.decrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void allTasksComplete(){
|
public void allTasksComplete() {
|
||||||
if(this.numOfTasks.get() == 0){
|
if (this.numOfTasks.get() == 0) {
|
||||||
BitmapFactory.Options o = new BitmapFactory.Options();
|
BitmapFactory.Options o = new BitmapFactory.Options();
|
||||||
o.inScaled = false;
|
o.inScaled = false;
|
||||||
|
|
||||||
|
|
@ -147,7 +147,7 @@ public class UserPicture {
|
||||||
// get layer hash value
|
// get layer hash value
|
||||||
String fullLayerString = "";
|
String fullLayerString = "";
|
||||||
|
|
||||||
for(String l : layerNames){
|
for (String l : layerNames) {
|
||||||
fullLayerString = fullLayerString.concat(l);
|
fullLayerString = fullLayerString.concat(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,8 +155,18 @@ public class UserPicture {
|
||||||
currentCacheFileName = layersHash.concat(".png");
|
currentCacheFileName = layersHash.concat(".png");
|
||||||
|
|
||||||
// does it already exist?
|
// does it already exist?
|
||||||
|
<<<<<<< HEAD
|
||||||
return BitmapUtils.loadFromFile(currentCacheFileName);
|
return BitmapUtils.loadFromFile(currentCacheFileName);
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
Bitmap cache = BitmapUtils.loadFromFile(currentCacheFileName);
|
||||||
|
|
||||||
|
// yes => load image to bitmap
|
||||||
|
if (cache != null) {
|
||||||
|
imageView.setImageBitmap(cache);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
>>>>>>> d0ae3a5b4a54a09409b3701d256c7715181ae781
|
||||||
|
|
||||||
private void generateImage(List<String> layerNames) {
|
private void generateImage(List<String> layerNames) {
|
||||||
Integer layerNumber = 0;
|
Integer layerNumber = 0;
|
||||||
|
|
@ -164,19 +174,19 @@ public class UserPicture {
|
||||||
for (String layer : layerNames) {
|
for (String layer : layerNames) {
|
||||||
layers.add(0);
|
layers.add(0);
|
||||||
SpriteTarget target = new SpriteTarget(layerNumber, layer);
|
SpriteTarget target = new SpriteTarget(layerNumber, layer);
|
||||||
Picasso.with(this.context).load("https://habitica-assets.s3.amazonaws.com/mobileApp/images/"+ layer +".png").into(target);
|
Picasso.with(this.context).load("https://habitica-assets.s3.amazonaws.com/mobileApp/images/" + layer + ".png").into(target);
|
||||||
layerNumber = layerNumber + 1;
|
layerNumber = layerNumber + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateHashCode(String value){
|
private static String generateHashCode(String value) {
|
||||||
|
|
||||||
MessageDigest md = null;
|
MessageDigest md = null;
|
||||||
byte[] digest = new byte[0];
|
byte[] digest = new byte[0];
|
||||||
try {
|
try {
|
||||||
md = MessageDigest.getInstance("MD5");
|
md = MessageDigest.getInstance("MD5");
|
||||||
|
|
||||||
md.update(value.getBytes());
|
md.update(value.getBytes());
|
||||||
digest = md.digest();
|
digest = md.digest();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
@ -186,9 +196,10 @@ public class UserPicture {
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||||
|
|
||||||
public static String bytesToHex(byte[] bytes) {
|
public static String bytesToHex(byte[] bytes) {
|
||||||
char[] hexChars = new char[bytes.length * 2];
|
char[] hexChars = new char[bytes.length * 2];
|
||||||
for ( int j = 0; j < bytes.length; j++ ) {
|
for (int j = 0; j < bytes.length; j++) {
|
||||||
int v = bytes[j] & 0xFF;
|
int v = bytes[j] & 0xFF;
|
||||||
hexChars[j * 2] = hexArray[v >>> 4];
|
hexChars[j * 2] = hexArray[v >>> 4];
|
||||||
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
||||||
|
|
@ -196,7 +207,7 @@ public class UserPicture {
|
||||||
return new String(hexChars);
|
return new String(hexChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyCanvas(Bitmap img, Canvas canvas, Integer layerNumber) {
|
private void modifyCanvas(Bitmap img, Canvas canvas, Integer layerNumber) {
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
paint.setFilterBitmap(false);
|
paint.setFilterBitmap(false);
|
||||||
|
|
||||||
|
|
@ -208,22 +219,33 @@ public class UserPicture {
|
||||||
yOffset = 0;
|
yOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
if (this.hasPetMount && !((this.hasBackground && layerNumber == 1) ||
|
if (this.hasPetMount && !((this.hasBackground && layerNumber == 1) ||
|
||||||
(!this.hasBackground && layerNumber == 0) ||
|
(!this.hasBackground && layerNumber == 0) ||
|
||||||
(this.hasPetMount && layerNumber == this.layers.size()-2) ||
|
(this.hasPetMount && layerNumber == this.layers.size()-2) ||
|
||||||
(!this.hasPetMount && layerNumber == this.layers.size()-1)
|
(!this.hasPetMount && layerNumber == this.layers.size()-1)
|
||||||
|
=======
|
||||||
|
if (this.hasMount && !((this.hasBackground && layerNumber == 1) ||
|
||||||
|
(!this.hasBackground && layerNumber == 0) ||
|
||||||
|
(this.hasPet && layerNumber == this.layers.size() - 2) ||
|
||||||
|
(!this.hasPet && layerNumber == this.layers.size() - 1)
|
||||||
|
>>>>>>> d0ae3a5b4a54a09409b3701d256c7715181ae781
|
||||||
)) {
|
)) {
|
||||||
yOffset = 0;
|
yOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
if (this.hasPetMount && layerNumber == this.layers.size()-1) {
|
if (this.hasPetMount && layerNumber == this.layers.size()-1) {
|
||||||
|
=======
|
||||||
|
if (this.hasPet && layerNumber == this.layers.size() - 1) {
|
||||||
|
>>>>>>> d0ae3a5b4a54a09409b3701d256c7715181ae781
|
||||||
xOffset = 0;
|
xOffset = 0;
|
||||||
yOffset = 43;
|
yOffset = 43;
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.drawBitmap(img, new Rect(0, 0, img.getWidth(), img.getHeight()),
|
canvas.drawBitmap(img, new Rect(0, 0, img.getWidth(), img.getHeight()),
|
||||||
new Rect(xOffset, yOffset, img.getWidth()+xOffset, img.getHeight()+yOffset), paint);
|
new Rect(xOffset, yOffset, img.getWidth() + xOffset, img.getHeight() + yOffset), paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SpriteTarget implements Target {
|
private class SpriteTarget implements Target {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class SimpleWidget extends AppWidgetProvider {
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
@Override
|
@Override
|
||||||
public void onAppWidgetOptionsChanged (Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
|
public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
|
||||||
Log.v(LOG, "onAppWidgetOptionChanged call");
|
Log.v(LOG, "onAppWidgetOptionChanged call");
|
||||||
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
|
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
|
||||||
|
|
||||||
|
|
@ -59,6 +59,7 @@ public class SimpleWidget extends AppWidgetProvider {
|
||||||
/**
|
/**
|
||||||
* Determine appropriate view based on width provided.<br/>
|
* Determine appropriate view based on width provided.<br/>
|
||||||
* see http://stackoverflow.com/questions/14270138/dynamically-adjusting-widgets-content-and-layout-to-the-size-the-user-defined-t
|
* see http://stackoverflow.com/questions/14270138/dynamically-adjusting-widgets-content-and-layout-to-the-size-the-user-defined-t
|
||||||
|
*
|
||||||
* @param minWidth
|
* @param minWidth
|
||||||
* @param minHeight
|
* @param minHeight
|
||||||
* @return
|
* @return
|
||||||
|
|
@ -97,7 +98,4 @@ public class SimpleWidget extends AppWidgetProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,9 @@ import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.APIHelper;
|
import com.habitrpg.android.habitica.APIHelper;
|
||||||
|
|
@ -19,11 +15,11 @@ import com.habitrpg.android.habitica.MainActivity;
|
||||||
import com.habitrpg.android.habitica.R;
|
import com.habitrpg.android.habitica.R;
|
||||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||||
import com.habitrpg.android.habitica.userpicture.UserPicture;
|
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The service that should update the simple widget
|
* The service that should update the simple widget
|
||||||
|
*
|
||||||
* @see com.habitrpg.android.habitica.widget.SimpleWidget
|
* @see com.habitrpg.android.habitica.widget.SimpleWidget
|
||||||
* Created by Mickael on 01/11/13.
|
* Created by Mickael on 01/11/13.
|
||||||
*/
|
*/
|
||||||
|
|
@ -45,7 +41,7 @@ public class UpdateWidgetService extends Service implements HabitRPGUserCallback
|
||||||
Log.w(LOG, "Direct" + String.valueOf(allWidgetIds2.length));
|
Log.w(LOG, "Direct" + String.valueOf(allWidgetIds2.length));
|
||||||
|
|
||||||
HostConfig hc = PrefsActivity.fromContext(this);
|
HostConfig hc = PrefsActivity.fromContext(this);
|
||||||
if(hc!=null && hc.getApi()!=null && !hc.getApi().equals("") && hc.getUser()!=null && !hc.getUser().equals("") ) {
|
if (hc != null && hc.getApi() != null && !hc.getApi().equals("") && hc.getUser() != null && !hc.getUser().equals("")) {
|
||||||
this.apiHelper = new APIHelper(this, hc);
|
this.apiHelper = new APIHelper(this, hc);
|
||||||
apiHelper.retrieveUser(new HabitRPGUserCallback(this));
|
apiHelper.retrieveUser(new HabitRPGUserCallback(this));
|
||||||
for (int widgetId : allWidgetIds) {
|
for (int widgetId : allWidgetIds) {
|
||||||
|
|
@ -53,23 +49,23 @@ public class UpdateWidgetService extends Service implements HabitRPGUserCallback
|
||||||
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w(LOG,"HostConfig is null");
|
Log.w(LOG, "HostConfig is null");
|
||||||
for (int widgetId : allWidgetIds) {
|
for (int widgetId : allWidgetIds) {
|
||||||
RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.simple_widget);
|
RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.simple_widget);
|
||||||
RemoteViews textConnect = new RemoteViews(this.getPackageName(),R.layout.simple_textview);
|
RemoteViews textConnect = new RemoteViews(this.getPackageName(), R.layout.simple_textview);
|
||||||
textConnect.setTextViewText(R.id.TV_simple_textview,getString(R.string.please_connect));
|
textConnect.setTextViewText(R.id.TV_simple_textview, getString(R.string.please_connect));
|
||||||
remoteViews.removeAllViews(R.id.LL_header);
|
remoteViews.removeAllViews(R.id.LL_header);
|
||||||
remoteViews.addView(R.id.LL_header, textConnect);
|
remoteViews.addView(R.id.LL_header, textConnect);
|
||||||
|
|
||||||
|
|
||||||
Intent clickIntent = new Intent(this.getApplicationContext(),SimpleWidget.class);
|
Intent clickIntent = new Intent(this.getApplicationContext(), SimpleWidget.class);
|
||||||
clickIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
clickIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||||
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
|
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
|
||||||
PendingIntent updateIntent = PendingIntent.getBroadcast(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent updateIntent = PendingIntent.getBroadcast(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
remoteViews.setOnClickPendingIntent(R.id.BT_refresh, updateIntent);
|
remoteViews.setOnClickPendingIntent(R.id.BT_refresh, updateIntent);
|
||||||
|
|
||||||
Intent openAppIntent = new Intent(this.getApplicationContext(), MainActivity.class);
|
Intent openAppIntent = new Intent(this.getApplicationContext(), MainActivity.class);
|
||||||
PendingIntent openApp = PendingIntent.getActivity(this,0,openAppIntent,PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent openApp = PendingIntent.getActivity(this, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
remoteViews.setOnClickPendingIntent(R.id.widget_main_view, openApp);
|
remoteViews.setOnClickPendingIntent(R.id.widget_main_view, openApp);
|
||||||
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
||||||
|
|
||||||
|
|
@ -81,18 +77,18 @@ public class UpdateWidgetService extends Service implements HabitRPGUserCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateData(HabitRPGUser user, AppWidgetManager appWidgetManager) {
|
private void updateData(HabitRPGUser user, AppWidgetManager appWidgetManager) {
|
||||||
ComponentName thisWidget = new ComponentName(this,SimpleWidget.class);
|
ComponentName thisWidget = new ComponentName(this, SimpleWidget.class);
|
||||||
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
|
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
|
||||||
for (int widgetId : allWidgetIds) {
|
for (int widgetId : allWidgetIds) {
|
||||||
RemoteViews remoteViews = new RemoteViews(this.getPackageName(),R.layout.simple_widget);
|
RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.simple_widget);
|
||||||
remoteViews.setTextViewText(R.id.TV_HP, "" + user.getStats().getHp().intValue() + "/" + (int) user.getStats().getMaxHealth() + " " + this.getString(R.string.HP_default));
|
remoteViews.setTextViewText(R.id.TV_HP, "" + user.getStats().getHp().intValue() + "/" + (int) user.getStats().getMaxHealth() + " " + this.getString(R.string.HP_default));
|
||||||
remoteViews.setTextViewText(R.id.TV_XP, "" + user.getStats().getExp().intValue() + "/" + (int) user.getStats().getToNextLevel() + " " + this.getString(R.string.XP_default));
|
remoteViews.setTextViewText(R.id.TV_XP, "" + user.getStats().getExp().intValue() + "/" + (int) user.getStats().getToNextLevel() + " " + this.getString(R.string.XP_default));
|
||||||
//remoteViews.setImageViewBitmap(R.id.IMG_ProfilePicture, dealWithUserPicture(user,this));
|
//remoteViews.setImageViewBitmap(R.id.IMG_ProfilePicture, dealWithUserPicture(user,this));
|
||||||
remoteViews.setProgressBar(R.id.V_HPBar,(int)user.getStats().getMaxHealth(), user.getStats().getHp().intValue(), false);
|
remoteViews.setProgressBar(R.id.V_HPBar, (int) user.getStats().getMaxHealth(), user.getStats().getHp().intValue(), false);
|
||||||
remoteViews.setProgressBar(R.id.V_XPBar,(int)user.getStats().getToNextLevel(),user.getStats().getExp().intValue(), false);
|
remoteViews.setProgressBar(R.id.V_XPBar, (int) user.getStats().getToNextLevel(), user.getStats().getExp().intValue(), false);
|
||||||
|
|
||||||
// If user click on refresh: refresh
|
// If user click on refresh: refresh
|
||||||
Intent clickIntent = new Intent(this.getApplicationContext(),SimpleWidget.class);
|
Intent clickIntent = new Intent(this.getApplicationContext(), SimpleWidget.class);
|
||||||
clickIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
clickIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||||
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
|
clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
|
||||||
PendingIntent updateIntent = PendingIntent.getBroadcast(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent updateIntent = PendingIntent.getBroadcast(this, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
@ -100,11 +96,11 @@ public class UpdateWidgetService extends Service implements HabitRPGUserCallback
|
||||||
|
|
||||||
//If user click on life and xp: open the app
|
//If user click on life and xp: open the app
|
||||||
Intent openAppIntent = new Intent(this.getApplicationContext(), MainActivity.class);
|
Intent openAppIntent = new Intent(this.getApplicationContext(), MainActivity.class);
|
||||||
PendingIntent openApp = PendingIntent.getActivity(this,0,openAppIntent,PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent openApp = PendingIntent.getActivity(this, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
remoteViews.setOnClickPendingIntent(R.id.LL_header, openApp);
|
remoteViews.setOnClickPendingIntent(R.id.LL_header, openApp);
|
||||||
remoteViews.setOnClickPendingIntent(R.id.IMG_ProfilePicture, openApp);
|
remoteViews.setOnClickPendingIntent(R.id.IMG_ProfilePicture, openApp);
|
||||||
|
|
||||||
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
appWidgetManager.updateAppWidget(widgetId, remoteViews);
|
||||||
|
|
||||||
|
|
||||||
//If user click on the
|
//If user click on the
|
||||||
|
|
@ -120,7 +116,7 @@ public class UpdateWidgetService extends Service implements HabitRPGUserCallback
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUserReceived(HabitRPGUser user) {
|
public void onUserReceived(HabitRPGUser user) {
|
||||||
this.updateData(user,appWidgetManager);
|
this.updateData(user, appWidgetManager);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,30 +124,4 @@ public class UpdateWidgetService extends Service implements HabitRPGUserCallback
|
||||||
public void onUserFail() {
|
public void onUserFail() {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private Bitmap dealWithUserPicture(HabitRPGUser look, Context c) {
|
|
||||||
UserPicture up = new UserPicture(look);
|
|
||||||
Resources r = getResources();
|
|
||||||
int w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, r.getDimension(R.dimen.avatar_width), r.getDisplayMetrics());
|
|
||||||
int h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, r.getDimension(R.dimen.avatar_height), r.getDisplayMetrics());
|
|
||||||
Bitmap img = up.getPicture();
|
|
||||||
return Bitmap.createScaledBitmap(img, w,h,false);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @Override public void onNewUser(String s, String s2) {}
|
|
||||||
// @Override public void onUserReceived(User user) {
|
|
||||||
// Log.i(LOG,"User received");
|
|
||||||
// updateData(user, appWidgetManager);
|
|
||||||
// }
|
|
||||||
// @Override public void onUserItemsReceived(UserLook.UserItems userItems, Reward.SpecialReward specialReward) {}
|
|
||||||
// @Override public void onPostResult(double v, double v2, double v3, double v4, double v5) {}
|
|
||||||
// @Override public void onPreResult() {}
|
|
||||||
// @Override public void onError(HabitRPGException e) {}
|
|
||||||
// @Override public void onPostTaskAnswer(Task habitItem) {}
|
|
||||||
// @Override public void onDeletedTask(Task habitItem) {}
|
|
||||||
// @Override public void onEditTaskAnswer(Task habitItem) {}
|
|
||||||
// @Override public void onUserConnected(String s, String s2) {}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by admin on 18/11/15.
|
||||||
|
*/
|
||||||
|
public class Authentication {
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.magicmicky.habitrpgwrapper.lib.models;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import com.habitrpg.android.habitica.HabitDatabase;
|
import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -15,8 +16,9 @@ import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
public class BasicStats extends BaseModel {
|
public class BasicStats extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey(autoincrement = true)
|
@PrimaryKey
|
||||||
long id;
|
@NotNull
|
||||||
|
String id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
public float con, str, per;
|
public float con, str, per;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -16,19 +17,20 @@ import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
public class Gear extends BaseModel {
|
public class Gear extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey(autoincrement = true)
|
@PrimaryKey
|
||||||
long id;
|
@NotNull
|
||||||
|
String user_id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "equipped_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "equipped_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "user_id")})
|
||||||
private Outfit equipped;
|
private Outfit equipped;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "costume_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "costume_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "user_id")})
|
||||||
private Outfit costume;
|
private Outfit costume;
|
||||||
|
|
||||||
public Outfit getCostume() {
|
public Outfit getCostume() {
|
||||||
|
|
@ -47,5 +49,11 @@ public class Gear extends BaseModel {
|
||||||
this.equipped = equipped;
|
this.equipped = equipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
equipped.user_id = user_id+"_equipped";
|
||||||
|
costume.user_id = user_id+"_costume";
|
||||||
|
|
||||||
|
super.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,34 +37,32 @@ public class HabitRPGUser extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "stats_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "stats_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "id")})
|
||||||
private Stats stats;
|
private Stats stats;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "preferences_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "preferences_id",
|
||||||
columnType = String.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "userId")})
|
foreignColumnName = "user_id")})
|
||||||
private Preferences preferences;
|
private Preferences preferences;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "profile_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "profile_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "user_Id")})
|
||||||
private Profile profile;
|
private Profile profile;
|
||||||
|
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "party_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "party_id",
|
||||||
columnType = String.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "id")})
|
||||||
private UserParty party;
|
private UserParty party;
|
||||||
|
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "items_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "items_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "user_id")})
|
||||||
private Items items;
|
private Items items;
|
||||||
|
|
||||||
public Preferences getPreferences() {
|
public Preferences getPreferences() {
|
||||||
|
|
@ -149,6 +147,7 @@ public class HabitRPGUser extends BaseModel {
|
||||||
habits = new Select()
|
habits = new Select()
|
||||||
.from(Task.class)
|
.from(Task.class)
|
||||||
.where(Condition.column("type").eq("habit"))
|
.where(Condition.column("type").eq("habit"))
|
||||||
|
.and(Condition.column("user_id").eq(this.id))
|
||||||
.queryList();
|
.queryList();
|
||||||
}
|
}
|
||||||
return habits;
|
return habits;
|
||||||
|
|
@ -160,6 +159,7 @@ public class HabitRPGUser extends BaseModel {
|
||||||
dailys = new Select()
|
dailys = new Select()
|
||||||
.from(Task.class)
|
.from(Task.class)
|
||||||
.where(Condition.column("type").eq("daily"))
|
.where(Condition.column("type").eq("daily"))
|
||||||
|
.and(Condition.column("user_id").eq(this.id))
|
||||||
.queryList();
|
.queryList();
|
||||||
}
|
}
|
||||||
return dailys;
|
return dailys;
|
||||||
|
|
@ -171,6 +171,7 @@ public class HabitRPGUser extends BaseModel {
|
||||||
todos = new Select()
|
todos = new Select()
|
||||||
.from(Task.class)
|
.from(Task.class)
|
||||||
.where(Condition.column("type").eq("todo"))
|
.where(Condition.column("type").eq("todo"))
|
||||||
|
.and(Condition.column("user_id").eq(this.id))
|
||||||
.queryList();
|
.queryList();
|
||||||
}
|
}
|
||||||
return todos;
|
return todos;
|
||||||
|
|
@ -181,6 +182,8 @@ public class HabitRPGUser extends BaseModel {
|
||||||
if(rewards == null) {
|
if(rewards == null) {
|
||||||
rewards = new Select()
|
rewards = new Select()
|
||||||
.from(Task.class)
|
.from(Task.class)
|
||||||
|
.where(Condition.column("type").eq("reward"))
|
||||||
|
.and(Condition.column("user_id").eq(this.id))
|
||||||
.queryList();
|
.queryList();
|
||||||
}
|
}
|
||||||
return rewards;
|
return rewards;
|
||||||
|
|
@ -191,6 +194,7 @@ public class HabitRPGUser extends BaseModel {
|
||||||
if(tags == null) {
|
if(tags == null) {
|
||||||
tags = new Select()
|
tags = new Select()
|
||||||
.from(Tag.class)
|
.from(Tag.class)
|
||||||
|
.where(Condition.column("user_id").eq(this.id))
|
||||||
.queryList();
|
.queryList();
|
||||||
}
|
}
|
||||||
return tags;
|
return tags;
|
||||||
|
|
@ -198,9 +202,26 @@ public class HabitRPGUser extends BaseModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
|
// We need to set the user_id to all other objects
|
||||||
|
preferences.user_id = id;
|
||||||
|
stats.id = id;
|
||||||
|
profile.user_Id = id;
|
||||||
|
items.user_id = id;
|
||||||
|
|
||||||
preferences.userId = id;
|
|
||||||
|
|
||||||
|
ArrayList<Task> allTasks = new ArrayList<Task>();
|
||||||
|
allTasks.addAll(dailys);
|
||||||
|
allTasks.addAll(todos);
|
||||||
|
allTasks.addAll(habits);
|
||||||
|
allTasks.addAll(rewards);
|
||||||
|
|
||||||
|
for (Task t : allTasks) {
|
||||||
|
t.user_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Tag t : tags) {
|
||||||
|
t.user_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
super.save();
|
super.save();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.magicmicky.habitrpgwrapper.lib.models;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.HabitDatabase;
|
import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -11,6 +12,7 @@ public class Hair extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
|
@NotNull
|
||||||
public String userId;
|
public String userId;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -18,8 +19,9 @@ import java.util.Date;
|
||||||
public class Items extends BaseModel {
|
public class Items extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey(autoincrement = true)
|
@PrimaryKey
|
||||||
long id;
|
@NotNull
|
||||||
|
String user_id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
private String currentMount, currentPet;
|
private String currentMount, currentPet;
|
||||||
|
|
@ -34,8 +36,8 @@ public class Items extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "gear_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "gear_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "user_id")})
|
||||||
private Gear gear;
|
private Gear gear;
|
||||||
|
|
||||||
public Items(String currentMount, String currentPet, int lastDrop_count, Date lastDrop_date) {
|
public Items(String currentMount, String currentPet, int lastDrop_count, Date lastDrop_date) {
|
||||||
|
|
@ -86,4 +88,11 @@ public class Items extends BaseModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Items() {}
|
public Items() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
gear.user_id = user_id;
|
||||||
|
|
||||||
|
super.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by admin on 18/11/15.
|
||||||
|
*/
|
||||||
|
public class LocalAuthentication {
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package com.magicmicky.habitrpgwrapper.lib.models;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.HabitDatabase;
|
import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -14,8 +15,9 @@ public class Outfit extends BaseModel {
|
||||||
|
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey(autoincrement = true)
|
@PrimaryKey
|
||||||
long id;
|
@NotNull
|
||||||
|
String user_id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
String armor, back, body, eyeWear, head, headAccessory, shield, weapon;
|
String armor, back, body, eyeWear, head, headAccessory, shield, weapon;
|
||||||
|
|
|
||||||
|
|
@ -11,18 +11,17 @@ import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
* Created by MagicMicky on 12/06/2014.
|
* Created by MagicMicky on 12/06/2014.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Table(databaseName = HabitDatabase.NAME, allFields = true)
|
public abstract class PlayerMinStats extends BasicStats {
|
||||||
public class PlayerMinStats extends BasicStats {
|
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "trainingstats_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "trainingstats_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "id")})
|
||||||
public BasicStats training;//stats.training
|
public BasicStats training;//stats.training
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "buffs_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "buffs_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "id")})
|
||||||
public Buffs buffs;//stats.buffs
|
public Buffs buffs;//stats.buffs
|
||||||
|
|
||||||
|
|
@ -110,4 +109,11 @@ public class PlayerMinStats extends BasicStats {
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() {
|
||||||
|
training.id = id+"_training";
|
||||||
|
buffs.id = id;
|
||||||
|
|
||||||
|
super.save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -16,8 +17,9 @@ import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
public class Preferences extends BaseModel {
|
public class Preferences extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey()
|
@PrimaryKey
|
||||||
String userId;
|
@NotNull
|
||||||
|
String user_id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
private boolean costume, toolbarCollapsed, advancedCollapsed, tagsCollapsed, newTaskEdit, disableClasses, stickyHeader, sleep, hideHeader;
|
private boolean costume, toolbarCollapsed, advancedCollapsed, tagsCollapsed, newTaskEdit, disableClasses, stickyHeader, sleep, hideHeader;
|
||||||
|
|
@ -43,7 +45,9 @@ public class Preferences extends BaseModel {
|
||||||
public Preferences() {
|
public Preferences() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Preferences(boolean costume, boolean toolbarCollapsed, boolean advancedCollapsed, boolean tagsCollapsed, boolean newTaskEdit, boolean disableClasses, boolean stickyHeader, boolean sleep, boolean hideHeader, String allocationMode, String shirt, String skin, String size, int dayStart, int timezoneOffset, Hair hair) {
|
public Preferences(boolean costume, boolean toolbarCollapsed, boolean advancedCollapsed, boolean tagsCollapsed,
|
||||||
|
boolean newTaskEdit, boolean disableClasses, boolean stickyHeader, boolean sleep, boolean hideHeader,
|
||||||
|
String allocationMode, String shirt, String skin, String size, int dayStart, int timezoneOffset, Hair hair) {
|
||||||
this.costume = costume;
|
this.costume = costume;
|
||||||
this.toolbarCollapsed = toolbarCollapsed;
|
this.toolbarCollapsed = toolbarCollapsed;
|
||||||
this.advancedCollapsed = advancedCollapsed;
|
this.advancedCollapsed = advancedCollapsed;
|
||||||
|
|
@ -65,7 +69,9 @@ public class Preferences extends BaseModel {
|
||||||
return background;
|
return background;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackground(String background) {this.background = background;}
|
public void setBackground(String background) {
|
||||||
|
this.background = background;
|
||||||
|
}
|
||||||
|
|
||||||
public int getDayStart() {
|
public int getDayStart() {
|
||||||
return dayStart;
|
return dayStart;
|
||||||
|
|
@ -205,7 +211,10 @@ public class Preferences extends BaseModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
hair.userId = userId;
|
hair.userId = user_id;
|
||||||
|
|
||||||
|
if (suppressModals != null)
|
||||||
|
suppressModals.userId = user_id;
|
||||||
|
|
||||||
super.save();
|
super.save();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ package com.magicmicky.habitrpgwrapper.lib.models;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.HabitDatabase;
|
import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -14,8 +15,9 @@ import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
public class Profile extends BaseModel {
|
public class Profile extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey(autoincrement = true)
|
@PrimaryKey
|
||||||
long id;
|
@NotNull
|
||||||
|
String user_Id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
private String name;
|
private String name;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.magicmicky.habitrpgwrapper.lib.models;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.HabitDatabase;
|
import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -14,6 +15,7 @@ public class SuppressedModals extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
|
@NotNull
|
||||||
public String userId;
|
public String userId;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
import com.raizlabs.android.dbflow.annotation.ModelContainer;
|
import com.raizlabs.android.dbflow.annotation.ModelContainer;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.OneToMany;
|
import com.raizlabs.android.dbflow.annotation.OneToMany;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
|
|
@ -24,8 +25,13 @@ public class Tag extends BaseModel{
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
|
@NotNull
|
||||||
public String id;
|
public String id;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@NotNull
|
||||||
|
public String user_id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ public enum TaskDirection {
|
||||||
up("up"),
|
up("up"),
|
||||||
down("down");
|
down("down");
|
||||||
private final String dir;
|
private final String dir;
|
||||||
private TaskDirection(String dir) {
|
TaskDirection(String dir) {
|
||||||
this.dir=dir;
|
this.dir=dir;
|
||||||
}
|
}
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.magicmicky.habitrpgwrapper.lib.models.tasks;
|
||||||
|
|
||||||
import com.habitrpg.android.habitica.HabitDatabase;
|
import com.habitrpg.android.habitica.HabitDatabase;
|
||||||
import com.raizlabs.android.dbflow.annotation.Column;
|
import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
|
|
@ -13,8 +14,9 @@ import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||||
public class Days extends BaseModel {
|
public class Days extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey(autoincrement = true)
|
@PrimaryKey
|
||||||
long id;
|
@NotNull
|
||||||
|
String user_id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
private boolean m, t,w, th,f,s,su;
|
private boolean m, t,w, th,f,s,su;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import com.raizlabs.android.dbflow.annotation.Column;
|
||||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference;
|
||||||
import com.raizlabs.android.dbflow.annotation.ModelContainer;
|
import com.raizlabs.android.dbflow.annotation.ModelContainer;
|
||||||
|
import com.raizlabs.android.dbflow.annotation.NotNull;
|
||||||
import com.raizlabs.android.dbflow.annotation.OneToMany;
|
import com.raizlabs.android.dbflow.annotation.OneToMany;
|
||||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||||
import com.raizlabs.android.dbflow.annotation.Table;
|
import com.raizlabs.android.dbflow.annotation.Table;
|
||||||
|
|
@ -36,7 +37,12 @@ public class Task extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
|
@NotNull
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
public String user_id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
public Float priority;
|
public Float priority;
|
||||||
|
|
||||||
|
|
@ -75,8 +81,8 @@ public class Task extends BaseModel {
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "days_id",
|
@ForeignKey(references = {@ForeignKeyReference(columnName = "days_id",
|
||||||
columnType = Long.class,
|
columnType = String.class,
|
||||||
foreignColumnName = "id")})
|
foreignColumnName = "user_id")})
|
||||||
public Days repeat;
|
public Days repeat;
|
||||||
//TODO: private String lastCompleted;
|
//TODO: private String lastCompleted;
|
||||||
|
|
||||||
|
|
@ -344,18 +350,32 @@ public class Task extends BaseModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
|
List<TaskTag> tmpTags = tags;
|
||||||
|
List<ChecklistItem> tmpChecklist = checklist;
|
||||||
|
|
||||||
|
// remove them, so that the database don't add empty entries
|
||||||
|
|
||||||
|
tags = null;
|
||||||
|
checklist = null;
|
||||||
|
|
||||||
|
if(repeat != null)
|
||||||
|
repeat.user_id = user_id;
|
||||||
|
|
||||||
super.save();
|
super.save();
|
||||||
|
|
||||||
|
tags = tmpTags;
|
||||||
|
checklist = tmpChecklist;
|
||||||
|
|
||||||
if (this.tags != null) {
|
if (this.tags != null) {
|
||||||
for (TaskTag tag : this.tags) {
|
for (TaskTag tag : this.tags) {
|
||||||
tag.setTask(this);
|
tag.setTask(this);
|
||||||
tag.save();
|
tag.async().save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.checklist != null) {
|
if (this.checklist != null) {
|
||||||
for (ChecklistItem item : this.checklist) {
|
for (ChecklistItem item : this.checklist) {
|
||||||
item.setTask(this);
|
item.setTask(this);
|
||||||
item.save();
|
item.async().save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue