mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
begin tavern redesign
This commit is contained in:
parent
d7cad56596
commit
1e4f5006c4
5 changed files with 143 additions and 104 deletions
|
|
@ -2,47 +2,33 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<include layout="@layout/shop_header" />
|
||||
|
||||
<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" />
|
||||
android:background="@color/days_gray"
|
||||
android:layout_marginTop="@dimen/spacing_large"
|
||||
android:layout_marginBottom="@dimen/spacing_large"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dailiesButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/tavern.inn.rest"
|
||||
android:layout_marginLeft="@dimen/spacing_large"
|
||||
android:layout_marginRight="@dimen/spacing_large"
|
||||
style="@style/Button.Purple.Small"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/inn_description"
|
||||
android:layout_margin="16dp"/>
|
||||
android:layout_margin="@dimen/spacing_large"/>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/days_gray" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -25,5 +25,6 @@
|
|||
<string name="questShop_owner" translatable="false">Ian</string>
|
||||
<string name="seasonalShop_owner" translatable="false">Leslie</string>
|
||||
<string name="timetravelers_owner" translatable="false">Time Travelers</string>
|
||||
<string name="tavern_owner" translatable="false">Daniel</string>
|
||||
<string name="empty" translatable="false"> </string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -346,7 +346,11 @@
|
|||
<string name="sectionquestMounts">Quest</string>
|
||||
<string name="sectionspecialMounts">Rare</string>
|
||||
<string name="world_quest">World Quest</string>
|
||||
<string name="inn_description">Rest in the Inn to prevent your undone Dailies from hurting you overnight! (Note: does not prevent you from receiving Boss damage.)</string>
|
||||
<string name="inn_description">Need a break? Check into Daniel’s Inn to pause some of Habitica’s more difficult game mechanics:\n\n
|
||||
• Missed Dailies won’t damage you\n
|
||||
• Tasks won’t lose streaks or decay in color\n
|
||||
• Bosses won’t do damage for your missed Dailies\n
|
||||
• Your boss damage or collection quest items will stay pending until check-out</string>
|
||||
<string name="empty_items" >You don\'t have any %s</string>
|
||||
<string name="user_level" >Lvl %d</string>
|
||||
<string name="user_level_with_class" >Lvl %1$d %2$s</string>
|
||||
|
|
@ -719,4 +723,5 @@
|
|||
<string name="class_gear_disclaimer">You can only purchase gear for your current class</string>
|
||||
<string name="available_stats" formatted="false">%d points</string>
|
||||
<string name="toogle_emojis">Toogle Emojis</string>
|
||||
<string name="tavern_description">Welcome to the Inn! Pull up a chair to chat, or take a break from your tasks.</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
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);
|
||||
|
||||
getCompositeSubscription().add(userRepository.getUser(userId).subscribe(user -> {
|
||||
this.user = user;
|
||||
this.updatePausedState();
|
||||
}, RxErrorHandler.handleEmptyError()));
|
||||
}
|
||||
|
||||
private void updatePausedState() {
|
||||
if (dailiesButton == null) {
|
||||
return;
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Shader
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
|
||||
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.OnClick
|
||||
import com.facebook.common.executors.CallerThreadExecutor
|
||||
import com.facebook.common.references.CloseableReference
|
||||
import com.facebook.datasource.DataSource
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
|
||||
import com.facebook.imagepipeline.image.CloseableImage
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder
|
||||
import com.habitrpg.android.habitica.helpers.RemoteConfigManager
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import kotlinx.android.synthetic.main.shop_header.*
|
||||
import kotlinx.android.synthetic.main.fragment_tavern_detail.*
|
||||
import rx.Observable
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.functions.Action1
|
||||
|
||||
class TavernDetailFragment : BaseFragment() {
|
||||
|
||||
@Inject
|
||||
lateinit var userRepository: UserRepository
|
||||
@field:[Inject Named(AppModule.NAMED_USER_ID)]
|
||||
lateinit var userId: String
|
||||
@Inject
|
||||
lateinit var configManager: RemoteConfigManager
|
||||
|
||||
|
||||
private var user: User? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
super.onCreateView(inflater, container, savedInstanceState)
|
||||
return inflater.inflate(R.layout.fragment_tavern_detail, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
compositeSubscription.add(userRepository.getUser(userId).subscribe(Action1 {
|
||||
this.user = it
|
||||
this.updatePausedState()
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
descriptionView.setText(R.string.tavern_description)
|
||||
namePlate.setText(R.string.tavern_owner)
|
||||
|
||||
DataBindingUtils.loadImage(sceneView, "tavern_scene" + configManager.shopSpriteSuffix())
|
||||
|
||||
backgroundView.scaleType = ImageView.ScaleType.FIT_START
|
||||
|
||||
val imageRequest = ImageRequestBuilder
|
||||
.newBuilderWithSource(Uri.parse("https://habitica-assets.s3.amazonaws.com/mobileApp/images/tavern_background" + configManager.shopSpriteSuffix() + ".png"))
|
||||
.build()
|
||||
|
||||
val imagePipeline = Fresco.getImagePipeline()
|
||||
val dataSource = imagePipeline.fetchDecodedImage(imageRequest, this)
|
||||
|
||||
dataSource.subscribe(object : BaseBitmapDataSubscriber() {
|
||||
override fun onFailureImpl(dataSource: DataSource<CloseableReference<CloseableImage>>?) {
|
||||
dataSource?.close()
|
||||
}
|
||||
|
||||
public override fun onNewResultImpl(bitmap: Bitmap?) {
|
||||
if (dataSource.isFinished && bitmap != null) {
|
||||
val aspectRatio = bitmap.width / bitmap.height.toFloat()
|
||||
val height = context?.resources?.getDimension(R.dimen.shop_height)?.toInt() ?: 0
|
||||
val width = Math.round(height * aspectRatio)
|
||||
val drawable = BitmapDrawable(context?.resources, Bitmap.createScaledBitmap(bitmap, width, height, false))
|
||||
drawable.tileModeX = Shader.TileMode.REPEAT
|
||||
Observable.just(drawable)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(Action1 { backgroundView.background = it }, RxErrorHandler.handleEmptyError())
|
||||
dataSource.close()
|
||||
}
|
||||
}
|
||||
}, CallerThreadExecutor.getInstance())
|
||||
}
|
||||
|
||||
private fun updatePausedState() {
|
||||
if (dailiesButton == null) {
|
||||
return
|
||||
}
|
||||
if (user?.preferences?.sleep == true) {
|
||||
dailiesButton .setText(R.string.tavern_inn_checkOut)
|
||||
} else {
|
||||
dailiesButton.setText(R.string.tavern_inn_rest)
|
||||
}
|
||||
}
|
||||
|
||||
override fun injectFragment(component: AppComponent) {
|
||||
component.inject(this)
|
||||
}
|
||||
|
||||
@OnClick(R.id.dailiesButton)
|
||||
fun dailiesButtonClicked() {
|
||||
user?.let { userRepository.sleep(it).subscribe(Action1 { }, RxErrorHandler.handleEmptyError()) }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue