Skip to content

Commit

Permalink
commit before implementing own swipecallback
Browse files Browse the repository at this point in the history
  • Loading branch information
zafodB committed Jun 9, 2021
1 parent ee90bba commit 1d3f3b7
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 255 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ dependencies {
exclude group: 'com.github.Stericson'
}

implementation "androidx.constraintlayout:constraintlayout:2.0.4"

//androidX legacy support
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.1.1'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dk/aau/netsec/hostage/model/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Profile implements JSONSerializable<Profile> {
@Transient
public boolean mShowTooltip = false;
@Transient
public boolean mShowMenu = true;
boolean mShowMenu = false;

public Profile(){
this.mEditable = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import java.util.LinkedList;
Expand All @@ -24,16 +23,34 @@ public class ProfileManagerRecyclerAdapter extends RecyclerView.Adapter<Recycler
List<Profile> list;
Context context;

private final int SHOW_MENU = 1;
private final int HIDE_MENU = 2;

public ProfileManagerRecyclerAdapter(Context context, List<Profile> articlesList) {
this.list = articlesList;
this.context = context;
}

@Override
public int getItemViewType(int position) {
if (list.get(position).ismShowMenu()) {
return SHOW_MENU;
} else {
return HIDE_MENU;
}
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View v;
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.profile_manager_list_item, parent, false);
return new MyViewHolder(v);
if (viewType == SHOW_MENU) {
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.profile_recycler_item_filip, parent, false);
return new MenuViewHolder(v);
} else {
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.profile_manager_list_item, parent, false);
return new MyViewHolder(v);
}
}

@Override
Expand All @@ -49,53 +66,40 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
((MyViewHolder) holder).itemActivated.setVisibility(View.GONE);
}
((MyViewHolder) holder).itemText.setText(entity.mText);
}

((MyViewHolder) holder).mBadgesContainer.removeAllViews();
boolean hasProtocols = false;

List<String> profiles = new LinkedList<String>(entity.getActiveProtocols());
((MyViewHolder) holder).mBadgesContainer.removeAllViews();
boolean hasProtocols = false;

List<String> profiles = new LinkedList<String>(entity.getActiveProtocols());
//
if (entity.mGhostActive) {
profiles.add("GHOST");
}
for (String protocol : profiles) {
hasProtocols = true;
TextView textView = new TextView(new ContextThemeWrapper(((MyViewHolder) holder).container.getContext(), R.style.ProfileManagerListBadge));
textView.setText(protocol);
((MyViewHolder) holder).mBadgesContainer.addView(textView);
}

if (!hasProtocols) {
if (entity.mGhostActive) {
profiles.add("GHOST");
}
for (String protocol : profiles) {
hasProtocols = true;
TextView textView = new TextView(new ContextThemeWrapper(((MyViewHolder) holder).container.getContext(), R.style.ProfileManagerListBadge));
textView.setText(protocol);
((MyViewHolder) holder).mBadgesContainer.addView(textView);
}

if (!hasProtocols) {
((MyViewHolder) holder).mBadgesContainer.setVisibility(View.INVISIBLE);
} else {
} else {
((MyViewHolder) holder).mBadgesContainer.setVisibility(View.VISIBLE);
}
}
}
if (holder instanceof MenuViewHolder){
;
// Do stuff with menu here?
}
}

@Override
public int getItemCount() {
return list.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView itemText;
ImageView imageView;
ImageView itemActivated;
RelativeLayout container;
FlowLayout mBadgesContainer;

public MyViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.profile_manager_item_label);
itemText = itemView.findViewById(R.id.profile_manager_item_text);
imageView = itemView.findViewById(R.id.profile_manager_item_image);
itemActivated = itemView.findViewById(R.id.profile_manager_item_activated);
container = itemView.findViewById(R.id.swipelist_frontview);
mBadgesContainer = itemView.findViewById(R.id.badges_container);
}
}

public void addProfile(Profile profile) {
list.add(profile);
Expand All @@ -107,7 +111,7 @@ public void removeProfile(Profile profile) {
}

public void showMenu(int position) {
for(int i=0; i<list.size(); i++){
for (int i = 0; i < list.size(); i++) {
list.get(i).setmShowMenu(false);
}
list.get(position).setmShowMenu(true);
Expand All @@ -116,18 +120,44 @@ public void showMenu(int position) {


public boolean isMenuShown() {
for(int i=0; i<list.size(); i++){
if(list.get(i).ismShowMenu()){
for (int i = 0; i < list.size(); i++) {
if (list.get(i).ismShowMenu()) {
return true;
}
}
return false;
}

public void closeMenu() {
for(int i=0; i<list.size(); i++){
for (int i = 0; i < list.size(); i++) {
list.get(i).setmShowMenu(false);
}
notifyDataSetChanged();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView itemText;
ImageView imageView;
ImageView itemActivated;
RelativeLayout container;
FlowLayout mBadgesContainer;

public MyViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.profile_manager_item_label);
itemText = itemView.findViewById(R.id.profile_manager_item_text);
imageView = itemView.findViewById(R.id.profile_manager_item_image);
itemActivated = itemView.findViewById(R.id.profile_manager_item_activated);
container = itemView.findViewById(R.id.swipelist_frontview_filip);
mBadgesContainer = itemView.findViewById(R.id.badges_container);
}
}

public class MenuViewHolder extends RecyclerView.ViewHolder{
public MenuViewHolder(View view){
super(view);
}
}

}

Loading

0 comments on commit 1d3f3b7

Please sign in to comment.