Block funktion
parent
29b1d0cf27
commit
d3ff1f170c
|
@ -5,14 +5,16 @@ public class Whatsapp {
|
||||||
private String name;
|
private String name;
|
||||||
private String teleN;
|
private String teleN;
|
||||||
private String nachricht;
|
private String nachricht;
|
||||||
public ArrayList <String> speicherContact;
|
private ArrayList <String> speicherContact;
|
||||||
private ArrayList <String> speicherNummern;
|
private ArrayList <String> speicherNummern;
|
||||||
|
private ArrayList <String> blockContact;
|
||||||
|
|
||||||
public Whatsapp(String name, String teleN) {
|
public Whatsapp(String name, String teleN) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.nachricht = null;
|
this.nachricht = null;
|
||||||
this.teleN = teleN;
|
this.teleN = teleN;
|
||||||
this.speicherContact = new ArrayList<>();
|
this.speicherContact = new ArrayList<>();
|
||||||
|
this.blockContact = new ArrayList<>();
|
||||||
speicherContact.add(this.name);
|
speicherContact.add(this.name);
|
||||||
this.speicherNummern = new ArrayList<>();
|
this.speicherNummern = new ArrayList<>();
|
||||||
speicherNummern.add(teleN);
|
speicherNummern.add(teleN);
|
||||||
|
@ -38,6 +40,20 @@ public class Whatsapp {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void blocKontakt(Whatsapp block) {
|
||||||
|
if (!blockContact.contains(block.getName())) {
|
||||||
|
this.blockContact.add(block.getName());
|
||||||
|
System.out.println(this.name + " hat " + block.getName() + " blockiert");
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
System.err.println("Ist bereit Blockiert");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList <String> getblockContact(){
|
||||||
|
return blockContact;
|
||||||
|
}
|
||||||
|
|
||||||
public String searchContact(String name){
|
public String searchContact(String name){
|
||||||
for (int i = 0; i <speicherContact.size(); i++ )
|
for (int i = 0; i <speicherContact.size(); i++ )
|
||||||
if (speicherContact.get(i).equalsIgnoreCase(name))
|
if (speicherContact.get(i).equalsIgnoreCase(name))
|
||||||
|
@ -73,25 +89,35 @@ public class Whatsapp {
|
||||||
|
|
||||||
// nachrichten zwischen zwei Usern
|
// nachrichten zwischen zwei Usern
|
||||||
class Nachrichten{
|
class Nachrichten{
|
||||||
Whatsapp sender;
|
private Whatsapp sender;
|
||||||
Whatsapp receiver;
|
private Whatsapp receiver;
|
||||||
ArrayList<String> saveMessages;
|
private ArrayList<String> saveMessages;
|
||||||
|
|
||||||
public Nachrichten(Whatsapp sender, Whatsapp receiver) {
|
public Nachrichten(Whatsapp sender, Whatsapp receiver) {
|
||||||
|
|
||||||
this.sender = sender; //obai
|
this.sender = sender; //obai
|
||||||
this.receiver = receiver; //omar
|
this.receiver = receiver; //omar
|
||||||
this.saveMessages = new ArrayList<>();
|
this.saveMessages = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(Whatsapp sender, Whatsapp receiver, String message) {
|
public void sendMessage(Whatsapp sender, Whatsapp receiver, String message) {
|
||||||
|
if (receiver.getblockContact().contains(sender.getName())) {
|
||||||
|
String blockMessage = "Du wurdest von " + receiver.getName() + " blockiert!";
|
||||||
|
System.err.println(blockMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (sender.getblockContact().contains(receiver.getName())) {
|
||||||
|
String blockMessage = "Du hast " + receiver.getName() + " blockiert!";
|
||||||
|
System.err.println(blockMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (receiver != null) {
|
if (receiver != null) {
|
||||||
String infoMessage = sender.getName() + " sendet " + receiver.getName() +" : " + message;
|
receiver.setNachricht(message);
|
||||||
|
String infoMessage = sender.getName() + " sendet " + receiver.getName() + " : " + receiver.getNachricht();
|
||||||
saveMessages.add(infoMessage);
|
saveMessages.add(infoMessage);
|
||||||
}else
|
|
||||||
System.out.println("User does not exist");
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<String> getinfoMessage() {
|
public ArrayList<String> getinfoMessage() {
|
||||||
return saveMessages;
|
return saveMessages;
|
||||||
|
@ -109,6 +135,7 @@ class Groups{
|
||||||
Whatsapp hersteller;
|
Whatsapp hersteller;
|
||||||
ArrayList<Whatsapp> admins;
|
ArrayList<Whatsapp> admins;
|
||||||
ArrayList<Whatsapp> addmembers;
|
ArrayList<Whatsapp> addmembers;
|
||||||
|
ArrayList<String> allMessages;
|
||||||
String groupsname;
|
String groupsname;
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,19 +144,41 @@ class Groups{
|
||||||
this.groupsname = groupsname;
|
this.groupsname = groupsname;
|
||||||
this.addmembers = new ArrayList<>();
|
this.addmembers = new ArrayList<>();
|
||||||
this.admins = new ArrayList<>();
|
this.admins = new ArrayList<>();
|
||||||
|
this.allMessages = new ArrayList<>();
|
||||||
addmembers.add(hersteller);
|
addmembers.add(hersteller);
|
||||||
admins.add(hersteller);
|
admins.add(hersteller);
|
||||||
System.out.println(this.hersteller.getName() + "(Admin): hat die Groupe " + this.groupsname + " erstellt");
|
System.out.println(this.hersteller.getName() + "(Admin): hat die Groupe " + this.groupsname + " erstellt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMemebr(Whatsapp remover, Whatsapp toBeRemoved) {
|
public void sendeMessages(Whatsapp sender, String message) {
|
||||||
|
if (addmembers.contains(sender)) {
|
||||||
|
String speicher = sender.getName() + " : " + message ;
|
||||||
|
allMessages.add(speicher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getallMessages(){
|
||||||
|
return allMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printallMessages() {
|
||||||
|
for (String s: allMessages)
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeMember(Whatsapp remover, Whatsapp toBeRemoved) {
|
||||||
if (!admins.contains(remover)) {
|
if (!admins.contains(remover)) {
|
||||||
System.err.println("Du bist kein Admin");
|
System.err.println("Du bist kein Admin");
|
||||||
return;
|
return;
|
||||||
}else
|
|
||||||
addmembers.remove(toBeRemoved);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (!addmembers.contains(toBeRemoved)) {
|
||||||
|
System.err.println("Mitglied nicht in der Gruppe");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
addmembers.remove(toBeRemoved);
|
||||||
|
System.out.println(toBeRemoved.getName() + " wurde aus der Gruppe entfernt.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addMembers(Whatsapp member) {
|
public void addMembers(Whatsapp member) {
|
||||||
if (!addmembers.contains(member))
|
if (!addmembers.contains(member))
|
||||||
|
@ -139,13 +188,18 @@ class Groups{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAdmin(Whatsapp admin, Whatsapp toBeAdmin) {
|
public void addAdmin(Whatsapp admin, Whatsapp toBeAdmin) {
|
||||||
if (admins.contains(admin)){
|
if (!admins.contains(admin)) {
|
||||||
this.admins.add(toBeAdmin);
|
|
||||||
System.out.println(admin.getName() + " hat " + toBeAdmin.getName() + " als Admin gennengezichnet");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
System.err.println("Du musst Admin sein");
|
System.err.println("Du musst Admin sein");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (admins.contains(toBeAdmin)) {
|
||||||
|
System.err.println(toBeAdmin.getName() + " ist bereits Admin.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
admins.add(toBeAdmin);
|
||||||
|
System.out.println(admin.getName() + " hat " + toBeAdmin.getName() + " als Admin benannt.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<Whatsapp> getaddmembers(){
|
public ArrayList<Whatsapp> getaddmembers(){
|
||||||
|
|
||||||
|
@ -161,19 +215,14 @@ class Groups{
|
||||||
System.out.println("Alle Members:");
|
System.out.println("Alle Members:");
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (Whatsapp s : addmembers) {
|
for (Whatsapp s : addmembers) {
|
||||||
String memberName = printer.speicherContact.contains(s.getName()) ? s.getName() : "Unbekannt";
|
String memberName = printer.getContact().contains(s.getName()) ? s.getName() : "Unbekannt";
|
||||||
|
|
||||||
if (admins.contains(s))
|
if (admins.contains(s))
|
||||||
System.out.println("Mitglied(Admin) " + i + " : " + memberName);
|
System.out.println("Mitglied(Admin) " + i + " : " + memberName);
|
||||||
else
|
else
|
||||||
System.out.println("Mitglied " + i + " : " + memberName);
|
System.out.println("Mitglied " + i + " : " + memberName);
|
||||||
|
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,26 +10,32 @@ public class WhatsappTest {
|
||||||
Whatsapp oula = new Whatsapp("oula", "049321321");
|
Whatsapp oula = new Whatsapp("oula", "049321321");
|
||||||
|
|
||||||
|
|
||||||
// Nachrichten messages = new Nachrichten(obai,omar);
|
Nachrichten messages = new Nachrichten(obai,omar);
|
||||||
// messages.sendMessage(obai, omar, "Hallo Omar");
|
messages.sendMessage(obai, omar, "Hallo omar");
|
||||||
// messages.sendMessage(omar, obai, "Hallo Obai");
|
messages.sendMessage(omar, obai, "Hallo obai");
|
||||||
// messages.sendMessage(omar, obai, "was machst du?");
|
messages.sendMessage(omar, obai, "was machst du?");
|
||||||
// messages.printsaveMessages();
|
messages.printsaveMessages();
|
||||||
|
omar.blocKontakt(obai);
|
||||||
Groups gr1 = new Groups(obai,"Almidani");
|
messages.sendMessage(omar, obai, "was machst du?");
|
||||||
gr1.addMembers(omar);
|
messages.printsaveMessages();
|
||||||
gr1.addMembers(abd);
|
|
||||||
|
|
||||||
obai.addContact("abd","004848214");
|
|
||||||
obai.addContact("omar","004848214");
|
|
||||||
gr1.addAdmin(obai, omar);
|
|
||||||
gr1.printaddmembers(obai);
|
|
||||||
System.out.println();
|
|
||||||
System.out.println();
|
|
||||||
System.out.println();
|
|
||||||
gr1.printaddmembers(omar);
|
|
||||||
|
|
||||||
|
|
||||||
|
// Groups gr1 = new Groups(obai,"Almidani");
|
||||||
|
// gr1.addMembers(omar);
|
||||||
|
// gr1.addMembers(abd);
|
||||||
|
//
|
||||||
|
// obai.addContact("abd","004848214");
|
||||||
|
// obai.addContact("omar","004848214");
|
||||||
|
// gr1.addAdmin(obai, omar);
|
||||||
|
// gr1.printaddmembers(obai);
|
||||||
|
// System.out.println();
|
||||||
|
// System.out.println();
|
||||||
|
// System.out.println();
|
||||||
|
// gr1.printaddmembers(omar);
|
||||||
|
// gr1.sendeMessages(abd, "Hallo Omar");
|
||||||
|
// gr1.sendeMessages(omar, "Hallo Abd");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// gr1.printallMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue