built MeetingsController into MainActivity

This commit is contained in:
2021-05-15 17:56:33 +02:00
parent fe99d0a377
commit 7cce6f1280
@@ -43,7 +43,8 @@ import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
public boolean testing; private boolean testing;
private final MeetingsController meetingsController = new MeetingsController(this);
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -64,8 +65,7 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
final ScrollView scrollview = findViewById(R.id.scrollArea); final ScrollView scrollview = findViewById(R.id.scrollArea);
int meetingIndex = meetingsController.searchMeetingInList(meetingsController.getMeetings(), meetingName);
int meetingIndex = searchMeetingInList(getMeetings(), meetingName);
if (meetingIndex == -1) { if (meetingIndex == -1) {
if (meetingName != null) { if (meetingName != null) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this); AlertDialog.Builder dialog = new AlertDialog.Builder(this);
@@ -77,8 +77,8 @@ public class MainActivity extends AppCompatActivity {
joinImmediately = false; joinImmediately = false;
} }
if (meetingIndex <= getMeetings().size() && meetingIndex != -1) { if (meetingIndex <= meetingsController.getMeetings().size() && meetingIndex != -1) {
setLastMeeting(meetingIndex); meetingsController.setLastMeeting(meetingIndex);
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName); AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
textMeetingName.setEnabled(false); textMeetingName.setEnabled(false);
textMeetingName.setAdapter(null); textMeetingName.setAdapter(null);
@@ -91,9 +91,9 @@ public class MainActivity extends AppCompatActivity {
//watchMeetingNameBox(); //watchMeetingNameBox();
fillDropdownMeetingName(); fillDropdownMeetingName();
if (getLastMeeting() != -1) { if (meetingsController.getLastMeeting() != -1) {
try { try {
fillMeeting(getLastMeeting()); fillMeeting(meetingsController.getLastMeeting());
scrollview.post(() -> scrollview.scrollTo(0, scrollview.getChildAt(0).getHeight())); scrollview.post(() -> scrollview.scrollTo(0, scrollview.getChildAt(0).getHeight()));
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this); AlertDialog.Builder dialog = new AlertDialog.Builder(this);
@@ -101,8 +101,8 @@ public class MainActivity extends AppCompatActivity {
dialog.setTitle(R.string.hint); dialog.setTitle(R.string.hint);
AlertDialog alertDialog = dialog.create(); AlertDialog alertDialog = dialog.create();
alertDialog.show(); alertDialog.show();
setLastMeeting(-1); meetingsController.setLastMeeting(-1);
saveMeetingList(new ArrayList<>()); meetingsController.saveMeetingList(new ArrayList<>());
} }
} }
watchSaveIcon(); watchSaveIcon();
@@ -119,9 +119,8 @@ public class MainActivity extends AppCompatActivity {
} }
if (joinImmediately) { if (joinImmediately) {
Meeting currMeeting = getMeetings().get(meetingIndex); Meeting currMeeting = meetingsController.getMeetings().get(meetingIndex);
String url = buildZoomURL(currMeeting.meetingID, currMeeting.meetingPWD, currMeeting.attendees.get(currMeeting.lastAtt).name, currMeeting.attendees.get(currMeeting.lastAtt).num); new ZoomLink(this, currMeeting).launch();
launchZoomUrl(url);
} else { } else {
AppUpdater appUpdater = new AppUpdater(this).setUpdateFrom(UpdateFrom.XML).setUpdateXML("https://baldaufwd.de/ZoomHelper/updatetest.xml"); AppUpdater appUpdater = new AppUpdater(this).setUpdateFrom(UpdateFrom.XML).setUpdateXML("https://baldaufwd.de/ZoomHelper/updatetest.xml");
APKDownloader apkDownloader = new APKDownloader(); APKDownloader apkDownloader = new APKDownloader();
@@ -204,11 +203,11 @@ public class MainActivity extends AppCompatActivity {
Meeting mtgToImport = new Meeting(meetingName, meetingID, meetingPWD, "", ""); Meeting mtgToImport = new Meeting(meetingName, meetingID, meetingPWD, "", "");
if (searchMeetingInList(getMeetings(), mtgToImport.meetingName) == -1 && !checkOnly) { if (meetingsController.searchMeetingInList(meetingsController.getMeetings(), mtgToImport.meetingName) == -1 && !checkOnly) {
fillMeeting(mtgToImport); fillMeeting(mtgToImport);
} else { } else {
builder.setPositiveButton(R.string.override, (dialog, which) -> { builder.setPositiveButton(R.string.override, (dialog, which) -> {
int found = searchMeetingInList(getMeetings(), mtgToImport.meetingName); int found = meetingsController.searchMeetingInList(meetingsController.getMeetings(), mtgToImport.meetingName);
importMeeting(mtgToImport, false); importMeeting(mtgToImport, false);
fillMeeting(found); fillMeeting(found);
dialog.dismiss(); dialog.dismiss();
@@ -233,7 +232,7 @@ public class MainActivity extends AppCompatActivity {
} }
private void showCreateShortcutUI() { private void showCreateShortcutUI() {
int meeting = searchMeetingInList(getMeetings(), createCurrMeetingFromUI().meetingName); int meeting = meetingsController.searchMeetingInList(meetingsController.getMeetings(), createCurrMeetingFromUI().meetingName);
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -271,7 +270,7 @@ public class MainActivity extends AppCompatActivity {
private void createMeetingShortcut(int meetingIndex, boolean joinImmediately) { private void createMeetingShortcut(int meetingIndex, boolean joinImmediately) {
Meeting meeting = getMeetings().get(meetingIndex); Meeting meeting = meetingsController.getMeetings().get(meetingIndex);
if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) { if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, meeting.meetingName) ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, meeting.meetingName)
@@ -324,46 +323,7 @@ public class MainActivity extends AppCompatActivity {
private void watchDeleteIcon() { private void watchDeleteIcon() {
ImageView trashIcon = findViewById(R.id.imageTrash); ImageView trashIcon = findViewById(R.id.imageTrash);
trashIcon.setOnClickListener(v -> removeMeeting(searchMeetingInList(getMeetings(), createCurrMeetingFromUI().meetingName))); trashIcon.setOnClickListener(v -> meetingsController.removeMeeting(meetingsController.searchMeetingInList(meetingsController.getMeetings(), createCurrMeetingFromUI().meetingName)));
}
private void removeMeeting(int meeting) {
ArrayList<Meeting> meetings = getMeetings();
if (meetings.size() > 0 && meeting != -1) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name);
builder.setMessage(getString(R.string.suretoremove, meetings.get(meeting).meetingName));
builder.setPositiveButton(R.string.yes, (dialog, which) -> {
dialog.dismiss();
meetings.remove(meeting);
saveMeetingList(meetings);
if (meetings.size() > 1) {
fillDropdownMeetingName();
if (getLastMeeting() > meetings.size() - 1) {
setLastMeeting(meetings.size() - 1);
fillMeeting(getLastMeeting());
}
} else if (meetings.size() == 1) {
setLastMeeting(0);
fillDropdownMeetingName();
fillMeeting(getLastMeeting());
} else {
setLastMeeting(-1);
fillDropdownMeetingName();
fillBlank();
}
});
builder.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss());
AlertDialog alert = builder.create();
alert.show();
}
} }
@@ -399,7 +359,7 @@ public class MainActivity extends AppCompatActivity {
public void fillWithSelectedMeeting() { public void fillWithSelectedMeeting() {
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName); AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
int search = searchMeetingInList(getMeetings(), textMeetingName.getText().toString()); int search = meetingsController.searchMeetingInList(meetingsController.getMeetings(), textMeetingName.getText().toString());
if (search != -1) { if (search != -1) {
fillMeeting(search); fillMeeting(search);
} }
@@ -407,7 +367,7 @@ public class MainActivity extends AppCompatActivity {
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
public void fillDropdownMeetingName() { public void fillDropdownMeetingName() {
ArrayList<Meeting> meetings = getMeetings(); ArrayList<Meeting> meetings = meetingsController.getMeetings();
String[] meetingNames = new String[meetings.size()]; String[] meetingNames = new String[meetings.size()];
for (int i = 0; i < meetings.size(); i++) { for (int i = 0; i < meetings.size(); i++) {
@@ -415,7 +375,6 @@ public class MainActivity extends AppCompatActivity {
} }
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName); AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
//ImageView dropdown = findViewById(R.id.iconDropdownMeetingName);
AutoSuggestAdapter adapter = new AutoSuggestAdapter(this, android.R.layout.simple_dropdown_item_1line); AutoSuggestAdapter adapter = new AutoSuggestAdapter(this, android.R.layout.simple_dropdown_item_1line);
adapter.setData(Arrays.asList(meetingNames)); adapter.setData(Arrays.asList(meetingNames));
textMeetingName.setAdapter(adapter); textMeetingName.setAdapter(adapter);
@@ -423,16 +382,11 @@ public class MainActivity extends AppCompatActivity {
textMeetingName.setOnTouchListener((paramView, paramMotionEvent) -> false); textMeetingName.setOnTouchListener((paramView, paramMotionEvent) -> false);
textMeetingName.setOnItemClickListener((arg0, view, arg2, arg3) -> fillWithSelectedMeeting()); textMeetingName.setOnItemClickListener((arg0, view, arg2, arg3) -> fillWithSelectedMeeting());
/*dropdown.setOnClickListener(v -> {
textMeetingName.showDropDown();
adapter.getFilter().filter(null);
});*/
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
public void fillDropdownAttendeeName(int meetingIndex) { public void fillDropdownAttendeeName(int meetingIndex) {
Meeting meeting = getMeetings().get(meetingIndex); Meeting meeting = meetingsController.getMeetings().get(meetingIndex);
ArrayList<Attendee> attendees = meeting.attendees; ArrayList<Attendee> attendees = meeting.attendees;
String[] attNames = new String[attendees.size()]; String[] attNames = new String[attendees.size()];
@@ -459,8 +413,8 @@ public class MainActivity extends AppCompatActivity {
private void fillWithSelectedAtt(int meetingIndex) { private void fillWithSelectedAtt(int meetingIndex) {
AutoCompleteTextView textName = findViewById(R.id.textBoxName); AutoCompleteTextView textName = findViewById(R.id.textBoxName);
EditText editAtt = findViewById(R.id.editAtt); EditText editAtt = findViewById(R.id.editAtt);
int found = getMeetings().get(meetingIndex).searchAttendee(textName.getText().toString()); int found = meetingsController.getMeetings().get(meetingIndex).searchAttendee(textName.getText().toString());
editAtt.setText(getMeetings().get(meetingIndex).attendees.get(found).num); editAtt.setText(meetingsController.getMeetings().get(meetingIndex).attendees.get(found).num);
} }
@@ -483,155 +437,19 @@ public class MainActivity extends AppCompatActivity {
} }
public void fillMeeting(int id) { public void fillMeeting(int id) {
fillMeeting(getMeetings().get(id)); fillMeeting(meetingsController.getMeetings().get(id));
fillDropdownAttendeeName(id); fillDropdownAttendeeName(id);
} }
private void launchZoomUrl(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
if (testing) {
//For Debugging: Show URL in Alert
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage(url);
dialog.setTitle("Zoom URL (for testing)");
AlertDialog alertDialog = dialog.create();
alertDialog.show();
}
}
private String buildZoomURL(String confno, String pwd, String name, String attendees) {
Uri.Builder builder = new Uri.Builder();
builder.scheme("zoomus")
.authority("zoom.us")
.appendPath("join")
.appendQueryParameter("confno", confno.replace(" ", ""))
.appendQueryParameter("pwd", pwd);
if (!Objects.equals(attendees, "")) {
builder.appendQueryParameter("uname", name + " (" + attendees + ")");
} else
builder.appendQueryParameter("uname", name);
return builder.build().toString();
}
public String meetingsToString(ArrayList<Meeting> listMeetings) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objOutputStream = null;
try {
objOutputStream = new ObjectOutputStream(byteArrayOutputStream);
} catch (IOException e) {
e.printStackTrace();
}
for (Object obj : listMeetings) {
try {
if (objOutputStream == null) throw new AssertionError();
objOutputStream.writeObject(obj);
} catch (IOException e) {
e.printStackTrace();
}
try {
objOutputStream.reset();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
if (objOutputStream == null) throw new AssertionError();
objOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return Base64.encodeToString(byteArrayOutputStream.toByteArray(), 0);
}
public ArrayList<Meeting> stringToMeetings(String string) {
byte[] bytes = Base64.decode(string, 0);
ArrayList<Meeting> listMeetings = new ArrayList<>();
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream obj = null;
try {
obj = new ObjectInputStream(bis);
} catch (IOException e) {
e.printStackTrace();
}
try {
while (bis.available() != -1) {
//Read object from file
if (obj == null) throw new AssertionError();
Meeting meeting = (Meeting) obj.readObject();
listMeetings.add(meeting);
}
} catch (EOFException ex) {
//ex.printStackTrace();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
return listMeetings;
}
@SuppressLint("ApplySharedPref")
public void saveMeetingList(ArrayList<Meeting> meetingList) {
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
prefsEditor.putString("Meetings", meetingsToString(meetingList));
prefsEditor.commit();
}
@SuppressLint("ApplySharedPref")
public void setLastMeeting(int id) {
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
prefsEditor.putInt("LastMeeting", id);
prefsEditor.commit();
}
public int getLastMeeting() {
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
return mPrefs.getInt("LastMeeting", -1);
}
public ArrayList<Meeting> getMeetings() {
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
String value = mPrefs.getString("Meetings", "");
ArrayList<Meeting> meetingList;
if (value.equals("")) {
meetingList = new ArrayList<>();
} else {
meetingList = stringToMeetings(value);
}
return meetingList;
}
public int searchMeetingInList(ArrayList<Meeting> meetings, String name) {
int found = -1;
for (int i = 0; i < meetings.size(); i++) {
if (meetings.get(i).meetingName.equals(name)) {
found = i;
break;
}
}
return found;
}
public void btnSave_onClick(View view) { public void btnSave_onClick(View view) {
saveMeetingFromUI(); saveMeetingFromUI();
} }
public void btnJoin_onClick(View view) { public void btnJoin_onClick(View view) {
saveMeetingFromUI(); saveMeetingFromUI();
Meeting currMeeting = createCurrMeetingFromUI(); Meeting currMeeting = createCurrMeetingFromUI();
String url = buildZoomURL(currMeeting.meetingID, currMeeting.meetingPWD, currMeeting.attendees.get(currMeeting.lastAtt).name, currMeeting.attendees.get(currMeeting.lastAtt).num); new ZoomLink(this, currMeeting).launch();
launchZoomUrl(url);
} }
public Meeting createCurrMeetingFromUI() { public Meeting createCurrMeetingFromUI() {
@@ -646,28 +464,28 @@ public class MainActivity extends AppCompatActivity {
public void importMeeting(Meeting meeting, boolean updateAttendee) { public void importMeeting(Meeting meeting, boolean updateAttendee) {
ArrayList<Meeting> listMeetings = getMeetings(); ArrayList<Meeting> listMeetings = meetingsController.getMeetings();
int foundCurr = searchMeetingInList(listMeetings, meeting.meetingName); int foundCurr = meetingsController.searchMeetingInList(listMeetings, meeting.meetingName);
if (foundCurr == -1) { if (foundCurr == -1) {
listMeetings.add(meeting); listMeetings.add(meeting);
if (listMeetings.size() == 1) { if (listMeetings.size() == 1) {
setLastMeeting(0); meetingsController.setLastMeeting(0);
} else { } else {
setLastMeeting(listMeetings.size() - 1); meetingsController.setLastMeeting(listMeetings.size() - 1);
} }
} else { } else {
Meeting currMeeting = getMeetings().get(foundCurr); Meeting currMeeting = meetingsController.getMeetings().get(foundCurr);
currMeeting.meetingID = meeting.meetingID; currMeeting.meetingID = meeting.meetingID;
currMeeting.meetingPWD = meeting.meetingPWD; currMeeting.meetingPWD = meeting.meetingPWD;
if (updateAttendee) if (updateAttendee)
currMeeting.updateAttendee(meeting.attendees.get(0).name, meeting.attendees.get(0).num); currMeeting.updateAttendee(meeting.attendees.get(0).name, meeting.attendees.get(0).num);
listMeetings.set(foundCurr, currMeeting); listMeetings.set(foundCurr, currMeeting);
setLastMeeting(foundCurr); meetingsController.setLastMeeting(foundCurr);
} }
saveMeetingList(listMeetings); meetingsController.saveMeetingList(listMeetings);
fillDropdownMeetingName(); fillDropdownMeetingName();
fillDropdownAttendeeName(getLastMeeting()); fillDropdownAttendeeName(meetingsController.getLastMeeting());
Toast.makeText(getApplicationContext(), "Meeting gespeichert", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Meeting gespeichert", Toast.LENGTH_SHORT).show();
} }