readd pausing dailies

This commit is contained in:
Phillip Thelen 2017-05-18 15:48:42 +02:00
parent 9f8b9b1bf0
commit d0645de11f
6 changed files with 153 additions and 22 deletions

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="180dp"
android:src="@drawable/npc_daniel"
android:scaleType="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
/>
<Button
android:id="@+id/dailies_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/tavern.inn.rest"
android:layout_marginRight="16dp"
style="@style/Button.Purple.Small"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/days_gray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/inn_description"
android:layout_margin="16dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/days_gray" />
</LinearLayout>
</LinearLayout>

View file

@ -77,9 +77,9 @@
<string name="about.give_us_feedback">Send us Feedback!</string>
<string name="about.bugreport">Report a Bug</string>
<string name="about.source_code">Source Code</string>
<string name="repeatEvery">Repeat Every</string>
<string name="repeatEvery">Repeat Every</string>
<!-- Network Errors -->
<string name="network_error_title">Connection Error</string>
@ -118,17 +118,17 @@
<string name="frequency">Frequency</string>
<string name="frequency_weekly">On Certain Days of the Week</string>
<string name="frequency_daily">Every X Days</string>
<string name="repeatables_summary_title">Summary</string>
<string name="repeatables_title">Repeats</string>
<string name="repeatables_on_title">Repeats On</string>
<string name="repeatables_frequency_daily">Daily</string>
<string name="repeatables_frequency_weekly">Weekly</string>
<string name="repeatables_frequency_monthly">Monthly</string>
<string name="repeatables_frequency_yearly">Yearly</string>
<string name="repeatables_frequency_day_of_month">Day of Month</string>
<string name="repeatables_frequency_day_of_week">Day of Week</string>
<string name="repeatables_summary_title">Summary</string>
<string name="repeatables_title">Repeats</string>
<string name="repeatables_on_title">Repeats On</string>
<string name="repeatables_frequency_daily">Daily</string>
<string name="repeatables_frequency_weekly">Weekly</string>
<string name="repeatables_frequency_monthly">Monthly</string>
<string name="repeatables_frequency_yearly">Yearly</string>
<string name="repeatables_frequency_day_of_month">Day of Month</string>
<string name="repeatables_frequency_day_of_week">Day of Week</string>
<string name="monday">Monday</string>
<string name="tuesday">Tuesday</string>
@ -583,8 +583,8 @@
<string name="reload_content">Reload Content</string>
<string name="dailyDueDefaultView">Set Dailies default to due tab</string>
<string name="dailyDueDefaultViewDescription">With this option set, the Dailies tasks will default to due instead of all</string>
<string name="repeat_summary">"Repeats %1$s every %2$s %3$s %4$s"</string>
<string name="repeat_summary">"Repeats %1$s every %2$s %3$s %4$s"</string>
<string name="no_billing_gems">Your device does not have any of the supported payment methods. Please use the habitica website if you want to purchase gems.</string>
<string name="no_billing_subscriptions">Your device does not have any of the supported payment methods. Please use the habitica website if you want to purchase a subscription.</string>
<string name="save">Save</string>
@ -602,4 +602,5 @@
<string name="description_optional">Description (optional)</string>
<string name="new_challenge_title">New challenge title</string>
<string name="ownership">Ownership</string>
<string name="inn">Inn</string>
</resources>

View file

@ -70,6 +70,7 @@ import com.habitrpg.android.habitica.ui.fragments.social.GuildsOverviewFragment;
import com.habitrpg.android.habitica.ui.fragments.social.InboxFragment;
import com.habitrpg.android.habitica.ui.fragments.social.InboxMessageListFragment;
import com.habitrpg.android.habitica.ui.fragments.social.PublicGuildsFragment;
import com.habitrpg.android.habitica.ui.fragments.social.TavernDetailFragment;
import com.habitrpg.android.habitica.ui.fragments.social.TavernFragment;
import com.habitrpg.android.habitica.ui.fragments.social.challenges.ChallengeDetailDialogHolder;
import com.habitrpg.android.habitica.ui.fragments.social.challenges.ChallengeListFragment;
@ -265,4 +266,6 @@ public interface AppComponent {
void inject(CreateChallengeActivity createChallengeActivity);
void inject(ChallengeDetailDialogHolder challengeDetailDialogHolder);
void inject(TavernDetailFragment tavernDetailFragment);
}

View file

@ -104,8 +104,9 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserLocalRepository>
public Observable<User> sleep(User user) {
return apiClient.sleep()
.map(isSleeping -> {
user.getPreferences().setSleep(isSleeping);
localRepository.saveUser(user);
localRepository.executeTransaction(realm -> {
user.getPreferences().setSleep(isSleeping);
});
return user;
});
}

View file

@ -0,0 +1,71 @@
package com.habitrpg.android.habitica.ui.fragments.social;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.components.AppComponent;
import com.habitrpg.android.habitica.data.UserRepository;
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
import com.habitrpg.android.habitica.models.user.User;
import com.habitrpg.android.habitica.modules.AppModule;
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.OnClick;
public class TavernDetailFragment extends BaseFragment {
@Inject
UserRepository userRepository;
@Inject
@Named(AppModule.NAMED_USER_ID)
String userId;
@BindView(R.id.dailies_button)
Button dailiesButton;
private User user;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.fragment_tavern_detail, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
compositeSubscription.add(userRepository.getUser(userId).subscribe(user -> {
this.user = user;
this.updatePausedState();
}, RxErrorHandler.handleEmptyError()));
}
private void updatePausedState() {
if (user.getPreferences().getSleep()) {
dailiesButton.setText(R.string.tavern_inn_checkOut);
} else {
dailiesButton.setText(R.string.tavern_inn_rest);
}
}
@Override
public void injectFragment(AppComponent component) {
component.inject(this);
}
@OnClick(R.id.dailies_button)
public void dailiesButtonClicked() {
userRepository.sleep(user).subscribe(user -> {}, RxErrorHandler.handleEmptyError());
}
}

View file

@ -35,6 +35,7 @@ public class TavernFragment extends BaseMainFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
this.usesTabLayout = true;
hideToolbar();
disableToolbarScrolling();
super.onCreateView(inflater, container, savedInstanceState);
@ -110,12 +111,16 @@ public class TavernFragment extends BaseMainFragment {
switch (position) {
case 0: {
fragment = new TavernDetailFragment();
break;
}
case 1: {
chatListFragment = new ChatListFragment();
chatListFragment.configure("habitrpg", user, true);
fragment = chatListFragment;
break;
}
case 1: {
case 2: {
fragment = questInfoFragment = GroupInformationFragment.newInstance(tavern, user);
break;
}
@ -129,17 +134,19 @@ public class TavernFragment extends BaseMainFragment {
@Override
public int getCount() {
if (tavern != null && tavern.quest != null && tavern.quest.key != null) {
return 2;
return 3;
}
return 1;
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getContext().getString(R.string.chat);
return getContext().getString(R.string.inn);
case 1:
return getContext().getString(R.string.chat);
case 2:
return getContext().getString(R.string.world_quest);
}
return "";