mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
commit
237b66cb6b
18 changed files with 275 additions and 58 deletions
1
Habitica/assets/migrations/Habitica/2.sql
Normal file
1
Habitica/assets/migrations/Habitica/2.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE HabitRPGUser ADD COLUMN authentication_id varchar(255);
|
||||
|
|
@ -49,6 +49,7 @@ dependencies {
|
|||
compile('com.mikepenz:materialdrawer:4.3.8@aar') {
|
||||
transitive = true
|
||||
}
|
||||
compile 'com.mikepenz:google-material-typeface:2.2.0.1@aar'
|
||||
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile 'com.android.support:design:23.1.1'
|
||||
|
|
|
|||
BIN
Habitica/res/drawable-mdpi/sidebar_background.png
Normal file
BIN
Habitica/res/drawable-mdpi/sidebar_background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
|
|
@ -83,20 +83,6 @@
|
|||
<color name="new_task_bar_color">#555555</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
|
||||
<!-- MaterialDrawer DEFAULT DARK colors -->
|
||||
<color name="material_drawer_dark_background">#303030</color>
|
||||
<!-- MaterialDrawer DEFAULT DARK text / items colors -->
|
||||
<color name="material_drawer_dark_icons">#000</color>
|
||||
<color name="material_drawer_dark_primary_text">#de9a9a9a</color>
|
||||
<color name="material_drawer_dark_primary_icon">#8AFFFFFF</color>
|
||||
<color name="material_drawer_dark_secondary_text">#de9a9a9a</color>
|
||||
<color name="material_drawer_dark_hint_text">#42FFFFFF</color>
|
||||
<color name="material_drawer_dark_divider">#1FFFFFFF</color>
|
||||
<!-- MaterialDrawer DEFAULT DARK drawer colors -->
|
||||
<color name="material_drawer_dark_selected">#202020</color>
|
||||
<color name="material_drawer_dark_selected_text">@color/brand</color>
|
||||
<color name="material_drawer_dark_header_selection_text">#FFF</color>
|
||||
|
||||
<color name="checkbox_tint_color">#ffd8dcdd</color>
|
||||
|
||||
<color name="cell_separator">#c3c2c6</color>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
<item name="material_drawer_hint_text">@color/material_drawer_hint_text</item>
|
||||
<item name="material_drawer_divider">@color/material_drawer_divider</item>
|
||||
<item name="material_drawer_selected">@color/material_drawer_selected</item>
|
||||
<item name="material_drawer_selected_text">@color/brand</item>
|
||||
<item name="material_drawer_selected_text">@color/brand_200</item>
|
||||
<item name="material_drawer_header_selection_text">@color/material_drawer_header_selection_text</item>
|
||||
|
||||
<item name="popupMenuStyle">@style/PopupTheme</item>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.CollapsingToolbarLayout;
|
||||
import android.support.design.widget.TabLayout;
|
||||
|
|
@ -12,9 +13,14 @@ import android.widget.TextView;
|
|||
import com.crashlytics.android.Crashlytics;
|
||||
import com.crashlytics.android.core.CrashlyticsCore;
|
||||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPicture;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPictureRunnable;
|
||||
import com.instabug.wrapper.support.activity.InstabugAppCompatActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
|
@ -44,6 +50,7 @@ public abstract class AvatarActivityBase extends InstabugAppCompatActivity {
|
|||
|
||||
TextView titleTextView;
|
||||
|
||||
AccountHeader accountHeader;
|
||||
Drawer drawer;
|
||||
//endregion
|
||||
|
||||
|
|
@ -91,10 +98,29 @@ public abstract class AvatarActivityBase extends InstabugAppCompatActivity {
|
|||
viewPager.setBackgroundColor(getResources().getColor(R.color.white));
|
||||
|
||||
avatarInHeader = new AvatarWithBarsViewModel(this, avatar_with_bars);
|
||||
|
||||
accountHeader = MainDrawerBuilder.CreateDefaultAccountHeader(this).build();
|
||||
drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar, accountHeader)
|
||||
.build();
|
||||
}
|
||||
|
||||
protected void setTitle(String text) {
|
||||
toolbar.setTitle(text);
|
||||
}
|
||||
|
||||
public void updateSidebar() {
|
||||
final IProfile profile = accountHeader.getProfiles().get(0);
|
||||
if (User.getAuthentication() != null) {
|
||||
if (User.getAuthentication().getLocalAuthentication() != null) {
|
||||
profile.withEmail(User.getAuthentication().getLocalAuthentication().getEmail());
|
||||
}
|
||||
}
|
||||
profile.withName(User.getProfile().getName());
|
||||
new UserPicture(User, this, true, false).setPictureWithRunnable(new UserPictureRunnable() {
|
||||
public void run(Bitmap avatar) {
|
||||
profile.withIcon(avatar);
|
||||
accountHeader.updateProfile(profile);
|
||||
}
|
||||
});
|
||||
accountHeader.updateProfile(profile);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,24 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPicture;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPictureRunnable;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.BillingRequests;
|
||||
|
|
@ -28,7 +38,7 @@ public class GemPurchaseActivity extends AppCompatActivity {
|
|||
Toolbar toolbar;
|
||||
|
||||
Drawer drawer;
|
||||
|
||||
AccountHeader accountHeader;
|
||||
// endregion
|
||||
|
||||
// region IAP
|
||||
|
|
@ -63,9 +73,28 @@ public class GemPurchaseActivity extends AppCompatActivity {
|
|||
actionBar.setTitle("Purchase Gems");
|
||||
}
|
||||
|
||||
drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar)
|
||||
accountHeader = MainDrawerBuilder.CreateDefaultAccountHeader(this).build();
|
||||
Drawer drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar, accountHeader)
|
||||
.withSelectedItem(2)
|
||||
.build();
|
||||
|
||||
HostConfig hostConfig = PrefsActivity.fromContext(this);
|
||||
HabitRPGUser user = new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(hostConfig.getUser())).querySingle();
|
||||
|
||||
final IProfile profile = accountHeader.getProfiles().get(0);
|
||||
if (user.getAuthentication() != null) {
|
||||
if (user.getAuthentication().getLocalAuthentication() != null) {
|
||||
profile.withEmail(user.getAuthentication().getLocalAuthentication().getEmail());
|
||||
}
|
||||
} profile.withName(user.getProfile().getName());
|
||||
new UserPicture(user, this, true, false).setPictureWithRunnable(new UserPictureRunnable() {
|
||||
public void run(Bitmap avatar) {
|
||||
profile.withIcon(avatar);
|
||||
accountHeader.updateProfile(profile);
|
||||
}
|
||||
});
|
||||
accountHeader.updateProfile(profile);
|
||||
|
||||
checkout.start();
|
||||
// you only need this if this activity starts purchase process
|
||||
checkout.createPurchaseFlow(new RequestListener<Purchase>() {
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ public class HabitDatabase {
|
|||
|
||||
public static final String NAME = "Habitica";
|
||||
|
||||
public static final int VERSION = 1;
|
||||
public static final int VERSION = 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
|
|
@ -45,6 +46,7 @@ import com.habitrpg.android.habitica.ui.adapter.IReceiveNewEntries;
|
|||
import com.habitrpg.android.habitica.ui.fragments.TaskRecyclerViewFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.Debounce;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPicture;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPictureRunnable;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.SuppressedModals;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
|
||||
|
|
@ -55,10 +57,10 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
|||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.TaskTag;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.DrawerBuilder;
|
||||
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener;
|
||||
import com.mikepenz.materialdrawer.model.SectionDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SwitchDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener;
|
||||
import com.raizlabs.android.dbflow.runtime.FlowContentObserver;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
|
|
@ -125,8 +127,6 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
return;
|
||||
}
|
||||
|
||||
drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar)
|
||||
.build();
|
||||
|
||||
filterDrawer = new DrawerBuilder()
|
||||
.withActivity(this)
|
||||
|
|
@ -610,7 +610,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
adapter.dailyResetOffset = User.getPreferences().getDayStart();
|
||||
}
|
||||
updateHeader();
|
||||
|
||||
updateSidebar();
|
||||
displayDeathDialogIfNeeded();
|
||||
}
|
||||
});
|
||||
|
|
@ -731,7 +731,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
detailView.setText(this.getString(R.string.levelup_detail, level));
|
||||
|
||||
ImageView avatarView = (ImageView)customView.findViewById(R.id.avatarView);
|
||||
UserPicture userPicture = new UserPicture(User, this, false, false, false);
|
||||
UserPicture userPicture = new UserPicture(User, this, false, false);
|
||||
userPicture.setPictureOn(avatarView);
|
||||
}
|
||||
|
||||
|
|
@ -775,7 +775,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
|
|||
AvatarWithBarsViewModel.setHpBarData(hpBar, User.getStats(), this);
|
||||
|
||||
ImageView avatarView = (ImageView)customView.findViewById(R.id.avatarView);
|
||||
UserPicture userPicture = new UserPicture(User, this, false, false, false);
|
||||
UserPicture userPicture = new UserPicture(User, this, false, false);
|
||||
userPicture.setPictureOn(avatarView);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,9 +42,6 @@ public class PartyActivity extends AvatarActivityBase implements AppBarLayout.On
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar)
|
||||
.build();
|
||||
|
||||
setViewPagerAdapter();
|
||||
|
||||
this.hostConfig = PrefsActivity.fromContext(this);
|
||||
|
|
@ -56,7 +53,7 @@ public class PartyActivity extends AvatarActivityBase implements AppBarLayout.On
|
|||
return;
|
||||
|
||||
updateUserAvatars();
|
||||
|
||||
updateSidebar();
|
||||
final ContentCache contentCache = new ContentCache(mAPIHelper.apiService);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
|
@ -15,8 +16,13 @@ import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
|||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.ui.fragments.ChatListFragment;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPicture;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPictureRunnable;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
|
|
@ -36,6 +42,8 @@ public class TavernActivity extends AppCompatActivity {
|
|||
private APIHelper mAPIHelper;
|
||||
private HabitRPGUser User;
|
||||
|
||||
private AccountHeader accountHeader;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -60,7 +68,8 @@ public class TavernActivity extends AppCompatActivity {
|
|||
toolbar.setTitleTextColor(this.getResources().getColor(R.color.white));
|
||||
}
|
||||
|
||||
Drawer drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar)
|
||||
accountHeader = MainDrawerBuilder.CreateDefaultAccountHeader(this).build();
|
||||
Drawer drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar, accountHeader)
|
||||
.withSelectedItem(2)
|
||||
.build();
|
||||
|
||||
|
|
@ -70,12 +79,29 @@ public class TavernActivity extends AppCompatActivity {
|
|||
User = new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(hostConfig.getUser())).querySingle();
|
||||
|
||||
avatarInHeader.updateData(User);
|
||||
updateSidebar();
|
||||
|
||||
mAPIHelper = new APIHelper(this, hostConfig);
|
||||
|
||||
setFragment(new ChatListFragment(this, "habitrpg", mAPIHelper, User, true));
|
||||
}
|
||||
|
||||
private void updateSidebar() {
|
||||
final IProfile profile = accountHeader.getProfiles().get(0);
|
||||
if (User.getAuthentication() != null) {
|
||||
if (User.getAuthentication().getLocalAuthentication() != null) {
|
||||
profile.withEmail(User.getAuthentication().getLocalAuthentication().getEmail());
|
||||
}
|
||||
} profile.withName(User.getProfile().getName());
|
||||
new UserPicture(User, this, true, false).setPictureWithRunnable(new UserPictureRunnable() {
|
||||
public void run(Bitmap avatar) {
|
||||
profile.withIcon(avatar);
|
||||
accountHeader.updateProfile(profile);
|
||||
}
|
||||
});
|
||||
accountHeader.updateProfile(profile);
|
||||
}
|
||||
|
||||
// This could be moved into an abstract BaseActivity
|
||||
// class for being re-used by several instances
|
||||
protected void setFragment(Fragment fragment) {
|
||||
|
|
|
|||
|
|
@ -12,13 +12,17 @@ import com.habitrpg.android.habitica.PartyActivity;
|
|||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.TavernActivity;
|
||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.AccountHeaderBuilder;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.DrawerBuilder;
|
||||
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SectionDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
|
@ -47,7 +51,25 @@ public class MainDrawerBuilder {
|
|||
ClassMap.put(SIDEBAR_ABOUT, AboutActivity.class);
|
||||
}
|
||||
|
||||
public static DrawerBuilder CreateDefaultBuilderSettings(final Activity activity, Toolbar toolbar) {
|
||||
public static AccountHeaderBuilder CreateDefaultAccountHeader(final Activity activity) {
|
||||
AccountHeaderBuilder builder = new AccountHeaderBuilder()
|
||||
.withActivity(activity)
|
||||
.withHeaderBackground(R.drawable.sidebar_background)
|
||||
.addProfiles(
|
||||
new ProfileDrawerItem()
|
||||
)
|
||||
.withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
|
||||
@Override
|
||||
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.withSelectionListEnabledForSingleProfile(false);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
public static DrawerBuilder CreateDefaultBuilderSettings(final Activity activity, Toolbar toolbar, AccountHeader accountHeader) {
|
||||
DrawerBuilder builder = new DrawerBuilder()
|
||||
.withActivity(activity);
|
||||
|
||||
|
|
@ -56,6 +78,7 @@ public class MainDrawerBuilder {
|
|||
}
|
||||
|
||||
builder.withHeaderDivider(false)
|
||||
.withAccountHeader(accountHeader)
|
||||
.addDrawerItems(
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_tasks)).withIdentifier(SIDEBAR_TASKS),
|
||||
|
||||
|
|
@ -73,8 +96,8 @@ public class MainDrawerBuilder {
|
|||
|
||||
new DividerDrawerItem(),
|
||||
//new SecondaryDrawerItem().withName(activity.getString(R.string.sidebar_news)),
|
||||
new SecondaryDrawerItem().withName(activity.getString(R.string.sidebar_settings)).withIdentifier(SIDEBAR_SETTINGS),
|
||||
new SecondaryDrawerItem().withName(activity.getString(R.string.sidebar_about)).withIdentifier(SIDEBAR_ABOUT)
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_settings)).withIdentifier(SIDEBAR_SETTINGS),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_about)).withIdentifier(SIDEBAR_ABOUT)
|
||||
|
||||
)
|
||||
.withStickyFooterDivider(false)
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class PartyMemberRecyclerViewAdapter extends RecyclerView.Adapter<PartyMe
|
|||
public void bind(HabitRPGUser user) {
|
||||
android.content.Context ctx = itemView.getContext();
|
||||
|
||||
UserPicture userPicture = new UserPicture(user, ctx, false, false, false);
|
||||
UserPicture userPicture = new UserPicture(user, ctx, false, false);
|
||||
userPicture.setPictureOn(imageView);
|
||||
|
||||
AvatarWithBarsViewModel.setHpBarData(hpBar, user.getStats(), ctx);
|
||||
|
|
|
|||
|
|
@ -29,10 +29,11 @@ public class UserPicture {
|
|||
|
||||
private HabitRPGUser user;
|
||||
private ImageView imageView;
|
||||
private UserPictureRunnable runnable;
|
||||
private Context context;
|
||||
private AtomicInteger numOfTasks = new AtomicInteger(0);
|
||||
|
||||
private boolean hasBackground, hasMount, hasPet;
|
||||
private boolean hasBackground, hasPetMount;
|
||||
|
||||
private String currentCacheFileName;
|
||||
|
||||
|
|
@ -42,16 +43,14 @@ public class UserPicture {
|
|||
this.user = user;
|
||||
this.context = context;
|
||||
this.hasBackground = true;
|
||||
this.hasPet = true;
|
||||
this.hasMount = true;
|
||||
this.hasPetMount = true;
|
||||
}
|
||||
|
||||
public UserPicture(HabitRPGUser user, Context context, boolean hasBackground, boolean hasPet, boolean hasMount) {
|
||||
public UserPicture(HabitRPGUser user, Context context, boolean hasBackground, boolean hasPetMount) {
|
||||
this.user = user;
|
||||
this.context = context;
|
||||
this.hasBackground = hasBackground;
|
||||
this.hasPet = hasPet;
|
||||
this.hasMount = hasMount;
|
||||
this.hasPetMount = hasPetMount;
|
||||
}
|
||||
|
||||
public void removeTask() {
|
||||
|
|
@ -73,30 +72,65 @@ public class UserPicture {
|
|||
}
|
||||
layerNumber++;
|
||||
}
|
||||
if (!this.hasBackground && !this.hasPet) {
|
||||
if (!this.hasPetMount) {
|
||||
res = Bitmap.createBitmap(res, 25, 18, compactWidth, compactHeight);
|
||||
}
|
||||
BitmapUtils.saveToFile(currentCacheFileName, res);
|
||||
this.imageView.setImageBitmap(res);
|
||||
if (this.imageView != null) {
|
||||
this.imageView.setImageBitmap(res);
|
||||
} else {
|
||||
this.runnable.run(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPictureOn(ImageView imageView) {
|
||||
this.imageView = imageView;
|
||||
|
||||
List<String> layerNames = this.getLayerNames();
|
||||
|
||||
Bitmap cache = this.getCachedImage(layerNames);
|
||||
|
||||
// yes => load image to bitmap
|
||||
if(cache != null){
|
||||
imageView.setImageBitmap(cache);
|
||||
return;
|
||||
}
|
||||
|
||||
// no => generate it
|
||||
generateImage(layerNames);
|
||||
}
|
||||
|
||||
public void setPictureWithRunnable(UserPictureRunnable runnable) {
|
||||
this.runnable = runnable;
|
||||
List<String> layerNames = this.getLayerNames();
|
||||
|
||||
Bitmap cache = this.getCachedImage(layerNames);
|
||||
|
||||
// yes => load image to bitmap
|
||||
if(cache != null){
|
||||
runnable.run(cache);
|
||||
return;
|
||||
}
|
||||
|
||||
generateImage(layerNames);
|
||||
}
|
||||
|
||||
private List<String> getLayerNames() {
|
||||
List<String> layerNames = this.user.getAvatarLayerNames();
|
||||
|
||||
String mountName = this.user.getItems().getCurrentMount();
|
||||
|
||||
if (mountName != null && !mountName.isEmpty() && hasMount) {
|
||||
if (mountName != null && !mountName.isEmpty() && hasPetMount) {
|
||||
layerNames.add(0, "Mount_Body_" + mountName);
|
||||
layerNames.add("Mount_Head_" + mountName);
|
||||
}
|
||||
|
||||
String petName = this.user.getItems().getCurrentPet();
|
||||
|
||||
if (petName != null && !petName.isEmpty() && hasPet) {
|
||||
if (petName != null && !petName.isEmpty() && hasPetMount) {
|
||||
layerNames.add("Pet-" + petName);
|
||||
this.hasPet = true;
|
||||
this.hasPetMount = true;
|
||||
}
|
||||
|
||||
String backgroundName = this.user.getPreferences().getBackground();
|
||||
|
|
@ -106,7 +140,10 @@ public class UserPicture {
|
|||
this.hasBackground = true;
|
||||
}
|
||||
|
||||
return layerNames;
|
||||
}
|
||||
|
||||
private Bitmap getCachedImage(List<String> layerNames) {
|
||||
// get layer hash value
|
||||
String fullLayerString = "";
|
||||
|
||||
|
|
@ -118,15 +155,10 @@ public class UserPicture {
|
|||
currentCacheFileName = layersHash.concat(".png");
|
||||
|
||||
// does it already exist?
|
||||
Bitmap cache = BitmapUtils.loadFromFile(currentCacheFileName);
|
||||
return BitmapUtils.loadFromFile(currentCacheFileName);
|
||||
}
|
||||
|
||||
// yes => load image to bitmap
|
||||
if (cache != null) {
|
||||
imageView.setImageBitmap(cache);
|
||||
return;
|
||||
}
|
||||
|
||||
// no => generate it
|
||||
private void generateImage(List<String> layerNames) {
|
||||
Integer layerNumber = 0;
|
||||
this.numOfTasks.set(layerNames.size());
|
||||
for (String layer : layerNames) {
|
||||
|
|
@ -177,15 +209,15 @@ public class UserPicture {
|
|||
yOffset = 0;
|
||||
}
|
||||
|
||||
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)
|
||||
if (this.hasPetMount && !((this.hasBackground && layerNumber == 1) ||
|
||||
(!this.hasBackground && layerNumber == 0) ||
|
||||
(this.hasPetMount && layerNumber == this.layers.size()-2) ||
|
||||
(!this.hasPetMount && layerNumber == this.layers.size()-1)
|
||||
)) {
|
||||
yOffset = 0;
|
||||
}
|
||||
|
||||
if (this.hasPet && layerNumber == this.layers.size() - 1) {
|
||||
if (this.hasPetMount && layerNumber == this.layers.size()-1) {
|
||||
xOffset = 0;
|
||||
yOffset = 43;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package com.habitrpg.android.habitica.userpicture;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
/**
|
||||
* Created by viirus on 16/11/15.
|
||||
*/
|
||||
public interface UserPictureRunnable {
|
||||
|
||||
void run(Bitmap avatarBitmap);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.ForeignKey;
|
||||
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.Table;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
/**
|
||||
* Created by admin on 18/11/15.
|
||||
*/
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class Authentication extends BaseModel {
|
||||
|
||||
@Column
|
||||
@PrimaryKey
|
||||
@NotNull
|
||||
String user_id;
|
||||
|
||||
@SerializedName("local")
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "localauthentication_user_id",
|
||||
columnType = String.class,
|
||||
foreignColumnName = "user_id")})
|
||||
public LocalAuthentication localAuthentication;
|
||||
|
||||
public LocalAuthentication getLocalAuthentication() { return localAuthentication; }
|
||||
|
||||
public void setLocalAuthentication(LocalAuthentication LocalAuthentication) {this.localAuthentication = LocalAuthentication; }
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
if (localAuthentication != null)
|
||||
localAuthentication.user_id = user_id;
|
||||
|
||||
super.save();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
|
|
@ -65,6 +66,13 @@ public class HabitRPGUser extends BaseModel {
|
|||
foreignColumnName = "user_id")})
|
||||
private Items items;
|
||||
|
||||
@Column
|
||||
@ForeignKey(references = {@ForeignKeyReference(columnName = "authentication_id",
|
||||
columnType = String.class,
|
||||
foreignColumnName = "user_id")})
|
||||
@SerializedName("auth")
|
||||
private Authentication authentication;
|
||||
|
||||
public Preferences getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
|
|
@ -141,6 +149,10 @@ public class HabitRPGUser extends BaseModel {
|
|||
return this.balance;
|
||||
}
|
||||
|
||||
public Authentication getAuthentication() { return authentication; }
|
||||
|
||||
public void setAuthentication(Authentication authentication) {this.authentication = authentication; }
|
||||
|
||||
@OneToMany(methods = {OneToMany.Method.SAVE, OneToMany.Method.DELETE}, variableName = "habits")
|
||||
public List<Task> getHabits() {
|
||||
if(habits == null) {
|
||||
|
|
@ -207,6 +219,7 @@ public class HabitRPGUser extends BaseModel {
|
|||
stats.id = id;
|
||||
profile.user_Id = id;
|
||||
items.user_id = id;
|
||||
authentication.user_id = id;
|
||||
|
||||
|
||||
ArrayList<Task> allTasks = new ArrayList<Task>();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
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.Table;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
/**
|
||||
* Created by admin on 18/11/15.
|
||||
*/
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class LocalAuthentication extends BaseModel {
|
||||
|
||||
@Column
|
||||
@PrimaryKey
|
||||
@NotNull
|
||||
String user_id;
|
||||
|
||||
@Column
|
||||
String email, username;
|
||||
|
||||
public String getEmail() { return email; }
|
||||
public String getUsername() { return username; }
|
||||
|
||||
public void setEmail(String email) {this.email = email; }
|
||||
public void setUsername(String username) {this.username = username; }
|
||||
}
|
||||
Loading…
Reference in a new issue