Small fixes and improvements

This commit is contained in:
M66B
2019-01-18 11:26:02 +00:00
parent 84f63ab473
commit 2ac7976681
9 changed files with 34 additions and 82 deletions

View File

@@ -24,6 +24,7 @@ import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.text.Collator;
@@ -52,6 +53,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
private View itemView;
private TextView tvName;
private TextView tvOrder;
private ImageView ivStop;
ViewHolder(View itemView) {
super(itemView);
@@ -59,6 +61,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
this.itemView = itemView.findViewById(R.id.clItem);
tvName = itemView.findViewById(R.id.tvName);
tvOrder = itemView.findViewById(R.id.tvOrder);
ivStop = itemView.findViewById(R.id.ivStop);
}
private void wire() {
@@ -73,6 +76,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
itemView.setActivated(!rule.enabled);
tvName.setText(rule.name);
tvOrder.setText(Integer.toString(rule.order));
ivStop.setVisibility(rule.stop ? View.VISIBLE : View.INVISIBLE);
}
@Override

View File

@@ -134,7 +134,7 @@ public class EntityRule {
try {
JSONObject jargs = new JSONObject(action);
int type = jargs.getInt("type");
Log.i("Executing rule=" + type + " message=" + message.id);
Log.i("Executing rule=" + type + ":" + name + " message=" + message.id);
switch (type) {
case TYPE_SEEN:

View File

@@ -34,7 +34,6 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.Lifecycle;
public class FragmentAnswer extends FragmentBase {
private ViewGroup view;
@@ -70,7 +69,7 @@ public class FragmentAnswer extends FragmentBase {
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_delete:
onActionDelete();
@@ -84,8 +83,6 @@ public class FragmentAnswer extends FragmentBase {
}
});
((ActivityBase) getActivity()).addBackPressedListener(onBackPressedListener);
// Initialize
grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);
@@ -93,12 +90,6 @@ public class FragmentAnswer extends FragmentBase {
return view;
}
@Override
public void onDestroyView() {
((ActivityBase) getActivity()).removeBackPressedListener(onBackPressedListener);
super.onDestroyView();
}
@Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -223,31 +214,4 @@ public class FragmentAnswer extends FragmentBase {
}
}.execute(this, args, "answer:save");
}
private void handleExit() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_ask_save)
.setPositiveButton(R.string.title_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onActionSave();
}
})
.setNegativeButton(R.string.title_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
}
ActivityBase.IBackPressedListener onBackPressedListener = new ActivityBase.IBackPressedListener() {
@Override
public boolean onBackPressed() {
handleExit();
return true;
}
};
}

View File

@@ -45,7 +45,6 @@ import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.Lifecycle;
public class FragmentRule extends FragmentBase {
private ViewGroup view;
@@ -136,7 +135,7 @@ public class FragmentRule extends FragmentBase {
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_delete:
onActionTrash();
@@ -150,8 +149,6 @@ public class FragmentRule extends FragmentBase {
}
});
((ActivityBase) getActivity()).addBackPressedListener(onBackPressedListener);
// Initialize
bottom_navigation.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE);
@@ -161,12 +158,6 @@ public class FragmentRule extends FragmentBase {
return view;
}
@Override
public void onDestroyView() {
((ActivityBase) getActivity()).removeBackPressedListener(onBackPressedListener);
super.onDestroyView();
}
@Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -388,8 +379,7 @@ public class FragmentRule extends FragmentBase {
JSONObject jsender = jcondition.optJSONObject("sender");
JSONObject jsubject = jcondition.optJSONObject("subject");
if (TextUtils.isEmpty(jsender.optString("value")) &&
TextUtils.isEmpty(jsubject.optString("value")))
if (jsender == null && jsubject == null)
throw new IllegalArgumentException(context.getString(R.string.title_rule_condition_missing));
if (TextUtils.isEmpty(order))
@@ -439,33 +429,6 @@ public class FragmentRule extends FragmentBase {
}
}
private void handleExit() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_ask_save)
.setPositiveButton(R.string.title_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onActionSave();
}
})
.setNegativeButton(R.string.title_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
}
ActivityBase.IBackPressedListener onBackPressedListener = new ActivityBase.IBackPressedListener() {
@Override
public boolean onBackPressed() {
handleExit();
return true;
}
};
private class Action {
int type;
String name;