mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 04:09:03 +00:00
Clean up code, fix keyboard dismissing issues
This commit is contained in:
parent
d2e7b0fe26
commit
f850fe7d68
5 changed files with 64 additions and 46 deletions
|
|
@ -7,7 +7,8 @@
|
|||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/tagEditText" android:layout_gravity="center_horizontal"/>
|
||||
android:id="@+id/tagEditText" android:layout_gravity="center_horizontal"
|
||||
android:focusable="true" android:singleLine="true"/>
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -806,6 +806,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
drawer.closeDrawer();
|
||||
} else if (drawer.getDrawerLayout().isDrawerOpen(GravityCompat.END)) {
|
||||
drawer.getDrawerLayout().closeDrawer(GravityCompat.END);
|
||||
EventBus.getDefault().post(new ToggledEditTagsEvent(false));
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
if (this.activeFragment != null) {
|
||||
|
|
|
|||
|
|
@ -42,11 +42,13 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
|||
import com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener;
|
||||
import com.mikepenz.materialdrawer.model.SwitchDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
import com.mikepenz.materialize.util.UIUtils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -65,6 +67,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
|
|
@ -122,7 +125,7 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
|
||||
if (user != null) {
|
||||
tags = user.getTags();
|
||||
fillTagFilterDrawerEditing(tags);
|
||||
fillTagFilterDrawer(tags);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +282,7 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
super.updateUserData(user);
|
||||
stopAnimatingRefreshItem();
|
||||
if (this.user != null) {
|
||||
fillTagFilterDrawerEditing(tags);
|
||||
fillTagFilterDrawer(tags);
|
||||
for (TaskRecyclerViewFragment fragm : ViewFragmentsDictionary.values()) {
|
||||
if (fragm != null) {
|
||||
BaseTasksRecyclerViewAdapter adapter = fragm.recyclerAdapter;
|
||||
|
|
@ -452,31 +455,16 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
@Subscribe
|
||||
public void onEvent(ToggledEditTagsEvent event) {
|
||||
if(user != null) {
|
||||
if(this.editingTags == event.editing) {
|
||||
return;
|
||||
}
|
||||
this.editingTags = event.editing;
|
||||
fillTagFilterDrawerEditing(tags);
|
||||
fillTagFilterDrawer(tags);
|
||||
}
|
||||
|
||||
}
|
||||
//endregion Events
|
||||
|
||||
public void fillTagFilterDrawer(List<Tag> tagList) {
|
||||
if (this.tagsHelper != null) {
|
||||
List<IDrawerItem> items = new ArrayList<>();
|
||||
items.add(new EditTagsSectionDrawer());
|
||||
items.add(new EditTextDrawer());
|
||||
for (Tag t : tagList) {
|
||||
items.add(new SwitchDrawerItem()
|
||||
.withName(t.getName())
|
||||
.withTag(t)
|
||||
.withChecked(this.tagsHelper.isTagChecked(t.getId()))
|
||||
.withOnCheckedChangeListener(this)
|
||||
);
|
||||
}
|
||||
this.activity.fillFilterDrawer(items);
|
||||
}
|
||||
}
|
||||
|
||||
public void fillTagFilterDrawerEditing(List<Tag> tagList) {
|
||||
if (this.tagsHelper != null) {
|
||||
List<IDrawerItem> items = new ArrayList<>();
|
||||
|
||||
|
|
@ -485,8 +473,8 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
items.add(new EditTextDrawer());
|
||||
for (Tag t : tagList) {
|
||||
items.add(new EditTagsDrawerItem()
|
||||
.withName(t.getName())
|
||||
.withTag(t)
|
||||
.withName(t.getName())
|
||||
.withTag(t)
|
||||
);
|
||||
}
|
||||
this.activity.fillFilterDrawer(items);
|
||||
|
|
@ -538,7 +526,7 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
|
||||
//Add 2 for the same reason as above
|
||||
int pos = tags.indexOf(t) + 2;
|
||||
IDrawerItem item = null;
|
||||
IDrawerItem item;
|
||||
|
||||
if(this.editingTags) {
|
||||
item = new EditTagsDrawerItem()
|
||||
|
|
@ -598,15 +586,12 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
|
||||
public void showEditTagDialog(Tag tag) {
|
||||
|
||||
EditText tagEditText = null;
|
||||
Button btnDelete = null;
|
||||
|
||||
//inflate the alertdialog view
|
||||
final View editTagDialogView = this.activity.getLayoutInflater().inflate(R.layout.dialog_edit_tag,null);
|
||||
|
||||
//Init the components
|
||||
if(editTagDialogView != null) {
|
||||
tagEditText = (EditText)editTagDialogView.findViewById(R.id.tagEditText);
|
||||
EditText tagEditText = (EditText)editTagDialogView.findViewById(R.id.tagEditText);
|
||||
tagEditText.setText(tag.getName());
|
||||
|
||||
btnDelete = (Button)editTagDialogView.findViewById(R.id.btnDelete);
|
||||
|
|
@ -615,29 +600,50 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
|
||||
AlertDialog alert = new AlertDialog.Builder(this.activity)
|
||||
.setTitle(getString(R.string.edit_tag_title))
|
||||
.setPositiveButton(getString(R.string.save_changes), (dialog, which) -> {
|
||||
EditText tet = (EditText)editTagDialogView.findViewById(R.id.tagEditText);
|
||||
String newTagName = tet.getText().toString();
|
||||
if(!newTagName.equals("")) {
|
||||
String uuid = tag.getId();
|
||||
tag.setName(newTagName);
|
||||
EventBus.getDefault().post(new UpdateTagCommand(tag, uuid));
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.save_changes), null)
|
||||
.setNeutralButton(getString(R.string.dialog_go_back), (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
EditText tagEditText = (EditText)editTagDialogView.findViewById(R.id.tagEditText);
|
||||
UiUtils.dismissKeyboard(this.activity,tagEditText);
|
||||
dialog.cancel();
|
||||
})
|
||||
.create();
|
||||
btnDelete.setOnClickListener((View v) -> {showDeleteTagDialog(alert,tag);});
|
||||
alert.setView(editTagDialogView);
|
||||
alert.show();
|
||||
|
||||
alert.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
EditText tagEditText = (EditText)editTagDialogView.findViewById(R.id.tagEditText);
|
||||
String newTagName = tagEditText.getText().toString();
|
||||
|
||||
if(newTagName.equals("")) {
|
||||
return;
|
||||
}
|
||||
|
||||
UiUtils.dismissKeyboard(activity,tagEditText);
|
||||
|
||||
if(newTagName.equals(tag.getName())) {
|
||||
alert.dismiss();
|
||||
return;
|
||||
}
|
||||
|
||||
String uuid = tag.getId();
|
||||
tag.setName(newTagName);
|
||||
EventBus.getDefault().post(new UpdateTagCommand(tag, uuid));
|
||||
alert.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void showDeleteTagDialog(AlertDialog d, Tag tag) {
|
||||
AlertDialog alert2 = new AlertDialog.Builder(this.activity)
|
||||
AlertDialog confirmDeleteAlert = new AlertDialog.Builder(this.activity)
|
||||
.setTitle(getString(R.string.confirm_delete_tag_title)).setMessage(getString(R.string.confirm_delete_tag_message))
|
||||
.setPositiveButton(getString(R.string.yes),(dialog,which) -> {
|
||||
EventBus.getDefault().post(new DeleteTagCommand(tag));
|
||||
UiUtils.dismissKeyboard(this.activity,d.getCurrentFocus());
|
||||
//dismiss both dialogs
|
||||
dialog.dismiss();
|
||||
d.dismiss();
|
||||
})
|
||||
|
|
@ -645,9 +651,6 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
dialog.dismiss();
|
||||
})
|
||||
.create();
|
||||
alert2.show();
|
||||
confirmDeleteAlert.show();
|
||||
}
|
||||
|
||||
//TODO: Fix Keyboard dismissal.
|
||||
//TODO: Check code for redundancies/improvements
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.support.design.widget.Snackbar;
|
|||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
|
|
@ -28,6 +29,20 @@ public class UiUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides soft keyboard if it's opened.
|
||||
* This eliminates weird behavior when hiding keyboard from within Dialog
|
||||
*
|
||||
* @param view View that currently has focus
|
||||
* @param activity - Current activity
|
||||
*/
|
||||
public static void dismissKeyboard(Activity activity, View view) {
|
||||
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if(view != null) {
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows snackbar in given container.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ import com.mikepenz.materialdrawer.model.BaseViewHolder;
|
|||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
|
|
|||
Loading…
Reference in a new issue