added custom confirm dialog layout

Signed-off-by: nuclearfog <hatespirit666@gmail.com>
This commit is contained in:
nuclearfog 2021-10-24 15:32:47 +02:00
parent b28e675083
commit 0bfbd410c3
No known key found for this signature in database
GPG Key ID: AA0271FBE406DB98
10 changed files with 186 additions and 108 deletions

View File

@ -1,5 +1,10 @@
package org.nuclearfog.twidda.activity; package org.nuclearfog.twidda.activity;
import static android.os.AsyncTask.Status.RUNNING;
import static org.nuclearfog.twidda.activity.ListDetail.RET_LIST_CHANGED;
import static org.nuclearfog.twidda.activity.ListDetail.RET_LIST_DATA;
import static org.nuclearfog.twidda.activity.UserLists.RET_LIST_CREATED;
import android.app.Dialog; import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -13,7 +18,6 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
@ -30,11 +34,6 @@ import org.nuclearfog.twidda.dialog.ConfirmDialog.OnConfirmListener;
import org.nuclearfog.twidda.dialog.ProgressDialog; import org.nuclearfog.twidda.dialog.ProgressDialog;
import org.nuclearfog.twidda.dialog.ProgressDialog.OnProgressStopListener; import org.nuclearfog.twidda.dialog.ProgressDialog.OnProgressStopListener;
import static android.os.AsyncTask.Status.RUNNING;
import static org.nuclearfog.twidda.activity.ListDetail.RET_LIST_CHANGED;
import static org.nuclearfog.twidda.activity.ListDetail.RET_LIST_DATA;
import static org.nuclearfog.twidda.activity.UserLists.RET_LIST_CREATED;
/** /**
* Activity for the list editor * Activity for the list editor
* *
@ -51,7 +50,7 @@ public class ListEditor extends AppCompatActivity implements OnClickListener, On
private EditText titleInput, subTitleInput; private EditText titleInput, subTitleInput;
private CompoundButton visibility; private CompoundButton visibility;
private Dialog leaveDialog, loadingCircle; private Dialog leaveDialog, loadingCircle;
private AlertDialog errorDialog; private ConfirmDialog errorDialog;
@Nullable @Nullable
private TwitterList userList; private TwitterList userList;

View File

@ -1,5 +1,13 @@
package org.nuclearfog.twidda.activity; package org.nuclearfog.twidda.activity;
import static android.os.AsyncTask.Status.RUNNING;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.Toast.LENGTH_SHORT;
import static org.nuclearfog.twidda.activity.MediaViewer.KEY_MEDIA_LINK;
import static org.nuclearfog.twidda.activity.MediaViewer.KEY_MEDIA_TYPE;
import static org.nuclearfog.twidda.activity.MediaViewer.MEDIAVIEWER_IMAGE;
import android.app.Dialog; import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.location.Location; import android.location.Location;
@ -13,7 +21,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.MessageUpdater; import org.nuclearfog.twidda.backend.MessageUpdater;
@ -27,14 +34,6 @@ import org.nuclearfog.twidda.dialog.ConfirmDialog.OnConfirmListener;
import org.nuclearfog.twidda.dialog.ProgressDialog; import org.nuclearfog.twidda.dialog.ProgressDialog;
import org.nuclearfog.twidda.dialog.ProgressDialog.OnProgressStopListener; import org.nuclearfog.twidda.dialog.ProgressDialog.OnProgressStopListener;
import static android.os.AsyncTask.Status.RUNNING;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.Toast.LENGTH_SHORT;
import static org.nuclearfog.twidda.activity.MediaViewer.KEY_MEDIA_LINK;
import static org.nuclearfog.twidda.activity.MediaViewer.KEY_MEDIA_TYPE;
import static org.nuclearfog.twidda.activity.MediaViewer.MEDIAVIEWER_IMAGE;
/** /**
* Direct message popup activity * Direct message popup activity
* *
@ -51,8 +50,8 @@ public class MessageEditor extends MediaActivity implements OnClickListener, OnC
private EditText receiver, message; private EditText receiver, message;
private ImageButton media, preview; private ImageButton media, preview;
private Dialog loadingCircle, leaveDialog; private Dialog loadingCircle;
private AlertDialog errorDialog; private ConfirmDialog errorDialog, leaveDialog;
@Nullable @Nullable
private String mediaPath; private String mediaPath;

View File

@ -28,7 +28,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet; import androidx.constraintlayout.widget.ConstraintSet;
@ -71,8 +70,8 @@ public class ProfileEditor extends MediaActivity implements OnClickListener, OnP
private ImageView profile_image, profile_banner, toolbar_background, changeBannerBtn; private ImageView profile_image, profile_banner, toolbar_background, changeBannerBtn;
private EditText name, link, loc, bio; private EditText name, link, loc, bio;
private Button addBannerBtn; private Button addBannerBtn;
private Dialog loadingCircle, closeDialog; private Dialog loadingCircle;
private AlertDialog errorDialog; private ConfirmDialog errorDialog, closeDialog;
private User user; private User user;
private String profileLink, bannerLink; private String profileLink, bannerLink;

View File

@ -24,7 +24,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.TweetUpdater; import org.nuclearfog.twidda.backend.TweetUpdater;
@ -84,8 +83,8 @@ public class TweetEditor extends MediaActivity implements OnClickListener, OnPro
private GlobalSettings settings; private GlobalSettings settings;
private ImageButton mediaBtn, previewBtn, locationBtn; private ImageButton mediaBtn, previewBtn, locationBtn;
private AlertDialog errorDialog; private ConfirmDialog errorDialog, closingDialog;
private Dialog loadingCircle, closingDialog; private Dialog loadingCircle;
private EditText tweetText; private EditText tweetText;
private View locationPending; private View locationPending;

View File

@ -1,16 +1,14 @@
package org.nuclearfog.twidda.dialog; package org.nuclearfog.twidda.dialog;
import static android.util.TypedValue.COMPLEX_UNIT_SP; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.view.View;
import android.content.DialogInterface.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.database.GlobalSettings; import org.nuclearfog.twidda.database.GlobalSettings;
/** /**
@ -18,7 +16,7 @@ import org.nuclearfog.twidda.database.GlobalSettings;
* *
* @author nuclearfog * @author nuclearfog
*/ */
public class ConfirmDialog extends AlertDialog implements OnClickListener { public class ConfirmDialog extends Dialog implements OnClickListener {
/** /**
* types of dialogs, every dialog has its own message and title * types of dialogs, every dialog has its own message and title
@ -46,6 +44,9 @@ public class ConfirmDialog extends AlertDialog implements OnClickListener {
LIST_EDITOR_ERROR LIST_EDITOR_ERROR
} }
private TextView txtTitle, txtMessage;
private Button confirm, cancel;
private DialogType type; private DialogType type;
private OnConfirmListener listener; private OnConfirmListener listener;
@ -54,7 +55,22 @@ public class ConfirmDialog extends AlertDialog implements OnClickListener {
* @param listener listener for the confirmation button * @param listener listener for the confirmation button
*/ */
public ConfirmDialog(Context context, DialogType type, OnConfirmListener listener) { public ConfirmDialog(Context context, DialogType type, OnConfirmListener listener) {
super(context); super(context, R.style.ConfirmDialog);
setContentView(R.layout.dialog_confirm);
View root = findViewById(R.id.confirm_rootview);
confirm = findViewById(R.id.confirm_yes);
cancel = findViewById(R.id.confirm_no);
txtTitle = findViewById(R.id.confirm_title);
txtMessage = findViewById(R.id.confirm_message);
confirm.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check, 0, 0, 0);
cancel.setCompoundDrawablesWithIntrinsicBounds(R.drawable.cross, 0, 0, 0);
GlobalSettings settings = GlobalSettings.getInstance(context);
AppStyles.setTheme(settings, root);
confirm.setOnClickListener(this);
cancel.setOnClickListener(this);
this.type = type; this.type = type;
this.listener = listener; this.listener = listener;
build(); build();
@ -62,143 +78,120 @@ public class ConfirmDialog extends AlertDialog implements OnClickListener {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(View v) {
if (which == BUTTON_POSITIVE) { if (v.getId() == R.id.confirm_yes) {
listener.onConfirm(type); listener.onConfirm(type);
dismiss();
} else if (v.getId() == R.id.confirm_no) {
dismiss();
} }
} }
/**
@Override * set message text
public void show() { *
super.show(); * @param message message text
setTheme(); */
public void setMessage(String message) {
txtMessage.setText(message);
} }
/** /**
* creates an alert dialog * creates an alert dialog
*/ */
private void build() { private void build() {
Context c = getContext();
String posButton = c.getString(R.string.dialog_button_yes);
String negButton = c.getString(R.string.dialog_button_no);
String message = "";
String title = "";
switch (type) { switch (type) {
case MESSAGE_DELETE: case MESSAGE_DELETE:
message = c.getString(R.string.confirm_delete_message); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_delete_message);
break; break;
case WRONG_PROXY: case WRONG_PROXY:
title = c.getString(R.string.info_error); txtTitle.setText(R.string.info_error);
message = c.getString(R.string.error_wrong_connection_settings); txtMessage.setText(R.string.error_wrong_connection_settings);
posButton = c.getString(R.string.dialog_button_cancel); confirm.setText(R.string.dialog_button_cancel);
negButton = c.getString(R.string.confirm_back); cancel.setText(R.string.confirm_back);
break; break;
case DEL_DATABASE: case DEL_DATABASE:
message = c.getString(R.string.confirm_delete_database); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_delete_database);
break; break;
case APP_LOG_OUT: case APP_LOG_OUT:
message = c.getString(R.string.confirm_log_lout); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_log_lout);
break; break;
case LIST_EDITOR_LEAVE: case LIST_EDITOR_LEAVE:
case PROFILE_EDITOR_LEAVE: case PROFILE_EDITOR_LEAVE:
message = c.getString(R.string.confirm_discard); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_discard);
break; break;
case TWEET_EDITOR_LEAVE: case TWEET_EDITOR_LEAVE:
message = c.getString(R.string.confirm_cancel_tweet); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_cancel_tweet);
break; break;
case LIST_EDITOR_ERROR: case LIST_EDITOR_ERROR:
case MESSAGE_EDITOR_ERROR: case MESSAGE_EDITOR_ERROR:
case TWEET_EDITOR_ERROR: case TWEET_EDITOR_ERROR:
case PROFILE_EDITOR_ERROR: case PROFILE_EDITOR_ERROR:
title = c.getString(R.string.info_error); txtTitle.setText(R.string.info_error);
posButton = c.getString(R.string.confirm_retry_button); confirm.setText(R.string.confirm_retry_button);
negButton = c.getString(R.string.dialog_button_cancel); cancel.setText(R.string.dialog_button_cancel);
break; break;
case MESSAGE_EDITOR_LEAVE: case MESSAGE_EDITOR_LEAVE:
message = c.getString(R.string.confirm_cancel_message); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_cancel_message);
break; break;
case TWEET_DELETE: case TWEET_DELETE:
message = c.getString(R.string.confirm_delete_tweet); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_delete_tweet);
break; break;
case PROFILE_UNFOLLOW: case PROFILE_UNFOLLOW:
message = c.getString(R.string.confirm_unfollow); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_unfollow);
break; break;
case PROFILE_BLOCK: case PROFILE_BLOCK:
message = c.getString(R.string.confirm_block); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_block);
break; break;
case PROFILE_MUTE: case PROFILE_MUTE:
message = c.getString(R.string.confirm_mute); txtTitle.setVisibility(View.GONE);
txtMessage.setText(R.string.confirm_mute);
break; break;
case LIST_REMOVE_USER: case LIST_REMOVE_USER:
message = c.getString(R.string.confirm_remove_user_from_list); txtTitle.setVisibility(View.GONE);
posButton = c.getString(R.string.dialog_button_ok); txtMessage.setText(R.string.confirm_remove_user_from_list);
negButton = c.getString(R.string.dialog_button_cancel); confirm.setText(R.string.dialog_button_ok);
cancel.setText(R.string.dialog_button_cancel);
break; break;
case LIST_UNFOLLOW: case LIST_UNFOLLOW:
message = c.getString(R.string.confirm_unfollow_list); txtMessage.setText(R.string.confirm_unfollow_list);
txtTitle.setVisibility(View.GONE);
break; break;
case LIST_DELETE: case LIST_DELETE:
message = c.getString(R.string.confirm_delete_list); txtMessage.setText(R.string.confirm_delete_list);
txtTitle.setVisibility(View.GONE);
break; break;
case REMOVE_ACCOUNT: case REMOVE_ACCOUNT:
message = c.getString(R.string.confirm_remove_account); txtMessage.setText(R.string.confirm_remove_account);
posButton = c.getString(R.string.dialog_button_ok); confirm.setText(R.string.dialog_button_ok);
negButton = c.getString(R.string.dialog_button_cancel); cancel.setText(R.string.dialog_button_cancel);
txtTitle.setVisibility(View.GONE);
break; break;
} }
setTitle(title);
setMessage(message);
setButton(BUTTON_NEGATIVE, negButton, this);
setButton(BUTTON_POSITIVE, posButton, this);
}
/**
*
*/
private void setTheme() {
GlobalSettings settings = GlobalSettings.getInstance(getContext());
TextView message = findViewById(android.R.id.message);
TextView title = findViewById(android.R.id.title);
Button button1 = findViewById(android.R.id.button1);
Button button2 = findViewById(android.R.id.button2);
if (getWindow() != null) {
getWindow().getDecorView().setBackgroundColor(settings.getBackgroundColor());
}
if (message != null) {
message.setTypeface(settings.getTypeFace());
message.setTextColor(settings.getFontColor());
message.setTextSize(COMPLEX_UNIT_SP, 20);
}
if (title != null) {
title.setTypeface(settings.getTypeFace());
title.setTextColor(settings.getFontColor());
}
if (button1 != null) {
button1.setTypeface(settings.getTypeFace());
button1.setTextColor(settings.getFontColor());
}
if (button2 != null) {
button2.setTypeface(settings.getTypeFace());
button2.setTextColor(settings.getFontColor());
}
} }
/** /**

View File

@ -5,7 +5,6 @@ import static org.nuclearfog.twidda.activity.AccountActivity.RET_ACCOUNT_CHANGE;
import static org.nuclearfog.twidda.dialog.ConfirmDialog.DialogType; import static org.nuclearfog.twidda.dialog.ConfirmDialog.DialogType;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import org.nuclearfog.twidda.adapter.AccountAdapter; import org.nuclearfog.twidda.adapter.AccountAdapter;
import org.nuclearfog.twidda.adapter.AccountAdapter.OnAccountClickListener; import org.nuclearfog.twidda.adapter.AccountAdapter.OnAccountClickListener;
@ -30,7 +29,7 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
private AccountLoader loginTask; private AccountLoader loginTask;
private GlobalSettings settings; private GlobalSettings settings;
private AccountAdapter adapter; private AccountAdapter adapter;
private AlertDialog dialog; private ConfirmDialog dialog;
private Account selection; private Account selection;

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M8.294,16.998c-0.435,0 -0.847,-0.203 -1.111,-0.553L3.61,11.724c-0.465,-0.613 -0.344,-1.486 0.27,-1.951c0.615,-0.467 1.488,-0.344 1.953,0.27l2.351,3.104l5.911,-9.492c0.407,-0.652 1.267,-0.852 1.921,-0.445c0.653,0.406 0.854,1.266 0.446,1.92L9.478,16.34c-0.242,0.391 -0.661,0.635 -1.12,0.656C8.336,16.998 8.316,16.998 8.294,16.998z"
android:fillColor="#FFFFFF" />
</vector>

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/confirm_rootview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/confirm_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_marginLeft="@dimen/confirm_text_margin"
android:layout_marginStart="@dimen/confirm_text_margin"
android:layout_marginTop="@dimen/confirm_text_margin"
android:layout_marginRight="@dimen/confirm_text_margin"
android:layout_marginEnd="@dimen/confirm_text_margin"
android:textSize="@dimen/confirm_title_fontsize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/confirm_message"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/confirm_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/confirm_text_margin"
android:textSize="@dimen/confirm_message_fontsize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/confirm_title"
app:layout_constraintBottom_toTopOf="@id/confirm_barrier"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/confirm_barrier"
android:layout_width="0dp"
android:layout_height="0dp"
app:barrierDirection="top"
app:constraint_referenced_ids="confirm_no,confirm_yes" />
<Button
android:id="@+id/confirm_no"
style="@style/FeedbackButton"
android:layout_width="0dp"
android:layout_height="@dimen/settings_button_height"
android:text="@android:string/cancel"
android:layout_margin="@dimen/confirm_button_margin"
android:textSize="@dimen/confirm_button_fontsize"
android:padding="@dimen/confirm_button_padding"
android:singleLine="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/confirm_yes" />
<Button
android:id="@+id/confirm_yes"
style="@style/FeedbackButton"
android:layout_width="0dp"
android:layout_height="@dimen/settings_button_height"
android:text="@android:string/ok"
android:layout_margin="@dimen/confirm_button_margin"
android:textSize="@dimen/confirm_button_fontsize"
android:padding="@dimen/confirm_button_padding"
android:singleLine="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -187,6 +187,14 @@
<!--dimens of dialog_license.xml--> <!--dimens of dialog_license.xml-->
<dimen name="license_textsize">8sp</dimen> <dimen name="license_textsize">8sp</dimen>
<!--dimens of dialog_confirm.xml-->
<dimen name="confirm_button_margin">10dp</dimen>
<dimen name="confirm_text_margin">14dp</dimen>
<dimen name="confirm_button_padding">5dp</dimen>
<dimen name="confirm_button_fontsize">14sp</dimen>
<dimen name="confirm_message_fontsize">18sp</dimen>
<dimen name="confirm_title_fontsize">22sp</dimen>
<!--dimens of dialog_userlist.xml--> <!--dimens of dialog_userlist.xml-->
<dimen name="userlist_button_height">20dp</dimen> <dimen name="userlist_button_height">20dp</dimen>
<dimen name="userlist_button_padding">5dp</dimen> <dimen name="userlist_button_padding">5dp</dimen>

View File

@ -33,6 +33,11 @@
<item name="android:backgroundDimEnabled">true</item> <item name="android:backgroundDimEnabled">true</item>
</style> </style>
<style name="ConfirmDialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="android:background">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
<style name="LoadingDialog"> <style name="LoadingDialog">
<item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item> <item name="android:background">@android:color/transparent</item>