Use popup in NekoSettings

This commit is contained in:
luvletter2333 2021-12-23 23:24:49 +08:00
parent 67703b1717
commit be93f69a31
No known key found for this signature in database
GPG Key ID: A26A8880836E1978
5 changed files with 43 additions and 20 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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 listcustom
@ -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();
}
}