use KeyChoiceAdapter in SelectSignKeyIdListFragment
This commit is contained in:
@@ -4,6 +4,7 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -25,12 +26,27 @@ import org.sufficientlysecure.keychain.ui.adapter.KeyChoiceAdapter.KeyChoiceItem
|
||||
|
||||
|
||||
public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
|
||||
private final OnKeyClickListener onKeyClickListener;
|
||||
private Integer activeItem;
|
||||
|
||||
public KeyChoiceAdapter(boolean isMultiChoice, List<UnifiedKeyInfo> items) {
|
||||
public static KeyChoiceAdapter createSingleClickableAdapter(List<UnifiedKeyInfo> items,
|
||||
OnKeyClickListener onKeyClickListener) {
|
||||
return new KeyChoiceAdapter(items, Objects.requireNonNull(onKeyClickListener), Mode.IDLE);
|
||||
}
|
||||
|
||||
public static KeyChoiceAdapter createSingleChoiceAdapter(List<UnifiedKeyInfo> items) {
|
||||
return new KeyChoiceAdapter(items, null, Mode.SINGLE);
|
||||
}
|
||||
|
||||
public static KeyChoiceAdapter createMultiChoiceAdapter(List<UnifiedKeyInfo> items) {
|
||||
return new KeyChoiceAdapter(items, null, Mode.MULTI);
|
||||
}
|
||||
|
||||
private KeyChoiceAdapter(List<UnifiedKeyInfo> items, OnKeyClickListener onKeyClickListener, int idle) {
|
||||
super(getKeyChoiceItems(items));
|
||||
setMode(isMultiChoice ? Mode.MULTI : Mode.SINGLE);
|
||||
setMode(idle);
|
||||
addListener((OnItemClickListener) (view, position) -> onClickItem(position));
|
||||
this.onKeyClickListener = onKeyClickListener;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -50,10 +66,15 @@ public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
|
||||
if (getMode() == Mode.MULTI) {
|
||||
toggleSelection(position);
|
||||
notifyItemChanged(position);
|
||||
} else {
|
||||
return true;
|
||||
} else if (getMode() == Mode.SINGLE) {
|
||||
setActiveItem(position);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
KeyChoiceItem item = getItem(position);
|
||||
onKeyClickListener.onKeyClick(item.keyInfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setActiveItem(Integer newActiveItem) {
|
||||
@@ -212,4 +233,8 @@ public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnKeyClickListener {
|
||||
void onKeyClick(UnifiedKeyInfo keyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.ui.base;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.Gravity;
|
||||
@@ -32,7 +32,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
@@ -124,9 +124,16 @@ public class RecyclerFragment<A extends RecyclerView.Adapter> extends Fragment {
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
|
||||
|
||||
FrameLayout listContainer = new FrameLayout(context);
|
||||
LinearLayout listContainer = new LinearLayout(context);
|
||||
listContainer.setOrientation(LinearLayout.VERTICAL);
|
||||
listContainer.setId(INTERNAL_LIST_CONTAINER_ID);
|
||||
|
||||
LinearLayout headerLayout = new LinearLayout(context);
|
||||
headerLayout.setId(R.id.headerlayout);
|
||||
|
||||
listContainer.addView(headerLayout, new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
TextView textView = new TextView(context);
|
||||
textView.setId(INTERNAL_EMPTY_VIEW_ID);
|
||||
textView.setGravity(Gravity.CENTER);
|
||||
|
||||
Reference in New Issue
Block a user