<commit_before>package de.fau.cs.mad.yasme.android.ui.fragments;

import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import de.fau.cs.mad.yasme.android.R;
import de.fau.cs.mad.yasme.android.asyncTasks.database.GetTask;
import de.fau.cs.mad.yasme.android.asyncTasks.server.ChangeUserTask;
import de.fau.cs.mad.yasme.android.controller.FragmentObservable;
import de.fau.cs.mad.yasme.android.controller.Log;
import de.fau.cs.mad.yasme.android.controller.NotifiableFragment;
import de.fau.cs.mad.yasme.android.controller.ObservableRegistry;
import de.fau.cs.mad.yasme.android.controller.Toaster;
import de.fau.cs.mad.yasme.android.entities.Chat;
import de.fau.cs.mad.yasme.android.entities.User;
import de.fau.cs.mad.yasme.android.storage.DatabaseManager;
import de.fau.cs.mad.yasme.android.storage.dao.ChatDAO;
import de.fau.cs.mad.yasme.android.ui.UserAdapter;
import de.fau.cs.mad.yasme.android.ui.activities.ChatSettingsActivity;

/**
 * Created by <NAME> <<EMAIL>> on 03.08.14.
 */
public class ChatSettingsRemove extends Fragment implements NotifiableFragment<Chat> {
    private List<User> users;
    private UserAdapter mDelAdapter = null;
    private View chatRem;
    private Chat chat;

    public ChatSettingsRemove() {
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d(this.getClass().getSimpleName(),"onStart");
        FragmentObservable<ChatSettingsRemove, Chat> obs = 
            ObservableRegistry.getObservable(ChatSettingsRemove.class);
        obs.register(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d(this.getClass().getSimpleName(),"onStop");
        FragmentObservable<ChatSettingsRemove, Chat> obs = 
            ObservableRegistry.getObservable(ChatSettingsRemove.class);
        obs.remove(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d(this.getClass().getSimpleName(),"onResume");
        if (mDelAdapter != null) {
            mDelAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(this.getClass().getSimpleName(),"onCreate");
        FragmentObservable<ChatSettingsRemove, Chat> obs = 
            ObservableRegistry.getObservable(ChatSettingsRemove.class);
        obs.register(this);
        users = new ArrayList<User>();
        users.add(new User("WUBDIDU",999));
        mDelAdapter = new UserAdapter(getActivity(), R.layout.user_item, users);
        mDelAdapter.setNotifyOnChange(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.d(this.getClass().getSimpleName(),"onCreateView");
        if (null == chat) {
            Bundle bundle = getArguments();
            long chatId = bundle.getLong(ChatSettingsActivity.CHAT_ID);
            // Make sure that fragment is registered. Registering twice won't cause any issues
            FragmentObservable<ChatSettingsRemove, Chat> obs = ObservableRegistry.getObservable(ChatSettingsRemove.class);
            obs.register(this);

            // load chat from database
            if (chatId <= 0) {
                throw new IllegalArgumentException("chatId <= 0");
            }
            ChatDAO chatDAO = DatabaseManager.INSTANCE.getChatDAO();
            new GetTask<>(chatDAO, chatId, this.getClass()).execute();
        }
        View rootView = inflater.inflate(R.layout.fragment_chat_settings_remove, container, false);

        chatRem = rootView.findViewById(R.id.chat_settings_remove);

        if(null != chat) {
            fillRemView();
        }
        //users = new ArrayList<User>();
        return rootView;
    }

    @Override
    public void notifyFragment(Chat chat) {
        Log.d(this.getClass().getSimpleName(),"NOTIFICATION");
        if(null==chat) {
            throw new IllegalArgumentException("chat is null in "+this.getClass().getSimpleName());
        }
        this.chat = chat;
        fillRemView();
    }

    private void fillRemView() {
        ListView participants = (ListView) chatRem.findViewById(R.id.chat_rem_participants);
        Log.d(this.getClass().getSimpleName(),"Participants: " + participants);
        users.clear();
        for (User u : chat.getParticipants()) {
            Log.d(this.getClass().getSimpleName(),"User: "+u.getName());
            if(u.getId() == DatabaseManager.INSTANCE.getUserId()) {
                continue;
            }
            users.add(u);
        }
        // Set the adapter
        mDelAdapter.addAll(users);
        mDelAdapter.notifyDataSetChanged();
        participants.setAdapter(mDelAdapter);

        // Set OnItemClickListener so we can be notified on item clicks
        participants.setOnItemClickListener(<commit_msg>Double list removed. User delete works now without any complications.<commit_after>package de.fau.cs.mad.yasme.android.ui.fragments;

import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import de.fau.cs.mad.yasme.android.R;
import de.fau.cs.mad.yasme.android.asyncTasks.database.GetTask;
import de.fau.cs.mad.yasme.android.asyncTasks.server.ChangeUserTask;
import de.fau.cs.mad.yasme.android.controller.FragmentObservable;
import de.fau.cs.mad.yasme.android.controller.Log;
import de.fau.cs.mad.yasme.android.controller.NotifiableFragment;
import de.fau.cs.mad.yasme.android.controller.ObservableRegistry;
import de.fau.cs.mad.yasme.android.controller.Toaster;
import de.fau.cs.mad.yasme.android.entities.Chat;
import de.fau.cs.mad.yasme.android.entities.User;
import de.fau.cs.mad.yasme.android.storage.DatabaseManager;
import de.fau.cs.mad.yasme.android.storage.dao.ChatDAO;
import de.fau.cs.mad.yasme.android.ui.UserAdapter;
import de.fau.cs.mad.yasme.android.ui.activities.ChatSettingsActivity;

/**
 * Created by <NAME> <<EMAIL>> on 03.08.14.
 */
public class ChatSettingsRemove extends Fragment implements NotifiableFragment<Chat> {
    private List<User> users;
    private UserAdapter mDelAdapter = null;
    private View chatRem;
    private Chat chat;

    public ChatSettingsRemove() {
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d(this.getClass().getSimpleName(),"onStart");
        FragmentObservable<ChatSettingsRemove, Chat> obs = 
            ObservableRegistry.getObservable(ChatSettingsRemove.class);
        obs.register(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d(this.getClass().getSimpleName(),"onStop");
        FragmentObservable<ChatSettingsRemove, Chat> obs = 
            ObservableRegistry.getObservable(ChatSettingsRemove.class);
        obs.remove(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d(this.getClass().getSimpleName(),"onResume");
        if (mDelAdapter != null) {
            mDelAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(this.getClass().getSimpleName(),"onCreate");
        FragmentObservable<ChatSettingsRemove, Chat> obs = 
            ObservableRegistry.getObservable(ChatSettingsRemove.class);
        obs.register(this);
        users = new ArrayList<User>();
//        users.add(new User("WUBDIDU",999));
        mDelAdapter = new UserAdapter(getActivity(), R.layout.user_item, users);
        mDelAdapter.setNotifyOnChange(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.d(this.getClass().getSimpleName(),"onCreateView");
        if (null == chat) {
            Bundle bundle = getArguments();
            long chatId = bundle.getLong(ChatSettingsActivity.CHAT_ID);
            // Make sure that fragment is registered. Registering twice won't cause any issues
            FragmentObservable<ChatSettingsRemove, Chat> obs = ObservableRegistry.getObservable(ChatSettingsRemove.class);
            obs.register(this);

            // load chat from database
            if (chatId <= 0) {
                throw new IllegalArgumentException("chatId <= 0");
            }
            ChatDAO chatDAO = DatabaseManager.INSTANCE.getChatDAO();
            new GetTask<>(chatDAO, chatId, this.getClass()).execute();
        }
        View rootView = inflater.inflate(R.layout.fragment_chat_settings_remove, container, false);

        chatRem = rootView.findViewById(R.id.chat_settings_remove);

        if(null != chat) {
            fillRemView();
        }
        //users = new ArrayList<User>();
        return rootView;
    }

    @Override
    public void notifyFragment(Chat chat) {
        Log.d(this.getClass().getSimpleName(),"NOTIFICATION");
        if(null==chat) {
            throw new IllegalArgumentException("chat is null in "+this.getClass().getSimpleName());
        }
        this.chat = chat;
        fillRemView();
    }

    private void fillRemView() {
        ListView participants = (ListView) chatRem.findViewById(R.id.chat_rem_participants);
        Log.d(this.getClass().getSimpleName(),"Participants: " + participants);
        users.clear();
        for (User u : chat.getParticipants()) {
            Log.d(this.getClass().getSimpleName(),"User: "+u.getName());
            if(u.getId() == DatabaseManager.INSTANCE.getUserId()) {
                continue;
            }
            users.add(u);
        }
        // Set the adapter
        //mDelAdapter.addAll(users);
        //mDelAdapter.notifyDataSetChanged();
        participants.setAdapter(mDelAdapter);

        // Set OnItemClickListener so we can be notified on item clicks
        participants.setOnItemClickListener(
{'fraction_non_alphanumeric': 0.1182980347261973, 'fraction_numerical': 0.0020988360999809196, 'mean_word_length': 3.007262996941896, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4559356', 'n_tokens_mistral': 3079, 'n_tokens_neox': 3018, 'n_words': 532}