|
16 | 16 |
|
17 | 17 | import com.google.android.material.floatingactionbutton.FloatingActionButton; |
18 | 18 |
|
| 19 | +import org.json.JSONException; |
| 20 | +import org.json.JSONObject; |
| 21 | + |
19 | 22 | import java.io.Serializable; |
20 | 23 | import java.time.Instant; |
21 | 24 | import java.util.ArrayList; |
22 | 25 | import java.util.HashMap; |
| 26 | +import java.util.Iterator; |
23 | 27 | import java.util.List; |
24 | 28 | import java.util.stream.Collectors; |
25 | 29 |
|
|
30 | 34 | import open.furaffinity.client.adapter.imageListAdapter; |
31 | 35 | import open.furaffinity.client.listener.EndlessRecyclerViewScrollListener; |
32 | 36 | import open.furaffinity.client.pages.loginCheck; |
| 37 | +import open.furaffinity.client.sqlite.browseContract; |
33 | 38 | import open.furaffinity.client.utilities.kvPair; |
34 | 39 | import open.furaffinity.client.utilities.uiControls; |
35 | 40 |
|
@@ -63,6 +68,8 @@ public class browse extends appFragment { |
63 | 68 | private boolean isLoading = false; |
64 | 69 | private List<HashMap<String, String>> mDataSet; |
65 | 70 |
|
| 71 | + private String browseParamaters = null; |
| 72 | + |
66 | 73 | private int recyclerViewPosition = -1; |
67 | 74 | private int pageNumber = -1; |
68 | 75 | private int pageCacheCheckResultCount = 0; |
@@ -138,8 +145,6 @@ private void initCurrentSettings() { |
138 | 145 | } |
139 | 146 |
|
140 | 147 | protected void initPages() { |
141 | | - ((mainActivity)requireActivity()).drawerFragmentPush(this.getClass().getName(), ""); |
142 | | - |
143 | 148 | if (mDataSet == null) { |
144 | 149 | mDataSet = new ArrayList<>(); |
145 | 150 | } |
@@ -233,7 +238,69 @@ public void requestFailed(abstractPage abstractPage) { |
233 | 238 | }); |
234 | 239 | } |
235 | 240 |
|
| 241 | + private JSONObject getSearchParamaterObject() { |
| 242 | + JSONObject result = new JSONObject(); |
| 243 | + |
| 244 | + try { |
| 245 | + result.put(browseContract.browseItemEntry.COLUMN_NAME_CAT, page.getCurrentCat()); |
| 246 | + result.put(browseContract.browseItemEntry.COLUMN_NAME_ATYPE, page.getCurrentAtype()); |
| 247 | + result.put(browseContract.browseItemEntry.COLUMN_NAME_SPECIES, page.getCurrentSpecies()); |
| 248 | + result.put(browseContract.browseItemEntry.COLUMN_NAME_GENDER, page.getCurrentGender()); |
| 249 | + result.put(browseContract.browseItemEntry.COLUMN_NAME_PERPAGE, page.getCurrentPerpage()); |
| 250 | + result.put(browseContract.browseItemEntry.COLUMN_NAME_RATINGGENERAL, (!page.getCurrentRatingGeneral().equals(""))); |
| 251 | + result.put(browseContract.browseItemEntry.COLUMN_NAME_RATINGMATURE, (!page.getCurrentRatingMature().equals(""))); |
| 252 | + result.put(browseContract.browseItemEntry.COLUMN_NAME_RATINGADULT, (!page.getCurrentRatingAdult().equals(""))); |
| 253 | + } catch (JSONException e) { |
| 254 | + e.printStackTrace(); |
| 255 | + } |
| 256 | + |
| 257 | + return result; |
| 258 | + } |
| 259 | + |
236 | 260 | private void loadCurrentSettings() { |
| 261 | + if(browseParamaters != null) { |
| 262 | + try { |
| 263 | + JSONObject loadedBrowseParamaters = new JSONObject(browseParamaters); |
| 264 | + |
| 265 | + for (Iterator<String> it = loadedBrowseParamaters.keys(); it.hasNext(); ) { |
| 266 | + String key = it.next(); |
| 267 | + |
| 268 | + switch(key) { |
| 269 | + case browseContract.browseItemEntry.COLUMN_NAME_CAT: |
| 270 | + page.setCat(loadedBrowseParamaters.getString(browseContract.browseItemEntry.COLUMN_NAME_CAT)); |
| 271 | + break; |
| 272 | + case browseContract.browseItemEntry.COLUMN_NAME_ATYPE: |
| 273 | + page.setAtype(loadedBrowseParamaters.getString(browseContract.browseItemEntry.COLUMN_NAME_ATYPE)); |
| 274 | + break; |
| 275 | + case browseContract.browseItemEntry.COLUMN_NAME_SPECIES: |
| 276 | + page.setSpecies(loadedBrowseParamaters.getString(browseContract.browseItemEntry.COLUMN_NAME_SPECIES)); |
| 277 | + break; |
| 278 | + case browseContract.browseItemEntry.COLUMN_NAME_GENDER: |
| 279 | + page.setGender(loadedBrowseParamaters.getString(browseContract.browseItemEntry.COLUMN_NAME_GENDER)); |
| 280 | + break; |
| 281 | + case browseContract.browseItemEntry.COLUMN_NAME_PERPAGE: |
| 282 | + page.setPerpage(loadedBrowseParamaters.getString(browseContract.browseItemEntry.COLUMN_NAME_PERPAGE)); |
| 283 | + break; |
| 284 | + case browseContract.browseItemEntry.COLUMN_NAME_RATINGGENERAL: |
| 285 | + page.setRatingGeneral(loadedBrowseParamaters.getBoolean(browseContract.browseItemEntry.COLUMN_NAME_RATINGGENERAL)); |
| 286 | + break; |
| 287 | + case browseContract.browseItemEntry.COLUMN_NAME_RATINGMATURE: |
| 288 | + page.setRatingMature(loadedBrowseParamaters.getBoolean(browseContract.browseItemEntry.COLUMN_NAME_RATINGMATURE)); |
| 289 | + break; |
| 290 | + case browseContract.browseItemEntry.COLUMN_NAME_RATINGADULT: |
| 291 | + page.setRatingAdult(loadedBrowseParamaters.getBoolean(browseContract.browseItemEntry.COLUMN_NAME_RATINGADULT)); |
| 292 | + break; |
| 293 | + default: |
| 294 | + break; |
| 295 | + } |
| 296 | + } |
| 297 | + } catch (JSONException e) { |
| 298 | + e.printStackTrace(); |
| 299 | + } |
| 300 | + |
| 301 | + browseParamaters = null; |
| 302 | + } |
| 303 | + |
237 | 304 | uiControls.spinnerSetAdapter(requireContext(), browseCatSpinner, page.getCat(), page.getCurrentCat(), true, true); |
238 | 305 | uiControls.spinnerSetAdapter(requireContext(), browseAtypeSpinner, page.getAtype(), page.getCurrentAtype(), true, true); |
239 | 306 | uiControls.spinnerSetAdapter(requireContext(), browseSpeciesSpinner, page.getSpecies(), page.getCurrentSpecies(), true, true); |
@@ -348,6 +415,7 @@ public void onLoadMore(int pageNumber, int totalItemsCount, RecyclerView view) { |
348 | 415 | if (settingsTableLayout.getVisibility() == View.VISIBLE) { |
349 | 416 | settingsTableLayout.setVisibility(View.GONE); |
350 | 417 | saveCurrentSettings(); |
| 418 | + ((mainActivity)requireActivity()).drawerFragmentPush(this.getClass().getName(), getSearchParamaterObject().toString()); |
351 | 419 | swipeRefreshLayout.setVisibility(View.VISIBLE); |
352 | 420 | } else { |
353 | 421 | swipeRefreshLayout.setVisibility(View.GONE); |
@@ -378,26 +446,32 @@ private int getRecyclerFirstItem() { |
378 | 446 | public void onCreate(Bundle savedInstanceState) { |
379 | 447 | super.onCreate(savedInstanceState); |
380 | 448 |
|
381 | | - Context context = requireActivity(); |
382 | | - SharedPreferences sharedPref = context.getSharedPreferences(getString(R.string.settingsFile), Context.MODE_PRIVATE); |
| 449 | + browseParamaters = ((mainActivity) requireActivity()).getBrowseParamaters(); |
383 | 450 |
|
384 | | - if (sharedPref.getBoolean(getString(R.string.cachedBrowseStateSetting), open.furaffinity.client.fragmentDrawers.settings.cachedBrowseDefault)) { |
385 | | - long sessionTimestamp = sharedPref.getLong(getString(R.string.browseSessionTimestamp), 0); |
386 | | - long sessionInvalidateCachedTime = sharedPref.getInt(getString(R.string.InvalidateCachedBrowseTimeSetting), settings.InvalidateCachedBrowseTimeDefault); |
387 | | - sessionInvalidateCachedTime = sessionInvalidateCachedTime * 60;//convert min to seconds |
| 451 | + if (browseParamaters == null) { |
| 452 | + Context context = requireActivity(); |
| 453 | + SharedPreferences sharedPref = context.getSharedPreferences(getString(R.string.settingsFile), Context.MODE_PRIVATE); |
388 | 454 |
|
389 | | - long currentTimestamp = Instant.now().getEpochSecond(); |
390 | | - long minTimestamp = currentTimestamp - sessionInvalidateCachedTime; |
| 455 | + if (sharedPref.getBoolean(getString(R.string.cachedBrowseStateSetting), open.furaffinity.client.fragmentDrawers.settings.cachedBrowseDefault)) { |
| 456 | + long sessionTimestamp = sharedPref.getLong(getString(R.string.browseSessionTimestamp), 0); |
| 457 | + long sessionInvalidateCachedTime = sharedPref.getInt(getString(R.string.InvalidateCachedBrowseTimeSetting), settings.InvalidateCachedBrowseTimeDefault); |
| 458 | + sessionInvalidateCachedTime = sessionInvalidateCachedTime * 60;//convert min to seconds |
| 459 | + |
| 460 | + long currentTimestamp = Instant.now().getEpochSecond(); |
| 461 | + long minTimestamp = currentTimestamp - sessionInvalidateCachedTime; |
391 | 462 |
|
392 | | - if (sessionTimestamp >= minTimestamp && sessionTimestamp <= currentTimestamp) { |
393 | | - pageCacheCheckResultCount = sharedPref.getInt(context.getString(R.string.InvalidateCachedBrowseAfterSetting), settings.InvalidateCachedBrowseAfterDefault); |
| 463 | + if (sessionTimestamp >= minTimestamp && sessionTimestamp <= currentTimestamp) { |
| 464 | + pageCacheCheckResultCount = sharedPref.getInt(context.getString(R.string.InvalidateCachedBrowseAfterSetting), settings.InvalidateCachedBrowseAfterDefault); |
394 | 465 |
|
395 | | - String mDataSetString = sharedPref.getString(context.getString(R.string.browseSessionDataSet), null); |
396 | | - pageNumber = sharedPref.getInt(context.getString(R.string.browseSessionPage), -1); |
397 | | - recyclerViewPosition = sharedPref.getInt(context.getString(R.string.browseSessionRecyclerView), -1); |
| 466 | + String mDataSetString = sharedPref.getString(context.getString(R.string.browseSessionDataSet), null); |
| 467 | + pageNumber = sharedPref.getInt(context.getString(R.string.browseSessionPage), -1); |
| 468 | + recyclerViewPosition = sharedPref.getInt(context.getString(R.string.browseSessionRecyclerView), -1); |
398 | 469 |
|
399 | | - if (mDataSetString != null) { |
400 | | - mDataSet = (List<HashMap<String, String>>) open.furaffinity.client.utilities.serialization.deSearilizeFromString(mDataSetString); |
| 470 | + if (mDataSetString != null) { |
| 471 | + mDataSet = (List<HashMap<String, String>>) open.furaffinity.client.utilities.serialization.deSearilizeFromString(mDataSetString); |
| 472 | + } else { |
| 473 | + isCacheInitialized = true; |
| 474 | + } |
401 | 475 | } else { |
402 | 476 | isCacheInitialized = true; |
403 | 477 | } |
|
0 commit comments