Fix various issues

This commit is contained in:
Phillip Thelen 2018-02-16 11:06:42 +01:00
parent c4f435c296
commit 6a5ffdc370
11 changed files with 62 additions and 25 deletions

View file

@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.habitrpg.android.habitica"
android:versionCode="1969"
android:versionName="1.4"
android:versionCode="1970"
android:versionName="1.4.1"
android:screenOrientation="portrait"
android:installLocation="auto" >

View file

@ -16,6 +16,8 @@ import com.habitrpg.android.habitica.models.shops.ShopItem;
import com.habitrpg.android.habitica.models.user.Items;
import com.habitrpg.android.habitica.models.user.User;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Map;
@ -37,7 +39,7 @@ public interface InventoryRepository extends ContentRepository {
Observable<RealmResults<Equipment>> getOwnedEquipment();
Observable<? extends RealmResults<? extends Item>> getOwnedItems(Class<? extends Item> itemClass, User user);
Observable<? extends Map<String, Item>> getOwnedItems(User user);
Observable<? extends Map<String, Item>> getOwnedItems(@NotNull User user);
Observable<Equipment> getEquipment(String key);

View file

@ -35,13 +35,13 @@ interface SocialRepository : BaseRepository {
fun postGroupChat(groupId: String, message: String): Observable<PostChatMessageResult>
fun retrieveGroup(id: String): Observable<Group>
fun getGroup(id: String): Observable<Group>
fun getGroup(id: String?): Observable<Group>
fun leaveGroup(id: String): Observable<Group>
fun leaveGroup(id: String?): Observable<Group>
fun joinGroup(id: String): Observable<Group>
fun joinGroup(id: String?): Observable<Group>
fun updateGroup(group: Group, name: String, description: String, leader: String, privacy: String): Observable<Void>
fun updateGroup(group: Group?, name: String?, description: String?, leader: String?, privacy: String?): Observable<Void>
fun retrieveGroups(type: String): Observable<List<Group>>
fun getGroups(type: String): Observable<RealmResults<Group>>
@ -62,11 +62,11 @@ interface SocialRepository : BaseRepository {
fun acceptQuest(user: User, partyId: String): Observable<Void>
fun rejectQuest(user: User, partyId: String): Observable<Void>
fun leaveQuest(partyId: String): Observable<Void>
fun leaveQuest(partyId: String?): Observable<Void>
fun cancelQuest(partyId: String): Observable<Void>
fun cancelQuest(partyId: String?): Observable<Void>
fun abortQuest(partyId: String): Observable<Quest>
fun abortQuest(partyId: String?): Observable<Quest>
fun rejectGroupInvite(groupId: String): Observable<Void>

View file

@ -97,17 +97,26 @@ class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: Ap
}.doOnNext({ localRepository.save(it) })
}
override fun getGroup(id: String): Observable<Group> {
override fun getGroup(id: String?): Observable<Group> {
if (id == null) {
return Observable.just(null)
}
return localRepository.getGroup(id)
}
override fun leaveGroup(id: String): Observable<Group> {
override fun leaveGroup(id: String?): Observable<Group> {
if (id == null) {
return Observable.just(null)
}
return apiClient.leaveGroup(id)
.flatMap { localRepository.getGroup(id).first() }
.doOnNext { group -> localRepository.executeTransaction { group.isMember = false } }
}
override fun joinGroup(id: String): Observable<Group> {
override fun joinGroup(id: String?): Observable<Group> {
if (id == null) {
return Observable.just(null)
}
return apiClient.joinGroup(id)
.doOnNext { group ->
group?.isMember = true
@ -115,7 +124,10 @@ class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: Ap
}
}
override fun updateGroup(group: Group, name: String, description: String, leader: String, privacy: String): Observable<Void> {
override fun updateGroup(group: Group?, name: String?, description: String?, leader: String?, privacy: String?): Observable<Void> {
if (group == null) {
return Observable.just(null)
}
val copiedGroup = localRepository.getUnmanagedCopy(group)
copiedGroup.name = name
copiedGroup.description = description
@ -188,16 +200,22 @@ class SocialRepositoryImpl(localRepository: SocialLocalRepository, apiClient: Ap
.doOnNext { localRepository.updateRSVPNeeded(user, false) }
}
override fun leaveQuest(partyId: String): Observable<Void> {
override fun leaveQuest(partyId: String?): Observable<Void> {
return apiClient.leaveQuest(partyId)
}
override fun cancelQuest(partyId: String): Observable<Void> {
override fun cancelQuest(partyId: String?): Observable<Void> {
if (partyId == null) {
return Observable.just(null)
}
return apiClient.cancelQuest(partyId)
.doOnNext { localRepository.removeQuest(partyId) }
}
override fun abortQuest(partyId: String): Observable<Quest> {
override fun abortQuest(partyId: String?): Observable<Quest> {
if (partyId == null) {
return Observable.just(null)
}
return apiClient.abortQuest(partyId)
.doOnNext { localRepository.removeQuest(partyId) }
}

View file

@ -365,7 +365,11 @@ public class MainActivity extends BaseActivity implements TutorialView.OnTutoria
if (activeFragment != null && activeFragment.get() != null && activeFragment.get().tabLayout == null) {
activeFragment = null;
if (drawerFragment != null) {
drawerFragment.setSelection(this.sharedPreferences.getString("lastActivePosition", NavigationDrawerFragment.SIDEBAR_TASKS), true);
String selection = NavigationDrawerFragment.SIDEBAR_TASKS;
try {
selection = this.sharedPreferences.getString("lastActivePosition", NavigationDrawerFragment.SIDEBAR_TASKS);
} catch (java.lang.RuntimeException ignored) {}
drawerFragment.setSelection(selection, true);
}
}
}

View file

@ -348,8 +348,12 @@ class NavigationDrawerFragment : DialogFragment() {
adapter.updateItem(item)
}
fun setUsername(name: String) {
toolbarTitle.text = name
fun setUsername(name: String?) {
if (name?.isNotEmpty() == true) {
toolbarTitle.text = name
} else {
toolbarTitle.text = "Habitica"
}
}
override fun onSaveInstanceState(outState: Bundle) {

View file

@ -88,7 +88,9 @@ class AvatarCustomizationFragment : BaseMainFragment() {
super.onViewCreated(view, savedInstanceState)
setGridSpanCount(view.width)
recyclerView.layoutManager = layoutManager
if (recyclerView.layoutManager == null) {
recyclerView.layoutManager = layoutManager
}
recyclerView.addItemDecoration(MarginDecoration(context))
recyclerView.adapter = adapter

View file

@ -148,8 +148,10 @@ class ShopFragment : BaseFragment() {
compositeSubscription.add(this.inventoryRepository.getOwnedItems(user)
.subscribe(Action1 { adapter?.setOwnedItems(it) }, RxErrorHandler.handleEmptyError()))
user.notNull {
compositeSubscription.add(this.inventoryRepository.getOwnedItems(it)
.subscribe(Action1 { adapter?.setOwnedItems(it) }, RxErrorHandler.handleEmptyError()))
}
compositeSubscription.add(this.inventoryRepository.inAppRewards
.map<List<String>> { it.map { it.key } }
.subscribe(Action1 { adapter?.setPinnedItemKeys(it) }, RxErrorHandler.handleEmptyError()))

View file

@ -101,7 +101,9 @@ public class QuestDetailFragment extends BaseMainFragment {
public void onResume() {
super.onResume();
getCompositeSubscription().add(socialRepository.getGroup(partyId).subscribe(this::updateParty, RxErrorHandler.handleEmptyError()));
getCompositeSubscription().add(inventoryRepository.getQuestContent(questKey).subscribe(this::updateQuestContent, RxErrorHandler.handleEmptyError()));
if (questKey != null) {
getCompositeSubscription().add(inventoryRepository.getQuestContent(questKey).subscribe(this::updateQuestContent, RxErrorHandler.handleEmptyError()));
}
}

View file

@ -135,6 +135,9 @@ public class PartyDetailFragment extends BaseFragment {
}
private void updateParty(Group party) {
if (party == null) {
return;
}
this.party = party;
this.quest = party.getQuest();
if (titleView == null) {

View file

@ -121,7 +121,7 @@ public abstract class BaseTaskViewHolder extends RecyclerView.ViewHolder impleme
this.titleTextView.setText(this.task.getText());
this.notesTextView.setText(this.task.getNotes());
}
if (this.task.getNotes().length() > 0) {
if (this.task.getNotes() != null && this.task.getNotes().length() > 0) {
this.notesTextView.setVisibility(View.VISIBLE);
} else {
this.notesTextView.setVisibility(View.GONE);