refactoring MainActivity
This commit is contained in:
@@ -4,10 +4,8 @@ import android.annotation.SuppressLint;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
import android.view.View;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.EditText;
|
||||
@@ -27,12 +25,6 @@ import com.github.javiersantos.appupdater.enums.UpdateFrom;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
@@ -43,28 +35,44 @@ import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private boolean testing;
|
||||
private final MeetingsController meetingsController = new MeetingsController(this);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
Intent myIntent = getIntent(); // gets the previously created intent
|
||||
//get intent parameters
|
||||
Intent myIntent = getIntent();
|
||||
String action = myIntent.getAction();
|
||||
String type = myIntent.getType();
|
||||
|
||||
|
||||
String meetingName = myIntent.getStringExtra("meetingName");
|
||||
boolean joinImmediately = myIntent.getBooleanExtra("joinImmediately", false);
|
||||
testing = myIntent.getBooleanExtra("testing", false);
|
||||
|
||||
|
||||
//boolean testing = myIntent.getBooleanExtra("testing", false);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
final ScrollView scrollview = findViewById(R.id.scrollArea);
|
||||
|
||||
//views
|
||||
final ScrollView scrollview = findViewById(R.id.scrollArea);
|
||||
final ImageView saveIcon = findViewById(R.id.imageSave);
|
||||
final ImageView trashIcon = findViewById(R.id.imageTrash);
|
||||
final ImageView AttIcon = findViewById(R.id.imageAttend);
|
||||
final ImageView AddIcon = findViewById(R.id.imageAdd);
|
||||
final EditText meetingID = findViewById(R.id.textBoxID);
|
||||
final ImageView ShareIcon = findViewById(R.id.imageShare);
|
||||
final ImageView ShortcutIcon = findViewById(R.id.imageCreateShortcut);
|
||||
|
||||
//add event listeners to views
|
||||
saveIcon.setOnClickListener(v -> saveMeetingFromUI());
|
||||
trashIcon.setOnClickListener(v -> meetingsController.removeMeeting(meetingsController.searchMeetingInList(meetingsController.getMeetings(), createCurrMeetingFromUI().meetingName)));
|
||||
AttIcon.setOnClickListener(v -> btnJoin_onClick(null));
|
||||
AddIcon.setOnClickListener(v -> {
|
||||
fillBlank();
|
||||
meetingID.requestFocus();
|
||||
});
|
||||
ShareIcon.setOnClickListener(v -> shareMeeting(createCurrMeetingFromUI()));
|
||||
ShortcutIcon.setOnClickListener(v -> showCreateShortcutUI());
|
||||
|
||||
//show alert if meeting from shortcut not found
|
||||
int meetingIndex = meetingsController.searchMeetingInList(meetingsController.getMeetings(), meetingName);
|
||||
if (meetingIndex == -1) {
|
||||
if (meetingName != null) {
|
||||
@@ -77,21 +85,21 @@ public class MainActivity extends AppCompatActivity {
|
||||
joinImmediately = false;
|
||||
}
|
||||
|
||||
//adjust ui for meeting from shortcut
|
||||
if (meetingIndex <= meetingsController.getMeetings().size() && meetingIndex != -1) {
|
||||
meetingsController.setLastMeeting(meetingIndex);
|
||||
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
|
||||
textMeetingName.setEnabled(false);
|
||||
textMeetingName.setAdapter(null);
|
||||
ImageView imageTrash = findViewById(R.id.imageTrash);
|
||||
imageTrash.setVisibility(View.GONE);
|
||||
trashIcon.setVisibility(View.GONE);
|
||||
TextInputLayout layoutMeetingName = findViewById(R.id.layoutMeetingName);
|
||||
layoutMeetingName.setEndIconMode(TextInputLayout.END_ICON_NONE);
|
||||
}
|
||||
|
||||
|
||||
//watchMeetingNameBox();
|
||||
fillDropdownMeetingName();
|
||||
if (meetingsController.getLastMeeting() != -1) {
|
||||
|
||||
//fill ui with data from last selected meeting or show error if config version changed or index out of bounds
|
||||
if (meetingsController.getLastMeeting() != -1) {
|
||||
try {
|
||||
fillMeeting(meetingsController.getLastMeeting());
|
||||
scrollview.post(() -> scrollview.scrollTo(0, scrollview.getChildAt(0).getHeight()));
|
||||
@@ -105,23 +113,20 @@ public class MainActivity extends AppCompatActivity {
|
||||
meetingsController.saveMeetingList(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
watchSaveIcon();
|
||||
watchAttIcon();
|
||||
watchDeleteIcon();
|
||||
watchNewIcon();
|
||||
watchShareIcon();
|
||||
watchShortcutIcon();
|
||||
|
||||
//handle meeting invitation text sent to ZoomHelper
|
||||
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||
if ("text/plain".equals(type)) {
|
||||
handleSendText(myIntent); // Handle text being sent
|
||||
handleSendText(myIntent);
|
||||
}
|
||||
}
|
||||
|
||||
//join meeting immediately, otherwise enable app updater
|
||||
if (joinImmediately) {
|
||||
Meeting currMeeting = meetingsController.getMeetings().get(meetingIndex);
|
||||
new ZoomLink(this, currMeeting).launch();
|
||||
} else {
|
||||
//TODO: updatetest.xml -> update.xml when finished testing
|
||||
AppUpdater appUpdater = new AppUpdater(this).setUpdateFrom(UpdateFrom.XML).setUpdateXML("https://baldaufwd.de/ZoomHelper/updatetest.xml");
|
||||
APKDownloader apkDownloader = new APKDownloader();
|
||||
appUpdater.setButtonUpdateClickListener((dialog, which) -> apkDownloader.downloadAPK(this, "ZoomHelper.apk", Uri.parse("https://baldaufwd.de/ZoomHelper/ZoomHelper.apk")));
|
||||
@@ -131,18 +136,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
//check for importable meeting invitation from clipboard when ZoomHelper gained focus
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
if (hasFocus) {
|
||||
importFromClipboard();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void importFromClipboard() {
|
||||
LinearLayout layoutBegin = findViewById(R.id.layoutBegin);
|
||||
ClipboardManager clipboard = (ClipboardManager) getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
|
||||
final LinearLayout layoutBegin = findViewById(R.id.layoutBegin);
|
||||
final ClipboardManager clipboard = (ClipboardManager) getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
|
||||
|
||||
Snackbar snackbar = Snackbar.make(layoutBegin,R.string.foundImportableMeetingClipboard,Snackbar.LENGTH_INDEFINITE).setDuration(7000);
|
||||
Snackbar snackbar = Snackbar.make(layoutBegin, R.string.foundImportableMeetingClipboard, Snackbar.LENGTH_INDEFINITE).setDuration(7000);
|
||||
snackbar.setAction(R.string.importMeeting, view -> {
|
||||
String text = clipboard.getPrimaryClip().getItemAt(0).getText().toString();
|
||||
handleSendText(text);
|
||||
@@ -176,15 +181,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (sharedText != null) {
|
||||
Matcher matcher = Pattern.compile("(?i)(?<=(Meeting-ID:)|(Meeting\\sID:)|(ID:)).+").matcher(sharedText);
|
||||
if (matcher.find()) {
|
||||
meetingID = matcher.group(0).trim();
|
||||
meetingID = Objects.requireNonNull(matcher.group(0)).trim();
|
||||
}
|
||||
matcher = Pattern.compile("(?i)(?<=(Kenncode:)|(Passwort:)|(Passcode:)|(Password:)).+").matcher(sharedText);
|
||||
if (matcher.find()) {
|
||||
meetingPWD = matcher.group(0).trim();
|
||||
meetingPWD = Objects.requireNonNull(matcher.group(0)).trim();
|
||||
}
|
||||
matcher = Pattern.compile("(?i)(?<=(Thema:)|(Meeting\\sName:)|(Topic:)).+").matcher(sharedText);
|
||||
if (matcher.find()) {
|
||||
meetingName = matcher.group(0).trim();
|
||||
meetingName = Objects.requireNonNull(matcher.group(0)).trim();
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
@@ -193,9 +198,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
if (meetingID.equals("")) {
|
||||
builder.setMessage(R.string.importError);
|
||||
builder.setPositiveButton(R.string.ok, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
builder.setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss());
|
||||
AlertDialog alert = builder.create();
|
||||
if (!checkOnly) alert.show();
|
||||
return false;
|
||||
@@ -226,11 +229,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void watchShortcutIcon() {
|
||||
ImageView ShortcutIcon = findViewById(R.id.imageCreateShortcut);
|
||||
ShortcutIcon.setOnClickListener(v -> showCreateShortcutUI());
|
||||
}
|
||||
|
||||
private void showCreateShortcutUI() {
|
||||
int meeting = meetingsController.searchMeetingInList(meetingsController.getMeetings(), createCurrMeetingFromUI().meetingName);
|
||||
|
||||
@@ -246,11 +244,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
showCreateShortcutUI();
|
||||
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
}
|
||||
else {
|
||||
builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
} else {
|
||||
builder.setMessage(R.string.WantToJoinImmediately);
|
||||
builder.setPositiveButton(R.string.joinImmediately, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
@@ -264,12 +259,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
|
||||
//createMeetingShortcut(searchMeetingInList(getMeetings(), createCurrMeetingFromUI().meetingName), false);
|
||||
}
|
||||
|
||||
private void createMeetingShortcut(int meetingIndex, boolean joinImmediately) {
|
||||
|
||||
Meeting meeting = meetingsController.getMeetings().get(meetingIndex);
|
||||
|
||||
if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
|
||||
@@ -291,12 +283,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void watchShareIcon() {
|
||||
ImageView ShareIcon = findViewById(R.id.imageShare);
|
||||
ShareIcon.setOnClickListener(v -> shareMeeting(createCurrMeetingFromUI()));
|
||||
}
|
||||
|
||||
private void shareMeeting(Meeting meeting) {
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
@@ -307,26 +293,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(shareIntent);
|
||||
}
|
||||
|
||||
private void watchNewIcon() {
|
||||
ImageView AddIcon = findViewById(R.id.imageAdd);
|
||||
EditText meetingID = findViewById(R.id.textBoxID);
|
||||
AddIcon.setOnClickListener(v -> {
|
||||
fillBlank();
|
||||
meetingID.requestFocus();
|
||||
});
|
||||
}
|
||||
|
||||
private void watchAttIcon() {
|
||||
ImageView AttIcon = findViewById(R.id.imageAttend);
|
||||
AttIcon.setOnClickListener(v -> btnJoin_onClick(null));
|
||||
}
|
||||
|
||||
private void watchDeleteIcon() {
|
||||
ImageView trashIcon = findViewById(R.id.imageTrash);
|
||||
trashIcon.setOnClickListener(v -> meetingsController.removeMeeting(meetingsController.searchMeetingInList(meetingsController.getMeetings(), createCurrMeetingFromUI().meetingName)));
|
||||
}
|
||||
|
||||
|
||||
public void fillBlank() {
|
||||
EditText editMeetingName = findViewById(R.id.TextMeetingName);
|
||||
EditText editID = findViewById(R.id.textBoxID);
|
||||
@@ -342,21 +308,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
editAtt.setText("");
|
||||
}
|
||||
|
||||
private void watchSaveIcon() {
|
||||
ImageView saveIcon = findViewById(R.id.imageSave);
|
||||
saveIcon.setOnClickListener(v -> saveMeetingFromUI());
|
||||
}
|
||||
|
||||
public void watchMeetingNameBox() {
|
||||
EditText meetingNameBox = findViewById(R.id.TextMeetingName);
|
||||
meetingNameBox.setOnFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus) {
|
||||
fillWithSelectedMeeting();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void fillWithSelectedMeeting() {
|
||||
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
|
||||
int search = meetingsController.searchMeetingInList(meetingsController.getMeetings(), textMeetingName.getText().toString());
|
||||
@@ -395,19 +346,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
AutoCompleteTextView textName = findViewById(R.id.textBoxName);
|
||||
//ImageView dropdown = findViewById(R.id.iconDropdownAttName);
|
||||
AutoSuggestAdapter adapter = new AutoSuggestAdapter(this, android.R.layout.simple_dropdown_item_1line);
|
||||
|
||||
adapter.setData(Arrays.asList(attNames));
|
||||
textName.setAdapter(adapter);
|
||||
|
||||
textName.setOnTouchListener((paramView, paramMotionEvent) -> false);
|
||||
|
||||
textName.setOnItemClickListener((arg0, view, arg2, arg3) -> fillWithSelectedAtt(meetingIndex));
|
||||
|
||||
/*dropdown.setOnClickListener(v -> {
|
||||
textName.showDropDown();
|
||||
adapter.getFilter().filter(null);
|
||||
});*/
|
||||
}
|
||||
|
||||
private void fillWithSelectedAtt(int meetingIndex) {
|
||||
@@ -417,7 +363,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
editAtt.setText(meetingsController.getMeetings().get(meetingIndex).attendees.get(found).num);
|
||||
}
|
||||
|
||||
|
||||
public void fillMeeting(Meeting meeting) {
|
||||
EditText editMeetingName = findViewById(R.id.TextMeetingName);
|
||||
EditText editID = findViewById(R.id.textBoxID);
|
||||
@@ -441,7 +386,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
fillDropdownAttendeeName(id);
|
||||
}
|
||||
|
||||
|
||||
public void btnSave_onClick(View view) {
|
||||
saveMeetingFromUI();
|
||||
}
|
||||
@@ -462,7 +406,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
return new Meeting(editMeetingName.getText().toString(), editID.getText().toString(), editPW.getText().toString(), editName.getText().toString(), editAtt.getText().toString());
|
||||
}
|
||||
|
||||
|
||||
public void importMeeting(Meeting meeting, boolean updateAttendee) {
|
||||
ArrayList<Meeting> listMeetings = meetingsController.getMeetings();
|
||||
int foundCurr = meetingsController.searchMeetingInList(listMeetings, meeting.meetingName);
|
||||
@@ -486,7 +429,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
meetingsController.saveMeetingList(listMeetings);
|
||||
fillDropdownMeetingName();
|
||||
fillDropdownAttendeeName(meetingsController.getLastMeeting());
|
||||
Toast.makeText(getApplicationContext(), "Meeting gespeichert", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getApplicationContext(), R.string.meetingSaved, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
public void importMeeting(Meeting meeting) {
|
||||
@@ -499,7 +442,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (currMeetingUI.meetingID.equals("")) {
|
||||
EditText editID = findViewById(R.id.textBoxID);
|
||||
editID.requestFocus();
|
||||
editID.setError("Meeting kann nicht ohne ID gespeichert werden!");
|
||||
editID.setError(getString(R.string.meetingWithoutID));
|
||||
return;
|
||||
} else if (currMeetingUI.meetingName.equals("")) {
|
||||
EditText editMName = findViewById(R.id.TextMeetingName);
|
||||
@@ -508,5 +451,4 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
importMeeting(currMeetingUI);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user