From 343b6541119e586bad11fcfbea855f952c2fff3f Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 23 Jun 2022 16:08:36 +0200 Subject: [PATCH] Move cache in main menu --- .../app/fedilab/android/BaseMainActivity.java | 11 ++++----- .../activities/PartnerShipActivity.java | 20 ---------------- .../activities/WebviewConnectActivity.java | 21 ----------------- .../timeline/FragmentMastodonTimeline.java | 23 ++++++++++--------- .../res/drawable/ic_baseline_cached_24.xml | 10 ++++++++ .../main/res/menu/activity_main_drawer.xml | 4 ++++ app/src/main/res/menu/main.xml | 4 ---- 7 files changed, 31 insertions(+), 62 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_cached_24.xml diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 3e5ee3a3..6b8f26c5 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -356,6 +356,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } else if (id == R.id.nav_announcements) { Intent intent = new Intent(this, AnnouncementActivity.class); startActivity(intent); + } else if (id == R.id.nav_cache) { + Intent intent = new Intent(BaseMainActivity.this, CacheActivity.class); + startActivity(intent); } binding.drawerLayout.close(); return false; @@ -521,10 +524,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intent = new Intent(BaseMainActivity.this, InstanceActivity.class); startActivity(intent); return true; - } else if (itemId == R.id.action_cache) { - Intent intent = new Intent(BaseMainActivity.this, CacheActivity.class); - startActivity(intent); - return true; } else if (itemId == R.id.action_proxy) { Intent intent = new Intent(BaseMainActivity.this, ProxyActivity.class); startActivity(intent); @@ -749,7 +748,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } popup.setOnDismissListener(menu1 -> { if (binding.viewPager.getAdapter() != null) { - Fragment fragment = (Fragment) getSupportFragmentManager().findFragmentByTag("f" + binding.viewPager.getCurrentItem()); + Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + binding.viewPager.getCurrentItem()); if (fragment instanceof FragmentMastodonTimeline && fragment.isVisible()) { FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment); fragmentMastodonTimeline.refreshAllAdapters(); @@ -880,7 +879,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt */ private void scrollToTop() { if (binding.viewPager.getAdapter() != null) { - Fragment fragment = (Fragment) getSupportFragmentManager().findFragmentByTag("f" + binding.viewPager.getCurrentItem()); + Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + binding.viewPager.getCurrentItem()); if (fragment instanceof FragmentMastodonTimeline) { FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment); fragmentMastodonTimeline.scrollToTop(); diff --git a/app/src/main/java/app/fedilab/android/activities/PartnerShipActivity.java b/app/src/main/java/app/fedilab/android/activities/PartnerShipActivity.java index 3e17e678..ffa8e130 100644 --- a/app/src/main/java/app/fedilab/android/activities/PartnerShipActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/PartnerShipActivity.java @@ -20,15 +20,10 @@ import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.Bundle; import android.text.method.LinkMovementMethod; -import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; -import androidx.appcompat.app.ActionBar; import androidx.core.app.ActivityOptionsCompat; import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; @@ -62,21 +57,6 @@ public class PartnerShipActivity extends BaseActivity { getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.cyanea_primary))); } - - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); - assert inflater != null; - View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(PartnerShipActivity.this), false); - view.setBackground(new ColorDrawable(ContextCompat.getColor(PartnerShipActivity.this, R.color.cyanea_primary))); - actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); - ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); - TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); - toolbar_close.setOnClickListener(v -> finish()); - toolbar_title.setText(R.string.action_partnership); - } - TextView about_partnership = findViewById(R.id.about_partnership); about_partnership.setMovementMethod(LinkMovementMethod.getInstance()); diff --git a/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java b/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java index 3bd1f6fe..fa211284 100644 --- a/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/WebviewConnectActivity.java @@ -28,27 +28,19 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.drawable.ColorDrawable; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ProgressBar; -import android.widget.TextView; -import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; import androidx.preference.PreferenceManager; @@ -134,19 +126,6 @@ public class WebviewConnectActivity extends BaseActivity { } if (login_url == null) finish(); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - assert inflater != null; - View view = inflater.inflate(R.layout.simple_bar, new LinearLayout(WebviewConnectActivity.this), false); - view.setBackground(new ColorDrawable(ContextCompat.getColor(WebviewConnectActivity.this, R.color.cyanea_primary))); - actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); - ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); - TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); - toolbar_close.setOnClickListener(v -> finish()); - toolbar_title.setText(R.string.add_account); - } clearCookies(WebviewConnectActivity.this); binding.webviewConnect.getSettings().setJavaScriptEnabled(true); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 493e796e..e1489a25 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -249,12 +249,16 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. return binding.getRoot(); } + private void initializeStatusesCommonView(final Statuses statuses) { + initializeStatusesCommonView(statuses, -1); + } + /** * Intialize the common view for statuses on different timelines * * @param statuses {@link Statuses} */ - private void initializeStatusesCommonView(final Statuses statuses) { + private void initializeStatusesCommonView(final Statuses statuses, int position) { flagLoading = false; if (binding == null) { return; @@ -327,6 +331,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. binding.recyclerView.setLayoutManager(mLayoutManager); binding.recyclerView.setAdapter(statusAdapter); + if (position != -1 && position < this.statuses.size()) { + binding.recyclerView.scrollToPosition(position); + } if (searchCache == null) { binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @@ -372,7 +379,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. if (binding == null) { return; } - int currentPosition = mLayoutManager.findFirstVisibleItemPosition(); binding.swipeContainer.setRefreshing(false); binding.loadingNextElements.setVisibility(View.GONE); flagLoading = false; @@ -394,10 +400,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. fetched_statuses.statuses = mediaStatuses; } //Update the timeline with new statuses - int inserted = updateStatusListWith(direction, fetched_statuses.statuses, fetchingMissing); - if (fetchingMissing) { - // binding.recyclerView.scrollToPosition(currentPosition + inserted); - } + updateStatusListWith(direction, fetched_statuses.statuses, fetchingMissing); if (!fetchingMissing) { if (fetched_statuses.pagination.max_id == null) { flagLoading = true; @@ -418,9 +421,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. * * @param statusListReceived - List Statuses received * @param fetchingMissing - boolean if the call concerns fetching messages (ie: refresh of from fetch more button) - * @return int - Number of messages that have been inserted in the middle of the timeline (ie between other statuses) */ - private int updateStatusListWith(DIRECTION direction, List statusListReceived, boolean fetchingMissing) { + private void updateStatusListWith(DIRECTION direction, List statusListReceived, boolean fetchingMissing) { int numberInserted = 0; int lastInsertedPosition = 0; int initialInsertedPosition = STATUS_PRESENT; @@ -459,7 +461,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } } } - return numberInserted; } /** @@ -571,14 +572,14 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. return; } QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(MainActivity.currentUserID, MainActivity.currentInstance, timelineType, ident); - if (direction != DIRECTION.REFRESH && !fetchingMissing && !binding.swipeContainer.isRefreshing() && direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) { + if (!fetchingMissing && !binding.swipeContainer.isRefreshing() && direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) { Statuses statuses = new Statuses(); statuses.statuses = quickLoad.statuses; statuses.pagination = new Pagination(); statuses.pagination.max_id = quickLoad.statuses.get(quickLoad.statuses.size() - 1).id; statuses.pagination.min_id = quickLoad.statuses.get(0).id; Handler mainHandler = new Handler(Looper.getMainLooper()); - Runnable myRunnable = () -> initializeStatusesCommonView(statuses); + Runnable myRunnable = () -> initializeStatusesCommonView(statuses, quickLoad.position); mainHandler.post(myRunnable); } else { Handler mainHandler = new Handler(Looper.getMainLooper()); diff --git a/app/src/main/res/drawable/ic_baseline_cached_24.xml b/app/src/main/res/drawable/ic_baseline_cached_24.xml new file mode 100644 index 00000000..a40e971b --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_cached_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index b7e788b4..cd0a799f 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -53,6 +53,10 @@ android:id="@+id/nav_settings" android:icon="@drawable/ic_baseline_settings_24" android:title="@string/settings" /> + -