mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Fix various issues
This commit is contained in:
parent
59b55001df
commit
99dad8f16e
9 changed files with 158 additions and 166 deletions
|
|
@ -84,7 +84,7 @@ dependencies {
|
|||
// IAP Handling / Verification
|
||||
implementation 'org.solovyev.android:checkout:1.2.1'
|
||||
//Facebook
|
||||
implementation('com.facebook.android:facebook-android-sdk:4.19.0') {
|
||||
implementation('com.facebook.android:facebook-android-sdk:4.30.0') {
|
||||
transitive = true
|
||||
}
|
||||
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public interface InventoryRepository extends ContentRepository {
|
|||
Observable<RealmResults<ShopItem>> getInAppRewards();
|
||||
Observable<List<ShopItem>> retrieveInAppRewards();
|
||||
|
||||
Observable<RealmResults<Equipment>> getOwnedEquipment(String type);
|
||||
Observable<RealmResults<Equipment>> getOwnedEquipment(@NotNull String type);
|
||||
Observable<RealmResults<Equipment>> getOwnedEquipment();
|
||||
|
||||
Observable<? extends RealmResults<? extends Item>> getOwnedItems(Class<? extends Item> itemClass, User user);
|
||||
|
|
@ -48,16 +48,16 @@ public interface InventoryRepository extends ContentRepository {
|
|||
void saveEquipment(Equipment equipment);
|
||||
|
||||
Observable<RealmResults<Mount>> getMounts();
|
||||
Observable<RealmResults<Mount>> getMounts(String type, String group);
|
||||
Observable<RealmResults<Mount>> getMounts(@NotNull String type, @NotNull String group);
|
||||
|
||||
Observable<RealmResults<Mount>> getOwnedMounts();
|
||||
Observable<RealmResults<Mount>> getOwnedMounts(String animalType, String animalGroup);
|
||||
Observable<RealmResults<Mount>> getOwnedMounts(@NotNull String animalType, @NotNull String animalGroup);
|
||||
|
||||
Observable<RealmResults<Pet>> getPets();
|
||||
Observable<RealmResults<Pet>> getPets(String type, String group);
|
||||
Observable<RealmResults<Pet>> getPets(@NotNull String type, @NotNull String group);
|
||||
|
||||
Observable<RealmResults<Pet>> getOwnedPets();
|
||||
Observable<RealmResults<Pet>> getOwnedPets(String type, String group);
|
||||
Observable<RealmResults<Pet>> getOwnedPets(@NotNull String type, @NotNull String group);
|
||||
|
||||
void updateOwnedEquipment(User user);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ object NumberAbbreviator {
|
|||
usedNumber /= 1000
|
||||
}
|
||||
|
||||
val formatter = DecimalFormat("###.##" + abbreviationForCounter(context, counter))
|
||||
val formatter = DecimalFormat("###.##" + abbreviationForCounter(context, counter).replace(".", ""))
|
||||
formatter.roundingMode = RoundingMode.FLOOR
|
||||
return formatter.format(usedNumber)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,15 +71,6 @@ class AvatarCustomizationFragment : BaseMainFragment() {
|
|||
}
|
||||
.subscribe(Action1 { }, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
return if (adapter.getItemViewType(position) == 0) {
|
||||
layoutManager.spanCount
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
|
|
@ -89,7 +80,16 @@ class AvatarCustomizationFragment : BaseMainFragment() {
|
|||
|
||||
setGridSpanCount(view.width)
|
||||
if (recyclerView.layoutManager == null) {
|
||||
recyclerView.layoutManager = layoutManager
|
||||
recyclerView.layoutManager = GridLayoutManager(activity, 2)
|
||||
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int {
|
||||
return if (adapter.getItemViewType(position) == 0) {
|
||||
layoutManager.spanCount
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
recyclerView.addItemDecoration(MarginDecoration(context))
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class EquipmentDetailFragment : BaseMainFragment() {
|
|||
recyclerView.addItemDecoration(DividerItemDecoration(getActivity()!!, DividerItemDecoration.VERTICAL))
|
||||
recyclerView.itemAnimator = SafeDefaultItemAnimator()
|
||||
|
||||
inventoryRepository.getOwnedEquipment(type).first().subscribe(Action1<RealmResults<Equipment>> { this.adapter.updateData(it) }, RxErrorHandler.handleEmptyError())
|
||||
type?.let { inventoryRepository.getOwnedEquipment(it).first().subscribe(Action1<RealmResults<Equipment>> { this.adapter.updateData(it) }, RxErrorHandler.handleEmptyError()) }
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,9 @@ public class MountDetailRecyclerFragment extends BaseMainFragment {
|
|||
}
|
||||
|
||||
private void loadItems() {
|
||||
inventoryRepository.getMounts(animalType, animalGroup).first().subscribe(adapter::updateData, RxErrorHandler.handleEmptyError());
|
||||
if (animalType != null && animalGroup != null) {
|
||||
inventoryRepository.getMounts(animalType, animalGroup).first().subscribe(adapter::updateData, RxErrorHandler.handleEmptyError());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,145 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.inventory.stable;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository;
|
||||
import com.habitrpg.android.habitica.events.commands.FeedCommand;
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
|
||||
import com.habitrpg.android.habitica.models.user.User;
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.PetDetailRecyclerAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemRecyclerFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarginDecoration;
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class PetDetailRecyclerFragment extends BaseMainFragment {
|
||||
private static final String ANIMAL_TYPE_KEY = "ANIMAL_TYPE_KEY";
|
||||
|
||||
@Inject
|
||||
InventoryRepository inventoryRepository;
|
||||
|
||||
public RecyclerView recyclerView;
|
||||
public PetDetailRecyclerAdapter adapter;
|
||||
public String animalType;
|
||||
public String animalGroup;
|
||||
GridLayoutManager layoutManager = null;
|
||||
|
||||
private View view;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
this.usesTabLayout = false;
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (view == null) {
|
||||
view = inflater.inflate(R.layout.fragment_recyclerview, container, false);
|
||||
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
|
||||
|
||||
layoutManager = new GridLayoutManager(getActivity(), 2);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.addItemDecoration(new MarginDecoration(getActivity()));
|
||||
|
||||
adapter = (PetDetailRecyclerAdapter) recyclerView.getAdapter();
|
||||
if (adapter == null) {
|
||||
adapter = new PetDetailRecyclerAdapter(null, true);
|
||||
adapter.context = this.getActivity();
|
||||
adapter.itemType = this.animalType;
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setItemAnimator(new SafeDefaultItemAnimator());
|
||||
this.loadItems();
|
||||
|
||||
getCompositeSubscription().add(adapter.getEquipEvents()
|
||||
.flatMap(key -> inventoryRepository.equip(user, "pet", key))
|
||||
.subscribe(items -> {}, RxErrorHandler.handleEmptyError()));
|
||||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
this.animalType = savedInstanceState.getString(ANIMAL_TYPE_KEY, "");
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
inventoryRepository.close();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(AppComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
final View finalView = view;
|
||||
finalView.post(() -> setGridSpanCount(finalView.getWidth()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(ANIMAL_TYPE_KEY, this.animalType);
|
||||
}
|
||||
|
||||
private void setGridSpanCount(int width) {
|
||||
int spanCount = 0;
|
||||
if (getContext() != null && getContext().getResources() != null) {
|
||||
float itemWidth;
|
||||
itemWidth = getContext().getResources().getDimension(R.dimen.pet_width);
|
||||
|
||||
spanCount = (int) (width / itemWidth);
|
||||
}
|
||||
if (spanCount == 0) {
|
||||
spanCount = 1;
|
||||
}
|
||||
layoutManager.setSpanCount(spanCount);
|
||||
layoutManager.requestLayout();
|
||||
}
|
||||
|
||||
private void loadItems() {
|
||||
inventoryRepository.getPets(animalType, animalGroup).first().subscribe(adapter::updateData, RxErrorHandler.handleEmptyError());
|
||||
inventoryRepository.getOwnedMounts(animalType, animalGroup).subscribe(adapter::setOwnedMounts, RxErrorHandler.handleEmptyError());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void showFeedingDialog(FeedCommand event) {
|
||||
if (event.usingPet == null || event.usingFood == null) {
|
||||
ItemRecyclerFragment fragment = new ItemRecyclerFragment();
|
||||
fragment.feedingPet = event.usingPet;
|
||||
fragment.isFeeding = true;
|
||||
fragment.isHatching = false;
|
||||
fragment.itemType = "food";
|
||||
fragment.itemTypeText = getString(R.string.food);
|
||||
fragment.show(getFragmentManager(), "feedDialog");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserData(User user) {
|
||||
super.updateUserData(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String customTitle() {
|
||||
if (!isAdded()) {
|
||||
return "";
|
||||
}
|
||||
return getString(R.string.pets);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.inventory.stable
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.AppComponent
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.events.commands.FeedCommand
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.inventory.Mount
|
||||
import com.habitrpg.android.habitica.models.inventory.Pet
|
||||
import com.habitrpg.android.habitica.models.user.Items
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.PetDetailRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.items.ItemRecyclerFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarginDecoration
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import io.realm.RealmResults
|
||||
import kotlinx.android.synthetic.main.fragment_recyclerview.*
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import rx.functions.Action1
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
class PetDetailRecyclerFragment : BaseMainFragment() {
|
||||
|
||||
@Inject
|
||||
lateinit var inventoryRepository: InventoryRepository
|
||||
|
||||
var adapter: PetDetailRecyclerAdapter = PetDetailRecyclerAdapter(null, true)
|
||||
var animalType: String = ""
|
||||
var animalGroup: String = ""
|
||||
internal var layoutManager: GridLayoutManager? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
this.usesTabLayout = false
|
||||
super.onCreateView(inflater, container, savedInstanceState)
|
||||
if (savedInstanceState != null) {
|
||||
this.animalType = savedInstanceState.getString(ANIMAL_TYPE_KEY, "")
|
||||
}
|
||||
|
||||
return inflater.inflate(R.layout.fragment_recyclerview, container, false)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
inventoryRepository.close()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun injectFragment(component: AppComponent) {
|
||||
component.inject(this)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val finalView = view
|
||||
|
||||
layoutManager = GridLayoutManager(getActivity(), 2)
|
||||
recyclerView.layoutManager = layoutManager
|
||||
recyclerView.addItemDecoration(MarginDecoration(getActivity()))
|
||||
|
||||
adapter.context = this.getActivity()
|
||||
adapter.itemType = this.animalType
|
||||
recyclerView.adapter = adapter
|
||||
recyclerView.itemAnimator = SafeDefaultItemAnimator()
|
||||
this.loadItems()
|
||||
|
||||
compositeSubscription.add(adapter.equipEvents
|
||||
.flatMap<Items> { key -> inventoryRepository.equip(user, "pet", key) }
|
||||
.subscribe(Action1 { }, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
finalView.post { setGridSpanCount(finalView.width) }
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putString(ANIMAL_TYPE_KEY, this.animalType)
|
||||
}
|
||||
|
||||
private fun setGridSpanCount(width: Int) {
|
||||
var spanCount = 0
|
||||
if (context != null && context!!.resources != null) {
|
||||
val itemWidth: Float = context!!.resources.getDimension(R.dimen.pet_width)
|
||||
|
||||
spanCount = (width / itemWidth).toInt()
|
||||
}
|
||||
if (spanCount == 0) {
|
||||
spanCount = 1
|
||||
}
|
||||
layoutManager?.spanCount = spanCount
|
||||
layoutManager?.requestLayout()
|
||||
}
|
||||
|
||||
private fun loadItems() {
|
||||
if (animalType.isNotEmpty() && animalGroup.isNotEmpty()) {
|
||||
inventoryRepository.getPets(animalType, animalGroup).first().subscribe(Action1<RealmResults<Pet>> { adapter.updateData(it) }, RxErrorHandler.handleEmptyError())
|
||||
inventoryRepository.getOwnedMounts(animalType, animalGroup).subscribe(Action1<RealmResults<Mount>> { adapter.setOwnedMounts(it) }, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun showFeedingDialog(event: FeedCommand) {
|
||||
if (event.usingPet == null || event.usingFood == null) {
|
||||
val fragment = ItemRecyclerFragment()
|
||||
fragment.feedingPet = event.usingPet
|
||||
fragment.isFeeding = true
|
||||
fragment.isHatching = false
|
||||
fragment.itemType = "food"
|
||||
fragment.itemTypeText = getString(R.string.food)
|
||||
fragment.show(fragmentManager, "feedDialog")
|
||||
}
|
||||
}
|
||||
|
||||
override fun customTitle(): String {
|
||||
return if (!isAdded) {
|
||||
""
|
||||
} else getString(R.string.pets)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val ANIMAL_TYPE_KEY = "ANIMAL_TYPE_KEY"
|
||||
}
|
||||
}
|
||||
|
|
@ -72,8 +72,13 @@ class InboxMessageListFragment : BaseMainFragment(), SwipeRefreshLayout.OnRefres
|
|||
|
||||
communityGuidelinesView.visibility = View.GONE
|
||||
|
||||
view.invalidate()
|
||||
view.forceLayout()
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context?) {
|
||||
view?.invalidate()
|
||||
view?.forceLayout()
|
||||
|
||||
super.onAttach(context)
|
||||
}
|
||||
|
||||
private fun loadMessages() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue