mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
show gem errors / recolor gem buttons (based on state)
This commit is contained in:
parent
ad567b8f48
commit
bcc9b13602
10 changed files with 133 additions and 19 deletions
5
Habitica/res/drawable/challenge_gem_add_button.xml
Normal file
5
Habitica/res/drawable/challenge_gem_add_button.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/challenge_gem_add_button_disabled" android:state_enabled="false"></item>
|
||||
<item android:drawable="@drawable/challenge_gem_add_button_enabled" android:state_enabled="true"></item>
|
||||
</selector>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item >
|
||||
<bitmap
|
||||
android:src="@drawable/plus"
|
||||
android:tint="#e1e0e3" />
|
||||
</item>
|
||||
</layer-list>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item >
|
||||
<bitmap
|
||||
android:src="@drawable/plus"
|
||||
android:tint="@color/brand_400" />
|
||||
</item>
|
||||
</layer-list>
|
||||
5
Habitica/res/drawable/challenge_gem_remove_button.xml
Normal file
5
Habitica/res/drawable/challenge_gem_remove_button.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/challenge_gem_remove_button_disabled" android:state_enabled="false"></item>
|
||||
<item android:drawable="@drawable/challenge_gem_remove_button_enabled" android:state_enabled="true"></item>
|
||||
</selector>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item >
|
||||
<bitmap
|
||||
android:src="@drawable/minus"
|
||||
android:tint="#e1e0e3" />
|
||||
</item>
|
||||
</layer-list>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item >
|
||||
<bitmap
|
||||
android:src="@drawable/minus"
|
||||
android:tint="@color/brand_400" />
|
||||
</item>
|
||||
</layer-list>
|
||||
|
|
@ -87,6 +87,17 @@
|
|||
android:text="@string/gem_reward"
|
||||
android:textColor="#cc000000" />
|
||||
|
||||
<TextView
|
||||
style="@style/Caption3"
|
||||
android:id="@+id/create_challenge_gem_error"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="23dp"
|
||||
android:text="@string/gem_reward"
|
||||
android:textColor="#f74e52"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -98,8 +109,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:drawableLeft="@drawable/plus"
|
||||
android:drawableTint="@color/brand_400" />
|
||||
android:drawableLeft="@drawable/challenge_gem_add_button"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="18dp"
|
||||
|
|
@ -115,7 +125,7 @@
|
|||
android:gravity="center"
|
||||
android:inputType="number"
|
||||
android:textColor="#8a000000"
|
||||
android:text="1"
|
||||
android:text="0"
|
||||
android:id="@+id/create_challenge_prize"
|
||||
android:textAlignment="center" />
|
||||
|
||||
|
|
@ -125,8 +135,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:drawableRight="@drawable/minus"
|
||||
android:drawableTint="@color/brand_400" />
|
||||
android:drawableRight="@drawable/challenge_gem_remove_button"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -563,4 +563,6 @@
|
|||
<string name="create_challenge">Create challenge</string>
|
||||
<string name="tavern">Tavern</string>
|
||||
<string name="edit_challenge">Edit Challenge</string>
|
||||
<string name="challenge_create_error_tavern_one_gem">You need at least 1 gem to create a challenge in Tavern.</string>
|
||||
<string name="challenge_create_error_enough_gems">You don\'t have enough gems to create a challenge.</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -18,9 +18,12 @@ import android.view.MenuItem;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
|
@ -63,9 +66,17 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
@BindView(R.id.create_challenge_tag)
|
||||
EditText create_challenge_tag;
|
||||
|
||||
@BindView(R.id.create_challenge_gem_error)
|
||||
TextView create_challenge_gem_error;
|
||||
|
||||
@BindView(R.id.challenge_location_spinner)
|
||||
Spinner challenge_location_spinner;
|
||||
|
||||
@BindView(R.id.challenge_add_gem_btn)
|
||||
Button challenge_add_gem_btn;
|
||||
|
||||
@BindView(R.id.challenge_remove_gem_btn)
|
||||
Button challenge_remove_gem_btn;
|
||||
|
||||
@BindView(R.id.create_challenge_task_list)
|
||||
RecyclerView create_challenge_task_list;
|
||||
|
|
@ -112,7 +123,7 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_save) {
|
||||
if(editMode){
|
||||
if (editMode) {
|
||||
updateChallenge();
|
||||
} else {
|
||||
createChallenge();
|
||||
|
|
@ -129,7 +140,7 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
Intent intent = getIntent();
|
||||
Bundle bundle = intent.getExtras();
|
||||
|
||||
if(bundle != null) {
|
||||
if (bundle != null) {
|
||||
challengeId = bundle.getString(CHALLENGE_ID_KEY, null);
|
||||
}
|
||||
|
||||
|
|
@ -147,13 +158,13 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
String taskIdToDelete = deleteTask.TaskIdToDelete;
|
||||
challengeTasks.removeTask(taskIdToDelete);
|
||||
|
||||
if(editMode){
|
||||
if(addedTasks.containsKey(taskIdToDelete)){
|
||||
if (editMode) {
|
||||
if (addedTasks.containsKey(taskIdToDelete)) {
|
||||
addedTasks.remove(taskIdToDelete);
|
||||
} else{
|
||||
} else {
|
||||
removedTasks.put(taskIdToDelete, null);
|
||||
|
||||
if(updatedTasks.containsKey(taskIdToDelete)){
|
||||
if (updatedTasks.containsKey(taskIdToDelete)) {
|
||||
updatedTasks.remove(taskIdToDelete);
|
||||
}
|
||||
}
|
||||
|
|
@ -181,6 +192,8 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
currentVal++;
|
||||
|
||||
create_challenge_prize.setText("" + currentVal);
|
||||
|
||||
checkGemAndLocation();
|
||||
}
|
||||
|
||||
@OnClick(R.id.challenge_remove_gem_btn)
|
||||
|
|
@ -189,10 +202,37 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
int currentVal = Integer.parseInt(create_challenge_prize.getText().toString());
|
||||
currentVal--;
|
||||
|
||||
if (currentVal == 0)
|
||||
currentVal = 1;
|
||||
|
||||
create_challenge_prize.setText("" + currentVal);
|
||||
|
||||
checkGemAndLocation();
|
||||
}
|
||||
|
||||
private void checkGemAndLocation() {
|
||||
String inputValue = create_challenge_prize.getText().toString();
|
||||
|
||||
if(inputValue.isEmpty()){
|
||||
inputValue = "0";
|
||||
}
|
||||
|
||||
int currentVal = Integer.parseInt(inputValue);
|
||||
|
||||
// 0 is Tavern
|
||||
int selectedLocation = challenge_location_spinner.getSelectedItemPosition();
|
||||
|
||||
double gemCount = HabiticaApplication.User.getGemCount();
|
||||
|
||||
if (selectedLocation == 0 && currentVal == 0) {
|
||||
create_challenge_gem_error.setVisibility(View.VISIBLE);
|
||||
create_challenge_gem_error.setText(R.string.challenge_create_error_tavern_one_gem);
|
||||
} else if (currentVal > gemCount) {
|
||||
create_challenge_gem_error.setVisibility(View.VISIBLE);
|
||||
create_challenge_gem_error.setText(R.string.challenge_create_error_enough_gems);
|
||||
} else {
|
||||
create_challenge_gem_error.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
challenge_remove_gem_btn.setEnabled(currentVal != 0);
|
||||
|
||||
}
|
||||
|
||||
private void fillControls() {
|
||||
|
|
@ -221,6 +261,22 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
}, Throwable::printStackTrace);
|
||||
|
||||
challenge_location_spinner.setAdapter(locationAdapter);
|
||||
challenge_location_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
checkGemAndLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapterView) {
|
||||
|
||||
}
|
||||
});
|
||||
create_challenge_prize.setOnKeyListener((view, i, keyEvent) -> {
|
||||
checkGemAndLocation();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
addHabit = createTask(ChallengeTasksRecyclerViewAdapter.TASK_TYPE_ADD_ITEM, resources.getString(R.string.add_habit));
|
||||
addDaily = createTask(ChallengeTasksRecyclerViewAdapter.TASK_TYPE_ADD_ITEM, resources.getString(R.string.add_daily));
|
||||
|
|
@ -291,6 +347,8 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
checkGemAndLocation();
|
||||
|
||||
challengeRepository.getChallengeTasks(challengeId).subscribe(tasks -> {
|
||||
tasks.tasks.forEach((s, task) -> addOrUpdateTaskInList(task));
|
||||
}, Throwable::printStackTrace, () -> {
|
||||
|
|
@ -344,13 +402,13 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
startActivityForResult(intent, 1);
|
||||
}
|
||||
|
||||
private PostChallenge getChallengeData(){
|
||||
private PostChallenge getChallengeData() {
|
||||
PostChallenge c = new PostChallenge();
|
||||
|
||||
int locationPos = challenge_location_spinner.getSelectedItemPosition();
|
||||
Group locationGroup = locationAdapter.getItem(locationPos);
|
||||
|
||||
if(challengeId != null){
|
||||
if (challengeId != null) {
|
||||
c.id = challengeId;
|
||||
}
|
||||
|
||||
|
|
@ -419,13 +477,12 @@ public class CreateChallengeActivity extends BaseActivity {
|
|||
|
||||
challengeTasks.addTaskUnder(task, taskAbove);
|
||||
|
||||
if(editMode){
|
||||
if (editMode) {
|
||||
addedTasks.put(task.getId(), task);
|
||||
}
|
||||
} else {
|
||||
// don't need to add the task to updatedTasks if its already been added right now
|
||||
if(editMode && !addedTasks.containsKey(task.getId()))
|
||||
{
|
||||
if (editMode && !addedTasks.containsKey(task.getId())) {
|
||||
updatedTasks.put(task.getId(), task);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -216,6 +216,10 @@ public class HabitRPGUser extends BaseModel {
|
|||
return this.balance;
|
||||
}
|
||||
|
||||
public double getGemCount(){
|
||||
return this.balance * 4;
|
||||
}
|
||||
|
||||
public void setBalance(double balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue