Implement new class selection screen. Fixes #828

This commit is contained in:
Phillip Thelen 2019-04-17 14:48:08 +02:00
parent 6ab2868dcf
commit 0ee9936ec3
38 changed files with 563 additions and 462 deletions

View file

@ -145,7 +145,6 @@
</activity>
<activity
android:name=".ui.activities.ClassSelectionActivity"
android:theme="@style/AppThemeWithActionBarBlackText"
android:parentActivityName=".ui.activities.MainActivity"
android:screenOrientation="portrait"
tools:ignore="UnusedAttribute"

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="10dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M0,12l0,12 11.5,-5.7c6.3,-3.2 11.5,-6 11.5,-6.3 0,-0.3 -5.2,-3.1 -11.5,-6.3l-11.5,-5.7 0,12z"
android:strokeColor="@color/white"
android:fillColor="@color/white"/>
</vector>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/brand_100" />
<corners android:radius="@dimen/bar_radius"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/gray_700" />
<corners android:radius="@dimen/bar_radius"/>
<stroke android:width="2dp" android:color="@color/blue_10" />
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/gray_700" />
<corners android:radius="@dimen/bar_radius"/>
<stroke android:width="2dp" android:color="@color/brand_300" />
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/gray_700" />
<corners android:radius="@dimen/bar_radius"/>
<stroke android:width="2dp" android:color="@color/red_10" />
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/gray_700" />
<corners android:radius="@dimen/bar_radius"/>
<stroke android:width="2dp" android:color="@color/yellow_10" />
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/gray_20_alpha" />
<corners android:radius="@dimen/bar_radius"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/yellow_10" />
<corners android:radius="@dimen/rounded_button_radius"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

View file

@ -1,164 +1,183 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/healerWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardView.Default">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardContent"
android:background="@drawable/selection_highlight">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/healerAvatarView"
android:layout_width="@dimen/avatar_header_width"
android:layout_height="@dimen/avatar_header_height" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/healer"
style="@style/CardTitle"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/healer_description"
style="@style/CardText"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/mageWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardView.Default">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardContent"
android:background="@drawable/selection_highlight">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/mageAvatarView"
android:layout_width="@dimen/avatar_header_width"
android:layout_height="@dimen/avatar_header_height" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mage"
style="@style/CardTitle" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mage_description"
style="@style/CardText"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/rogueWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardView.Default">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardContent"
android:background="@drawable/selection_highlight">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/rogueAvatarView"
android:layout_width="@dimen/avatar_header_width"
android:layout_height="@dimen/avatar_header_height" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rogue"
style="@style/CardTitle" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rogue_description"
style="@style/CardText"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/warriorWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardView.Default">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardContent"
android:background="@drawable/selection_highlight">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/warriorAvatarView"
android:layout_width="@dimen/avatar_header_width"
android:layout_height="@dimen/avatar_header_height" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/warrior"
style="@style/CardTitle" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/warrior_description"
style="@style/CardText"/>
</LinearLayout>
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/optOutWrapper"
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CardView.Default">
android:minHeight="?attr/actionBarSize"
android:theme="@style/Toolbar"
android:background="@color/white"
app:layout_scrollFlags="scroll|enterAlways"
app:title="@string/choose_class"
app:titleTextColor="@color/gray_50"
app:theme="@style/ToolbarDarkBackArrow"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_marginBottom="@dimen/spacing_large">
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/healerWrapper"
android:layout_width="116dp"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@style/CardContent"
android:background="@drawable/selection_highlight">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/opt_out_class"
style="@style/CardTitle" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/opt_out_description"
style="@style/CardText"/>
android:gravity="center_horizontal"
android:layout_marginRight="48dp">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/healerAvatarView"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginBottom="4dp"
app:showBackground="false"
app:showMount="false"
app:showPet="false"
app:showSleeping="false"
tools:background="@color/gray_200"/>
<TextView
android:id="@+id/healerButton"
android:layout_width="116dp"
android:layout_height="43dp"
android:text="@string/healer"
style="@style/ClassSelectionClassButton"
android:textColor="@color/yellow_50" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<LinearLayout
android:id="@+id/mageWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/mageAvatarView"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginBottom="4dp"
app:showBackground="false"
app:showMount="false"
app:showPet="false"
app:showSleeping="false"
tools:background="@color/gray_200"/>
<TextView
android:id="@+id/mageButton"
android:layout_width="116dp"
android:layout_height="43dp"
android:text="@string/mage"
style="@style/ClassSelectionClassButton"
android:textColor="@color/blue_10" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_marginBottom="30dp">
<LinearLayout
android:id="@+id/rogueWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_marginRight="48dp">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/rogueAvatarView"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginBottom="4dp"
app:showBackground="false"
app:showMount="false"
app:showPet="false"
app:showSleeping="false"
tools:background="@color/gray_200"/>
<TextView
android:id="@+id/rogueButton"
android:layout_width="116dp"
android:layout_height="43dp"
android:text="@string/rogue"
style="@style/ClassSelectionClassButton"
android:textColor="@color/brand_300" />
</LinearLayout>
<LinearLayout
android:id="@+id/warriorWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<com.habitrpg.android.habitica.ui.AvatarView
android:id="@+id/warriorAvatarView"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginBottom="4dp"
app:showBackground="false"
app:showMount="false"
app:showPet="false"
app:showSleeping="false"
tools:background="@color/gray_200"/>
<TextView
android:id="@+id/warriorButton"
android:layout_width="116dp"
android:layout_height="43dp"
android:text="@string/warrior"
style="@style/ClassSelectionClassButton"
android:textColor="@color/red_10" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/selected_wrapper"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.7"
tools:background="@color/yellow_100"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingStart="22dp"
android:paddingEnd="22dp"
android:paddingBottom="@dimen/spacing_large">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="-8dp"
android:layout_marginBottom="8dp"
android:scaleType="center"
android:rotation="90"
android:src="@drawable/class_selection_inset_arrow"/>
<TextView
android:id="@+id/selected_title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Healer"
style="@style/Title1"
android:layout_marginBottom="@dimen/spacing_medium"/>
<TextView
android:id="@+id/selected_description_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="@string/healer_description"
android:gravity="center_horizontal"/>
<Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="@+id/selected_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:background="@drawable/layout_rounded_bg_yellow_10"
android:textColor="@color/white"
tools:text="Becoma a Healer"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/opt_out"
android:orderInCategory="1"
app:showAsAction="always"
android:title="@string/opt_out_class" />
</menu>

View file

@ -140,6 +140,7 @@
<color name="black_10_alpha">#16000000</color>
<color name="black_20_alpha">#33000000</color>
<color name="black_50_alpha">#89000000</color>
<color name="gray_20_alpha">#331a181d</color>
<color name="light_gray_bg">#F6F4F8</color>
<color name="skin_ddc994">#ddc994</color>
@ -167,4 +168,5 @@
<color name="bb_inActiveBottomBarItemColor">#747474</color>
<color name="bb_darkBackgroundColor">#212121</color>
<color name="bb_tabletRightBorderDark">#505050</color>
<color name="dark_brown">#794b00</color>
</resources>

View file

@ -884,4 +884,6 @@
<string name="update_available">Update available: %1$s (%2$d)</string>
<string name="need_help_header_description">Post a message in the %s to have your questions answered by a fellow player.</string>
<string name="need_more_help">Need more help?</string>
<string name="become_x">Become a %s</string>
<string name="x_class">%s Class</string>
</resources>

View file

@ -525,5 +525,17 @@
<item name="android:textAlignment">gravity</item>
</style>
<style name="ClassSelectionClassButton">
<item name="android:gravity">center</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
<item name="android:background">@drawable/layout_rounded_bg_gray_700</item>
</style>
<style name="ToolbarDarkBackArrow" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">@color/gray_50</item>
<item name="android:actionMenuTextColor">@color/gray_50</item>
</style>
<color name="taskform_gray">#99edecee</color>
</resources>

View file

@ -1,6 +0,0 @@
package com.habitrpg.android.habitica.events;
public class SelectClassEvent {
public boolean isInitialSelection;
public String currentClass;
}

View file

@ -10,19 +10,3 @@ import android.view.View
fun View.setScaledPadding(context: Context?, left: Int, top: Int, right: Int, bottom: Int) {
this.setPadding(left.dpToPx(context), top.dpToPx(context), right.dpToPx(context), bottom.dpToPx(context))
}
var <T : View> T.backgroundCompat: Drawable?
get() {
return background
}
set(value) {
if (value == null) {
return
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
background = value
} else {
@Suppress("DEPRECATION")
setBackgroundDrawable(value)
}
}

View file

@ -1,79 +0,0 @@
package com.habitrpg.android.habitica.interactors;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.habitrpg.android.habitica.events.SelectClassEvent;
import com.habitrpg.android.habitica.executors.PostExecutionThread;
import com.habitrpg.android.habitica.executors.ThreadExecutor;
import com.habitrpg.android.habitica.models.user.User;
import com.habitrpg.android.habitica.ui.activities.ClassSelectionActivity;
import javax.inject.Inject;
import io.reactivex.Flowable;
import static com.habitrpg.android.habitica.ui.activities.MainActivity.SELECT_CLASS_RESULT;
public class CheckClassSelectionUseCase extends UseCase<CheckClassSelectionUseCase.RequestValues, Void> {
@Inject
public CheckClassSelectionUseCase(ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {
super(threadExecutor, postExecutionThread);
}
@Override
protected Flowable<Void> buildUseCaseObservable(RequestValues requestValues) {
return Flowable.defer(() -> {
User user = requestValues.user;
if(requestValues.selectClassEvent == null) {
if (user.getStats().getLvl() >= 10 &&
!user.getPreferences().getDisableClasses() &&
!user.getFlags().getClassSelected()) {
SelectClassEvent event = new SelectClassEvent();
event.isInitialSelection = true;
event.currentClass = user.getStats().getHabitClass();
displayClassSelectionActivity(user, event, requestValues.activity);
}
} else {
displayClassSelectionActivity(user, requestValues.selectClassEvent, requestValues.activity);
}
return Flowable.empty();
});
}
private void displayClassSelectionActivity(User user, SelectClassEvent event, Activity activity) {
Bundle bundle = new Bundle();
bundle.putString("size", user.getPreferences().getSize());
bundle.putString("skin", user.getPreferences().getSkin());
bundle.putString("shirt", user.getPreferences().getShirt());
bundle.putInt("hairBangs", user.getPreferences().getHair().getBangs());
bundle.putInt("hairBase", user.getPreferences().getHair().getBase());
bundle.putString("hairColor", user.getPreferences().getHair().getColor());
bundle.putInt("hairMustache", user.getPreferences().getHair().getMustache());
bundle.putInt("hairBeard", user.getPreferences().getHair().getBeard());
bundle.putBoolean("isInitialSelection", event.isInitialSelection);
bundle.putString("currentClass", event.currentClass);
Intent intent = new Intent(activity, ClassSelectionActivity.class);
intent.putExtras(bundle);
activity.startActivityForResult(intent, SELECT_CLASS_RESULT);
}
public static final class RequestValues implements UseCase.RequestValues {
private final Activity activity;
private User user;
private SelectClassEvent selectClassEvent;
public RequestValues(User user, SelectClassEvent selectClassEvent, Activity activity) {
this.user = user;
this.selectClassEvent = selectClassEvent;
this.activity = activity;
}
}
}

View file

@ -0,0 +1,50 @@
package com.habitrpg.android.habitica.interactors
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.habitrpg.android.habitica.executors.PostExecutionThread
import com.habitrpg.android.habitica.executors.ThreadExecutor
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.activities.ClassSelectionActivity
import javax.inject.Inject
import io.reactivex.Flowable
import com.habitrpg.android.habitica.ui.activities.MainActivity.Companion.SELECT_CLASS_RESULT
class CheckClassSelectionUseCase @Inject
constructor(threadExecutor: ThreadExecutor, postExecutionThread: PostExecutionThread) : UseCase<CheckClassSelectionUseCase.RequestValues, Void>(threadExecutor, postExecutionThread) {
override fun buildUseCaseObservable(requestValues: RequestValues): Flowable<Void> {
return Flowable.defer {
val user = requestValues.user
if (requestValues.currentClass == null) {
if (user?.stats?.lvl ?: 0 >= 10 &&
user?.preferences?.disableClasses == false &&
user.flags?.classSelected == false) {
displayClassSelectionActivity(true, null, requestValues.activity)
}
} else {
displayClassSelectionActivity(requestValues.isInitialSelection, requestValues.currentClass, requestValues.activity)
}
Flowable.empty<Void>()
}
}
private fun displayClassSelectionActivity(isInitialSelection: Boolean, currentClass: String?, activity: Activity) {
val bundle = Bundle()
bundle.putBoolean("isInitialSelection", isInitialSelection)
bundle.putString("currentClass", currentClass)
val intent = Intent(activity, ClassSelectionActivity::class.java)
intent.putExtras(bundle)
activity.startActivityForResult(intent, SELECT_CLASS_RESULT)
}
class RequestValues(val user: User?, val isInitialSelection: Boolean, val currentClass: String?, val activity: Activity) : UseCase.RequestValues
}

View file

@ -1,97 +0,0 @@
package com.habitrpg.android.habitica.interactors;
import android.app.Activity;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.events.ShareEvent;
import com.habitrpg.android.habitica.executors.PostExecutionThread;
import com.habitrpg.android.habitica.executors.ThreadExecutor;
import com.habitrpg.android.habitica.helpers.RxErrorHandler;
import com.habitrpg.android.habitica.helpers.SoundManager;
import com.habitrpg.android.habitica.models.user.Stats;
import com.habitrpg.android.habitica.models.user.SuppressedModals;
import com.habitrpg.android.habitica.models.user.User;
import com.habitrpg.android.habitica.ui.AvatarView;
import org.greenrobot.eventbus.EventBus;
import javax.inject.Inject;
import io.reactivex.Flowable;
public class LevelUpUseCase extends UseCase<LevelUpUseCase.RequestValues, Stats> {
private SoundManager soundManager;
private CheckClassSelectionUseCase checkClassSelectionUseCase;
@Inject
public LevelUpUseCase(SoundManager soundManager, ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread,
CheckClassSelectionUseCase checkClassSelectionUseCase) {
super(threadExecutor, postExecutionThread);
this.soundManager = soundManager;
this.checkClassSelectionUseCase = checkClassSelectionUseCase;
}
@Override
protected Flowable<Stats> buildUseCaseObservable(RequestValues requestValues) {
return Flowable.defer(() -> {
soundManager.loadAndPlayAudio(SoundManager.SoundLevelUp);
SuppressedModals suppressedModals = requestValues.user.getPreferences().getSuppressModals();
if (suppressedModals != null) {
if (suppressedModals.getLevelUp()) {
checkClassSelectionUseCase.observable(new CheckClassSelectionUseCase.RequestValues(requestValues.user, null, requestValues.activity))
.subscribe(aVoid -> {}, RxErrorHandler.handleEmptyError());
return Flowable.just(requestValues.user.getStats());
}
}
View customView = requestValues.activity.getLayoutInflater().inflate(R.layout.dialog_levelup, null);
if (customView != null) {
AvatarView dialogAvatarView = customView.findViewById(R.id.avatarView);
dialogAvatarView.setAvatar(requestValues.user);
}
final ShareEvent event = new ShareEvent();
event.sharedMessage = requestValues.activity.getString(R.string.share_levelup, requestValues.newLevel) + " https://habitica.com/social/level-up";
AvatarView avatarView = new AvatarView(requestValues.activity, true, true, true);
avatarView.setAvatar(requestValues.user);
avatarView.onAvatarImageReady(avatarImage -> event.shareImage = avatarImage);
AlertDialog alert = new AlertDialog.Builder(requestValues.activity)
.setTitle(requestValues.activity.getString(R.string.levelup_header, requestValues.newLevel))
.setView(customView)
.setPositiveButton(R.string.levelup_button, (dialog, which) -> checkClassSelectionUseCase.observable(new CheckClassSelectionUseCase.RequestValues(requestValues.user, null, requestValues.activity))
.subscribe(aVoid -> {}, RxErrorHandler.handleEmptyError()))
.setNeutralButton(R.string.share, (dialog, which) -> {
EventBus.getDefault().post(event);
dialog.dismiss();
})
.create();
if (!requestValues.activity.isFinishing()) {
alert.show();
}
return Flowable.just(requestValues.user.getStats());
});
}
public static final class RequestValues implements UseCase.RequestValues {
private User user;
private int newLevel;
private Activity activity;
public RequestValues(User user, AppCompatActivity activity) {
this.user = user;
this.newLevel = user.getStats().getLvl();
this.activity = activity;
}
}
}

View file

@ -0,0 +1,88 @@
package com.habitrpg.android.habitica.interactors
import android.app.Activity
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import android.view.View
import android.widget.TextView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.events.ShareEvent
import com.habitrpg.android.habitica.executors.PostExecutionThread
import com.habitrpg.android.habitica.executors.ThreadExecutor
import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.helpers.SoundManager
import com.habitrpg.android.habitica.models.user.Stats
import com.habitrpg.android.habitica.models.user.SuppressedModals
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.AvatarView
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
import io.reactivex.Flowable
import io.reactivex.functions.Consumer
class LevelUpUseCase @Inject
constructor(private val soundManager: SoundManager, threadExecutor: ThreadExecutor, postExecutionThread: PostExecutionThread,
private val checkClassSelectionUseCase: CheckClassSelectionUseCase) : UseCase<LevelUpUseCase.RequestValues, Stats>(threadExecutor, postExecutionThread) {
override fun buildUseCaseObservable(requestValues: RequestValues): Flowable<Stats> {
return Flowable.defer {
soundManager.loadAndPlayAudio(SoundManager.SoundLevelUp)
val suppressedModals = requestValues.user.preferences?.suppressModals
if (suppressedModals?.levelUp == true) {
showClassSelection(requestValues)
return@defer Flowable.just<Stats>(requestValues.user.stats)
}
val customView = requestValues.activity.layoutInflater.inflate(R.layout.dialog_levelup, null)
if (customView != null) {
val dialogAvatarView = customView.findViewById<AvatarView>(R.id.avatarView)
dialogAvatarView.setAvatar(requestValues.user)
}
val event = ShareEvent()
event.sharedMessage = requestValues.activity.getString(R.string.share_levelup, requestValues.newLevel) + " https://habitica.com/social/level-up"
val avatarView = AvatarView(requestValues.activity, true, true, true)
avatarView.setAvatar(requestValues.user)
avatarView.onAvatarImageReady(object : AvatarView.Consumer<Bitmap?> {
override fun accept(t: Bitmap?) {
event.shareImage = t
}
})
val alert = AlertDialog.Builder(requestValues.activity)
.setTitle(requestValues.activity.getString(R.string.levelup_header, requestValues.newLevel))
.setView(customView)
.setPositiveButton(R.string.levelup_button) { _, _ ->
showClassSelection(requestValues)
}
.setNeutralButton(R.string.share) { dialog, _ ->
EventBus.getDefault().post(event)
dialog.dismiss()
}
.create()
if (!requestValues.activity.isFinishing) {
alert.show()
}
Flowable.just(requestValues.user.stats!!)
}
}
private fun showClassSelection(requestValues: RequestValues) {
checkClassSelectionUseCase.observable(CheckClassSelectionUseCase.RequestValues(requestValues.user, true, null, requestValues.activity))
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
}
class RequestValues(val user: User, val activity: AppCompatActivity) : UseCase.RequestValues {
val newLevel: Int = user.stats?.lvl ?: 0
}
}

View file

@ -1,9 +1,20 @@
package com.habitrpg.android.habitica.ui.activities
import android.app.ProgressDialog
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.util.AttributeSet
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AlertDialog
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.AppComponent
import com.habitrpg.android.habitica.data.UserRepository
@ -12,25 +23,52 @@ import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.user.*
import com.habitrpg.android.habitica.ui.AvatarView
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import io.reactivex.functions.Consumer
import javax.inject.Inject
class ClassSelectionActivity : BaseActivity(), Consumer<User> {
private var currentClass: String? = null
private var newClass: String = "healer"
set(value) {
field = value
when (value) {
"healer" -> healerSelected()
"wizard" -> mageSelected()
"mage" -> mageSelected()
"rogue" -> rogueSelected()
"warrior" -> warriorSelected()
}
}
private var className: String? = null
set(value) {
field = value
selectedTitleTextView.text = getString(R.string.x_class, className)
selectedButton.text = getString(R.string.become_x, className)
}
private var isInitialSelection: Boolean = false
private var classWasUnset: Boolean? = false
private var shouldFinish: Boolean? = false
internal val healerAvatarView: AvatarView by bindView(R.id.healerAvatarView)
private val toolbar: Toolbar by bindView(R.id.toolbar)
private val healerAvatarView: AvatarView by bindView(R.id.healerAvatarView)
private val healerWrapper: View by bindView(R.id.healerWrapper)
internal val mageAvatarView: AvatarView by bindView(R.id.mageAvatarView)
private val healerButton: TextView by bindView(R.id.healerButton)
private val mageAvatarView: AvatarView by bindView(R.id.mageAvatarView)
private val mageWrapper: View by bindView(R.id.mageWrapper)
internal val rogueAvatarView: AvatarView by bindView(R.id.rogueAvatarView)
private val mageButton: TextView by bindView(R.id.mageButton)
private val rogueAvatarView: AvatarView by bindView(R.id.rogueAvatarView)
private val rogueWrapper: View by bindView(R.id.rogueWrapper)
internal val warriorAvatarView: AvatarView by bindView(R.id.warriorAvatarView)
private val rogueButton: TextView by bindView(R.id.rogueButton)
private val warriorAvatarView: AvatarView by bindView(R.id.warriorAvatarView)
private val warriorWrapper: View by bindView(R.id.warriorWrapper)
private val optOutWrapper: View by bindView(R.id.optOutWrapper)
private val warriorButton: TextView by bindView(R.id.warriorButton)
private val selectedWrapperView: ViewGroup by bindView(R.id.selected_wrapper)
private val selectedTitleTextView: TextView by bindView(R.id.selected_title_textview)
private val selectedDescriptionTextView: TextView by bindView(R.id.selected_description_textview)
private val selectedButton: Button by bindView(R.id.selected_button)
@Inject
lateinit var userRepository: UserRepository
@ -44,27 +82,56 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
val intent = intent
val bundle = intent.extras
isInitialSelection = bundle?.getBoolean("isInitialSelection") ?: false
val preferences = Preferences()
preferences.setHair(Hair())
preferences.costume = false
compositeSubscription.add(userRepository.getUser().firstElement().subscribe(Consumer {
it.preferences?.let {preferences ->
val unmanagedPrefs = userRepository.getUnmanagedCopy(preferences)
unmanagedPrefs.costume = false
setAvatarViews(unmanagedPrefs)
}
}, RxErrorHandler.handleEmptyError()))
bundle.notNull { thisBundle ->
currentClass = thisBundle.getString("currentClass")
preferences.setSize(thisBundle.getString("size") ?: "slim")
preferences.setSkin(thisBundle.getString("skin") ?: "")
preferences.setShirt(thisBundle.getString("shirt") ?: "")
preferences.hair?.bangs = thisBundle.getInt("hairBangs")
preferences.hair?.base = thisBundle.getInt("hairBase")
preferences.hair?.color = thisBundle.getString("hairColor")
preferences.hair?.mustache = thisBundle.getInt("hairMustache")
preferences.hair?.beard = thisBundle.getInt("hairBeard")
}
if (!isInitialSelection) {
compositeSubscription.add(userRepository.changeClass()
.subscribe(Consumer { classWasUnset = true }, RxErrorHandler.handleEmptyError()))
}
healerWrapper.setOnClickListener { newClass = "healer" }
mageWrapper.setOnClickListener { newClass = "mage" }
rogueWrapper.setOnClickListener { newClass = "rogue" }
warriorWrapper.setOnClickListener { newClass = "warrior" }
selectedButton.setOnClickListener { displayConfirmationDialogForClass() }
}
override fun onStart() {
super.onStart()
newClass = currentClass ?: "healer"
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.class_selection, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.opt_out -> optOutSelected()
}
return super.onOptionsItemSelected(item)
}
private fun setAvatarViews(preferences: Preferences) {
val healerOutfit = Outfit()
healerOutfit.armor = "armor_healer_5"
healerOutfit.head = "head_healer_5"
@ -72,6 +139,8 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
healerOutfit.weapon = "weapon_healer_6"
val healer = this.makeUser(preferences, healerOutfit)
healerAvatarView.setAvatar(healer)
val healerIcon = BitmapDrawable(resources, HabiticaIconsHelper.imageOfHealerLightBg())
healerButton.setCompoundDrawablesWithIntrinsicBounds(healerIcon, null, null, null)
val mageOutfit = Outfit()
mageOutfit.armor = "armor_wizard_5"
@ -79,6 +148,8 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
mageOutfit.weapon = "weapon_wizard_6"
val mage = this.makeUser(preferences, mageOutfit)
mageAvatarView.setAvatar(mage)
val mageIcon = BitmapDrawable(resources, HabiticaIconsHelper.imageOfMageLightBg())
mageButton.setCompoundDrawablesWithIntrinsicBounds(mageIcon, null, null, null)
val rogueOutfit = Outfit()
rogueOutfit.armor = "armor_rogue_5"
@ -87,6 +158,8 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
rogueOutfit.weapon = "weapon_rogue_6"
val rogue = this.makeUser(preferences, rogueOutfit)
rogueAvatarView.setAvatar(rogue)
val rogueIcon = BitmapDrawable(resources, HabiticaIconsHelper.imageOfRogueLightBg())
rogueButton.setCompoundDrawablesWithIntrinsicBounds(rogueIcon, null, null, null)
val warriorOutfit = Outfit()
warriorOutfit.armor = "armor_warrior_5"
@ -95,17 +168,8 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
warriorOutfit.weapon = "weapon_warrior_6"
val warrior = this.makeUser(preferences, warriorOutfit)
warriorAvatarView.setAvatar(warrior)
if (!isInitialSelection) {
compositeSubscription.add(userRepository.changeClass()
.subscribe(Consumer { classWasUnset = true }, RxErrorHandler.handleEmptyError()))
}
healerWrapper.setOnClickListener { healerSelected() }
mageWrapper.setOnClickListener { mageSelected() }
rogueWrapper.setOnClickListener { rogueSelected() }
warriorWrapper.setOnClickListener { warriorSelected() }
optOutWrapper.setOnClickListener { optOutSelected() }
val warriorIcon = BitmapDrawable(resources, HabiticaIconsHelper.imageOfWarriorLightBg())
warriorButton.setCompoundDrawablesWithIntrinsicBounds(warriorIcon, null, null, null)
}
override fun injectActivity(component: AppComponent?) {
@ -122,19 +186,51 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
}
private fun healerSelected() {
displayConfirmationDialogForClass(getString(R.string.healer), Stats.HEALER)
className = getString(R.string.healer)
selectedDescriptionTextView.text = getString(R.string.healer_description)
selectedWrapperView.setBackgroundColor(ContextCompat.getColor(this, R.color.yellow_100))
selectedTitleTextView.setTextColor(ContextCompat.getColor(this, R.color.dark_brown))
selectedDescriptionTextView.setTextColor(ContextCompat.getColor(this, R.color.dark_brown))
selectedButton.setBackgroundResource(R.drawable.layout_rounded_bg_yellow_10)
updateButtonBackgrounds(healerButton, getDrawable(R.drawable.layout_rounded_bg_brand_700_yellow_border))
}
private fun mageSelected() {
displayConfirmationDialogForClass(getString(R.string.mage), Stats.MAGE)
className = getString(R.string.mage)
selectedDescriptionTextView.text = getString(R.string.mage_description)
selectedWrapperView.setBackgroundColor(ContextCompat.getColor(this, R.color.blue_100))
selectedTitleTextView.setTextColor(ContextCompat.getColor(this, R.color.white))
selectedDescriptionTextView.setTextColor(ContextCompat.getColor(this, R.color.white))
selectedButton.setBackgroundResource(R.drawable.layout_rounded_bg_gray_alpha)
updateButtonBackgrounds(mageButton, getDrawable(R.drawable.layout_rounded_bg_brand_700_blue_border))
}
private fun rogueSelected() {
displayConfirmationDialogForClass(getString(R.string.rogue), Stats.ROGUE)
className = getString(R.string.rogue)
selectedDescriptionTextView.text = getString(R.string.rogue_description)
selectedWrapperView.setBackgroundColor(ContextCompat.getColor(this, R.color.brand_300))
selectedTitleTextView.setTextColor(ContextCompat.getColor(this, R.color.white))
selectedDescriptionTextView.setTextColor(ContextCompat.getColor(this, R.color.white))
selectedButton.setBackgroundResource(R.drawable.layout_rounded_bg_brand_100)
updateButtonBackgrounds(rogueButton, getDrawable(R.drawable.layout_rounded_bg_brand_700_brand_border))
}
private fun warriorSelected() {
displayConfirmationDialogForClass(getString(R.string.warrior), Stats.WARRIOR)
className = getString(R.string.warrior)
selectedDescriptionTextView.text = getString(R.string.warrior_description)
selectedWrapperView.setBackgroundColor(ContextCompat.getColor(this, R.color.red_50))
selectedTitleTextView.setTextColor(ContextCompat.getColor(this, R.color.white))
selectedDescriptionTextView.setTextColor(ContextCompat.getColor(this, R.color.white))
selectedButton.setBackgroundResource(R.drawable.layout_rounded_bg_gray_alpha)
updateButtonBackgrounds(warriorButton, getDrawable(R.drawable.layout_rounded_bg_brand_700_red_border))
}
private fun updateButtonBackgrounds(selectedButton: TextView, background: Drawable?) {
val deselectedBackground = getDrawable(R.drawable.layout_rounded_bg_gray_700)
healerButton.background = if (healerButton == selectedButton) background else deselectedBackground
mageButton.background = if (mageButton == selectedButton) background else deselectedBackground
rogueButton.background = if (rogueButton == selectedButton) background else deselectedBackground
warriorButton.background = if (warriorButton == selectedButton) background else deselectedBackground
}
private fun optOutSelected() {
@ -148,16 +244,15 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
alert.show()
}
private fun displayConfirmationDialogForClass(className: String, classIdentifier: String) {
private fun displayConfirmationDialogForClass() {
if (!this.isInitialSelection && this.classWasUnset == false) {
val builder = AlertDialog.Builder(this)
.setTitle(getString(R.string.change_class_confirmation))
.setMessage(getString(R.string.change_class_equipment_warning, currentClass))
.setNegativeButton(getString(R.string.dialog_go_back)) { dialog, _ -> dialog.dismiss() }
.setPositiveButton(getString(R.string.choose_class)) { _, _ ->
selectClass(classIdentifier)
displayClassChanged(className)
selectClass(newClass)
displayClassChanged()
}
val alert = builder.create()
alert.show()
@ -165,15 +260,15 @@ class ClassSelectionActivity : BaseActivity(), Consumer<User> {
val builder = AlertDialog.Builder(this)
.setTitle(getString(R.string.class_confirmation, className))
.setNegativeButton(getString(R.string.dialog_go_back)) { dialog, _ -> dialog.dismiss() }
.setPositiveButton(getString(R.string.choose_class)) { _, _ -> selectClass(classIdentifier) }
.setPositiveButton(getString(R.string.choose_class)) { _, _ -> selectClass(newClass) }
val alert = builder.create()
alert.show()
}
}
private fun displayClassChanged(newClassName: String) {
private fun displayClassChanged() {
val changeConfirmedBuilder = AlertDialog.Builder(this)
.setTitle(getString(R.string.class_changed, newClassName))
.setTitle(getString(R.string.class_changed, className))
.setMessage(getString(R.string.class_changed_description))
.setPositiveButton(getString(R.string.complete_tutorial)) { dialog, _ -> dialog.dismiss() }
val changeDoneAlert = changeConfirmedBuilder.create()

View file

@ -655,12 +655,6 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
}
}
@Subscribe
fun displayClassSelectionActivity(event: SelectClassEvent) {
checkClassSelectionUseCase.observable(CheckClassSelectionUseCase.RequestValues(user, event, this))
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError())
}
private fun displayTutorialStep(step: TutorialStep, text: String, canBeDeferred: Boolean) {
removeActiveTutorialView()
val view = TutorialView(this, step, this)

View file

@ -7,7 +7,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.ui.helpers.bindOptionalView
import com.habitrpg.android.habitica.ui.menu.HabiticaDrawerItem
@ -129,7 +128,7 @@ class NavigationDrawerAdapter(tintColor: Int, backgroundTintColor: Int): android
val pR = pillView.paddingRight
val pB = pillView.paddingBottom
pillView.backgroundCompat = ContextCompat.getDrawable(itemView.context, R.drawable.pill_bg_purple_200)
pillView.background = ContextCompat.getDrawable(itemView.context, R.drawable.pill_bg_purple_200)
pillView.setTextColor(ContextCompat.getColor(itemView.context, R.color.white))
pillView.setPadding(pL, pT, pR, pB)
}

View file

@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -12,7 +11,6 @@ import android.widget.FrameLayout
import android.widget.TextView
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.models.inventory.Equipment
@ -87,11 +85,11 @@ class EquipmentRecyclerViewAdapter(data: OrderedRealmCollection<Equipment>?, aut
if (gear.key == equippedGear) {
this.equippedIndicator.visibility = View.VISIBLE
this.gearContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.brand_700))
imageViewWrapper.backgroundCompat = ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_white)
imageViewWrapper.background = ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_white)
} else {
this.equippedIndicator.visibility = View.GONE
this.gearContainer.setBackgroundResource(R.drawable.selection_highlight)
imageViewWrapper.backgroundCompat = ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_gray_700)
imageViewWrapper.background = ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_gray_700)
}
twoHandedView.visibility = if (gear.twoHanded) View.VISIBLE else View.GONE
DataBindingUtils.loadImage(imageView, "shop_"+gear.key)

View file

@ -3,13 +3,11 @@ package com.habitrpg.android.habitica.ui.adapter.inventory
import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.BitmapDrawable
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.helpers.RxErrorHandler
@ -78,7 +76,7 @@ class MountDetailRecyclerAdapter(data: OrderedRealmCollection<Mount>?, autoUpdat
if (ownedMount?.owned != true) {
this.imageView.alpha = 0.1f
}
imageView.backgroundCompat = null
imageView.background = null
val owned = ownedMount?.owned ?: false
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, if (owned) it else it.extractAlpha())
@ -86,7 +84,7 @@ class MountDetailRecyclerAdapter(data: OrderedRealmCollection<Mount>?, autoUpdat
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.backgroundCompat = drawable
imageView.background = drawable
}, RxErrorHandler.handleEmptyError())
}
}

View file

@ -9,7 +9,6 @@ import android.widget.TextView
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.events.commands.FeedCommand
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.helpers.RxErrorHandler
@ -111,14 +110,14 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
this.trainedProgressbar.visibility = View.GONE
this.imageView.alpha = 0.1f
}
imageView.backgroundCompat = null
imageView.background = null
val trained = ownedPet?.trained ?: 0
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, if (trained == 0) it.extractAlpha() else it)
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.backgroundCompat = drawable
imageView.background = drawable
}, RxErrorHandler.handleEmptyError())
}
}

View file

@ -8,7 +8,6 @@ import android.view.ViewGroup
import android.widget.TextView
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.helpers.MainNavigationController
import com.habitrpg.android.habitica.helpers.RxErrorHandler
@ -89,13 +88,13 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
}
this.ownedTextView.text = animal?.numberOwned?.toString()
ownedTextView.visibility = View.GONE
imageView.backgroundCompat = null
imageView.background = null
DataBindingUtils.loadImage(imageName) {
val drawable = BitmapDrawable(context?.resources, if (item.numberOwned > 0) it else it.extractAlpha())
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
imageView.backgroundCompat = drawable
imageView.background = drawable
}, RxErrorHandler.handleEmptyError())
}
if (item.numberOwned <= 0) {

View file

@ -131,12 +131,12 @@ class ChatRecyclerViewAdapter(data: OrderedRealmCollection<ChatMessage>?, autoUp
itemView.setOnClickListener {
expandMessage()
}
tvLikes.setOnClickListener { _ -> chatMessage.notNull { likeMessageEvents.onNext(it) } }
messageText.setOnClickListener { _ -> expandMessage() }
tvLikes.setOnClickListener { chatMessage.notNull { likeMessageEvents.onNext(it) } }
messageText.setOnClickListener { expandMessage() }
messageText.movementMethod = LinkMovementMethod.getInstance()
userLabel.setOnClickListener { _ -> chatMessage?.uuid.notNull {userLabelClickEvents.onNext(it) } }
avatarView.setOnClickListener { _ -> chatMessage?.uuid.notNull {userLabelClickEvents.onNext(it) } }
replyButton.setOnClickListener { _ ->
userLabel.setOnClickListener { chatMessage?.uuid.notNull {userLabelClickEvents.onNext(it) } }
avatarView.setOnClickListener { chatMessage?.uuid.notNull {userLabelClickEvents.onNext(it) } }
replyButton.setOnClickListener {
if (chatMessage?.username != null) {
chatMessage?.username.notNull { replyMessageEvents.onNext(it) }
} else {
@ -145,13 +145,13 @@ class ChatRecyclerViewAdapter(data: OrderedRealmCollection<ChatMessage>?, autoUp
}
replyButton.setCompoundDrawablesWithIntrinsicBounds(BitmapDrawable(res, HabiticaIconsHelper.imageOfChatReplyIcon()),
null, null, null)
copyButton.setOnClickListener { _ -> chatMessage.notNull { copyMessageEvents.onNext(it) } }
copyButton.setOnClickListener { chatMessage.notNull { copyMessageEvents.onNext(it) } }
copyButton.setCompoundDrawablesWithIntrinsicBounds(BitmapDrawable(res, HabiticaIconsHelper.imageOfChatCopyIcon()),
null, null, null)
reportButton.setOnClickListener { _ -> chatMessage.notNull { flagMessageEvents.onNext(it) } }
reportButton.setOnClickListener { chatMessage.notNull { flagMessageEvents.onNext(it) } }
reportButton.setCompoundDrawablesWithIntrinsicBounds(BitmapDrawable(res, HabiticaIconsHelper.imageOfChatReportIcon()),
null, null, null)
deleteButton.setOnClickListener { _ -> chatMessage.notNull { deleteMessageEvents.onNext(it) } }
deleteButton.setOnClickListener { chatMessage.notNull { deleteMessageEvents.onNext(it) } }
deleteButton.setCompoundDrawablesWithIntrinsicBounds(BitmapDrawable(res, HabiticaIconsHelper.imageOfChatDeleteIcon()),
null, null, null)
}
@ -188,13 +188,13 @@ class ChatRecyclerViewAdapter(data: OrderedRealmCollection<ChatMessage>?, autoUp
userLabel.tier == 8 -> {
modView.visibility = View.VISIBLE
modView.text = context.getString(R.string.moderator)
modView.backgroundCompat = ContextCompat.getDrawable(context, R.drawable.pill_bg_blue)
modView.background = ContextCompat.getDrawable(context, R.drawable.pill_bg_blue)
modView.setScaledPadding(context, 12, 4, 12, 4)
}
userLabel.tier == 9 -> {
modView.visibility = View.VISIBLE
modView.text = context.getString(R.string.staff)
modView.backgroundCompat = ContextCompat.getDrawable(context, R.drawable.pill_bg_purple_300)
modView.background = ContextCompat.getDrawable(context, R.drawable.pill_bg_purple_300)
modView.setScaledPadding(context, 12, 4, 12, 4)
}
else -> modView.visibility = View.GONE
@ -231,10 +231,10 @@ class ChatRecyclerViewAdapter(data: OrderedRealmCollection<ChatMessage>?, autoUp
}
val username = user?.formattedUsername
if ((name != null && msg.text?.contains(name) == true) || (username != null && msg.text?.contains(username) == true)) {
messageWrapper.backgroundCompat = ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_brand_700)
messageWrapper.background = if ((name != null && msg.text?.contains(name) == true) || (username != null && msg.text?.contains(username) == true)) {
ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg_brand_700)
} else {
messageWrapper.backgroundCompat = ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg)
ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg)
}
messageWrapper.setScaledPadding(context, 8, 8, 8, 8)

View file

@ -90,14 +90,6 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
}
"choose_class" -> {
val bundle = Bundle()
bundle.putString("size", user?.preferences?.size)
bundle.putString("skin", user?.preferences?.skin)
bundle.putString("shirt", user?.preferences?.shirt)
bundle.putInt("hairBangs", user?.preferences?.hair?.bangs ?: 0)
bundle.putInt("hairBase", user?.preferences?.hair?.base ?: 0)
bundle.putString("hairColor", user?.preferences?.hair?.color)
bundle.putInt("hairMustache", user?.preferences?.hair?.mustache ?: 0)
bundle.putInt("hairBeard", user?.preferences?.hair?.beard ?: 0)
bundle.putBoolean("isInitialSelection", user?.flags?.classSelected == false)
val intent = Intent(activity, ClassSelectionActivity::class.java)

View file

@ -17,9 +17,7 @@ import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.AppComponent
import com.habitrpg.android.habitica.data.SocialRepository
import com.habitrpg.android.habitica.data.UserRepository
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.helpers.MainNavigationController
import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.invitations.PartyInvite
import com.habitrpg.android.habitica.models.members.Member
@ -122,7 +120,7 @@ class GroupInformationFragment : BaseFragment() {
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
no_party_background.backgroundCompat = it
no_party_background.background = it
}, RxErrorHandler.handleEmptyError())
}
}

View file

@ -18,7 +18,6 @@ import com.habitrpg.android.habitica.components.AppComponent
import com.habitrpg.android.habitica.data.InventoryRepository
import com.habitrpg.android.habitica.data.SocialRepository
import com.habitrpg.android.habitica.data.UserRepository
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.helpers.MainNavigationController
import com.habitrpg.android.habitica.helpers.RemoteConfigManager
@ -154,7 +153,7 @@ class TavernDetailFragment : BaseFragment() {
for (tier in PlayerTier.getTiers()) {
context.notNull {
val container = FrameLayout(it)
container.backgroundCompat = ContextCompat.getDrawable(it, R.drawable.layout_rounded_bg_gray_700)
container.background = ContextCompat.getDrawable(it, R.drawable.layout_rounded_bg_gray_700)
val label = UsernameLabel(context, null)
label.tier = tier.id
label.username = tier.title
@ -191,7 +190,7 @@ class TavernDetailFragment : BaseFragment() {
promptView?.setTextColor(quest.colors?.lightColor ?: 0)
val background = ContextCompat.getDrawable(context, R.drawable.rounded_border)
background?.setColorFilter(quest.colors?.extraLightColor ?: 0, PorterDuff.Mode.MULTIPLY)
promptView?.backgroundCompat = background
promptView?.background = background
alert.setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.close)) { dialog, _ ->
dialog.dismiss()

View file

@ -17,7 +17,6 @@ import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.AppComponent
import com.habitrpg.android.habitica.data.ChallengeRepository
import com.habitrpg.android.habitica.data.SocialRepository
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.extensions.inflate
import com.habitrpg.android.habitica.extensions.notNull
import com.habitrpg.android.habitica.helpers.RxErrorHandler
@ -228,14 +227,14 @@ class ChallengeDetailFragment: BaseMainFragment() {
entry?.findViewById<View>(R.id.lock_icon_background_plus)?.setBackgroundColor(ContextCompat.getColor(it, task.mediumTaskColor))
val drawable = ContextCompat.getDrawable(it, R.drawable.circle_white)
drawable?.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(it, task.darkTaskColor), PorterDuff.Mode.MULTIPLY)
entry?.findViewById<View>(R.id.lock_icon_plus)?.backgroundCompat = drawable
entry?.findViewById<View>(R.id.lock_icon_plus)?.background = drawable
}
if (task.down == true) {
entry?.findViewById<ImageView>(R.id.lock_icon_minus)?.setImageBitmap(HabiticaIconsHelper.imageOfLocked(Color.parseColor("#B3FFFFFF")))
entry?.findViewById<View>(R.id.lock_icon_background_minus)?.setBackgroundColor(ContextCompat.getColor(it, task.mediumTaskColor))
val drawable = ContextCompat.getDrawable(it, R.drawable.circle_white)
drawable?.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(it, task.darkTaskColor), PorterDuff.Mode.MULTIPLY)
entry?.findViewById<View>(R.id.lock_icon_plus)?.backgroundCompat = drawable
entry?.findViewById<View>(R.id.lock_icon_plus)?.background = drawable
}
}
@ -264,7 +263,7 @@ class ChallengeDetailFragment: BaseMainFragment() {
entry?.findViewById<View>(R.id.lock_icon_background)?.setBackgroundColor(ContextCompat.getColor(it, task.mediumTaskColor))
val drawable = ContextCompat.getDrawable(it, R.drawable.circle_white)
drawable?.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(it, task.extraLightTaskColor), PorterDuff.Mode.MULTIPLY)
entry?.findViewById<View>(R.id.lock_icon)?.backgroundCompat = drawable
entry?.findViewById<View>(R.id.lock_icon)?.background = drawable
}
if (task.checklist != null && task.checklist?.isEmpty() == false) {
val checklistIndicatorWrapper = entry?.findViewById<View>(R.id.checklistIndicatorWrapper)
@ -298,7 +297,7 @@ class ChallengeDetailFragment: BaseMainFragment() {
entry?.findViewById<View>(R.id.lock_icon_background)?.setBackgroundColor(ContextCompat.getColor(it, task.mediumTaskColor))
val drawable = ContextCompat.getDrawable(it, R.drawable.circle_white)
drawable?.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(it, task.extraLightTaskColor), PorterDuff.Mode.MULTIPLY)
entry?.findViewById<View>(R.id.lock_icon)?.backgroundCompat = drawable
entry?.findViewById<View>(R.id.lock_icon)?.background = drawable
}
if (task.checklist != null && task.checklist?.isEmpty() == false) {

View file

@ -2,7 +2,6 @@ package com.habitrpg.android.habitica.ui.helpers
import android.graphics.Bitmap
import android.graphics.PorterDuff
import android.net.Uri
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import android.view.View
@ -20,7 +19,6 @@ import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
import com.facebook.imagepipeline.image.CloseableImage
import com.facebook.imagepipeline.request.ImageRequestBuilder
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
object DataBindingUtils {
@ -76,7 +74,7 @@ object DataBindingUtils {
fun setRoundedBackground(view: View, color: Int) {
val drawable = ResourcesCompat.getDrawable(view.resources, R.drawable.layout_rounded_bg, null)
drawable?.setColorFilter(color, PorterDuff.Mode.MULTIPLY)
view.backgroundCompat = drawable
view.background = drawable
}
fun setRoundedBackgroundInt(view: View, color: Int) {

View file

@ -9,7 +9,6 @@ import android.widget.TextView
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.HabiticaBaseApplication
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.models.shops.ShopItem
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.habitrpg.android.habitica.ui.helpers.bindView
@ -40,7 +39,7 @@ class ShopItemViewHolder(itemView: View) : androidx.recyclerview.widget.Recycler
field = value
if (value > 0) {
itemDetailIndicator.text = value.toString()
itemDetailIndicator.backgroundCompat = countDrawable
itemDetailIndicator.background = countDrawable
itemDetailIndicator.visibility = View.VISIBLE
}
}
@ -80,13 +79,13 @@ class ShopItemViewHolder(itemView: View) : androidx.recyclerview.widget.Recycler
itemDetailIndicator.text = null
itemDetailIndicator.visibility = View.GONE
if (item.isLimited) {
itemDetailIndicator.backgroundCompat = limitedDrawable
itemDetailIndicator.background = limitedDrawable
itemDetailIndicator.visibility = View.VISIBLE
}
priceLabel.isLocked = item.locked || !canBuy
if (item.locked) {
itemDetailIndicator.backgroundCompat = lockedDrawable
itemDetailIndicator.background = lockedDrawable
itemDetailIndicator.visibility = View.VISIBLE
}
}

View file

@ -9,7 +9,6 @@ import android.widget.FrameLayout
import android.widget.ImageView
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.extensions.layoutInflater
import com.habitrpg.android.habitica.helpers.RxErrorHandler
@ -58,7 +57,7 @@ class NPCBannerView(context: Context?, attrs: AttributeSet?) : FrameLayout(conte
Observable.just(drawable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(Consumer {
backgroundView.backgroundCompat = it
backgroundView.background = it
}, RxErrorHandler.handleEmptyError())
}
}

View file

@ -9,7 +9,6 @@ import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import kotlinx.android.synthetic.main.fixvalues_edittext.view.*
@ -28,7 +27,7 @@ class FixValuesEditText(context: Context, attrs: AttributeSet) : FrameLayout(con
val backgroundDrawable = ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg)
backgroundDrawable?.setColorFilter(field, PorterDuff.Mode.MULTIPLY)
backgroundDrawable?.alpha = 50
iconBackgroundView.backgroundCompat = backgroundDrawable
iconBackgroundView.background = backgroundDrawable
}
init {

View file

@ -1,9 +1,7 @@
package com.habitrpg.android.habitica.ui.views.social
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import androidx.core.content.ContextCompat
import androidx.core.widget.ImageViewCompat
import androidx.appcompat.widget.AppCompatImageButton
import android.util.AttributeSet
import android.view.Gravity
@ -16,7 +14,6 @@ import android.widget.TextView
import androidx.core.content.edit
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.models.inventory.Quest
import com.habitrpg.android.habitica.models.inventory.QuestContent
@ -24,7 +21,6 @@ import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import com.habitrpg.android.habitica.ui.views.HabiticaProgressBar
import com.habitrpg.android.habitica.ui.views.ValueBar
class QuestMenuView : LinearLayout {

View file

@ -19,7 +19,6 @@ import android.widget.TextView
import androidx.core.content.edit
import com.facebook.drawee.view.SimpleDraweeView
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.extensions.backgroundCompat
import com.habitrpg.android.habitica.ui.helpers.bindView
import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.inventory.Quest
@ -179,7 +178,7 @@ class QuestProgressView : LinearLayout {
GradientDrawable.Orientation.TOP_BOTTOM,
intArrayOf(ContextCompat.getColor(context, R.color.transparent), lightColor))
gradientDrawable.cornerRadius = 0f
questImageWrapper.backgroundCompat = gradientDrawable
questImageWrapper.background = gradientDrawable
}
updateCaretImage()
questDescriptionSection.caretColor = quest.colors?.extraLightColor ?: 0