mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-21 05:09:00 +00:00
fix issue with chat messages being posted multiple times
This commit is contained in:
parent
a74752fa41
commit
f8d128e73b
4 changed files with 44 additions and 30 deletions
|
|
@ -100,10 +100,21 @@ public class HabitItemRecyclerViewAdapter<THabitItem extends Task>
|
|||
this.layoutResource = layoutResource;
|
||||
this.viewHolderClass = viewHolderClass;
|
||||
this.dailyResetOffset = dailyResetOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
|
||||
super.onDetachedFromRecyclerView(recyclerView);
|
||||
EventBus.getDefault().unregister(this);
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(FilterTasksByTagsCommand cmd) {
|
||||
filter();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.amplitude.api.Amplitude;
|
||||
import com.habitrpg.android.habitica.events.DisplayTutorialEvent;
|
||||
|
|
@ -12,6 +17,7 @@ import com.raizlabs.android.dbflow.sql.builder.Condition;
|
|||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.EventBusException;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
|
@ -19,6 +25,8 @@ import java.util.Date;
|
|||
|
||||
public class BaseFragment extends DialogFragment {
|
||||
|
||||
private boolean registerEventBus = false;
|
||||
|
||||
public String tutorialStepIdentifier;
|
||||
public String tutorialText;
|
||||
|
||||
|
|
@ -46,6 +54,30 @@ public class BaseFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
// Receive Events
|
||||
try {
|
||||
EventBus.getDefault().register(this);
|
||||
registerEventBus = true;
|
||||
} catch (EventBusException ignored) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (registerEventBus) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
public String getDisplayedClassName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ import org.greenrobot.eventbus.EventBusException;
|
|||
|
||||
public abstract class BaseMainFragment extends BaseFragment {
|
||||
|
||||
private boolean registerEventBus = false;
|
||||
|
||||
public MainActivity activity;
|
||||
public TabLayout tabLayout;
|
||||
public FrameLayout floatingMenuWrapper;
|
||||
|
|
@ -67,6 +65,7 @@ public abstract class BaseMainFragment extends BaseFragment {
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey("userId")) {
|
||||
String userId = savedInstanceState.getString("userId");
|
||||
this.user = new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(userId)).querySingle();
|
||||
|
|
@ -89,14 +88,6 @@ public abstract class BaseMainFragment extends BaseFragment {
|
|||
floatingMenuWrapper.removeAllViews();
|
||||
}
|
||||
|
||||
// Receive Events
|
||||
try {
|
||||
EventBus.getDefault().register(this);
|
||||
registerEventBus = true;
|
||||
} catch (EventBusException ignored) {
|
||||
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
activity.setActiveFragment(this);
|
||||
|
|
@ -104,14 +95,6 @@ public abstract class BaseMainFragment extends BaseFragment {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (registerEventBus) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
|
|
@ -48,9 +46,6 @@ import retrofit.Callback;
|
|||
import retrofit.RetrofitError;
|
||||
import retrofit.client.Response;
|
||||
|
||||
/**
|
||||
* Created by Negue on 14.09.2015.
|
||||
*/
|
||||
public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, Callback<List<ChatMessage>> {
|
||||
|
||||
private Context ctx;
|
||||
|
|
@ -98,13 +93,6 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
|
||||
}
|
||||
|
||||
// Receive Events
|
||||
try {
|
||||
EventBus.getDefault().register(this);
|
||||
} catch (EventBusException ignored) {
|
||||
|
||||
}
|
||||
|
||||
if (view == null)
|
||||
view = inflater.inflate(R.layout.fragment_chatlist, container, false);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue