| 1 | package tw.nekomimi.nkmr; |
| 2 | |
| 3 | import android.content.Context; |
| 4 | import android.view.View; |
| 5 | import android.view.ViewGroup; |
| 6 | import android.widget.LinearLayout; |
| 7 | |
| 8 | import androidx.recyclerview.widget.RecyclerView; |
| 9 | |
| 10 | import org.telegram.messenger.AndroidUtilities; |
| 11 | import org.telegram.messenger.LocaleController; |
| 12 | import org.telegram.messenger.R; |
| 13 | import org.telegram.ui.ActionBar.AlertDialog; |
| 14 | import org.telegram.ui.ActionBar.BaseFragment; |
| 15 | import org.telegram.ui.ActionBar.Theme; |
| 16 | import org.telegram.ui.Cells.HeaderCell; |
| 17 | import org.telegram.ui.Cells.RadioColorCell; |
| 18 | import org.telegram.ui.Cells.TextCheckCell; |
| 19 | import org.telegram.ui.Cells.TextDetailSettingsCell; |
| 20 | import org.telegram.ui.Cells.TextSettingsCell; |
| 21 | import org.telegram.ui.Components.EditTextBoldCursor; |
| 22 | import org.telegram.ui.Components.LayoutHelper; |
| 23 | import org.telegram.ui.Components.RecyclerListView; |
| 24 | |
| 25 | import java.util.ArrayList; |
| 26 | |
| 27 | import cn.hutool.core.util.StrUtil; |
| 28 | import tw.nekomimi.nekogram.settings.NekoGeneralSettingsActivity; |
| 29 | import tw.nekomimi.nkmr.cells.NekomuraTGDivider; |
| 30 | |
| 31 | public class CellGroup { |
| 32 | public static final int ITEM_TYPE_DIVIDER = 1; |
| 33 | public static final int ITEM_TYPE_TEXT_SETTINGS_CELL = 2; |
| 34 | public static final int ITEM_TYPE_TEXT_CHECK = 3; |
| 35 | public static final int ITEM_TYPE_HEADER = 4; |
| 36 | public static final int ITEM_TYPE_TEXT_DETAIL = 5; |
| 37 | public static final int ITEM_TYPE_TEXT = 6; |
| 38 | |
| 39 | public BaseFragment thisFragment; |
| 40 | public RecyclerListView listView; |
| 41 | public RecyclerListView.SelectionAdapter listAdapter; |
| 42 | public ArrayList<NekomuraTGCell> rows; |
| 43 | |
| 44 | public CallBackSettingsChanged callBackSettingsChanged; |
| 45 | |
| 46 | public CellGroup(BaseFragment thisFragment) { |
| 47 | this.thisFragment = thisFragment; |
| 48 | this.rows = new ArrayList<>(); |
| 49 | } |
| 50 | |
| 51 | public void setListAdapter(RecyclerListView lv, RecyclerListView.SelectionAdapter la) { |
| 52 | this.listView = lv; |
| 53 | this.listAdapter = la; |
| 54 | } |
| 55 | |
| 56 | public NekomuraTGCell appendCell(NekomuraTGCell cell) { |
| 57 | cell.bindCellGroup(this); |
| 58 | this.rows.add(cell); |
| 59 | return cell; |
| 60 | } |
| 61 | |
| 62 | public NekomuraTGCell appendCell(NekomuraTGCell cell, boolean display) { |
| 63 | cell.bindCellGroup(this); |
| 64 | if (display) |
| 65 | this.rows.add(cell); |
| 66 | return cell; |
| 67 | } |
| 68 | |
| 69 | public interface CallBackSettingsChanged { |
| 70 | void run(String key, Object newValue); |
| 71 | } |
| 72 | |
| 73 | public void runCallback(String key, Object newValue) { |
| 74 | if (callBackSettingsChanged == null) return; |
| 75 | try { |
| 76 | callBackSettingsChanged.run(key, newValue); |
| 77 | } catch (Exception e) { |
| 78 | |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | public interface OnBindViewHolder { |
| 83 | void onBindViewHolder(RecyclerView.ViewHolder holder); |
| 84 | } |
| 85 | |
| 86 | //Utils |
| 87 | public static void hideItemFromRecyclerView(View cell, boolean hide) { |
| 88 | if (cell == null) return; |
| 89 | if (cell != null) return; //TODO hideItemFromRecyclerView |
| 90 | ViewGroup.LayoutParams params = cell.getLayoutParams(); |
| 91 | if (hide) { |
| 92 | cell.setVisibility(View.GONE); |
| 93 | params.height = 0; |
| 94 | } else { |
| 95 | cell.setVisibility(View.VISIBLE); |
| 96 | params.height = ViewGroup.LayoutParams.WRAP_CONTENT; |
| 97 | } |
| 98 | cell.setLayoutParams(params); |
| 99 | } |
| 100 | |
| 101 | public boolean needSetDivider(NekomuraTGCell cell) { |
| 102 | return !(rows.get(rows.indexOf(cell) + 1) instanceof NekomuraTGDivider); |
| 103 | } |
| 104 | |
| 105 | //TG Cells |
| 106 | |
| 107 | |
| 108 | //TextDetailSettingsCell |
| 109 | |
| 110 | |
| 111 | } |