mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-09 13:58:45 +00:00
Extract ChatListFragment
Extract MainActivity to AvatarActivityBase Party - Part 1 - Chat
This commit is contained in:
parent
2a5d0b79f2
commit
560669da95
12 changed files with 639 additions and 281 deletions
|
|
@ -92,6 +92,14 @@
|
|||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.habitrpg.android.habitica.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".PartyActivity"
|
||||
android:label="@string/title_activity_party"
|
||||
android:parentActivityName=".MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.habitrpg.android.habitica.MainActivity" />
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -68,16 +67,16 @@
|
|||
android:layout_gravity="bottom"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="0dp"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
android:fillViewport="false"
|
||||
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:layout_anchor="@+id/collapsing_toolbar"
|
||||
app:layout_anchorGravity="bottom"
|
||||
app:tabGravity="fill"
|
||||
|
||||
app:layout_collapseMode="pin"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="@android:color/white"
|
||||
app:tabMode="fixed"
|
||||
android:fillViewport="false" />
|
||||
app:tabMode="fixed" />
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
|
|
|||
81
Habitica/res/layout/activity_party.xml
Normal file
81
Habitica/res/layout/activity_party.xml
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:gravity="center"
|
||||
tools:context=".PartyActivity">
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:elevation="0dp"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<android.support.design.widget.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsing_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="210dp"
|
||||
android:fitsSystemWindows="true"
|
||||
|
||||
app:contentScrim="?attr/colorPrimary"
|
||||
app:expandedTitleMarginEnd="64dp"
|
||||
app:expandedTitleMarginStart="48dp"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed">
|
||||
|
||||
<include
|
||||
android:id="@+id/avatar_with_bars"
|
||||
layout="@layout/avatar_with_bars"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="140dp"
|
||||
android:layout_marginTop="70dp"
|
||||
app:layout_collapseMode="parallax" />
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:theme="@style/Toolbar"
|
||||
app:layout_collapseMode="pin"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
|
||||
</android.support.design.widget.CollapsingToolbarLayout>
|
||||
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/detail_tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="0dp"
|
||||
android:fillViewport="false"
|
||||
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:layout_anchor="@+id/collapsing_toolbar"
|
||||
app:layout_anchorGravity="bottom"
|
||||
|
||||
app:layout_collapseMode="pin"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="@android:color/white"
|
||||
app:tabMode="fixed" />
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
|
@ -33,20 +33,10 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/tavern.refresh.layout"
|
||||
<FrameLayout
|
||||
android:id="@+id/tavern.framelayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/tavern.list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:divider="@null"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
|
|
|||
19
Habitica/res/layout/fragment_chatlist.xml
Normal file
19
Habitica/res/layout/fragment_chatlist.xml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/chat.refresh.layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/chat.list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:divider="@null"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
|
|
@ -147,5 +147,5 @@
|
|||
<string name="saturday">Saturday</string>
|
||||
<string name="sunday">Sunday</string>
|
||||
<string name="title_activity_tavern">Tavern</string>
|
||||
|
||||
<string name="title_activity_party">Party</string>
|
||||
</resources>
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.CollapsingToolbarLayout;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.crashlytics.android.core.CrashlyticsCore;
|
||||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
import com.instabug.wrapper.support.activity.InstabugAppCompatActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
|
||||
/**
|
||||
* Created by Negue on 14.09.2015.
|
||||
*/
|
||||
public abstract class AvatarActivityBase extends InstabugAppCompatActivity {
|
||||
|
||||
//region View Elements
|
||||
@InjectView(R.id.viewpager)
|
||||
ViewPager viewPager;
|
||||
|
||||
@InjectView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@InjectView(R.id.detail_tabs)
|
||||
TabLayout detail_tabs;
|
||||
|
||||
@InjectView(R.id.avatar_with_bars)
|
||||
View avatar_with_bars;
|
||||
|
||||
@InjectView(R.id.collapsing_toolbar)
|
||||
CollapsingToolbarLayout collapsingToolbarLayout;
|
||||
|
||||
TextView titleTextView;
|
||||
|
||||
Drawer drawer;
|
||||
//endregion
|
||||
|
||||
protected HostConfig hostConfig;
|
||||
protected HabitRPGUser User;
|
||||
|
||||
AvatarWithBarsViewModel avatarInHeader;
|
||||
|
||||
protected abstract int getLayoutRes();
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getLayoutRes());
|
||||
|
||||
// Inject Controls
|
||||
ButterKnife.inject(this);
|
||||
|
||||
// Receive Events
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
// Initialize Crashlytics
|
||||
Crashlytics crashlytics = new Crashlytics.Builder()
|
||||
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
|
||||
.build();
|
||||
Fabric.with(this, crashlytics);
|
||||
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayUseLogoEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
}
|
||||
|
||||
toolbar.setPadding(0, getResources().getDimensionPixelSize(R.dimen.tool_bar_top_padding), 0, 0);
|
||||
}
|
||||
|
||||
viewPager.setBackgroundColor(getResources().getColor(R.color.white));
|
||||
|
||||
avatarInHeader = new AvatarWithBarsViewModel(this, avatar_with_bars);
|
||||
|
||||
|
||||
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){
|
||||
titleTextView.setText(text);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,20 +4,14 @@ import android.content.Intent;
|
|||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.crashlytics.android.core.CrashlyticsCore;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.TaskCreationCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.TaskScoringCallback;
|
||||
|
|
@ -33,13 +27,11 @@ import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
|
|||
import com.habitrpg.android.habitica.events.commands.CreateTagCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.FilterTasksByTagsCommand;
|
||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
import com.habitrpg.android.habitica.ui.EditTextDrawer;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.ui.adapter.HabitItemRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.TaskRecyclerViewFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.Debounce;
|
||||
import com.instabug.wrapper.support.activity.InstabugAppCompatActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TaskDirection;
|
||||
|
|
@ -63,15 +55,12 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import retrofit.Callback;
|
||||
import retrofit.RetrofitError;
|
||||
import retrofit.client.Response;
|
||||
|
||||
public class MainActivity extends InstabugAppCompatActivity implements HabitRPGUserCallback.OnUserReceived,
|
||||
public class MainActivity extends AvatarActivityBase implements HabitRPGUserCallback.OnUserReceived,
|
||||
TaskScoringCallback.OnTaskScored, FlowContentObserver.OnSpecificModelStateChangedListener,
|
||||
TaskCreationCallback.OnHabitCreated, TaskUpdateCallback.OnHabitUpdated,
|
||||
Callback<List<ItemData>>, OnCheckedChangeListener {
|
||||
|
|
@ -79,54 +68,22 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
static final int TASK_CREATED_RESULT = 1;
|
||||
static final int TASK_UPDATED_RESULT = 2;
|
||||
|
||||
//region View Elements
|
||||
@InjectView(R.id.viewpager)
|
||||
ViewPager materialViewPager;
|
||||
|
||||
@InjectView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@InjectView(R.id.detail_tabs)
|
||||
TabLayout detail_tabs;
|
||||
|
||||
@InjectView(R.id.avatar_with_bars)
|
||||
View avatar_with_bars;
|
||||
|
||||
Drawer drawer;
|
||||
|
||||
Drawer filterDrawer;
|
||||
//endregion
|
||||
|
||||
Map<Integer, TaskRecyclerViewFragment> ViewFragmentsDictionary = new HashMap<>();
|
||||
|
||||
List<Task> TaskList = new ArrayList<>();
|
||||
|
||||
private HostConfig hostConfig;
|
||||
APIHelper mAPIHelper;
|
||||
|
||||
// just to test the view
|
||||
private HabitRPGUser User;
|
||||
|
||||
AvatarWithBarsViewModel avatarInHeader;
|
||||
|
||||
FlowContentObserver observer;
|
||||
|
||||
@Override
|
||||
protected int getLayoutRes() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// Inject Controls
|
||||
ButterKnife.inject(this);
|
||||
|
||||
// Receive Events
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
// Initialize Crashlytics
|
||||
Crashlytics crashlytics = new Crashlytics.Builder()
|
||||
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
|
||||
.build();
|
||||
Fabric.with(this, crashlytics);
|
||||
|
||||
this.hostConfig = PrefsActivity.fromContext(this);
|
||||
if (hostConfig == null || hostConfig.getApi() == null || hostConfig.getApi().equals("") || hostConfig.getUser() == null || hostConfig.getUser().equals("")) {
|
||||
|
|
@ -135,45 +92,17 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
return;
|
||||
}
|
||||
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayUseLogoEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
}
|
||||
|
||||
toolbar.setPadding(0, getResources().getDimensionPixelSize(R.dimen.tool_bar_top_padding), 0, 0);
|
||||
}
|
||||
|
||||
materialViewPager.setBackgroundColor(getResources().getColor(R.color.white));
|
||||
|
||||
View mPagerRootView = materialViewPager.getRootView();
|
||||
|
||||
//View avatarHeaderView = mPagerRootView.findViewById(R.id.avatar_with_bars_layout);
|
||||
|
||||
avatarInHeader = new AvatarWithBarsViewModel(this, avatar_with_bars);
|
||||
|
||||
drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar)
|
||||
.withSelectedItem(0)
|
||||
.build();
|
||||
|
||||
final android.content.Context context = getApplicationContext();
|
||||
|
||||
filterDrawer = new DrawerBuilder()
|
||||
.withActivity(this)
|
||||
.withDrawerGravity(Gravity.RIGHT)
|
||||
.withCloseOnClick(false)
|
||||
.append(drawer);
|
||||
|
||||
materialViewPager.setOffscreenPageLimit(6);
|
||||
|
||||
materialViewPager.setCurrentItem(0);
|
||||
viewPager.setCurrentItem(0);
|
||||
|
||||
User = new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(hostConfig.getUser())).querySingle();
|
||||
this.observer = new FlowContentObserver();
|
||||
|
|
@ -181,16 +110,9 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
|
||||
this.observer.addSpecificModelChangeListener(this);
|
||||
|
||||
try {
|
||||
hasItemData = new Select().from(ItemData.class).querySingle() != null;
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
SetUserData();
|
||||
}
|
||||
|
||||
private boolean hasItemData = false;
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -217,7 +139,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
}
|
||||
|
||||
private void showSnackbar(String content, boolean negative) {
|
||||
Fragment f = ViewFragmentsDictionary.get(materialViewPager.getCurrentItem());
|
||||
Fragment f = ViewFragmentsDictionary.get(viewPager.getCurrentItem());
|
||||
|
||||
Snackbar snackbar = Snackbar.make(f.getView().findViewById(R.id.fab), content, Snackbar.LENGTH_LONG);
|
||||
|
||||
|
|
@ -396,7 +318,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
public void loadTaskLists() {
|
||||
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
materialViewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
|
||||
viewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
int oldPosition = -1;
|
||||
|
||||
|
|
@ -405,8 +327,6 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
int layoutOfType;
|
||||
TaskRecyclerViewFragment fragment;
|
||||
|
||||
String fragmentkey = "Recycler$" + position;
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
layoutOfType = R.layout.habit_item_card;
|
||||
|
|
@ -453,7 +373,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
});
|
||||
|
||||
|
||||
detail_tabs.setupWithViewPager(materialViewPager);
|
||||
detail_tabs.setupWithViewPager(viewPager);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -498,7 +418,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
|
||||
private void updateHeader() {
|
||||
updateUserAvatars();
|
||||
toolbar.setTitle(User.getProfile().getName() + " - Lv" + User.getStats().getLvl());
|
||||
setTitle(User.getProfile().getName() + " - Lv" + User.getStats().getLvl());
|
||||
|
||||
android.support.v7.app.ActionBarDrawerToggle actionBarDrawerToggle = drawer.getActionBarDrawerToggle();
|
||||
|
||||
|
|
@ -576,8 +496,6 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
|
||||
private boolean taskListAlreadyAdded;
|
||||
|
||||
private boolean getContentCalled = false;
|
||||
|
||||
private void SetUserData() {
|
||||
if (User != null) {
|
||||
runOnUiThread(new Runnable() {
|
||||
|
|
@ -640,7 +558,7 @@ public class MainActivity extends InstabugAppCompatActivity implements HabitRPGU
|
|||
private Debounce filterChangedHandler = new Debounce(1500, 1000) {
|
||||
@Override
|
||||
public void execute() {
|
||||
ArrayList<String> tagList = new ArrayList<String>();
|
||||
ArrayList<String> tagList = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, Boolean> f : tagFilterMap.entrySet()) {
|
||||
if (f.getValue()) {
|
||||
|
|
|
|||
143
Habitica/src/com/habitrpg/android/habitica/PartyActivity.java
Normal file
143
Habitica/src/com/habitrpg/android/habitica/PartyActivity.java
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
import com.habitrpg.android.habitica.events.commands.CreateTagCommand;
|
||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.ui.fragments.ChatListFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import butterknife.InjectView;
|
||||
|
||||
public class PartyActivity extends AvatarActivityBase implements AppBarLayout.OnOffsetChangedListener {
|
||||
|
||||
@InjectView(R.id.appbar)
|
||||
AppBarLayout appBarLayout;
|
||||
|
||||
private APIHelper mAPIHelper;
|
||||
|
||||
@Override
|
||||
protected int getLayoutRes() {
|
||||
return R.layout.activity_party;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
drawer = MainDrawerBuilder.CreateDefaultBuilderSettings(this, toolbar)
|
||||
.withSelectedItem(0)
|
||||
.build();
|
||||
|
||||
setViewPagerAdapter();
|
||||
|
||||
this.hostConfig = PrefsActivity.fromContext(this);
|
||||
User = new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(hostConfig.getUser())).querySingle();
|
||||
|
||||
mAPIHelper = new APIHelper(this, hostConfig);
|
||||
|
||||
|
||||
updateUserAvatars();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
appBarLayout.addOnOffsetChangedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
appBarLayout.removeOnOffsetChangedListener(this);
|
||||
}
|
||||
|
||||
private HashMap<Integer, Fragment> fragmentDictionary = new HashMap<>();
|
||||
|
||||
|
||||
public void setViewPagerAdapter() {
|
||||
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
viewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
|
||||
Fragment fragment;
|
||||
|
||||
switch (position) {
|
||||
case 1:
|
||||
fragment = new ChatListFragment(PartyActivity.this, "party", mAPIHelper, User, false);
|
||||
break;
|
||||
default:
|
||||
fragment = new Fragment();
|
||||
}
|
||||
|
||||
fragmentDictionary.put(position, fragment);
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return "Party";
|
||||
case 1:
|
||||
return "Chat";
|
||||
case 2:
|
||||
return "Members";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
detail_tabs.setupWithViewPager(viewPager);
|
||||
}
|
||||
|
||||
|
||||
private void updateUserAvatars() {
|
||||
avatarInHeader.UpdateData(User);
|
||||
}
|
||||
|
||||
//region Events
|
||||
|
||||
// until there is a party event
|
||||
public void onEvent(CreateTagCommand event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
|
||||
Fragment fragment = fragmentDictionary.get(viewPager.getCurrentItem());
|
||||
|
||||
if(!(fragment instanceof ChatListFragment))
|
||||
return;
|
||||
|
||||
ChatListFragment chatFragment = (ChatListFragment)fragment ;
|
||||
|
||||
// Disable Refresh if Header is collapsed
|
||||
|
||||
if (i == 0) {
|
||||
chatFragment.setRefreshEnabled(true);
|
||||
} else {
|
||||
chatFragment.setRefreshEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
//endregion Events
|
||||
}
|
||||
|
|
@ -1,49 +1,30 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.LayoutAnimationController;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.FlagChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.SendNewGroupMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ToggleInnCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ToggleLikeMessageCommand;
|
||||
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.adapter.TavernRecyclerViewAdapter;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
||||
import com.habitrpg.android.habitica.ui.fragments.ChatListFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.PostChatMessageResult;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import retrofit.Callback;
|
||||
import retrofit.RetrofitError;
|
||||
import retrofit.client.Response;
|
||||
|
||||
public class TavernActivity extends AppCompatActivity implements Callback<List<ChatMessage>>, SwipeRefreshLayout.OnRefreshListener {
|
||||
public class TavernActivity extends AppCompatActivity {
|
||||
|
||||
@InjectView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
|
@ -51,12 +32,6 @@ public class TavernActivity extends AppCompatActivity implements Callback<List<C
|
|||
@InjectView(R.id.avatar)
|
||||
LinearLayout avatarHeader;
|
||||
|
||||
@InjectView(R.id.tavern_list)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
@InjectView(R.id.tavern_refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
private AvatarWithBarsViewModel avatarInHeader;
|
||||
private APIHelper mAPIHelper;
|
||||
private HabitRPGUser User;
|
||||
|
|
@ -68,14 +43,8 @@ public class TavernActivity extends AppCompatActivity implements Callback<List<C
|
|||
|
||||
ButterKnife.inject(this);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
layoutManager.setSmoothScrollbarEnabled(true);
|
||||
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
|
||||
// Receive Events
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
|
|
@ -108,105 +77,21 @@ public class TavernActivity extends AppCompatActivity implements Callback<List<C
|
|||
|
||||
mAPIHelper = new APIHelper(this, hostConfig);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
onRefresh();
|
||||
setFragment(new ChatListFragment(this, "habitrpg", mAPIHelper, User, true));
|
||||
}
|
||||
|
||||
private void showSnackbar(String msg, boolean negative){
|
||||
Snackbar snackbar = Snackbar.make(recyclerView, msg, Snackbar.LENGTH_LONG);
|
||||
|
||||
if (negative) {
|
||||
View snackbarView = snackbar.getView();
|
||||
|
||||
//change Snackbar's background color;
|
||||
snackbarView.setBackgroundColor(Color.RED);
|
||||
}
|
||||
|
||||
snackbar.show();
|
||||
// This could be moved into an abstract BaseActivity
|
||||
// class for being re-used by several instances
|
||||
protected void setFragment(Fragment fragment) {
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
FragmentTransaction fragmentTransaction =
|
||||
fragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.tavern_framelayout, fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
public void onEvent(final FlagChatMessageCommand cmd){
|
||||
mAPIHelper.apiService.flagMessage(cmd.groupId, cmd.chatMessage.id, new Callback<Void>() {
|
||||
@Override
|
||||
public void success(Void aVoid, Response response) {
|
||||
showSnackbar("Flagged message by " + cmd.chatMessage.user, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
showSnackbar("Failed to flag message by " + cmd.chatMessage.user, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEvent(final ToggleLikeMessageCommand cmd){
|
||||
mAPIHelper.apiService.likeMessage(cmd.groupId, cmd.chatMessage.id, new Callback<List<Void>>() {
|
||||
@Override
|
||||
public void success(List<Void> aVoid, Response response) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
showSnackbar("Failed to like message by " + cmd.chatMessage.user, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEvent(final DeleteChatMessageCommand cmd) {
|
||||
mAPIHelper.apiService.deleteMessage(cmd.groupId, cmd.chatMessage.id, new Callback<Void>() {
|
||||
@Override
|
||||
public void success(Void aVoid, Response response) {
|
||||
if (currentChatMessages != null) {
|
||||
currentChatMessages.remove(cmd.chatMessage);
|
||||
|
||||
TavernActivity.this.success(currentChatMessages, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEvent(SendNewGroupMessageCommand cmd) {
|
||||
mAPIHelper.apiService.postGroupChat(cmd.TargetGroupId, cmd.Message, new Callback<PostChatMessageResult>() {
|
||||
@Override
|
||||
public void success(PostChatMessageResult msg, Response response) {
|
||||
if (currentChatMessages != null) {
|
||||
currentChatMessages.add(0, msg.message);
|
||||
|
||||
TavernActivity.this.success(currentChatMessages, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEvent(ToggleInnCommand event) {
|
||||
mAPIHelper.toggleSleep(new Callback<Void>() {
|
||||
@Override
|
||||
public void success(Void aVoid, Response response) {
|
||||
ToggledInnStateEvent innState = new ToggledInnStateEvent();
|
||||
innState.Inn = !User.getPreferences().getSleep();
|
||||
|
||||
User.getPreferences().setSleep(innState.Inn);
|
||||
|
||||
avatarInHeader.UpdateData(User);
|
||||
EventBus.getDefault().post(innState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
public void onEvent(ToggledInnStateEvent evt){
|
||||
avatarInHeader.UpdateData(User);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -224,39 +109,4 @@ public class TavernActivity extends AppCompatActivity implements Callback<List<C
|
|||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private List<ChatMessage> currentChatMessages;
|
||||
|
||||
@Override
|
||||
public void success(List<ChatMessage> chatMessages, Response response) {
|
||||
currentChatMessages = chatMessages;
|
||||
|
||||
// filter flagged messages
|
||||
for (int i = chatMessages.size() - 1; i >= 0; i--) {
|
||||
ChatMessage msg = chatMessages.get(i);
|
||||
|
||||
if(msg.flagCount >= 2){
|
||||
chatMessages.remove(msg);
|
||||
}
|
||||
}
|
||||
|
||||
TavernRecyclerViewAdapter tavernAdapter = new TavernRecyclerViewAdapter(chatMessages, this, User.getId());
|
||||
|
||||
//recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setAdapter(tavernAdapter);
|
||||
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
showSnackbar(error.getMessage(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
|
||||
mAPIHelper.apiService.listGroupChat("habitrpg", this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.widget.AdapterView;
|
|||
|
||||
import com.habitrpg.android.habitica.AboutActivity;
|
||||
import com.habitrpg.android.habitica.MainActivity;
|
||||
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;
|
||||
|
|
@ -27,6 +28,7 @@ public class MainDrawerBuilder {
|
|||
|
||||
static final int SIDEBAR_TASKS = 1;
|
||||
static final int SIDEBAR_TAVERN = 2;
|
||||
static final int SIDEBAR_PARTY = 3;
|
||||
static final int SIDEBAR_SETTINGS = 11;
|
||||
static final int SIDEBAR_ABOUT = 12;
|
||||
|
||||
|
|
@ -45,8 +47,8 @@ public class MainDrawerBuilder {
|
|||
|
||||
new SectionDrawerItem().withName(activity.getString(R.string.sidebar_section_social)),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_tavern)).withIdentifier(SIDEBAR_TAVERN),
|
||||
/*new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_party)),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_guilds)),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_party)).withIdentifier(SIDEBAR_PARTY),
|
||||
/*new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_guilds)),
|
||||
new PrimaryDrawerItem().withName(activity.getString(R.string.sidebar_challenges)),
|
||||
|
||||
new SectionDrawerItem().withName(activity.getString(R.string.sidebar_section_inventory)),
|
||||
|
|
@ -77,6 +79,10 @@ public class MainDrawerBuilder {
|
|||
selectedClass = TavernActivity.class;
|
||||
break;
|
||||
}
|
||||
case SIDEBAR_PARTY: {
|
||||
selectedClass = PartyActivity.class;
|
||||
break;
|
||||
}
|
||||
case SIDEBAR_SETTINGS: {
|
||||
selectedClass = PrefsActivity.class;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,239 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.FlagChatMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.SendNewGroupMessageCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ToggleInnCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.ToggleLikeMessageCommand;
|
||||
import com.habitrpg.android.habitica.ui.adapter.TavernRecyclerViewAdapter;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.PostChatMessageResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import retrofit.Callback;
|
||||
import retrofit.RetrofitError;
|
||||
import retrofit.client.Response;
|
||||
|
||||
/**
|
||||
* Created by Negue on 14.09.2015.
|
||||
*/
|
||||
public class ChatListFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, Callback<List<ChatMessage>> {
|
||||
|
||||
private Context ctx;
|
||||
private String groupId;
|
||||
private APIHelper apiHelper;
|
||||
private HabitRPGUser user;
|
||||
private String userId;
|
||||
private boolean isTavern;
|
||||
|
||||
public ChatListFragment(Context ctx, String groupId, APIHelper apiHelper, HabitRPGUser user, boolean isTavern){
|
||||
|
||||
this.ctx = ctx;
|
||||
this.groupId = groupId;
|
||||
this.apiHelper = apiHelper;
|
||||
this.user = user;
|
||||
this.userId = user.getId();
|
||||
this.isTavern = isTavern;
|
||||
|
||||
// Receive Events
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
private View view;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
if (view == null)
|
||||
view = inflater.inflate(R.layout.fragment_chatlist, container, false);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@InjectView(R.id.chat_list)
|
||||
RecyclerView mRecyclerView;
|
||||
|
||||
@InjectView(R.id.chat_refresh_layout)
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
LinearLayoutManager layoutManager;
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
ButterKnife.inject(this, view);
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
|
||||
layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
|
||||
|
||||
if (layoutManager == null) {
|
||||
layoutManager = new LinearLayoutManager(ctx);
|
||||
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
}
|
||||
|
||||
onRefresh();
|
||||
}
|
||||
|
||||
public void setRefreshEnabled(boolean enable) {
|
||||
if(swipeRefreshLayout != null){
|
||||
swipeRefreshLayout.setEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
|
||||
apiHelper.apiService.listGroupChat(groupId, this);
|
||||
}
|
||||
|
||||
private List<ChatMessage> currentChatMessages;
|
||||
|
||||
@Override
|
||||
public void success(List<ChatMessage> chatMessages, Response response) {
|
||||
currentChatMessages = chatMessages;
|
||||
|
||||
// filter flagged messages
|
||||
for (int i = chatMessages.size() - 1; i >= 0; i--) {
|
||||
ChatMessage msg = chatMessages.get(i);
|
||||
|
||||
if(msg.flagCount >= 2){
|
||||
chatMessages.remove(msg);
|
||||
}
|
||||
}
|
||||
|
||||
TavernRecyclerViewAdapter tavernAdapter = new TavernRecyclerViewAdapter(chatMessages, ctx, userId);
|
||||
|
||||
mRecyclerView.setAdapter(tavernAdapter);
|
||||
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void showSnackbar(String msg, boolean negative){
|
||||
Snackbar snackbar = Snackbar.make(mRecyclerView, msg, Snackbar.LENGTH_LONG);
|
||||
|
||||
if (negative) {
|
||||
View snackbarView = snackbar.getView();
|
||||
|
||||
//change Snackbar's background color;
|
||||
snackbarView.setBackgroundColor(Color.RED);
|
||||
}
|
||||
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
public void onEvent(final FlagChatMessageCommand cmd){
|
||||
apiHelper.apiService.flagMessage(cmd.groupId, cmd.chatMessage.id, new Callback<Void>() {
|
||||
@Override
|
||||
public void success(Void aVoid, Response response) {
|
||||
showSnackbar("Flagged message by " + cmd.chatMessage.user, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
showSnackbar("Failed to flag message by " + cmd.chatMessage.user, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEvent(final ToggleLikeMessageCommand cmd){
|
||||
apiHelper.apiService.likeMessage(cmd.groupId, cmd.chatMessage.id, new Callback<List<Void>>() {
|
||||
@Override
|
||||
public void success(List<Void> aVoid, Response response) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
showSnackbar("Failed to like message by " + cmd.chatMessage.user, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEvent(final DeleteChatMessageCommand cmd) {
|
||||
apiHelper.apiService.deleteMessage(cmd.groupId, cmd.chatMessage.id, new Callback<Void>() {
|
||||
@Override
|
||||
public void success(Void aVoid, Response response) {
|
||||
if (currentChatMessages != null) {
|
||||
currentChatMessages.remove(cmd.chatMessage);
|
||||
|
||||
ChatListFragment.this.success(currentChatMessages, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onEvent(SendNewGroupMessageCommand cmd) {
|
||||
apiHelper.apiService.postGroupChat(cmd.TargetGroupId, cmd.Message, new Callback<PostChatMessageResult>() {
|
||||
@Override
|
||||
public void success(PostChatMessageResult msg, Response response) {
|
||||
if (currentChatMessages != null) {
|
||||
currentChatMessages.add(0, msg.message);
|
||||
|
||||
ChatListFragment.this.success(currentChatMessages, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If the ChatList is Tavern, we're able to toggle the sleep-mode
|
||||
public void onEvent(ToggleInnCommand event) {
|
||||
apiHelper.toggleSleep(new Callback<Void>() {
|
||||
@Override
|
||||
public void success(Void aVoid, Response response) {
|
||||
ToggledInnStateEvent innState = new ToggledInnStateEvent();
|
||||
innState.Inn = !user.getPreferences().getSleep();
|
||||
|
||||
user.getPreferences().setSleep(innState.Inn);
|
||||
|
||||
EventBus.getDefault().post(innState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue