built MeetingsController into MainActivity
This commit is contained in:
@@ -43,7 +43,8 @@ import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public boolean testing;
|
||||
private boolean testing;
|
||||
private final MeetingsController meetingsController = new MeetingsController(this);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -64,8 +65,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_main);
|
||||
final ScrollView scrollview = findViewById(R.id.scrollArea);
|
||||
|
||||
|
||||
int meetingIndex = searchMeetingInList(getMeetings(), meetingName);
|
||||
int meetingIndex = meetingsController.searchMeetingInList(meetingsController.getMeetings(), meetingName);
|
||||
if (meetingIndex == -1) {
|
||||
if (meetingName != null) {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
||||
@@ -77,8 +77,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
joinImmediately = false;
|
||||
}
|
||||
|
||||
if (meetingIndex <= getMeetings().size() && meetingIndex != -1) {
|
||||
setLastMeeting(meetingIndex);
|
||||
if (meetingIndex <= meetingsController.getMeetings().size() && meetingIndex != -1) {
|
||||
meetingsController.setLastMeeting(meetingIndex);
|
||||
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
|
||||
textMeetingName.setEnabled(false);
|
||||
textMeetingName.setAdapter(null);
|
||||
@@ -91,9 +91,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
//watchMeetingNameBox();
|
||||
fillDropdownMeetingName();
|
||||
if (getLastMeeting() != -1) {
|
||||
if (meetingsController.getLastMeeting() != -1) {
|
||||
try {
|
||||
fillMeeting(getLastMeeting());
|
||||
fillMeeting(meetingsController.getLastMeeting());
|
||||
scrollview.post(() -> scrollview.scrollTo(0, scrollview.getChildAt(0).getHeight()));
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
||||
@@ -101,8 +101,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
dialog.setTitle(R.string.hint);
|
||||
AlertDialog alertDialog = dialog.create();
|
||||
alertDialog.show();
|
||||
setLastMeeting(-1);
|
||||
saveMeetingList(new ArrayList<>());
|
||||
meetingsController.setLastMeeting(-1);
|
||||
meetingsController.saveMeetingList(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
watchSaveIcon();
|
||||
@@ -119,9 +119,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
if (joinImmediately) {
|
||||
Meeting currMeeting = getMeetings().get(meetingIndex);
|
||||
String url = buildZoomURL(currMeeting.meetingID, currMeeting.meetingPWD, currMeeting.attendees.get(currMeeting.lastAtt).name, currMeeting.attendees.get(currMeeting.lastAtt).num);
|
||||
launchZoomUrl(url);
|
||||
Meeting currMeeting = meetingsController.getMeetings().get(meetingIndex);
|
||||
new ZoomLink(this, currMeeting).launch();
|
||||
} else {
|
||||
AppUpdater appUpdater = new AppUpdater(this).setUpdateFrom(UpdateFrom.XML).setUpdateXML("https://baldaufwd.de/ZoomHelper/updatetest.xml");
|
||||
APKDownloader apkDownloader = new APKDownloader();
|
||||
@@ -204,11 +203,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
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);
|
||||
} else {
|
||||
builder.setPositiveButton(R.string.override, (dialog, which) -> {
|
||||
int found = searchMeetingInList(getMeetings(), mtgToImport.meetingName);
|
||||
int found = meetingsController.searchMeetingInList(meetingsController.getMeetings(), mtgToImport.meetingName);
|
||||
importMeeting(mtgToImport, false);
|
||||
fillMeeting(found);
|
||||
dialog.dismiss();
|
||||
@@ -233,7 +232,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void showCreateShortcutUI() {
|
||||
int meeting = searchMeetingInList(getMeetings(), createCurrMeetingFromUI().meetingName);
|
||||
int meeting = meetingsController.searchMeetingInList(meetingsController.getMeetings(), createCurrMeetingFromUI().meetingName);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
|
||||
@@ -271,7 +270,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private void createMeetingShortcut(int meetingIndex, boolean joinImmediately) {
|
||||
|
||||
Meeting meeting = getMeetings().get(meetingIndex);
|
||||
Meeting meeting = meetingsController.getMeetings().get(meetingIndex);
|
||||
|
||||
if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
|
||||
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, meeting.meetingName)
|
||||
@@ -324,46 +323,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private void watchDeleteIcon() {
|
||||
ImageView trashIcon = findViewById(R.id.imageTrash);
|
||||
trashIcon.setOnClickListener(v -> removeMeeting(searchMeetingInList(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();
|
||||
|
||||
}
|
||||
trashIcon.setOnClickListener(v -> meetingsController.removeMeeting(meetingsController.searchMeetingInList(meetingsController.getMeetings(), createCurrMeetingFromUI().meetingName)));
|
||||
}
|
||||
|
||||
|
||||
@@ -399,7 +359,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public void fillWithSelectedMeeting() {
|
||||
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) {
|
||||
fillMeeting(search);
|
||||
}
|
||||
@@ -407,7 +367,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
public void fillDropdownMeetingName() {
|
||||
ArrayList<Meeting> meetings = getMeetings();
|
||||
ArrayList<Meeting> meetings = meetingsController.getMeetings();
|
||||
|
||||
String[] meetingNames = new String[meetings.size()];
|
||||
for (int i = 0; i < meetings.size(); i++) {
|
||||
@@ -415,7 +375,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
|
||||
//ImageView dropdown = findViewById(R.id.iconDropdownMeetingName);
|
||||
AutoSuggestAdapter adapter = new AutoSuggestAdapter(this, android.R.layout.simple_dropdown_item_1line);
|
||||
adapter.setData(Arrays.asList(meetingNames));
|
||||
textMeetingName.setAdapter(adapter);
|
||||
@@ -423,16 +382,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
textMeetingName.setOnTouchListener((paramView, paramMotionEvent) -> false);
|
||||
|
||||
textMeetingName.setOnItemClickListener((arg0, view, arg2, arg3) -> fillWithSelectedMeeting());
|
||||
|
||||
/*dropdown.setOnClickListener(v -> {
|
||||
textMeetingName.showDropDown();
|
||||
adapter.getFilter().filter(null);
|
||||
});*/
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
public void fillDropdownAttendeeName(int meetingIndex) {
|
||||
Meeting meeting = getMeetings().get(meetingIndex);
|
||||
Meeting meeting = meetingsController.getMeetings().get(meetingIndex);
|
||||
ArrayList<Attendee> attendees = meeting.attendees;
|
||||
|
||||
String[] attNames = new String[attendees.size()];
|
||||
@@ -459,8 +413,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
private void fillWithSelectedAtt(int meetingIndex) {
|
||||
AutoCompleteTextView textName = findViewById(R.id.textBoxName);
|
||||
EditText editAtt = findViewById(R.id.editAtt);
|
||||
int found = getMeetings().get(meetingIndex).searchAttendee(textName.getText().toString());
|
||||
editAtt.setText(getMeetings().get(meetingIndex).attendees.get(found).num);
|
||||
int found = meetingsController.getMeetings().get(meetingIndex).searchAttendee(textName.getText().toString());
|
||||
editAtt.setText(meetingsController.getMeetings().get(meetingIndex).attendees.get(found).num);
|
||||
}
|
||||
|
||||
|
||||
@@ -483,155 +437,19 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
public void fillMeeting(int id) {
|
||||
fillMeeting(getMeetings().get(id));
|
||||
fillMeeting(meetingsController.getMeetings().get(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) {
|
||||
saveMeetingFromUI();
|
||||
}
|
||||
|
||||
|
||||
public void btnJoin_onClick(View view) {
|
||||
saveMeetingFromUI();
|
||||
Meeting currMeeting = createCurrMeetingFromUI();
|
||||
String url = buildZoomURL(currMeeting.meetingID, currMeeting.meetingPWD, currMeeting.attendees.get(currMeeting.lastAtt).name, currMeeting.attendees.get(currMeeting.lastAtt).num);
|
||||
launchZoomUrl(url);
|
||||
new ZoomLink(this, currMeeting).launch();
|
||||
}
|
||||
|
||||
public Meeting createCurrMeetingFromUI() {
|
||||
@@ -646,28 +464,28 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
public void importMeeting(Meeting meeting, boolean updateAttendee) {
|
||||
ArrayList<Meeting> listMeetings = getMeetings();
|
||||
int foundCurr = searchMeetingInList(listMeetings, meeting.meetingName);
|
||||
ArrayList<Meeting> listMeetings = meetingsController.getMeetings();
|
||||
int foundCurr = meetingsController.searchMeetingInList(listMeetings, meeting.meetingName);
|
||||
if (foundCurr == -1) {
|
||||
listMeetings.add(meeting);
|
||||
if (listMeetings.size() == 1) {
|
||||
setLastMeeting(0);
|
||||
meetingsController.setLastMeeting(0);
|
||||
} else {
|
||||
setLastMeeting(listMeetings.size() - 1);
|
||||
meetingsController.setLastMeeting(listMeetings.size() - 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
Meeting currMeeting = getMeetings().get(foundCurr);
|
||||
Meeting currMeeting = meetingsController.getMeetings().get(foundCurr);
|
||||
currMeeting.meetingID = meeting.meetingID;
|
||||
currMeeting.meetingPWD = meeting.meetingPWD;
|
||||
if (updateAttendee)
|
||||
currMeeting.updateAttendee(meeting.attendees.get(0).name, meeting.attendees.get(0).num);
|
||||
listMeetings.set(foundCurr, currMeeting);
|
||||
setLastMeeting(foundCurr);
|
||||
meetingsController.setLastMeeting(foundCurr);
|
||||
}
|
||||
saveMeetingList(listMeetings);
|
||||
meetingsController.saveMeetingList(listMeetings);
|
||||
fillDropdownMeetingName();
|
||||
fillDropdownAttendeeName(getLastMeeting());
|
||||
fillDropdownAttendeeName(meetingsController.getLastMeeting());
|
||||
Toast.makeText(getApplicationContext(), "Meeting gespeichert", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user