|
1 | 1 | package com.whyun.witv.ui; |
2 | 2 |
|
3 | | -import android.net.wifi.WifiInfo; |
4 | | -import android.net.wifi.WifiManager; |
5 | 3 | import android.os.Bundle; |
6 | | -import android.widget.Button; |
7 | | -import android.widget.CheckBox; |
8 | | -import android.widget.EditText; |
9 | | -import android.widget.TextView; |
10 | | -import android.widget.Toast; |
11 | 4 |
|
12 | 5 | import androidx.fragment.app.FragmentActivity; |
13 | | -import androidx.recyclerview.widget.LinearLayoutManager; |
14 | | -import androidx.recyclerview.widget.RecyclerView; |
15 | 6 |
|
16 | 7 | import com.whyun.witv.R; |
17 | | -import com.whyun.witv.data.PreferenceManager; |
18 | | -import com.whyun.witv.data.db.AppDatabase; |
19 | | -import com.whyun.witv.data.db.entity.M3USource; |
20 | | -import com.whyun.witv.data.repository.ChannelRepository; |
21 | | -import com.whyun.witv.data.repository.EpgRepository; |
| 8 | +import com.whyun.witv.player.PlayerManager; |
22 | 9 |
|
23 | | -import java.util.ArrayList; |
24 | | -import java.util.List; |
25 | | -import java.util.Locale; |
26 | | -import java.util.concurrent.ExecutorService; |
27 | | -import java.util.concurrent.Executors; |
28 | | - |
29 | | -public class SettingsActivity extends FragmentActivity { |
30 | | - |
31 | | - private AppDatabase db; |
32 | | - private ChannelRepository channelRepo; |
33 | | - private EpgRepository epgRepo; |
34 | | - private PreferenceManager preferenceManager; |
35 | | - private SourceListAdapter adapter; |
36 | | - private EditText epgUrlInput; |
37 | | - private final ExecutorService executor = Executors.newSingleThreadExecutor(); |
| 10 | +public class SettingsActivity extends FragmentActivity implements SettingsPanelHost { |
38 | 11 |
|
39 | 12 | @Override |
40 | 13 | protected void onCreate(Bundle savedInstanceState) { |
41 | 14 | super.onCreate(savedInstanceState); |
42 | 15 | setContentView(R.layout.activity_settings); |
43 | | - |
44 | | - db = AppDatabase.getInstance(this); |
45 | | - channelRepo = new ChannelRepository(this); |
46 | | - epgRepo = new EpgRepository(this); |
47 | | - preferenceManager = new PreferenceManager(this); |
48 | | - |
49 | | - setupWebHint(); |
50 | | - setupSourceList(); |
51 | | - setupSettings(); |
52 | | - setupAutoPlay(); |
53 | | - setupShowLoadSpeed(); |
54 | | - } |
55 | | - |
56 | | - private void setupWebHint() { |
57 | | - TextView webHint = findViewById(R.id.web_hint); |
58 | | - String ip = getDeviceIp(); |
59 | | - webHint.setText(String.format("通过浏览器管理:http://%s:9978", ip)); |
60 | | - } |
61 | | - |
62 | | - private void setupSourceList() { |
63 | | - RecyclerView sourceList = findViewById(R.id.source_list); |
64 | | - sourceList.setLayoutManager(new LinearLayoutManager(this)); |
65 | | - adapter = new SourceListAdapter(new ArrayList<>(), this::onActivateSource); |
66 | | - sourceList.setAdapter(adapter); |
67 | | - loadSources(); |
68 | | - } |
69 | | - |
70 | | - private void setupSettings() { |
71 | | - epgUrlInput = findViewById(R.id.epg_url_input); |
72 | | - Button saveEpg = findViewById(R.id.btn_save_epg); |
73 | | - Button reloadEpg = findViewById(R.id.btn_reload_epg); |
74 | | - |
75 | | - executor.execute(() -> { |
76 | | - M3USource active = db.m3uSourceDao().getActive(); |
77 | | - if (active != null && active.epgUrl != null) { |
78 | | - runOnUiThread(() -> epgUrlInput.setText(active.epgUrl)); |
79 | | - } |
80 | | - }); |
81 | | - |
82 | | - saveEpg.setOnClickListener(v -> { |
83 | | - String epgUrl = epgUrlInput.getText().toString().trim(); |
84 | | - executor.execute(() -> { |
85 | | - M3USource active = db.m3uSourceDao().getActive(); |
86 | | - if (active != null) { |
87 | | - active.epgUrl = epgUrl; |
88 | | - db.m3uSourceDao().update(active); |
89 | | - runOnUiThread(() -> |
90 | | - Toast.makeText(this, "EPG 设置已保存", Toast.LENGTH_SHORT).show()); |
91 | | - } |
92 | | - }); |
93 | | - }); |
94 | | - |
95 | | - reloadEpg.setOnClickListener(v -> { |
96 | | - executor.execute(() -> { |
97 | | - M3USource active = db.m3uSourceDao().getActive(); |
98 | | - if (active != null && active.epgUrl != null && !active.epgUrl.isEmpty()) { |
99 | | - runOnUiThread(() -> |
100 | | - Toast.makeText(this, "正在刷新 EPG…", Toast.LENGTH_SHORT).show()); |
101 | | - try { |
102 | | - epgRepo.loadEpg(active.epgUrl); |
103 | | - preferenceManager.markEpgAutoRefreshSuccess(active.epgUrl); |
104 | | - runOnUiThread(() -> |
105 | | - Toast.makeText(this, "EPG 刷新完成", Toast.LENGTH_SHORT).show()); |
106 | | - } catch (Exception e) { |
107 | | - runOnUiThread(() -> |
108 | | - Toast.makeText(this, "EPG 刷新失败: " + e.getMessage(), |
109 | | - Toast.LENGTH_LONG).show()); |
110 | | - } |
111 | | - } else { |
112 | | - runOnUiThread(() -> |
113 | | - Toast.makeText(this, "请先设置 EPG 地址", Toast.LENGTH_SHORT).show()); |
114 | | - } |
115 | | - }); |
116 | | - }); |
117 | | - } |
118 | | - |
119 | | - private void setupAutoPlay() { |
120 | | - CheckBox autoPlayCheck = findViewById(R.id.cb_auto_play_last); |
121 | | - autoPlayCheck.setChecked(preferenceManager.isAutoPlayLastEnabled()); |
122 | | - autoPlayCheck.setOnCheckedChangeListener((buttonView, isChecked) -> { |
123 | | - preferenceManager.setAutoPlayLast(isChecked); |
124 | | - Toast.makeText(this, |
125 | | - isChecked ? "已开启启动播放上次频道" : "已关闭启动播放上次频道", |
126 | | - Toast.LENGTH_SHORT).show(); |
127 | | - }); |
128 | | - } |
129 | | - |
130 | | - private void setupShowLoadSpeed() { |
131 | | - CheckBox cb = findViewById(R.id.cb_show_load_speed); |
132 | | - cb.setChecked(preferenceManager.isShowLoadSpeedOverlay()); |
133 | | - cb.setOnCheckedChangeListener((buttonView, isChecked) -> { |
134 | | - preferenceManager.setShowLoadSpeedOverlay(isChecked); |
135 | | - Toast.makeText(this, |
136 | | - isChecked ? "已开启播放页加载速度显示" : "已关闭播放页加载速度显示", |
137 | | - Toast.LENGTH_SHORT).show(); |
138 | | - }); |
| 16 | + if (savedInstanceState == null) { |
| 17 | + getSupportFragmentManager().beginTransaction() |
| 18 | + .replace(R.id.settings_fragment_container, new SettingsCollapsibleFragment()) |
| 19 | + .commit(); |
| 20 | + } |
139 | 21 | } |
140 | 22 |
|
141 | | - private void loadSources() { |
142 | | - executor.execute(() -> { |
143 | | - List<M3USource> sources = db.m3uSourceDao().getAll(); |
144 | | - runOnUiThread(() -> adapter.updateData(sources)); |
145 | | - }); |
| 23 | + @Override |
| 24 | + public boolean shouldShowStreamSwitchGroup() { |
| 25 | + return false; |
146 | 26 | } |
147 | 27 |
|
148 | | - private void onActivateSource(M3USource source) { |
149 | | - executor.execute(() -> { |
150 | | - db.m3uSourceDao().deactivateAll(); |
151 | | - db.m3uSourceDao().activate(source.id); |
152 | | - |
153 | | - try { |
154 | | - List<com.whyun.witv.data.db.entity.Channel> channels = |
155 | | - db.channelDao().getBySource(source.id); |
156 | | - if (channels.isEmpty()) { |
157 | | - channelRepo.loadSource(source); |
158 | | - } |
159 | | - } catch (Exception e) { |
160 | | - e.printStackTrace(); |
161 | | - } |
162 | | - |
163 | | - loadSources(); |
164 | | - runOnUiThread(() -> |
165 | | - Toast.makeText(this, "已切换到: " + source.name, Toast.LENGTH_SHORT).show()); |
166 | | - }); |
| 28 | + @Override |
| 29 | + public PlayerManager getPlayerManagerOrNull() { |
| 30 | + return null; |
167 | 31 | } |
168 | 32 |
|
169 | | - private String getDeviceIp() { |
170 | | - try { |
171 | | - WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE); |
172 | | - if (wifiManager != null) { |
173 | | - WifiInfo wifiInfo = wifiManager.getConnectionInfo(); |
174 | | - int ipInt = wifiInfo.getIpAddress(); |
175 | | - if (ipInt != 0) { |
176 | | - return String.format(Locale.US, "%d.%d.%d.%d", |
177 | | - (ipInt & 0xff), (ipInt >> 8 & 0xff), |
178 | | - (ipInt >> 16 & 0xff), (ipInt >> 24 & 0xff)); |
179 | | - } |
180 | | - } |
181 | | - } catch (Exception ignored) { |
182 | | - } |
183 | | - return "0.0.0.0"; |
| 33 | + @Override |
| 34 | + public void onManualStreamSwitch(int index) { |
184 | 35 | } |
185 | 36 |
|
186 | 37 | @Override |
187 | | - protected void onDestroy() { |
188 | | - super.onDestroy(); |
189 | | - executor.shutdown(); |
| 38 | + public void onPlaybackOverlayPreferenceChanged() { |
190 | 39 | } |
191 | 40 | } |
0 commit comments