From be93f69a312ba3c89c64bfcfd06c13131cea7135 Mon Sep 17 00:00:00 2001 From: luvletter2333 Date: Thu, 23 Dec 2021 23:24:49 +0800 Subject: [PATCH] Use popup in NekoSettings --- .../tw/nekomimi/nekogram/InternalUpdater.java | 3 +- .../settings/NekoChatSettingsActivity.java | 2 +- .../NekoExperimentalSettingsActivity.java | 2 +- .../settings/NekoGeneralSettingsActivity.java | 2 +- .../nkmr/cells/NekomuraTGSelectBox.java | 54 +++++++++++++------ 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/InternalUpdater.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/InternalUpdater.java index 172b30216..cb454e616 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/InternalUpdater.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/InternalUpdater.java @@ -12,7 +12,6 @@ import android.widget.Toast; import androidx.core.content.FileProvider; -import com.google.android.exoplayer2.util.Log; import com.google.gson.Gson; import org.telegram.messenger.AndroidUtilities; @@ -213,7 +212,7 @@ public class InternalUpdater { NekomuraTGSelectBox sb = new NekomuraTGSelectBox(null, NekomuraConfig.update_download_soucre, sources_, null); nkmrCells.appendCell(sb); // new - sb.onClick(ctx); + sb.onClickWithDialog(ctx); } public static boolean openApkInstall(Activity activity, File f) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java index a4245cbdb..9ffe2a2b9 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -194,7 +194,7 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati if (a instanceof NekomuraTGTextCheck) { ((NekomuraTGTextCheck) a).onClick((TextCheckCell) view); } else if (a instanceof NekomuraTGSelectBox) { - ((NekomuraTGSelectBox) a).onClick(); + ((NekomuraTGSelectBox) a).onClick(view); } else if (a instanceof NekomuraTGTextInput) { ((NekomuraTGTextInput) a).onClick(); } else if (a instanceof NekomuraTGTextDetail) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java index ab419baf3..4e347d538 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java @@ -135,7 +135,7 @@ public class NekoExperimentalSettingsActivity extends BaseFragment { if (a instanceof NekomuraTGTextCheck) { ((NekomuraTGTextCheck) a).onClick((TextCheckCell) view); } else if (a instanceof NekomuraTGSelectBox) { - ((NekomuraTGSelectBox) a).onClick(); + ((NekomuraTGSelectBox) a).onClick(view); } else if (a instanceof NekomuraTGTextInput) { ((NekomuraTGTextInput) a).onClick(); } else if (a instanceof NekomuraTGTextDetail) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java index 3730543f4..910a55c53 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -217,7 +217,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment { if (a instanceof NekomuraTGTextCheck) { ((NekomuraTGTextCheck) a).onClick((TextCheckCell) view); } else if (a instanceof NekomuraTGSelectBox) { - ((NekomuraTGSelectBox) a).onClick(); + ((NekomuraTGSelectBox) a).onClick(view); } else if (a instanceof NekomuraTGTextInput) { ((NekomuraTGTextInput) a).onClick(); } else if (a instanceof NekomuraTGTextDetail) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nkmr/cells/NekomuraTGSelectBox.java b/TMessagesProj/src/main/java/tw/nekomimi/nkmr/cells/NekomuraTGSelectBox.java index cb4cc661d..fce6258d9 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nkmr/cells/NekomuraTGSelectBox.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nkmr/cells/NekomuraTGSelectBox.java @@ -1,6 +1,7 @@ package tw.nekomimi.nkmr.cells; import android.content.Context; +import android.view.View; import android.widget.LinearLayout; import androidx.recyclerview.widget.RecyclerView; @@ -13,8 +14,11 @@ import org.telegram.ui.ActionBar.Theme; import org.telegram.ui.Cells.RadioColorCell; import org.telegram.ui.Cells.TextSettingsCell; +import kotlin.Unit; +import tw.nekomimi.nekogram.PopupBuilder; import tw.nekomimi.nkmr.CellGroup; import tw.nekomimi.nkmr.ConfigItem; +import tw.nekomimi.nkmr.NekomuraConfig; // TextSettingsCell, select from a list // Can be used without select list(custom) @@ -62,24 +66,11 @@ public class NekomuraTGSelectBox extends AbstractCell { cell.setTextAndValue(title, valueText, cellGroup.needSetDivider(this)); } - public void onClick(Context ctx) { + public void onClickWithDialog(Context ctx) { ctxCustom = ctx; - onClick(); - } - - public void onClick() { - if (onClickCustom != null) { - try { - onClickCustom.run(); - } catch (Exception e) { - } - return; - } - Context context = ctxCustom != null ? ctxCustom : cellGroup.thisFragment.getParentActivity(); - if (context == null) { + if (context == null) return; - } AlertDialog.Builder builder = new AlertDialog.Builder(context); //TODO Replace with pop-up menu builder.setTitle(LocaleController.getString(bindConfig.getKey())); @@ -114,4 +105,37 @@ public class NekomuraTGSelectBox extends AbstractCell { builder.show(); } } + + public void onClick(View view) { + if (onClickCustom != null) { + try { + onClickCustom.run(); + } catch (Exception e) { + } + return; + } + + Context context = ctxCustom != null ? ctxCustom : cellGroup.thisFragment.getParentActivity(); + if (context == null) { + return; + } + + PopupBuilder builder = new PopupBuilder(view); + + builder.setItems(this.selectList, (i, __) -> { + bindConfig.setConfigInt(i); + + if (cellGroup.listAdapter != null) + cellGroup.listAdapter.notifyItemChanged(cellGroup.rows.indexOf(this)); + if (cellGroup.thisFragment != null) + cellGroup.thisFragment.parentLayout.rebuildAllFragmentViews(false, false); + + cellGroup.runCallback(bindConfig.getKey(), i); + + return Unit.INSTANCE; + }); + builder.show(); + + + } } \ No newline at end of file