better creation and handling of shortcuts

This commit is contained in:
2021-03-26 19:56:45 +01:00
parent 7bd15b4740
commit acf6f34dde
2 changed files with 93 additions and 41 deletions
@@ -34,6 +34,7 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
@@ -42,6 +43,7 @@ class InstantAutoComplete extends androidx.appcompat.widget.AppCompatAutoComplet
public InstantAutoComplete(Context context) {
super(context);
}
public InstantAutoComplete(Context arg0, AttributeSet arg1) {
super(arg0, arg1);
}
@@ -49,6 +51,7 @@ class InstantAutoComplete extends androidx.appcompat.widget.AppCompatAutoComplet
public InstantAutoComplete(Context arg0, AttributeSet arg1, int arg2) {
super(arg0, arg1, arg2);
}
@Override
public boolean enoughToFilter() {
return false;
@@ -57,19 +60,45 @@ class InstantAutoComplete extends androidx.appcompat.widget.AppCompatAutoComplet
}
public class MainActivity extends AppCompatActivity {
public boolean testing;
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent myIntent = getIntent(); // gets the previously created intent
int meetingIndex = myIntent.getIntExtra("meetingIndex", -1);
String meetingName = myIntent.getStringExtra("meetingName");
boolean joinImmediately = myIntent.getBooleanExtra("joinImmediately", false);
testing = myIntent.getBooleanExtra("testing", false);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ScrollView scrollview = findViewById(R.id.scrollArea);
int meetingIndex = searchMeetingInList(getMeetings(), meetingName);
if (meetingIndex == -1) {
if (meetingName != null) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage(R.string.shortcutLaunchFailedText);
dialog.setTitle(R.string.hint);
AlertDialog alertDialog = dialog.create();
alertDialog.show();
}
joinImmediately = false;
}
if (meetingIndex <= getMeetings().size() && meetingIndex != -1) {
setLastMeeting(meetingIndex);
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
textMeetingName.setEnabled(false);
textMeetingName.setAdapter(null);
ImageView imageTrash = findViewById(R.id.imageTrash);
imageTrash.setVisibility(View.GONE);
TextInputLayout layoutMeetingName = findViewById(R.id.layoutMeetingName);
layoutMeetingName.setEndIconMode(TextInputLayout.END_ICON_NONE);
}
watchMeetingNameBox();
@@ -78,8 +107,7 @@ public class MainActivity extends AppCompatActivity {
try {
fillMeeting(getLastMeeting());
scrollview.post(() -> scrollview.scrollTo(0, scrollview.getChildAt(0).getHeight()));
}
catch (IndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage(R.string.resetDataText);
dialog.setTitle(R.string.hint);
@@ -97,41 +125,61 @@ public class MainActivity extends AppCompatActivity {
watchShortcutIcon();
if (meetingIndex <= getMeetings().size() && meetingIndex != -1) {
setLastMeeting(meetingIndex);
AutoCompleteTextView textMeetingName = findViewById(R.id.TextMeetingName);
textMeetingName.setEnabled(false);
textMeetingName.setAdapter(null);
ImageView imageTrash = findViewById(R.id.imageTrash);
imageTrash.setVisibility(View.GONE);
TextInputLayout layoutMeetingName = findViewById(R.id.layoutMeetingName);
layoutMeetingName.setEndIconMode(TextInputLayout.END_ICON_NONE);
}
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);
} else {
AppUpdater appUpdater = new AppUpdater(this).setUpdateFrom(UpdateFrom.XML).setUpdateXML("https://baldaufwd.de/ZoomHelper/update.xml");
appUpdater.start();
}
}
private void watchShortcutIcon() {
ImageView ShortcutIcon = findViewById(R.id.imageCreateShortcut);
ShortcutIcon.setOnClickListener(v -> createMeetingShortcut(searchMeetingInList(getMeetings(), createCurrMeetingFromUI().meetingName)));
ShortcutIcon.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name);
builder.setMessage(R.string.WantToJoinImmediately);
builder.setPositiveButton(R.string.joinImmediately, (dialog, which) -> {
dialog.dismiss();
createMeetingShortcut(searchMeetingInList(getMeetings(), createCurrMeetingFromUI().meetingName), true);
});
builder.setNegativeButton(R.string.alwaysAsk, (dialog, which) -> {
dialog.dismiss();
createMeetingShortcut(searchMeetingInList(getMeetings(), createCurrMeetingFromUI().meetingName), false);
});
AlertDialog alert = builder.create();
alert.show();
//createMeetingShortcut(searchMeetingInList(getMeetings(), createCurrMeetingFromUI().meetingName), false);
});
}
private void createMeetingShortcut(int meetingIndex) {
private void createMeetingShortcut(int meetingIndex, boolean joinImmediately) {
Meeting meeting = getMeetings().get(meetingIndex);
if (ShortcutManagerCompat.isRequestPinShortcutSupported(this)) {
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, "#1")
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(this, meeting.meetingName)
.setShortLabel(meeting.meetingName)
.setLongLabel(meeting.meetingName)
.setIcon(IconCompat.createWithResource(this, R.mipmap.ic_launcher))
.setIntents(new Intent[]{
new Intent(this, MainActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
.putExtra("meetingIndex", meetingIndex)
.putExtra("meetingName", meeting.meetingName)
.putExtra("joinImmediately", joinImmediately)
.setAction("LOCATION_SHORTCUT"),
})
.build();
@@ -142,7 +190,6 @@ public class MainActivity extends AppCompatActivity {
}
private void watchShareIcon() {
ImageView ShareIcon = findViewById(R.id.imageShare);
ShareIcon.setOnClickListener(v -> shareMeeting(createCurrMeetingFromUI()));
@@ -340,6 +387,7 @@ public class MainActivity extends AppCompatActivity {
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);
@@ -347,6 +395,7 @@ public class MainActivity extends AppCompatActivity {
AlertDialog alertDialog = dialog.create();
alertDialog.show();
}
}
private String buildZoomURL(String confno, String pwd, String name, String attendees) {
@@ -498,8 +547,7 @@ public class MainActivity extends AppCompatActivity {
editID.requestFocus();
editID.setError("Meeting kann nicht ohne ID gespeichert werden!");
return;
}
else if (currMeetingUI.meetingName.equals("")) {
} else if (currMeetingUI.meetingName.equals("")) {
EditText editMName = findViewById(R.id.TextMeetingName);
editMName.setText(currMeetingUI.meetingID);
currMeetingUI.meetingName = currMeetingUI.meetingID;
+4
View File
@@ -22,5 +22,9 @@
<string name="idHint">Meeting ID</string>
<string name="shortcutTooltip">Direkte Verknüpfung zum gewählten Meeting erstellen</string>
<string name="ShortcutError">Dein Launcher unterstützt leider keine direkten Verknüpfungen</string>
<string name="shortcutLaunchFailedText">Das verknüpfte Meeting wurde nicht gefunden, da es zuvor gelöscht wurde</string>
<string name="WantToJoinImmediately">Wähle das Verhalten beim Öffnen der Verknüpfung aus</string>
<string name="joinImmediately">sofort beitreten</string>
<string name="alwaysAsk">Dialog immer anzeigen</string>
</resources>