Utilise dialog dsl in RationaleDialog
parent
72c07f4b99
commit
4641512644
@ -1,56 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.permissions;
|
|
||||||
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout.LayoutParams;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import org.session.libsession.utilities.ViewUtil;
|
|
||||||
|
|
||||||
import network.loki.messenger.R;
|
|
||||||
|
|
||||||
public class RationaleDialog {
|
|
||||||
|
|
||||||
public static AlertDialog.Builder createFor(@NonNull Context context, @NonNull String message, @DrawableRes int... drawables) {
|
|
||||||
View view = LayoutInflater.from(context).inflate(R.layout.permissions_rationale_dialog, null);
|
|
||||||
view.setClipToOutline(true);
|
|
||||||
ViewGroup header = view.findViewById(R.id.header_container);
|
|
||||||
TextView text = view.findViewById(R.id.message);
|
|
||||||
|
|
||||||
for (int i=0;i<drawables.length;i++) {
|
|
||||||
ImageView imageView = new ImageView(context);
|
|
||||||
imageView.setImageDrawable(context.getResources().getDrawable(drawables[i]));
|
|
||||||
imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
|
||||||
|
|
||||||
header.addView(imageView);
|
|
||||||
|
|
||||||
if (i != drawables.length - 1) {
|
|
||||||
TextView plus = new TextView(context);
|
|
||||||
plus.setText("+");
|
|
||||||
plus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 40);
|
|
||||||
plus.setTextColor(Color.WHITE);
|
|
||||||
|
|
||||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
|
||||||
layoutParams.setMargins(ViewUtil.dpToPx(context, 20), 0, ViewUtil.dpToPx(context, 20), 0);
|
|
||||||
|
|
||||||
plus.setLayoutParams(layoutParams);
|
|
||||||
header.addView(plus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
text.setText(message);
|
|
||||||
|
|
||||||
return new AlertDialog.Builder(context, R.style.ThemeOverlay_Session_AlertDialog).setView(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,54 @@
|
|||||||
|
package org.thoughtcrime.securesms.permissions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.util.TypedValue
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.LinearLayout.LayoutParams.WRAP_CONTENT
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.core.content.res.ResourcesCompat
|
||||||
|
import network.loki.messenger.R
|
||||||
|
import org.session.libsession.utilities.ViewUtil
|
||||||
|
import org.thoughtcrime.securesms.showSessionDialog
|
||||||
|
|
||||||
|
object RationaleDialog {
|
||||||
|
@JvmStatic
|
||||||
|
fun show(
|
||||||
|
context: Context,
|
||||||
|
message: String,
|
||||||
|
onPositive: Runnable,
|
||||||
|
onNegative: Runnable,
|
||||||
|
@DrawableRes vararg drawables: Int
|
||||||
|
): androidx.appcompat.app.AlertDialog {
|
||||||
|
val view = LayoutInflater.from(context).inflate(R.layout.permissions_rationale_dialog, null)
|
||||||
|
.apply { clipToOutline = true }
|
||||||
|
val header = view.findViewById<ViewGroup>(R.id.header_container)
|
||||||
|
view.findViewById<TextView>(R.id.message).text = message
|
||||||
|
drawables.forEach {
|
||||||
|
ImageView(context).apply {
|
||||||
|
setImageDrawable(ResourcesCompat.getDrawable(context.resources, it, context.theme))
|
||||||
|
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
|
||||||
|
}.also(header::addView)
|
||||||
|
}
|
||||||
|
if (drawables.isNotEmpty()) {
|
||||||
|
TextView(context).apply {
|
||||||
|
text = "+"
|
||||||
|
setTextSize(TypedValue.COMPLEX_UNIT_SP, 40f)
|
||||||
|
setTextColor(Color.WHITE)
|
||||||
|
layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT).apply {
|
||||||
|
ViewUtil.dpToPx(context, 20).let { setMargins(it, 0, it, 0) }
|
||||||
|
}
|
||||||
|
}.also(header::addView)
|
||||||
|
}
|
||||||
|
|
||||||
|
return context.showSessionDialog {
|
||||||
|
view(view)
|
||||||
|
button(R.string.Permissions_continue) { onPositive.run() }
|
||||||
|
button(R.string.Permissions_not_now) { onNegative.run() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue