BasePreferenceHelper.kt 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. package com.vpn.fastestvpnservice.helpers
  2. import android.app.Activity
  3. import android.content.Context
  4. import com.google.gson.Gson
  5. import com.google.gson.GsonBuilder
  6. import com.google.gson.reflect.TypeToken
  7. import com.vpn.fastestvpnservice.beans.IpInfo
  8. import com.vpn.fastestvpnservice.beans.Product
  9. import com.vpn.fastestvpnservice.beans.ProductFeatures
  10. import com.vpn.fastestvpnservice.beans.Protocol
  11. import com.vpn.fastestvpnservice.beans.Server
  12. import com.vpn.fastestvpnservice.beans.ServerData
  13. import com.vpn.fastestvpnservice.beans.TvDisableApps
  14. import com.vpn.fastestvpnservice.beans.TvEnableApps
  15. import com.vpn.fastestvpnservice.beans.TvSplitTunneling
  16. import com.vpn.fastestvpnservice.beans.UserResponse
  17. import com.vpn.fastestvpnservice.beans.WireGuard
  18. import com.vpn.fastestvpnservice.beans.languages
  19. import com.vpn.fastestvpnservice.beans.themesList
  20. import com.vpn.fastestvpnservice.constants.AppEnum
  21. import com.vpn.fastestvpnservice.constants.splitList
  22. class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
  23. fun clearAllData() {
  24. removePreference(context, KEY_FILENAME, KEY_USER)
  25. removePreference(context, KEY_FILENAME, KEY_USER_PASSWORD)
  26. removePreference(context, KEY_FILENAME, KEY_SERVERS_DATA)
  27. removePreference(context, KEY_FILENAME, KEY_SERVERS)
  28. removePreference(context, KEY_FILENAME, KEY_SELECTED_APPS)
  29. removePreference(context, KEY_FILENAME, KEY_SELECTED_APPS_NO_VPN)
  30. removePreference(context, KEY_FILENAME, KEY_SELECTED_APPS_NOT_ALLOW)
  31. removePreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL)
  32. removePreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL_TV)
  33. removePreference(context, KEY_FILENAME, PROTOCOL)
  34. removePreference(context, KEY_FILENAME, X_PLATFORM_TOKEN)
  35. removePreference(context, KEY_FILENAME, KEY_PRODUCT)
  36. removePreference(context, KEY_FILENAME, KEY_AVAILABLE_PROTOCOLS)
  37. removePreference(context, KEY_FILENAME, KEY_ENABLED_PROTOCOLS)
  38. removePreference(context, KEY_FILENAME, KEY_WIREGUARD)
  39. removePreference(context, KEY_FILENAME, KEY_FEATURES_DATA)
  40. removePreference(context, KEY_FILENAME, KEY_SPLIT_ENABLE_TV)
  41. removePreference(context, KEY_FILENAME, KEY_SPLIT_DISABLE_TV)
  42. removePreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL_ENTRY)
  43. removePreference(context, KEY_FILENAME, TV_SPLIT_CLASS)
  44. removePreference(context, KEY_FILENAME, KEY_ADBLOCK_SWITCH)
  45. removePreference(context, KEY_FILENAME, KEY_ISLOGGEDIN)
  46. // removePreference(context, KEY_FILENAME, THEME)
  47. removePreference(context, KEY_FILENAME, KEY_ISCONNECT)
  48. removePreference(context, KEY_FILENAME, KEY_SPLIT_POS)
  49. removePreference(context, KEY_FILENAME, FILTER)
  50. removePreference(context, KEY_FILENAME, SMART)
  51. removePreference(context, KEY_FILENAME, KEY_SMART_SERVER)
  52. removePreference(context, KEY_FILENAME, KEY_AUTO_OPENVPN)
  53. removePreference(context, KEY_FILENAME, KEY_RECOMMENDED)
  54. removePreference(context, KEY_FILENAME, KEY_SUBSCRIPTION)
  55. removePreference(context, KEY_FILENAME, KEY_CONNECTED_SERVER)
  56. removePreference(context, KEY_FILENAME, KEY_RECENTLY_SERVERS)
  57. removePreference(context, KEY_FILENAME, KEY_FEEDBACK)
  58. removePreference(context, KEY_FILENAME, KEY_LAUNCH)
  59. // removePreference(context, KEY_FILENAME, LANGUAGE)
  60. removePreference(context, KEY_FILENAME, KEY_SERVERS_ID)
  61. removePreference(context, KEY_FILENAME, KEY_RECENTLY_SERVERS_ID)
  62. }
  63. fun clearServerObject() {
  64. removePreference(context, KEY_FILENAME, KEY_SERVERS)
  65. }
  66. fun saveUser(user: UserResponse) {
  67. putStringPreference(context, KEY_FILENAME, KEY_USER, Gson().toJson(user))
  68. }
  69. fun getUser(): UserResponse? {
  70. return Gson().fromJson<UserResponse>(
  71. getStringPreference(context, KEY_FILENAME, KEY_USER), UserResponse::class.java
  72. )
  73. }
  74. fun saveProduct(product: Product) {
  75. putStringPreference(context, KEY_FILENAME, KEY_PRODUCT, Gson().toJson(product))
  76. }
  77. fun getProduct(): Product? {
  78. return Gson().fromJson<Product>(
  79. getStringPreference(context, KEY_FILENAME, KEY_PRODUCT), Product::class.java
  80. )
  81. }
  82. fun saveWireGuard(wireGuard: WireGuard) {
  83. putStringPreference(context, KEY_FILENAME, KEY_WIREGUARD, Gson().toJson(wireGuard))
  84. }
  85. fun getWireGuard(): WireGuard? {
  86. return Gson().fromJson<WireGuard>(
  87. getStringPreference(context, KEY_FILENAME, KEY_WIREGUARD), WireGuard::class.java
  88. )
  89. }
  90. fun saveIpInfo(ipInfo: IpInfo) {
  91. putStringPreference(context, KEY_FILENAME, KEY_IPINFO, Gson().toJson(ipInfo))
  92. }
  93. fun getIpinfo(): IpInfo? {
  94. return Gson().fromJson<IpInfo>(
  95. getStringPreference(context, KEY_FILENAME, KEY_IPINFO), IpInfo::class.java
  96. )
  97. }
  98. fun savePassword(pass: String) {
  99. putStringPreference(context, KEY_FILENAME, KEY_USER_PASSWORD, pass)
  100. }
  101. fun getPassword(): String {
  102. return getStringPreference(context, KEY_FILENAME, KEY_USER_PASSWORD)
  103. }
  104. fun saveServerData(list: ArrayList<ServerData>) {
  105. putStringPreference(context, KEY_FILENAME, KEY_SERVERS_DATA, Gson().toJson(list))
  106. }
  107. fun getServerData(): ArrayList<ServerData> {
  108. val type = object : TypeToken<ArrayList<ServerData?>?>() {}.type
  109. return Gson().fromJson<ArrayList<ServerData>>(
  110. getStringPreference(
  111. context, KEY_FILENAME, KEY_SERVERS_DATA
  112. ), type
  113. )
  114. }
  115. fun getRecentlyList(): ArrayList<Server>? {
  116. val type = object : TypeToken<ArrayList<Server?>?>() {}.type
  117. return Gson().fromJson<ArrayList<Server>>(
  118. getStringPreference(
  119. context, KEY_FILENAME, KEY_RECENTLY_SERVERS
  120. ), type
  121. )
  122. }
  123. fun setRecentlyList(list: ArrayList<Server>?) {
  124. putStringPreference(context, KEY_FILENAME, KEY_RECENTLY_SERVERS, Gson().toJson(list))
  125. }
  126. fun getRecentlyListId(): ArrayList<Int>? {
  127. val type = object : TypeToken<ArrayList<Int?>?>() {}.type
  128. return Gson().fromJson<ArrayList<Int>>(
  129. getStringPreference(
  130. context, KEY_FILENAME, KEY_RECENTLY_SERVERS_ID
  131. ), type
  132. )
  133. }
  134. fun setRecentlyListId(list: ArrayList<Int>?) {
  135. putStringPreference(context, KEY_FILENAME, KEY_RECENTLY_SERVERS_ID, Gson().toJson(list))
  136. }
  137. fun getServersId(): ArrayList<Int>? {
  138. val type = object : TypeToken<ArrayList<Int?>?>() {}.type
  139. return Gson().fromJson<ArrayList<Int>>(
  140. getStringPreference(
  141. context, KEY_FILENAME, KEY_SERVERS_ID
  142. ), type
  143. )
  144. }
  145. fun setServersId(list: ArrayList<Int>?) {
  146. putStringPreference(context, KEY_FILENAME, KEY_SERVERS_ID, Gson().toJson(list))
  147. }
  148. fun saveFeaturesData(list: ArrayList<ProductFeatures>) {
  149. putStringPreference(context, KEY_FILENAME, KEY_FEATURES_DATA, Gson().toJson(list))
  150. }
  151. fun getFeaturesData(): List<ProductFeatures> {
  152. val type = object : TypeToken<List<ProductFeatures?>?>() {}.type
  153. return Gson().fromJson<List<ProductFeatures>>(
  154. getStringPreference(
  155. context, KEY_FILENAME, KEY_FEATURES_DATA
  156. ), type
  157. )
  158. }
  159. fun saveEnabledProtocols(list: ArrayList<String>) {
  160. putStringPreference(context, KEY_FILENAME, KEY_ENABLED_PROTOCOLS, Gson().toJson(list))
  161. }
  162. fun getEnabledProtocols(): ArrayList<String> {
  163. val type = object : TypeToken<ArrayList<String?>?>() {}.type
  164. try {
  165. return Gson().fromJson<ArrayList<String>>(
  166. getStringPreference(
  167. context, KEY_FILENAME, KEY_ENABLED_PROTOCOLS
  168. ), type
  169. )
  170. }
  171. catch (e: Exception) {
  172. val tempList = ArrayList<String>()
  173. tempList.add("WG")
  174. tempList.add("IKEV2")
  175. tempList.add("TCP")
  176. tempList.add("UDP")
  177. return tempList
  178. }
  179. }
  180. fun saveAvailableProtocols(list: ArrayList<String>) {
  181. var tempList = ArrayList<String>()
  182. if (list.contains(AppEnum.WG_PROTOCOL.key)) {
  183. tempList.add(AppEnum.WG_PROTOCOL.key)
  184. }
  185. if (list.contains(AppEnum.IKEV2_PROTOCOL.key)) {
  186. tempList.add(AppEnum.IKEV2_PROTOCOL.key)
  187. }
  188. if (list.contains(AppEnum.TCP_PROTOCOL.key)) {
  189. tempList.add(AppEnum.TCP_PROTOCOL.key)
  190. }
  191. if (list.contains(AppEnum.UDP_PROTOCOL.key)) {
  192. tempList.add(AppEnum.UDP_PROTOCOL.key)
  193. }
  194. putStringPreference(context, KEY_FILENAME, KEY_AVAILABLE_PROTOCOLS, Gson().toJson(tempList))
  195. }
  196. fun getAvailableProtocols(): ArrayList<String> {
  197. val type = object : TypeToken<ArrayList<String?>?>() {}.type
  198. return try {
  199. Gson().fromJson<ArrayList<String>>(
  200. getStringPreference(
  201. context, KEY_FILENAME, KEY_AVAILABLE_PROTOCOLS
  202. ), type
  203. )
  204. } catch (e: Exception) {
  205. val tempList = ArrayList<String>()
  206. tempList.add("WG")
  207. tempList.add("IKEV2")
  208. tempList.add("TCP")
  209. tempList.add("UDP")
  210. return tempList
  211. }
  212. }
  213. fun getEnableTvAppsSplit(): ArrayList<TvEnableApps>? {
  214. val type = object : TypeToken<ArrayList<TvEnableApps?>?>() {}.type
  215. return Gson().fromJson<ArrayList<TvEnableApps>>(
  216. getStringPreference(
  217. context, KEY_FILENAME, KEY_SPLIT_ENABLE_TV
  218. ), type
  219. )
  220. }
  221. fun setEnableTvAppsSplit(allSplitTunnelEnabled: ArrayList<TvEnableApps>?) {
  222. if (allSplitTunnelEnabled == null) {
  223. removePreference(context, KEY_FILENAME, KEY_SPLIT_ENABLE_TV)
  224. return
  225. }
  226. putStringPreference(context, KEY_FILENAME, KEY_SPLIT_ENABLE_TV, Gson().toJson(allSplitTunnelEnabled))
  227. }
  228. fun getDisableTvAppsSplit(): ArrayList<TvDisableApps>? {
  229. val type = object : TypeToken<ArrayList<TvDisableApps?>?>() {}.type
  230. return Gson().fromJson<ArrayList<TvDisableApps>>(
  231. getStringPreference(
  232. context, KEY_FILENAME, KEY_SPLIT_DISABLE_TV
  233. ), type
  234. )
  235. }
  236. fun setDisableTvAppsSplit(allSplitTunnelEnabled: ArrayList<TvDisableApps>?) {
  237. if (allSplitTunnelEnabled == null) {
  238. removePreference(context, KEY_FILENAME, KEY_SPLIT_DISABLE_TV)
  239. return
  240. }
  241. putStringPreference(context, KEY_FILENAME, KEY_SPLIT_DISABLE_TV, Gson().toJson(allSplitTunnelEnabled))
  242. }
  243. fun getSplitTunnelTvAppsName(): ArrayList<String>? {
  244. val type = object : TypeToken<ArrayList<String?>?>() {}.type
  245. return Gson().fromJson<ArrayList<String>>(
  246. getStringPreference(
  247. context, KEY_FILENAME, KEY_SPLIT_TUNNEL
  248. ), type
  249. )
  250. }
  251. fun setSplitTunnelTvAppsName(allSplitTunnelEnabled: ArrayList<String>?) {
  252. if (allSplitTunnelEnabled == null) {
  253. removePreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL)
  254. return
  255. }
  256. putStringPreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL, Gson().toJson(allSplitTunnelEnabled))
  257. }
  258. fun getSplitTunnelTvAppsPackageName(): ArrayList<String>? {
  259. val type = object : TypeToken<ArrayList<String?>?>() {}.type
  260. return Gson().fromJson<ArrayList<String>>(
  261. getStringPreference(
  262. context, KEY_FILENAME, KEY_SPLIT_TUNNEL_TV
  263. ), type
  264. )
  265. }
  266. fun setSplitTunnelTvAppsPackageName(allSplitTunnelEnabled: ArrayList<String>?) {
  267. if (allSplitTunnelEnabled == null) {
  268. removePreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL_TV)
  269. return
  270. }
  271. putStringPreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL_TV, Gson().toJson(allSplitTunnelEnabled))
  272. }
  273. fun getSplitTunnelTvAppsEntry(): ArrayList<String>? {
  274. val type = object : TypeToken<ArrayList<String?>?>() {}.type
  275. return Gson().fromJson<ArrayList<String>>(
  276. getStringPreference(
  277. context, KEY_FILENAME, KEY_SPLIT_TUNNEL_ENTRY
  278. ), type
  279. )
  280. }
  281. fun setSplitTunnelTvAppsEntry(appsEntry: ArrayList<String>?) {
  282. if (appsEntry == null) {
  283. removePreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL_ENTRY)
  284. return
  285. }
  286. putStringPreference(context, KEY_FILENAME, KEY_SPLIT_TUNNEL_ENTRY, Gson().toJson(appsEntry))
  287. }
  288. fun setInstanceActivity(activity: Activity){
  289. putStringPreference(context, KEY_FILENAME, KEY_ACTIVITY, Gson().toJson(activity))
  290. }
  291. fun getInstanceActivity(): Activity? {
  292. var activity: Activity? = null
  293. val mainActivity = getStringPreference(context, KEY_FILENAME, KEY_ACTIVITY)
  294. if (mainActivity != null){
  295. val gson = GsonBuilder().create()
  296. activity = gson.fromJson(mainActivity, Activity::class.java)
  297. }
  298. return activity
  299. }
  300. fun getServerObject(): Server? {
  301. var serverObj: Server? = null
  302. val serverObjStr: String = getStringPreference(context, KEY_FILENAME, KEY_SERVERS)
  303. if (serverObjStr != null) {
  304. val gson = GsonBuilder().create()
  305. serverObj = gson.fromJson(serverObjStr, Server::class.java)
  306. }
  307. return serverObj
  308. }
  309. fun setServerObject(serverObj: Server?) {
  310. putStringPreference(context, KEY_FILENAME, KEY_SERVERS, Gson().toJson(serverObj))
  311. }
  312. fun getConnectedServer(): Server? {
  313. var serverObj: Server? = null
  314. val serverObjStr: String = getStringPreference(context, KEY_FILENAME, KEY_CONNECTED_SERVER)
  315. if (serverObjStr != null) {
  316. val gson = GsonBuilder().create()
  317. serverObj = gson.fromJson(serverObjStr, Server::class.java)
  318. }
  319. return serverObj
  320. }
  321. fun setConnectedServer(serverObj: Server?) {
  322. putStringPreference(context, KEY_FILENAME, KEY_CONNECTED_SERVER, Gson().toJson(serverObj))
  323. }
  324. fun getSmartServerObject(): Server? {
  325. var serverObj: Server? = null
  326. val serverObjStr: String = getStringPreference(context, KEY_FILENAME, KEY_SMART_SERVER)
  327. if (serverObjStr != null) {
  328. val gson = GsonBuilder().create()
  329. serverObj = gson.fromJson(serverObjStr, Server::class.java)
  330. }
  331. return serverObj
  332. }
  333. fun setSmartServerObject(smartObj: Server?) {
  334. putStringPreference(context, KEY_FILENAME, KEY_SMART_SERVER, Gson().toJson(smartObj))
  335. }
  336. fun getRecommendedServerObject(): Server? {
  337. var serverObj: Server? = null
  338. val serverObjStr: String = getStringPreference(context, KEY_FILENAME, KEY_RECOMMENDED)
  339. if (serverObjStr != null) {
  340. val gson = GsonBuilder().create()
  341. serverObj = gson.fromJson(serverObjStr, Server::class.java)
  342. }
  343. return serverObj
  344. }
  345. fun setRecommendedServerObject(recommended: Server?) {
  346. putStringPreference(context, KEY_FILENAME, KEY_RECOMMENDED, Gson().toJson(recommended))
  347. }
  348. fun getRecommendedList(): ArrayList<Server>? {
  349. val type = object : TypeToken<ArrayList<Server?>?>() {}.type
  350. return Gson().fromJson<ArrayList<Server>>(
  351. getStringPreference(
  352. context, KEY_FILENAME, KEY_RECOMMENDED_LIST
  353. ), type
  354. )
  355. }
  356. fun setRecommendedList(recommended: ArrayList<Server>?) {
  357. putStringPreference(context, KEY_FILENAME, KEY_RECOMMENDED_LIST, Gson().toJson(recommended))
  358. }
  359. fun getSubscriptionServerObject(): Server? {
  360. var serverObj: Server? = null
  361. val serverObjStr: String = getStringPreference(context, KEY_FILENAME, KEY_SUBSCRIPTION)
  362. if (serverObjStr != null) {
  363. val gson = GsonBuilder().create()
  364. serverObj = gson.fromJson(serverObjStr, Server::class.java)
  365. }
  366. return serverObj
  367. }
  368. fun setSubscriptionServerObject(subscription: Server?) {
  369. putStringPreference(context, KEY_FILENAME, KEY_SUBSCRIPTION, Gson().toJson(subscription))
  370. }
  371. fun getSplitTunneledApps(): String? {
  372. return getStringPreference(context, KEY_FILENAME, KEY_SELECTED_APPS)
  373. }
  374. fun setSplitTunneledApps(selectedApps: String?) {
  375. if (selectedApps == null) {
  376. removePreference(context, KEY_FILENAME, KEY_SELECTED_APPS)
  377. return
  378. }
  379. putStringPreference(context, KEY_FILENAME, KEY_SELECTED_APPS, selectedApps)
  380. }
  381. fun getSplitTunneledAppsNoVpn(): String? {
  382. return getStringPreference(context, KEY_FILENAME, KEY_SELECTED_APPS_NO_VPN)
  383. }
  384. fun setSplitTunneledAppsNoVpn(selectedApps: String?) {
  385. if (selectedApps == null) {
  386. removePreference(context, KEY_FILENAME, KEY_SELECTED_APPS_NO_VPN)
  387. return
  388. }
  389. putStringPreference(context, KEY_FILENAME, KEY_SELECTED_APPS_NO_VPN, selectedApps)
  390. }
  391. fun getSplitTunneledAppsNotAllow(): String? {
  392. return getStringPreference(context, KEY_FILENAME, KEY_SELECTED_APPS_NOT_ALLOW)
  393. }
  394. fun setSplitTunneledAppsNotAllow(selectedApps: String?) {
  395. if (selectedApps == null) {
  396. removePreference(context, KEY_FILENAME, KEY_SELECTED_APPS_NOT_ALLOW)
  397. return
  398. }
  399. putStringPreference(context, KEY_FILENAME, KEY_SELECTED_APPS_NOT_ALLOW, selectedApps)
  400. }
  401. fun saveAppDetails(appDetails: String) {
  402. putStringPreference(context, KEY_FILENAME, APP_DETAILS, appDetails)
  403. }
  404. fun getAppDetails(): String {
  405. return getStringPreference(context, KEY_FILENAME, APP_DETAILS)
  406. }
  407. fun saveFileDetails(fileDetails: String) {
  408. putStringPreference(context, KEY_FILENAME, FILE_DETAILS, fileDetails)
  409. }
  410. fun getFileDetails(): String {
  411. return getStringPreference(context, KEY_FILENAME, FILE_DETAILS)
  412. }
  413. fun saveTheme(theme: String) {
  414. putStringPreference(context, KEY_FILENAME, THEME, theme)
  415. }
  416. fun getTheme(): String {
  417. return try {
  418. getStringPreference(context, KEY_FILENAME, THEME, themesList[0])
  419. } catch (ex: Exception) {
  420. themesList[0]
  421. }
  422. }
  423. fun saveLanguage(language: String) {
  424. putStringPreference(context, KEY_FILENAME, LANGUAGE, language)
  425. }
  426. fun getLanguage(): String {
  427. return try {
  428. getStringPreference(context, KEY_FILENAME, LANGUAGE, languages[0].identifier)
  429. } catch (ex: Exception) {
  430. languages[0].identifier
  431. }
  432. }
  433. fun saveFilterList(filter: String) {
  434. putStringPreference(context, KEY_FILENAME, FILTER, filter)
  435. }
  436. fun getFilterList(): String {
  437. return getStringPreference(context, KEY_FILENAME, FILTER)
  438. }
  439. fun saveSmartList(smart: String) {
  440. putStringPreference(context, KEY_FILENAME, SMART, smart)
  441. }
  442. fun getSmartList(): String {
  443. return getStringPreference(context, KEY_FILENAME, SMART)
  444. }
  445. fun saveTvSplitTunnel(tvSplitTunneling: ArrayList<TvSplitTunneling>) {
  446. putStringPreference(context, KEY_FILENAME, TV_SPLIT_CLASS, Gson().toJson(tvSplitTunneling))
  447. }
  448. fun getTvSplitTunnel(): ArrayList<TvSplitTunneling> {
  449. val tvSplitTunneling = Gson().fromJson<ArrayList<TvSplitTunneling>>(
  450. getStringPreference(context, KEY_FILENAME, TV_SPLIT_CLASS), TvSplitTunneling::class.java
  451. )
  452. return tvSplitTunneling
  453. }
  454. fun saveProtocol(protocol: Protocol) {
  455. putStringPreference(context, KEY_FILENAME, PROTOCOL, Gson().toJson(protocol))
  456. }
  457. fun getProtocol(): Protocol {
  458. var protocol = Gson().fromJson<Protocol>(
  459. getStringPreference(context, KEY_FILENAME, PROTOCOL), Protocol::class.java
  460. )
  461. protocol?.let {
  462. return protocol
  463. } ?: kotlin.run {
  464. return Protocol(
  465. AppEnum.WG_PROTOCOL.title, AppEnum.WG_PROTOCOL.key, 1
  466. // AppEnum.AUTO_PROTOCOL.title, AppEnum.IKEV2_PROTOCOL.key, 0
  467. ) //By default (AUTO) Protocol is selected (index 0 = AUTO). Checking IKEV2 first then check TCP/UDP
  468. }
  469. }
  470. // fun saveRadioBtnSplitPos(position: Int) {
  471. // putIntegerPreference(context, KEY_FILENAME, KEY_SPLIT_POS, position)
  472. // }
  473. //
  474. // fun getRadioBtnSplitPos(): Int {
  475. // return getIntegerPreference(context, KEY_FILENAME, KEY_SPLIT_POS)
  476. // }
  477. fun saveAdBlockState(status: Boolean) {
  478. putBooleanPreference(context, KEY_FILENAME, KEY_ADBLOCK_SWITCH, status)
  479. }
  480. fun getAdBlockState(): Boolean {
  481. return getBooleanPreference(context, KEY_FILENAME, KEY_ADBLOCK_SWITCH)
  482. }
  483. fun saveLaunchState(status: Boolean) {
  484. putBooleanPreference(context, KEY_FILENAME, KEY_LAUNCH, status)
  485. }
  486. fun getLaunchState(): Boolean {
  487. return getBooleanPreference(context, KEY_FILENAME, KEY_LAUNCH)
  488. }
  489. fun saveFcmToken(token: String) {
  490. putStringPreference(context, KEY_FILENAME, KEY_FCM, token)
  491. }
  492. fun getLoggedInState(): Boolean {
  493. return getBooleanPreference(context, KEY_FILENAME, KEY_ISLOGGEDIN)
  494. }
  495. fun setLoggedInState(state: Boolean) {
  496. putBooleanPreference(context, KEY_FILENAME, KEY_ISLOGGEDIN, state)
  497. }
  498. fun getFeedbackState(): Boolean {
  499. return getBooleanPreference(context, KEY_FILENAME, KEY_FEEDBACK)
  500. }
  501. fun setFeedbackState(state: Boolean) {
  502. putBooleanPreference(context, KEY_FILENAME, KEY_FEEDBACK, state)
  503. }
  504. fun getConnectState(): Int {
  505. return getIntegerPreference(context, KEY_FILENAME, KEY_ISCONNECT)
  506. }
  507. fun setConnectState(state: Int) {
  508. putIntegerPreference(context, KEY_FILENAME, KEY_ISCONNECT, state)
  509. }
  510. fun isAutoOpenVpnConnected(): Boolean {
  511. return getBooleanPreference(context, KEY_FILENAME, KEY_AUTO_OPENVPN)
  512. }
  513. fun setAutoOpenVpnConnected(state: Boolean) {
  514. putBooleanPreference(context, KEY_FILENAME, KEY_AUTO_OPENVPN, state)
  515. }
  516. fun getFcmToken(): String {
  517. return getStringPreference(context, KEY_FILENAME, KEY_FCM)
  518. }
  519. fun saveXPlatformToken(token: String) {
  520. putStringPreference(context, KEY_FILENAME, X_PLATFORM_TOKEN, token)
  521. }
  522. fun getXPlatformToken(): String {
  523. return getStringPreference(context, KEY_FILENAME, X_PLATFORM_TOKEN)
  524. }
  525. fun saveSplitPosition(token: String) {
  526. putStringPreference(context, KEY_FILENAME, KEY_SPLIT_POS, token)
  527. }
  528. fun getSplitPosition(): String {
  529. return try {
  530. getStringPreference(context, KEY_FILENAME, KEY_SPLIT_POS, splitList[0])
  531. } catch (ex: Exception) {
  532. splitList[0]
  533. }
  534. }
  535. companion object {
  536. private const val KEY_FILENAME = "file_fastestvpn"
  537. private const val KEY_USER = "keydata_user"
  538. private const val KEY_PRODUCT = "keydata_product"
  539. private const val KEY_WIREGUARD = "keydata_wireguard"
  540. private const val KEY_IPINFO = "keydata_ipinfo"
  541. private const val KEY_USER_PASSWORD = "keydata_user_password"
  542. private const val KEY_SERVERS_DATA = "keydata_servers_data"
  543. private const val KEY_FEATURES_DATA = "keydata_features_data"
  544. private const val KEY_ENABLED_PROTOCOLS = "keydata_enabled_protocols"
  545. private const val KEY_AVAILABLE_PROTOCOLS = "keydata_available_protocols"
  546. private const val KEY_SERVERS = "keydata_server"
  547. private const val KEY_SELECTED_APPS = "keydata_selectedApps"
  548. private const val KEY_SELECTED_APPS_NO_VPN = "keydata_selectedAppsNoVpn"
  549. private const val KEY_SELECTED_APPS_NOT_ALLOW = "keydata_selectedAppsNotAllow"
  550. private const val KEY_SPLIT_TUNNEL = "keydata_tv_apps_name"
  551. private const val KEY_SPLIT_TUNNEL_TV = "keydata_tv_apps_package_name"
  552. private const val KEY_SPLIT_ENABLE_TV = "keydata_tv_apps_enable"
  553. private const val KEY_SPLIT_DISABLE_TV = "keydata_tv_apps_disable"
  554. private const val KEY_SPLIT_TUNNEL_ENTRY = "keydata_tv_apps_entry"
  555. private const val APP_DETAILS = "keydata_app_detail"
  556. private const val FILE_DETAILS = "keydata_file_details"
  557. private const val PROTOCOL = "keydata_protocol"
  558. private const val TV_SPLIT_CLASS = "keydata_tvsplitclass"
  559. private const val X_PLATFORM_TOKEN = "keydata_x_platform_token"
  560. private const val KEY_FCM = "keydata_fcm"
  561. private const val KEY_SPLIT_POS = "keydata_split_pos"
  562. private const val KEY_ACTIVITY = "keydata_activity"
  563. private const val KEY_ADBLOCK_SWITCH = "keydata_adblock"
  564. private const val KEY_ISLOGGEDIN = "key_isloggedin"
  565. private const val THEME = "key_theme"
  566. private const val KEY_ISCONNECT = "keydata_isconnect"
  567. private const val FILTER = "keydata_filter"
  568. private const val SMART = "keydata_smart"
  569. private const val KEY_SMART_SERVER = "keydata_smart_server"
  570. private const val KEY_AUTO_OPENVPN = "keydata_auto_openvpn"
  571. private const val KEY_RECOMMENDED = "keydata_recommended"
  572. private const val KEY_RECOMMENDED_LIST = "keydata_recommended_list"
  573. private const val KEY_CONNECTED_SERVER = "keydata_connected_server"
  574. private const val KEY_SUBSCRIPTION = "keydata_subscription"
  575. private const val KEY_RECENTLY_SERVERS = "keydata_recently_servers"
  576. private const val KEY_FEEDBACK = "key_feedback"
  577. private const val KEY_LAUNCH = "key_launch"
  578. private const val LANGUAGE = "key_language"
  579. private const val KEY_SERVERS_ID = "key_servers_id"
  580. private const val KEY_RECENTLY_SERVERS_ID = "keydata_recently_servers_id"
  581. }
  582. }