Move cache in main menu

This commit is contained in:
Thomas 2022-06-23 16:08:36 +02:00
parent bc44528557
commit 343b654111
7 changed files with 31 additions and 62 deletions

View File

@ -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();

View File

@ -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());

View File

@ -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);

View File

@ -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<Status> 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<Status> statusListReceived, boolean fetchingMissing) {
private void updateStatusListWith(DIRECTION direction, List<Status> 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());

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19,8l-4,4h3c0,3.31 -2.69,6 -6,6 -1.01,0 -1.97,-0.25 -2.8,-0.7l-1.46,1.46C8.97,19.54 10.43,20 12,20c4.42,0 8,-3.58 8,-8h3l-4,-4zM6,12c0,-3.31 2.69,-6 6,-6 1.01,0 1.97,0.25 2.8,0.7l1.46,-1.46C15.03,4.46 13.57,4 12,4c-4.42,0 -8,3.58 -8,8H1l4,4 4,-4H6z" />
</vector>

View File

@ -53,6 +53,10 @@
android:id="@+id/nav_settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="@string/settings" />
<item
android:id="@+id/nav_cache"
android:icon="@drawable/ic_baseline_cached_24"
android:title="@string/action_cache" />
<item
android:id="@+id/nav_about"
android:icon="@drawable/ic_baseline_info_24"

View File

@ -5,10 +5,6 @@
android:id="@+id/action_about_instance"
android:title="@string/action_about_instance"
app:showAsAction="never" />
<item
android:id="@+id/action_cache"
android:title="@string/action_cache"
app:showAsAction="never" />
<item
android:id="@+id/action_proxy"
android:title="@string/proxy_set"