forked from mirror/monocles_chat_clean
adds long click menu to about preference to copy either version number or open log viewer
All checks were successful
/ build (push) Successful in 6m59s
All checks were successful
/ build (push) Successful in 6m59s
This commit is contained in:
parent
3fcfe5b12b
commit
2996bd2fe8
6 changed files with 137 additions and 2 deletions
|
|
@ -137,6 +137,7 @@ dependencies {
|
|||
|
||||
implementation 'com.kizitonwose.calendar:view:2.5.4'
|
||||
implementation "io.noties.markwon:core:4.6.2"
|
||||
implementation 'de.thedevstack.android:logviewer:0.0.7'
|
||||
}
|
||||
|
||||
ext {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
app:fragment="eu.siacs.conversations.ui.fragment.settings.UpSettingsFragment"
|
||||
app:summary="@string/unified_push_summary"
|
||||
app:title="@string/unified_push_distributor" />
|
||||
<Preference
|
||||
<de.thedevstack.piratx.ui.PiratXLongClickAboutPreference
|
||||
android:key="about"
|
||||
android:icon="@drawable/monocleslogo_chat_signet"
|
||||
android:title="@string/title_activity_about_x">
|
||||
|
|
@ -58,5 +58,5 @@
|
|||
android:action="android.intent.action.VIEW"
|
||||
android:targetClass="eu.siacs.conversations.ui.AboutActivity"
|
||||
android:targetPackage="@string/applicationId" />
|
||||
</Preference>
|
||||
</de.thedevstack.piratx.ui.PiratXLongClickAboutPreference>
|
||||
</PreferenceScreen>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
<!--activity-alias android:name="de.monocles.chat.RegisterMonoclesActivity"
|
||||
android:targetActivity="de.thedevstack.piratx.ui.PiratXWelcomeActivity"
|
||||
/-->
|
||||
<activity android:name="de.thedevstack.logviewer.LogViewerActivity"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package de.thedevstack.piratx.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListPopupWindow;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.google.android.material.color.MaterialColors;
|
||||
|
||||
import de.thedevstack.logviewer.LogViewerActivity;
|
||||
import eu.siacs.conversations.R;
|
||||
|
||||
public class PiratXLongClickAboutPreference extends Preference {
|
||||
private float lastTouchX;
|
||||
private float lastTouchY;
|
||||
|
||||
public PiratXLongClickAboutPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
holder.itemView.setOnTouchListener((v, event) -> {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
lastTouchX = event.getX();
|
||||
lastTouchY = event.getY();
|
||||
}
|
||||
return false; // Important to fire the long click
|
||||
});
|
||||
|
||||
holder.itemView.setOnLongClickListener(v -> {
|
||||
showPopup(v);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private void showPopup(View anchor) {
|
||||
ListPopupWindow popup = new ListPopupWindow(getContext());
|
||||
|
||||
TextView titleView = new TextView(getContext());
|
||||
titleView.setText(getSummary());
|
||||
titleView.setPadding(32, 24, 32, 24);
|
||||
titleView.setTextSize(14);
|
||||
titleView.setTypeface(null, android.graphics.Typeface.BOLD);
|
||||
int secondaryColor = MaterialColors.getColor(getContext(), com.google.android.material.R.attr.colorSecondary, Color.BLACK);
|
||||
|
||||
titleView.setTextColor(secondaryColor);
|
||||
titleView.setSingleLine(true);
|
||||
titleView.setEllipsize(android.text.TextUtils.TruncateAt.END);
|
||||
|
||||
popup.setPromptView(titleView);
|
||||
popup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
|
||||
|
||||
String[] options = {
|
||||
getContext().getString(R.string.copy),
|
||||
getContext().getString(R.string.action_logs)
|
||||
};
|
||||
popup.setAdapter(new ArrayAdapter<>(getContext(),
|
||||
android.R.layout.simple_list_item_1, options));
|
||||
|
||||
popup.setAnchorView(anchor);
|
||||
popup.setHorizontalOffset((int) lastTouchX);
|
||||
|
||||
popup.setVerticalOffset((int) lastTouchY - anchor.getHeight());
|
||||
|
||||
popup.setWidth(500);
|
||||
popup.setModal(true);
|
||||
|
||||
popup.setOnItemClickListener((parent, view, position, id) -> {
|
||||
if (position == 0) {
|
||||
copyToClipboard();
|
||||
} else if (position == 1) {
|
||||
showLogViewer(view);
|
||||
}
|
||||
popup.dismiss();
|
||||
});
|
||||
|
||||
popup.show();
|
||||
}
|
||||
|
||||
private void showLogViewer(View v) {
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, LogViewerActivity.class);
|
||||
|
||||
if (!(context instanceof Activity)) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
private void copyToClipboard() {
|
||||
CharSequence summary = getSummary();
|
||||
|
||||
if (summary != null) {
|
||||
ClipboardManager clipboard = (ClipboardManager)
|
||||
getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
|
||||
ClipData clip = ClipData.newPlainText("PiratX Version", summary);
|
||||
|
||||
if (clipboard != null) {
|
||||
clipboard.setPrimaryClip(clip);
|
||||
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.copied_to_clipboard, summary), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,4 +24,7 @@
|
|||
<string name="pref_show_avatars_summary">Avatare der Kontakte in allen Chats anzeigen, nicht nur in Gruppenunterhaltungen.</string>
|
||||
<string name="retract_message_fallback">/me hat eine vorherige Nachricht zurückgezogen, Dein Client unterstützt dies nicht.</string>
|
||||
<string name="message_retracted">Diese Nachricht wurde zurückgezogen.</string>
|
||||
<string name="action_logs">Logs</string>
|
||||
<string name="copied_to_clipboard">\"%s\" in Zwischenablage kopiert.</string>
|
||||
<string name="copy">Kopieren</string>
|
||||
</resources>
|
||||
|
|
@ -8,4 +8,7 @@
|
|||
<string name="pref_show_avatars_summary">Display avatars of your contacts in all chats, not only in group chats.</string>
|
||||
<string name="retract_message_fallback">/me retracted a previous message, but it\'s unsupported by your client.</string>
|
||||
<string name="message_retracted">Diese Nachricht wurde zurückgezogen.</string>
|
||||
<string name="action_logs">Logs</string>
|
||||
<string name="copied_to_clipboard">\"%s\" copied to clipboard.</string>
|
||||
<string name="copy">Copy</string>
|
||||
</resources>
|
||||
Loading…
Add table
Add a link
Reference in a new issue