Skip to content
Snippets Groups Projects
Commit 2e0623a1 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Added proper backlog filtering, refactored some stuff

parent bc57c06a
No related branches found
No related tags found
No related merge requests found
Showing
with 585 additions and 134 deletions
package de.kuschku.util.keyboardutils;
import android.content.DialogInterface;
import android.view.KeyEvent;
import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
/**
* A util class that automatically handles <code>enter</code> and <code>esc</code> in dialogs
* properly: By calling onPositive or onNeutral
*/
public class DialogKeyboardUtil implements DialogInterface.OnKeyListener {
MaterialDialog dialog;
public DialogKeyboardUtil(MaterialDialog dialog) {
this.dialog = dialog;
}
@Override
public boolean onKey(DialogInterface d, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
dialog.getActionButton(DialogAction.POSITIVE).callOnClick();
dialog.dismiss();
return true;
} else if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
dialog.dismiss();
return true;
}
return false;
}
}
package de.kuschku.util.keyboardutils;
import android.support.v7.widget.AppCompatEditText;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
//TODO: FIND A WAY TO TEST THIS – THE EMULATOR DOESN'T WORK
public class EditTextKeyboardUtil implements AppCompatEditText.OnKeyListener {
AppCompatEditText editText;
boolean reverse;
public EditTextKeyboardUtil(AppCompatEditText editText) {
this.editText = editText;
}
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
Log.e("DEBUG", keyCode + " : " + event.toString());
if (event.isShiftPressed()) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (editText.getSelectionStart() == editText.getSelectionEnd())
reverse = true;
if (reverse) {
int start = Math.max(0, editText.getSelectionStart() - 1);
editText.setSelection(start, editText.getSelectionEnd());
} else {
int end = Math.min(editText.length(), editText.getSelectionEnd() - 1);
editText.setSelection(end, end);
}
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (editText.getSelectionStart() == editText.getSelectionEnd())
reverse = false;
if (reverse) {
int start = Math.max(0, editText.getSelectionStart() + 1);
editText.setSelection(start, editText.getSelectionEnd());
} else {
int end = Math.min(editText.length(), editText.getSelectionEnd() + 1);
editText.setSelection(end, end);
}
break;
}
} else {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
int start = Math.max(0, editText.getSelectionStart() - 1);
editText.setSelection(start, start);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
int end = Math.min(editText.length(), editText.getSelectionEnd() + 1);
editText.setSelection(end, end);
break;
}
}
return false;
}
}
package de.kuschku.util.niohelpers;
import android.util.Log;
public class Helper {
// Making default constructor invisible
private Helper() {
}
public static void printHexDump(byte[] data) {
Log.e("HexDump", "Hexdump following: ");
String bytes = "";
String text = "";
int i;
for (i = 0; i < data.length; i++) {
bytes += String.format("%02x ", data[i]);
text += encodeChar(data[1]);
if (i > 0 && (i + 1) % 8 == 0) {
Log.e("HexDump", String.format("%08x ", i - 7) + bytes + text);
bytes = "";
text = "";
}
}
Log.e("HexDump", String.format("%08x ", i - 7) + bytes + text);
}
private static char encodeChar(byte data) {
if (data < 127 && data > 32) return (char) data;
else return '.';
}
}
package de.kuschku.util.observables.callbacks;
public interface GeneralCallback {
void notifyChanged();
}
package de.kuschku.util.observables.callbacks.wrappers;
import java.util.HashSet;
import java.util.Set;
import de.kuschku.util.observables.IObservable;
import de.kuschku.util.observables.callbacks.GeneralCallback;
public class GeneralCallbackWrapper implements IObservable<GeneralCallback>, GeneralCallback {
Set<GeneralCallback> callbacks = new HashSet<>();
@Override
public void notifyChanged() {
for (GeneralCallback callback : callbacks) {
callback.notifyChanged();
}
}
@Override
public void addCallback(GeneralCallback callback) {
callbacks.add(callback);
}
@Override
public void removeCallback(GeneralCallback callback) {
callbacks.remove(callback);
}
}
package de.kuschku.util.observables.callbacks.wrappers;
import de.kuschku.util.observables.callbacks.UICallback;
public abstract class GeneralUICallbackWrapper implements UICallback {
public abstract void notifyChanged();
@Override
public void notifyItemInserted(int position) {
notifyChanged();
}
@Override
public void notifyItemChanged(int position) {
notifyChanged();
}
@Override
public void notifyItemRemoved(int position) {
notifyChanged();
}
@Override
public void notifyItemMoved(int from, int to) {
notifyChanged();
}
@Override
public void notifyItemRangeInserted(int position, int count) {
notifyChanged();
}
@Override
public void notifyItemRangeChanged(int position, int count) {
notifyChanged();
}
@Override
public void notifyItemRangeRemoved(int position, int count) {
notifyChanged();
}
}
package de.kuschku.util.observables.lists;
import android.support.annotation.NonNull;
import de.kuschku.util.observables.IObservable;
import de.kuschku.util.observables.callbacks.UICallback;
import de.kuschku.util.observables.callbacks.UIChildCallback;
import de.kuschku.util.observables.callbacks.UIChildParentCallback;
import de.kuschku.util.observables.callbacks.UIParentCallback;
import de.kuschku.util.observables.callbacks.wrappers.MultiUIChildParentCallback;
import de.kuschku.util.observables.callbacks.wrappers.ParentUICallbackWrapper;
public class ChildParentObservableSortedList<T extends IObservable<UIChildCallback>> extends ObservableSortedList<T> {
private MultiUIChildParentCallback callback = MultiUIChildParentCallback.of();
public ChildParentObservableSortedList(@NonNull Class<T> cl, @NonNull ItemComparator<T> comparator) {
super(cl, comparator);
registerCallbacks();
}
public ChildParentObservableSortedList(@NonNull Class<T> cl, @NonNull ItemComparator<T> comparator, boolean reverse) {
super(cl, comparator, reverse);
registerCallbacks();
}
private void registerCallbacks() {
super.addCallback(new MyWrapper(callback));
}
public void addChildParentCallback(@NonNull UIChildParentCallback callback) {
this.callback.addCallback(callback);
}
public void removeChildParentCallback(@NonNull UIChildParentCallback callback) {
this.callback.removeCallback(callback);
}
private class MyWrapper extends ParentUICallbackWrapper {
public MyWrapper(@NonNull UIParentCallback wrapped) {
super(wrapped);
}
@Override
public void notifyItemInserted(int position) {
super.notifyItemInserted(position);
get(position).addCallback(callback);
}
@Override
public void notifyItemChanged(int position) {
super.notifyItemChanged(position);
}
@Override
public void notifyItemRemoved(int position) {
super.notifyItemRemoved(position);
}
@Override
public void notifyItemMoved(int from, int to) {
super.notifyItemMoved(from, to);
}
@Override
public void notifyItemRangeInserted(int position, int count) {
super.notifyItemRangeInserted(position, count);
for (int i = position; i < position + count; i++) {
get(position).addCallback(callback);
}
}
@Override
public void notifyItemRangeChanged(int position, int count) {
super.notifyItemRangeChanged(position, count);
}
@Override
public void notifyItemRangeRemoved(int position, int count) {
super.notifyItemRangeRemoved(position, count);
}
}
}
...@@ -20,7 +20,7 @@ import static de.kuschku.util.AndroidAssert.assertTrue; ...@@ -20,7 +20,7 @@ import static de.kuschku.util.AndroidAssert.assertTrue;
public class ObservableSortedList<T> implements IObservableList<UICallback, T> { public class ObservableSortedList<T> implements IObservableList<UICallback, T> {
@NonNull @NonNull
public final SortedList<T> list; private final SortedList<T> list;
private final boolean reverse; private final boolean reverse;
@NonNull @NonNull
...@@ -120,7 +120,7 @@ public class ObservableSortedList<T> implements IObservableList<UICallback, T> { ...@@ -120,7 +120,7 @@ public class ObservableSortedList<T> implements IObservableList<UICallback, T> {
@Override @Override
public int lastIndexOf(Object object) { public int lastIndexOf(Object object) {
return 0; return indexOf(object);
} }
@NonNull @NonNull
...@@ -138,17 +138,28 @@ public class ObservableSortedList<T> implements IObservableList<UICallback, T> { ...@@ -138,17 +138,28 @@ public class ObservableSortedList<T> implements IObservableList<UICallback, T> {
@Nullable @Nullable
@Override @Override
public T remove(int location) { public T remove(int location) {
return null; T item = list.get(location);
list.remove(item);
return item;
} }
@Override @Override
public boolean remove(Object object) { public boolean remove(Object object) {
try {
list.remove((T) object);
return true;
} catch (ClassCastException e) {
return false; return false;
} }
}
@Override @Override
public boolean removeAll(@NonNull Collection<?> collection) { public boolean removeAll(@NonNull Collection<?> collection) {
return false; boolean result = true;
for (Object o : collection) {
result &= remove(o);
}
return result;
} }
@Override @Override
...@@ -164,7 +175,7 @@ public class ObservableSortedList<T> implements IObservableList<UICallback, T> { ...@@ -164,7 +175,7 @@ public class ObservableSortedList<T> implements IObservableList<UICallback, T> {
@Override @Override
public int size() { public int size() {
return 0; return list.size();
} }
@NonNull @NonNull
...@@ -193,6 +204,10 @@ public class ObservableSortedList<T> implements IObservableList<UICallback, T> { ...@@ -193,6 +204,10 @@ public class ObservableSortedList<T> implements IObservableList<UICallback, T> {
throw new MaterialDialog.NotImplementedException("Not implemented"); throw new MaterialDialog.NotImplementedException("Not implemented");
} }
public void notifyItemChanged(int position) {
callback.notifyItemChanged(position);
}
public interface ItemComparator<T> { public interface ItemComparator<T> {
int compare(T o1, T o2); int compare(T o1, T o2);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment