Some cleaning

This commit is contained in:
Thomas 2024-01-09 16:00:35 +01:00
parent 2edfd8c945
commit 1ff15b0f93
58 changed files with 215 additions and 282 deletions

View file

@ -36,7 +36,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.database.MatrixCursor; import android.database.MatrixCursor;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
@ -73,7 +72,6 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
import androidx.cursoradapter.widget.CursorAdapter; import androidx.cursoradapter.widget.CursorAdapter;
@ -81,7 +79,6 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.Navigation; import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.AppBarConfiguration;
@ -1625,8 +1622,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
if (binding.viewPager.getAdapter() != null) { if (binding.viewPager.getAdapter() != null) {
int tabPosition = binding.tabLayout.getSelectedTabPosition(); int tabPosition = binding.tabLayout.getSelectedTabPosition();
Fragment fragment = (Fragment) binding.viewPager.getAdapter().instantiateItem(binding.viewPager, Math.max(tabPosition, 0)); Fragment fragment = (Fragment) binding.viewPager.getAdapter().instantiateItem(binding.viewPager, Math.max(tabPosition, 0));
if (fragment instanceof FragmentMastodonTimeline && fragment.isVisible()) { if (fragment instanceof FragmentMastodonTimeline fragmentMastodonTimeline && fragment.isVisible()) {
FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment);
fragmentMastodonTimeline.refreshAllAdapters(); fragmentMastodonTimeline.refreshAllAdapters();
} }
} }
@ -1921,14 +1917,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
int position = binding.tabLayout.getSelectedTabPosition(); int position = binding.tabLayout.getSelectedTabPosition();
if (binding.viewPager.getAdapter() != null) { if (binding.viewPager.getAdapter() != null) {
Fragment fragment = (Fragment) binding.viewPager.getAdapter().instantiateItem(binding.viewPager, Math.max(position, 0)); Fragment fragment = (Fragment) binding.viewPager.getAdapter().instantiateItem(binding.viewPager, Math.max(position, 0));
if (fragment instanceof FragmentMastodonTimeline) { if (fragment instanceof FragmentMastodonTimeline fragmentMastodonTimeline) {
FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment);
fragmentMastodonTimeline.scrollToTop(); fragmentMastodonTimeline.scrollToTop();
} else if (fragment instanceof FragmentMastodonConversation) { } else if (fragment instanceof FragmentMastodonConversation fragmentMastodonConversation) {
FragmentMastodonConversation fragmentMastodonConversation = ((FragmentMastodonConversation) fragment);
fragmentMastodonConversation.scrollToTop(); fragmentMastodonConversation.scrollToTop();
} else if (fragment instanceof FragmentNotificationContainer) { } else if (fragment instanceof FragmentNotificationContainer fragmentNotificationContainer) {
FragmentNotificationContainer fragmentNotificationContainer = ((FragmentNotificationContainer) fragment);
fragmentNotificationContainer.scrollToTop(); fragmentNotificationContainer.scrollToTop();
} }
} }

View file

@ -28,7 +28,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import androidx.core.app.ActivityOptionsCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.ArrayList; import java.util.ArrayList;
@ -87,10 +86,10 @@ public class AboutActivity extends BaseBarActivity {
String finalVersion = version; String finalVersion = version;
binding.aboutVersionCopy.setOnClickListener(v->{ binding.aboutVersionCopy.setOnClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
String content = "Fedilab v" + finalVersion + " for " + (BuildConfig.DONATIONS?"FDroid":"Google"); String content = "Fedilab v" + finalVersion + " for " + (BuildConfig.DONATIONS ? "FDroid" : "Google");
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
if (clipboard != null) { if (clipboard != null) {

View file

@ -52,6 +52,7 @@ public class AccountReportActivity extends BaseBarActivity {
private ActivityAdminReportBinding binding; private ActivityAdminReportBinding binding;
private AdminVM adminVM; private AdminVM adminVM;
private AdminAccount targeted_account; private AdminAccount targeted_account;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -73,9 +74,10 @@ public class AccountReportActivity extends BaseBarActivity {
initializeAfterBundle(null); initializeAfterBundle(null);
} }
} }
private void initializeAfterBundle(Bundle bundle) { private void initializeAfterBundle(Bundle bundle) {
if(bundle != null) { if (bundle != null) {
account_id = bundle.getString(Helper.ARG_ACCOUNT_ID, null); account_id = bundle.getString(Helper.ARG_ACCOUNT_ID, null);
targeted_account = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); targeted_account = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT);
report = (AdminReport) bundle.getSerializable(Helper.ARG_REPORT); report = (AdminReport) bundle.getSerializable(Helper.ARG_REPORT);

View file

@ -39,7 +39,6 @@ import org.conscrypt.Conscrypt;
import java.security.Security; import java.security.Security;
import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.ThemeHelper; import app.fedilab.android.mastodon.helper.ThemeHelper;

View file

@ -50,7 +50,6 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.work.Data; import androidx.work.Data;
@ -485,9 +484,9 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
statusList = new ArrayList<>(); statusList = new ArrayList<>();
Bundle b = getIntent().getExtras(); Bundle b = getIntent().getExtras();
if(b != null) { if (b != null) {
long bundleId = b.getLong(Helper.ARG_INTENT_ID, -1); long bundleId = b.getLong(Helper.ARG_INTENT_ID, -1);
if(bundleId != -1 ) { if (bundleId != -1) {
new CachedBundle(ComposeActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); new CachedBundle(ComposeActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else { } else {
initializeAfterBundle(b); initializeAfterBundle(b);
@ -497,7 +496,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
private void initializeAfterBundle(Bundle b) { private void initializeAfterBundle(Bundle b) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
new Thread(()->{ new Thread(() -> {
if (b != null) { if (b != null) {
statusReply = (Status) b.getSerializable(Helper.ARG_STATUS_REPLY); statusReply = (Status) b.getSerializable(Helper.ARG_STATUS_REPLY);
statusQuoted = (Status) b.getSerializable(Helper.ARG_QUOTED_MESSAGE); statusQuoted = (Status) b.getSerializable(Helper.ARG_QUOTED_MESSAGE);
@ -802,7 +801,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
status.id = Helper.generateIdString(); status.id = Helper.generateIdString();
status.mentions = statusList.get(position - 1).mentions; status.mentions = statusList.get(position - 1).mentions;
status.visibility = statusList.get(position - 1).visibility; status.visibility = statusList.get(position - 1).visibility;
if(initialContent != null) { if (initialContent != null) {
status.text = initialContent; status.text = initialContent;
} }
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ComposeActivity.this); final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ComposeActivity.this);

View file

@ -33,7 +33,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputEditText;

View file

@ -40,7 +40,6 @@ import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityFollowedTagsBinding; import app.fedilab.android.databinding.ActivityFollowedTagsBinding;
import app.fedilab.android.databinding.PopupAddFollowedTagtBinding; import app.fedilab.android.databinding.PopupAddFollowedTagtBinding;
import app.fedilab.android.mastodon.client.entities.api.MastodonList;
import app.fedilab.android.mastodon.client.entities.api.Tag; import app.fedilab.android.mastodon.client.entities.api.Tag;
import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.client.entities.app.Timeline;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
@ -151,7 +150,7 @@ public class FollowedTagActivity extends BaseBarActivity implements FollowedTagA
popupAddFollowedTagtBinding.addTag.setFilters(new InputFilter[]{new InputFilter.LengthFilter(255)}); popupAddFollowedTagtBinding.addTag.setFilters(new InputFilter[]{new InputFilter.LengthFilter(255)});
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> { dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
String name = Objects.requireNonNull(popupAddFollowedTagtBinding.addTag.getText()).toString().trim(); String name = Objects.requireNonNull(popupAddFollowedTagtBinding.addTag.getText()).toString().trim();
if(tagList.contains(new Tag(name))) { if (tagList.contains(new Tag(name))) {
Toasty.error(FollowedTagActivity.this, getString(R.string.tag_already_followed), Toasty.LENGTH_LONG).show(); Toasty.error(FollowedTagActivity.this, getString(R.string.tag_already_followed), Toasty.LENGTH_LONG).show();
return; return;
} }

View file

@ -29,7 +29,6 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -60,63 +60,63 @@ class InstanceHealthActivity : DialogFragment() {
private fun checkInstance() { private fun checkInstance() {
val instanceSocialVM = val instanceSocialVM =
ViewModelProvider(this@InstanceHealthActivity)[InstanceSocialVM::class.java] ViewModelProvider(this@InstanceHealthActivity)[InstanceSocialVM::class.java]
instanceSocialVM.getInstances(BaseMainActivity.currentInstance.trim { it <= ' ' }) instanceSocialVM.getInstances(BaseMainActivity.currentInstance.trim { it <= ' ' })
.observe(this@InstanceHealthActivity) { instanceSocialList: InstanceSocial? -> .observe(this@InstanceHealthActivity) { instanceSocialList: InstanceSocial? ->
val instance = instanceSocialList?.instances?.firstOrNull { instance -> val instance = instanceSocialList?.instances?.firstOrNull { instance ->
instance.name.equals( instance.name.equals(
BaseMainActivity.currentInstance.trim { it <= ' ' }, BaseMainActivity.currentInstance.trim { it <= ' ' },
ignoreCase = true ignoreCase = true
) )
}
if (instance != null) {
instance.thumbnail?.takeIf { it != "null" }?.let { thumbnail ->
Glide.with(this@InstanceHealthActivity)
.asBitmap()
.placeholder(R.drawable.default_banner)
.load(thumbnail)
.into(binding.backgroundImage)
} }
binding.name.text = instance.name if (instance != null) {
if (instance.up) { instance.thumbnail?.takeIf { it != "null" }?.let { thumbnail ->
binding.up.setText(R.string.is_up) Glide.with(this@InstanceHealthActivity)
binding.up.setTextColor( .asBitmap()
ThemeHelper.getAttColor( .placeholder(R.drawable.default_banner)
requireContext(), .load(thumbnail)
R.attr.colorPrimary .into(binding.backgroundImage)
}
binding.name.text = instance.name
if (instance.up) {
binding.up.setText(R.string.is_up)
binding.up.setTextColor(
ThemeHelper.getAttColor(
requireContext(),
R.attr.colorPrimary
)
) )
} else {
binding.up.setText(R.string.is_down)
binding.up.setTextColor(
ThemeHelper.getAttColor(
requireContext(),
R.attr.colorError
)
)
}
binding.uptime.text = getString(
R.string.instance_health_uptime,
instance.uptime * 100
)
if (instance.checked_at != null)
binding.checkedAt.text =
getString(
R.string.instance_health_checkedat,
Helper.dateToString(instance.checked_at)
)
binding.values.text = getString(
R.string.instance_health_indication,
instance.version,
Helper.withSuffix(instance.active_users.toLong()),
Helper.withSuffix(instance.statuses.toLong())
) )
} else { } else {
binding.up.setText(R.string.is_down) binding.instanceData.isVisible = false
binding.up.setTextColor( binding.noInstance.isVisible = true
ThemeHelper.getAttColor(
requireContext(),
R.attr.colorError
)
)
} }
binding.uptime.text = getString( binding.loader.isVisible = false
R.string.instance_health_uptime,
instance.uptime * 100
)
if (instance.checked_at != null)
binding.checkedAt.text =
getString(
R.string.instance_health_checkedat,
Helper.dateToString(instance.checked_at)
)
binding.values.text = getString(
R.string.instance_health_indication,
instance.version,
Helper.withSuffix(instance.active_users.toLong()),
Helper.withSuffix(instance.statuses.toLong())
)
} else {
binding.instanceData.isVisible = false
binding.noInstance.isVisible = true
} }
binding.loader.isVisible = false
}
} }
override fun onDestroyView() { override fun onDestroyView() {

View file

@ -32,7 +32,6 @@ import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;

View file

@ -240,7 +240,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
} }
private Spannable linkify(Context context, String content) { private Spannable linkify(Context context, String content) {
if(content == null) { if (content == null) {
return new SpannableString(""); return new SpannableString("");
} }
Matcher matcher = WEB_URL.matcher(content); Matcher matcher = WEB_URL.matcher(content);
@ -263,7 +263,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
if(!underlineLinks) { if (!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined); ds.setUnderlineText(status != null && status.underlined);
} }
} }
@ -300,7 +300,8 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
finish(); finish();
try { try {
ActivityCompat.finishAfterTransition(MediaActivity.this); ActivityCompat.finishAfterTransition(MediaActivity.this);
}catch (Exception ignored){} } catch (Exception ignored) {
}
return true; return true;
} else if (item.getItemId() == R.id.action_save) { } else if (item.getItemId() == R.id.action_save) {
int position = binding.mediaViewpager.getCurrentItem(); int position = binding.mediaViewpager.getCurrentItem();

View file

@ -25,7 +25,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.app.ActivityOptionsCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -54,7 +54,6 @@ import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityOptionsCompat; import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -136,7 +135,7 @@ public class ProfileActivity extends BaseActivity {
Bundle args = intent.getExtras(); Bundle args = intent.getExtras();
if (args != null) { if (args != null) {
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
if(bundleId != -1 ) { if (bundleId != -1) {
new CachedBundle(ProfileActivity.this).getBundle(bundleId, currentAccount, bundle -> { new CachedBundle(ProfileActivity.this).getBundle(bundleId, currentAccount, bundle -> {
Account accountReceived = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); Account accountReceived = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
if (bundle.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) { if (bundle.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) {

View file

@ -31,7 +31,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;

View file

@ -74,9 +74,9 @@ public class ReportActivity extends BaseBarActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
Bundle args = getIntent().getExtras(); Bundle args = getIntent().getExtras();
if(args != null) { if (args != null) {
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
if(bundleId != -1 ) { if (bundleId != -1) {
new CachedBundle(ReportActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); new CachedBundle(ReportActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else { } else {
initializeAfterBundle(args); initializeAfterBundle(args);

View file

@ -114,14 +114,11 @@ public class SearchResultTabActivity extends BaseBarActivity {
Fragment fragment; Fragment fragment;
if (binding.searchViewpager.getAdapter() != null) { if (binding.searchViewpager.getAdapter() != null) {
fragment = (Fragment) binding.searchViewpager.getAdapter().instantiateItem(binding.searchViewpager, tab.getPosition()); fragment = (Fragment) binding.searchViewpager.getAdapter().instantiateItem(binding.searchViewpager, tab.getPosition());
if (fragment instanceof FragmentMastodonAccount) { if (fragment instanceof FragmentMastodonAccount fragmentMastodonAccount) {
FragmentMastodonAccount fragmentMastodonAccount = ((FragmentMastodonAccount) fragment);
fragmentMastodonAccount.scrollToTop(); fragmentMastodonAccount.scrollToTop();
} else if (fragment instanceof FragmentMastodonTimeline) { } else if (fragment instanceof FragmentMastodonTimeline fragmentMastodonTimeline) {
FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment);
fragmentMastodonTimeline.scrollToTop(); fragmentMastodonTimeline.scrollToTop();
} else if (fragment instanceof FragmentMastodonTag) { } else if (fragment instanceof FragmentMastodonTag fragmentMastodonTag) {
FragmentMastodonTag fragmentMastodonTag = ((FragmentMastodonTag) fragment);
fragmentMastodonTag.scrollToTop(); fragmentMastodonTag.scrollToTop();
} }
} }

View file

@ -112,7 +112,7 @@ public class AdminAccountActivity extends BaseActivity {
private void initializeAfterBundle(Bundle bundle) { private void initializeAfterBundle(Bundle bundle) {
if(bundle !=null) { if (bundle != null) {
adminAccount = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); adminAccount = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT);
account_id = bundle.getString(Helper.ARG_ACCOUNT_ID, null); account_id = bundle.getString(Helper.ARG_ACCOUNT_ID, null);
} }

View file

@ -27,7 +27,6 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.Objects; import java.util.Objects;

View file

@ -48,7 +48,6 @@ import com.bumptech.glide.request.transition.Transition;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
@ -115,7 +114,7 @@ public class AdminReportActivity extends BaseBarActivity {
private void initializeAfterBundle(Bundle bundle) { private void initializeAfterBundle(Bundle bundle) {
if(bundle != null) { if (bundle != null) {
adminAccount = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); adminAccount = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT);
if (adminAccount != null) { if (adminAccount != null) {
account = adminAccount.account; account = adminAccount.account;

View file

@ -19,16 +19,13 @@ import static app.fedilab.android.BaseMainActivity.emojis;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteBlobTooBigException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelProvider;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
@ -41,7 +38,6 @@ import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.mastodon.client.endpoints.MastodonInstanceService; import app.fedilab.android.mastodon.client.endpoints.MastodonInstanceService;
import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.viewmodel.mastodon.InstancesVM;
import app.fedilab.android.sqlite.Sqlite; import app.fedilab.android.sqlite.Sqlite;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import retrofit2.Call; import retrofit2.Call;
@ -230,17 +226,12 @@ public class EmojiInstance implements Serializable {
} }
} }
public interface EmojiFilteredCallBack{
void get(List<Emoji> emojiList);
}
/** /**
* Returns the emojis for an instance * Returns the emojis for an instance
* *
* @param instance String * @param instance String
* @param filter String * @param filter String
* @param callBack EmojiFilteredCallBack - Get filtered emojis * @param callBack EmojiFilteredCallBack - Get filtered emojis
*
* @return List<Emoji> - List of {@link Emoji} * @return List<Emoji> - List of {@link Emoji}
*/ */
public void getEmojiListFiltered(@NonNull String instance, @NonNull String filter, EmojiFilteredCallBack callBack) throws DBException { public void getEmojiListFiltered(@NonNull String instance, @NonNull String filter, EmojiFilteredCallBack callBack) throws DBException {
@ -248,12 +239,12 @@ public class EmojiInstance implements Serializable {
throw new DBException("db is null. Wrong initialization."); throw new DBException("db is null. Wrong initialization.");
} }
new Thread(() -> { new Thread(() -> {
List<Emoji> emojiArrayList= new ArrayList<>(); List<Emoji> emojiArrayList = new ArrayList<>();
List<Emoji> emojiFiltered= new ArrayList<>(); List<Emoji> emojiFiltered = new ArrayList<>();
if (emojis == null || !emojis.containsKey(BaseMainActivity.currentInstance) || emojis.get(BaseMainActivity.currentInstance) == null) { if (emojis == null || !emojis.containsKey(BaseMainActivity.currentInstance) || emojis.get(BaseMainActivity.currentInstance) == null) {
try { try {
Cursor c = db.query(Sqlite.TABLE_EMOJI_INSTANCE, null, Sqlite.COL_INSTANCE + " = '" + instance + "'", null, null, null, null, "1"); Cursor c = db.query(Sqlite.TABLE_EMOJI_INSTANCE, null, Sqlite.COL_INSTANCE + " = '" + instance + "'", null, null, null, null, "1");
emojiArrayList = cursorToEmojiList(c); emojiArrayList = cursorToEmojiList(c);
} catch (Exception e) { } catch (Exception e) {
MastodonInstanceService mastodonInstanceService = init(instance); MastodonInstanceService mastodonInstanceService = init(instance);
Call<List<Emoji>> emojiCall = mastodonInstanceService.customEmoji(); Call<List<Emoji>> emojiCall = mastodonInstanceService.customEmoji();
@ -271,9 +262,9 @@ public class EmojiInstance implements Serializable {
} else { } else {
emojiArrayList = emojis.get(instance); emojiArrayList = emojis.get(instance);
} }
if(emojiArrayList != null && emojiArrayList.size() > 0 ) { if (emojiArrayList != null && emojiArrayList.size() > 0) {
for(Emoji emoji: emojiArrayList) { for (Emoji emoji : emojiArrayList) {
if(emoji.shortcode.contains(filter)) { if (emoji.shortcode.contains(filter)) {
emojiFiltered.add(emoji); emojiFiltered.add(emoji);
} }
} }
@ -311,4 +302,8 @@ public class EmojiInstance implements Serializable {
} }
return filteredEmojis; return filteredEmojis;
} }
public interface EmojiFilteredCallBack {
void get(List<Emoji> emojiList);
}
} }

View file

@ -32,7 +32,8 @@ public class Tag implements Serializable {
@SerializedName("following") @SerializedName("following")
public boolean following = false; public boolean following = false;
public Tag() {} public Tag() {
}
public Tag(String name) { public Tag(String name) {
this.name = name; this.name = name;

View file

@ -56,7 +56,9 @@ public class CachedBundle {
private transient Context context; private transient Context context;
public CachedBundle() {} public CachedBundle() {
}
public CachedBundle(Context context) { public CachedBundle(Context context) {
//Creation of the DB with tables //Creation of the DB with tables
this.context = context; this.context = context;
@ -79,11 +81,11 @@ public class CachedBundle {
values.put(Sqlite.COL_BUNDLE, serializeBundle(bundle)); values.put(Sqlite.COL_BUNDLE, serializeBundle(bundle));
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date()));
values.put(Sqlite.COL_TYPE, CacheType.ARGS.getValue()); values.put(Sqlite.COL_TYPE, CacheType.ARGS.getValue());
if( bundle.containsKey(Helper.ARG_ACCOUNT) && currentUser != null) { if (bundle.containsKey(Helper.ARG_ACCOUNT) && currentUser != null) {
ContentValues valuesAccount = new ContentValues(); ContentValues valuesAccount = new ContentValues();
Bundle bundleAccount = new Bundle(); Bundle bundleAccount = new Bundle();
Account account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); Account account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
if(account != null) { if (account != null) {
bundleAccount.putSerializable(Helper.ARG_ACCOUNT, account); bundleAccount.putSerializable(Helper.ARG_ACCOUNT, account);
valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleAccount)); valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleAccount));
valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date()));
@ -95,11 +97,11 @@ public class CachedBundle {
db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount); db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount);
} }
} }
if( bundle.containsKey(Helper.ARG_STATUS) && currentUser != null) { if (bundle.containsKey(Helper.ARG_STATUS) && currentUser != null) {
ContentValues valuesAccount = new ContentValues(); ContentValues valuesAccount = new ContentValues();
Bundle bundleStatus = new Bundle(); Bundle bundleStatus = new Bundle();
Status status = (Status) bundle.getSerializable(Helper.ARG_STATUS); Status status = (Status) bundle.getSerializable(Helper.ARG_STATUS);
if(status != null) { if (status != null) {
bundleStatus.putSerializable(Helper.ARG_STATUS, status); bundleStatus.putSerializable(Helper.ARG_STATUS, status);
valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleStatus)); valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleStatus));
valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date()));
@ -119,36 +121,29 @@ public class CachedBundle {
} }
} }
public interface BundleCallback{
void get(Bundle bundle);
}
public interface BundleInsertCallback{
void inserted(long bundleId);
}
public void getBundle(long id, BaseAccount Account, BundleCallback callback) { public void getBundle(long id, BaseAccount Account, BundleCallback callback) {
new Thread(()->{ new Thread(() -> {
Bundle bundle = null; Bundle bundle = null;
try { try {
CachedBundle cachedBundle = getCachedBundle(String.valueOf(id)); CachedBundle cachedBundle = getCachedBundle(String.valueOf(id));
if (cachedBundle != null) { if (cachedBundle != null) {
bundle = cachedBundle.bundle; bundle = cachedBundle.bundle;
if(bundle != null && bundle.containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) { if (bundle != null && bundle.containsKey(Helper.ARG_CACHED_ACCOUNT_ID)) {
Account cachedAccount = getCachedAccount(Account, bundle.getString(Helper.ARG_CACHED_ACCOUNT_ID)); Account cachedAccount = getCachedAccount(Account, bundle.getString(Helper.ARG_CACHED_ACCOUNT_ID));
if(cachedAccount != null) { if (cachedAccount != null) {
bundle.putSerializable(Helper.ARG_ACCOUNT, cachedAccount); bundle.putSerializable(Helper.ARG_ACCOUNT, cachedAccount);
} }
} }
if(bundle != null && bundle.containsKey(Helper.ARG_CACHED_STATUS_ID)) { if (bundle != null && bundle.containsKey(Helper.ARG_CACHED_STATUS_ID)) {
Status cachedStatus = getCachedStatus(Account, bundle.getString(Helper.ARG_CACHED_STATUS_ID)); Status cachedStatus = getCachedStatus(Account, bundle.getString(Helper.ARG_CACHED_STATUS_ID));
if(cachedStatus != null) { if (cachedStatus != null) {
bundle.putSerializable(Helper.ARG_STATUS, cachedStatus); bundle.putSerializable(Helper.ARG_STATUS, cachedStatus);
} }
} }
} }
removeIntent(String.valueOf(id)); removeIntent(String.valueOf(id));
} catch (DBException ignored) {} } catch (DBException ignored) {
}
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Bundle finalBundle = bundle; Bundle finalBundle = bundle;
Runnable myRunnable = () -> callback.get(finalBundle); Runnable myRunnable = () -> callback.get(finalBundle);
@ -157,11 +152,12 @@ public class CachedBundle {
} }
public void insertBundle(Bundle bundle, BaseAccount Account, BundleInsertCallback callback) { public void insertBundle(Bundle bundle, BaseAccount Account, BundleInsertCallback callback) {
new Thread(()->{ new Thread(() -> {
long dbBundleId = -1; long dbBundleId = -1;
try { try {
dbBundleId = insertIntent(bundle, Account); dbBundleId = insertIntent(bundle, Account);
} catch (DBException ignored) {} } catch (DBException ignored) {
}
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
long finalDbBundleId = dbBundleId; long finalDbBundleId = dbBundleId;
Runnable myRunnable = () -> callback.inserted(finalDbBundleId); Runnable myRunnable = () -> callback.inserted(finalDbBundleId);
@ -169,8 +165,6 @@ public class CachedBundle {
}).start(); }).start();
} }
/** /**
* Returns a bundle by targeted account id * Returns a bundle by targeted account id
* *
@ -181,17 +175,17 @@ public class CachedBundle {
if (db == null) { if (db == null) {
throw new DBException("db is null. Wrong initialization."); throw new DBException("db is null. Wrong initialization.");
} }
if(account == null || target_id == null) { if (account == null || target_id == null) {
return null; return null;
} }
try { try {
Cursor c = db.query(Sqlite.TABLE_INTENT, null, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND " Cursor c = db.query(Sqlite.TABLE_INTENT, null, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND "
+ Sqlite.COL_INSTANCE + " = '" + account.instance+ "' AND " + Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND "
+ Sqlite.COL_TYPE + " = '" + CacheType.ACCOUNT.getValue() + "' AND " + Sqlite.COL_TYPE + " = '" + CacheType.ACCOUNT.getValue() + "' AND "
+ Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1"); + Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1");
CachedBundle cachedBundle = cursorToCachedBundle(c); CachedBundle cachedBundle = cursorToCachedBundle(c);
if(cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_ACCOUNT) ) { if (cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_ACCOUNT)) {
return (Account) cachedBundle.bundle.getSerializable(Helper.ARG_ACCOUNT); return (Account) cachedBundle.bundle.getSerializable(Helper.ARG_ACCOUNT);
} }
} catch (Exception e) { } catch (Exception e) {
return null; return null;
@ -199,7 +193,6 @@ public class CachedBundle {
return null; return null;
} }
/** /**
* Returns a bundle by targeted status id * Returns a bundle by targeted status id
* *
@ -210,17 +203,17 @@ public class CachedBundle {
if (db == null) { if (db == null) {
throw new DBException("db is null. Wrong initialization."); throw new DBException("db is null. Wrong initialization.");
} }
if(account == null || target_id == null) { if (account == null || target_id == null) {
return null; return null;
} }
try { try {
Cursor c = db.query(Sqlite.TABLE_INTENT, null, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND " Cursor c = db.query(Sqlite.TABLE_INTENT, null, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND "
+ Sqlite.COL_INSTANCE + " = '" + account.instance+ "' AND " + Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND "
+ Sqlite.COL_TYPE + " = '" + CacheType.STATUS.getValue() + "' AND " + Sqlite.COL_TYPE + " = '" + CacheType.STATUS.getValue() + "' AND "
+ Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1"); + Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1");
CachedBundle cachedBundle = cursorToCachedBundle(c); CachedBundle cachedBundle = cursorToCachedBundle(c);
if(cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_STATUS) ) { if (cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_STATUS)) {
return (Status) cachedBundle.bundle.getSerializable(Helper.ARG_STATUS); return (Status) cachedBundle.bundle.getSerializable(Helper.ARG_STATUS);
} }
} catch (Exception e) { } catch (Exception e) {
return null; return null;
@ -228,7 +221,6 @@ public class CachedBundle {
return null; return null;
} }
/** /**
* Returns a bundle by its ID * Returns a bundle by its ID
* *
@ -259,24 +251,21 @@ public class CachedBundle {
db.delete(Sqlite.TABLE_INTENT, Sqlite.COL_ID + " = '" + id + "'", null); db.delete(Sqlite.TABLE_INTENT, Sqlite.COL_ID + " = '" + id + "'", null);
} }
/** /**
* Remove a bundle from db * Remove a bundle from db
*
*/ */
private void removeIntent(BaseAccount account, String target_id) throws DBException { private void removeIntent(BaseAccount account, String target_id) throws DBException {
if (db == null) { if (db == null) {
throw new DBException("db is null. Wrong initialization."); throw new DBException("db is null. Wrong initialization.");
} }
if(account == null || target_id == null) { if (account == null || target_id == null) {
return; return;
} }
db.delete(Sqlite.TABLE_INTENT, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND " db.delete(Sqlite.TABLE_INTENT, Sqlite.COL_USER_ID + " = '" + account.user_id + "' AND "
+ Sqlite.COL_INSTANCE + " = '" + account.instance+ "' AND " + Sqlite.COL_INSTANCE + " = '" + account.instance + "' AND "
+ Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null); + Sqlite.COL_TARGET_ID + " = '" + target_id + "'", null);
} }
/*** /***
* Method to hydrate an CachedBundle from database * Method to hydrate an CachedBundle from database
* @param c Cursor * @param c Cursor
@ -325,7 +314,7 @@ public class CachedBundle {
zos.write(parcel.marshall()); zos.write(parcel.marshall());
zos.close(); zos.close();
base64 = Base64.encodeToString(bos.toByteArray(), 0); base64 = Base64.encodeToString(bos.toByteArray(), 0);
} catch(IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
parcel.recycle(); parcel.recycle();
@ -350,13 +339,12 @@ public class CachedBundle {
bundle = parcel.readBundle(getClass().getClassLoader()); bundle = parcel.readBundle(getClass().getClassLoader());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
parcel.recycle(); parcel.recycle();
} }
return bundle; return bundle;
} }
public enum CacheType { public enum CacheType {
@SerializedName("ARGS") @SerializedName("ARGS")
ARGS("ARGS"), ARGS("ARGS"),
@ -370,9 +358,19 @@ public class CachedBundle {
CacheType(String value) { CacheType(String value) {
this.value = value; this.value = value;
} }
public String getValue() { public String getValue() {
return value; return value;
} }
} }
public interface BundleCallback {
void get(Bundle bundle);
}
public interface BundleInsertCallback {
void inserted(long bundleId);
}
} }

View file

@ -69,20 +69,20 @@ class BlurHashDecoder {
val g = (value / 19) % 19 val g = (value / 19) % 19
val b = value % 19 val b = value % 19
return floatArrayOf( return floatArrayOf(
signedPow2((r - 9) / 9.0f) * maxAc, signedPow2((r - 9) / 9.0f) * maxAc,
signedPow2((g - 9) / 9.0f) * maxAc, signedPow2((g - 9) / 9.0f) * maxAc,
signedPow2((b - 9) / 9.0f) * maxAc signedPow2((b - 9) / 9.0f) * maxAc
) )
} }
private fun signedPow2(value: Float) = value.pow(2f).withSign(value) private fun signedPow2(value: Float) = value.pow(2f).withSign(value)
private fun composeBitmap( private fun composeBitmap(
width: Int, width: Int,
height: Int, height: Int,
numCompX: Int, numCompX: Int,
numCompY: Int, numCompY: Int,
colors: Array<FloatArray> colors: Array<FloatArray>
): Bitmap { ): Bitmap {
val imageArray = IntArray(width * height) val imageArray = IntArray(width * height)
for (y in 0 until height) { for (y in 0 until height) {
@ -100,7 +100,7 @@ class BlurHashDecoder {
} }
} }
imageArray[x + width * y] = imageArray[x + width * y] =
Color.rgb(linearToSrgb(r), linearToSrgb(g), linearToSrgb(b)) Color.rgb(linearToSrgb(r), linearToSrgb(g), linearToSrgb(b))
} }
} }
return Bitmap.createBitmap(imageArray, width, height, Bitmap.Config.ARGB_8888) return Bitmap.createBitmap(imageArray, width, height, Bitmap.Config.ARGB_8888)
@ -116,12 +116,12 @@ class BlurHashDecoder {
} }
private val charMap = listOf( private val charMap = listOf(
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '#', '$', '%', '*', '+', ',', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '#', '$', '%', '*', '+', ',',
'-', '.', ':', ';', '=', '?', '@', '[', ']', '^', '_', '{', '|', '}', '~' '-', '.', ':', ';', '=', '?', '@', '[', ']', '^', '_', '{', '|', '}', '~'
) )
.mapIndexed { i, c -> c to i } .mapIndexed { i, c -> c to i }
.toMap() .toMap()
} }

View file

@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.regex.Matcher; import java.util.regex.Matcher;
public class ComposeHelper { public class ComposeHelper {
@ -44,13 +43,13 @@ public class ComposeHelper {
Matcher matcher = mentionPatternALL.matcher(content); Matcher matcher = mentionPatternALL.matcher(content);
while (matcher.find()) { while (matcher.find()) {
String mentionLong = matcher.group(1); String mentionLong = matcher.group(1);
if(mentionLong != null) { if (mentionLong != null) {
if (!mentions.contains(mentionLong)) { if (!mentions.contains(mentionLong)) {
mentions.add(mentionLong); mentions.add(mentionLong);
} }
} }
String mentionShort = matcher.group(2); String mentionShort = matcher.group(2);
if(mentionShort != null) { if (mentionShort != null) {
if (!mentions.contains(mentionShort)) { if (!mentions.contains(mentionShort)) {
mentions.add(mentionShort); mentions.add(mentionShort);
} }

View file

@ -78,7 +78,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.browser.customtabs.CustomTabColorSchemeParams; import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent; import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@ -89,7 +88,6 @@ import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner; import androidx.lifecycle.ViewModelStoreOwner;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
@ -848,7 +846,7 @@ public class Helper {
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
public static String withSuffix(long count) { public static String withSuffix(long count) {
if (count < 1000) return "" + count; if (count < 1000) return String.valueOf(count);
int exp = (int) (Math.log(count) / Math.log(1000)); int exp = (int) (Math.log(count) / Math.log(1000));
Locale locale = null; Locale locale = null;
try { try {
@ -1000,8 +998,7 @@ public class Helper {
if (context == null) { if (context == null) {
return false; return false;
} }
if (context instanceof Activity) { if (context instanceof Activity activity) {
final Activity activity = (Activity) context;
return !activity.isDestroyed() && !activity.isFinishing(); return !activity.isDestroyed() && !activity.isFinishing();
} }
return true; return true;
@ -1611,7 +1608,7 @@ public class Helper {
message = message.substring(0, 499) + ""; message = message.substring(0, 499) + "";
} }
}*/ }*/
notificationBuilder.setGroup(account.mastodon_account != null ? account.mastodon_account.username + "@" + account.instance : "" + "@" + account.instance) notificationBuilder.setGroup(account.mastodon_account != null ? account.mastodon_account.username + "@" + account.instance : "@" + account.instance)
.setContentIntent(pIntent) .setContentIntent(pIntent)
.setContentText(message); .setContentText(message);
int ledColour = Color.BLUE; int ledColour = Color.BLUE;
@ -1673,7 +1670,7 @@ public class Helper {
.setLargeIcon(icon) .setLargeIcon(icon)
.setSmallIcon(getNotificationIcon(context)) .setSmallIcon(getNotificationIcon(context))
.setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setGroup(account.mastodon_account != null ? account.mastodon_account.username + "@" + account.instance : "" + "@" + account.instance) .setGroup(account.mastodon_account != null ? account.mastodon_account.username + "@" + account.instance : "@" + account.instance)
.setGroupSummary(true) .setGroupSummary(true)
.build(); .build();

View file

@ -679,8 +679,7 @@ public class PinnedTimelineHelper {
popup.setOnDismissListener(menu1 -> { popup.setOnDismissListener(menu1 -> {
if (activityMainBinding.viewPager.getAdapter() != null && activityMainBinding.tabLayout.getSelectedTabPosition() != -1) { if (activityMainBinding.viewPager.getAdapter() != null && activityMainBinding.tabLayout.getSelectedTabPosition() != -1) {
Fragment fragment = (Fragment) activityMainBinding.viewPager.getAdapter().instantiateItem(activityMainBinding.viewPager, activityMainBinding.tabLayout.getSelectedTabPosition()); Fragment fragment = (Fragment) activityMainBinding.viewPager.getAdapter().instantiateItem(activityMainBinding.viewPager, activityMainBinding.tabLayout.getSelectedTabPosition());
if (fragment instanceof FragmentMastodonTimeline && fragment.isVisible()) { if (fragment instanceof FragmentMastodonTimeline fragmentMastodonTimeline && fragment.isVisible()) {
FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment);
fragmentMastodonTimeline.refreshAllAdapters(); fragmentMastodonTimeline.refreshAllAdapters();
} }
} }

View file

@ -312,7 +312,7 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
if(!underlineLinks) { if (!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined); ds.setUnderlineText(status != null && status.underlined);
} }
if (linkColor != -1) { if (linkColor != -1) {
@ -604,7 +604,7 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
if(!underlineLinks) { if (!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined); ds.setUnderlineText(status != null && status.underlined);
} }
if (linkColor != -1) { if (linkColor != -1) {
@ -763,7 +763,7 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
if(!underlineLinks) { if (!underlineLinks) {
ds.setUnderlineText(status != null && status.underlined); ds.setUnderlineText(status != null && status.underlined);
} }
if (linkColor != -1) { if (linkColor != -1) {
@ -916,7 +916,7 @@ public class SpannableHelper {
@Override @Override
public void updateDrawState(@NonNull TextPaint ds) { public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds); super.updateDrawState(ds);
if(!underlineLinks) { if (!underlineLinks) {
ds.setUnderlineText(false); ds.setUnderlineText(false);
} }
if (linkColor != -1) { if (linkColor != -1) {

View file

@ -176,12 +176,10 @@ public class ThemeHelper {
String[] list; String[] list;
try { try {
list = context.getAssets().list("themes/contributors"); list = context.getAssets().list("themes/contributors");
if (list.length > 0) { for (String file : list) {
for (String file : list) { InputStream is = context.getAssets().open("themes/contributors/" + file);
InputStream is = context.getAssets().open("themes/contributors/" + file); LinkedHashMap<String, String> data = readCSVFile(is);
LinkedHashMap<String, String> data = readCSVFile(is); linkedHashMaps.add(data);
linkedHashMaps.add(data);
}
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -81,7 +81,7 @@ public class TranslateHelper {
String translate; String translate;
if (translates == null || translates.size() <= 1) { if (translates == null || translates.size() <= 1) {
translate = MyTransL.getLocale(); translate = MyTransL.getLocale();
if(translates != null && translates.size() == 1 ) { if (translates != null && translates.size() == 1) {
for (String val : translates) { for (String val : translates) {
translate = val; translate = val;
} }

View file

@ -102,9 +102,8 @@ public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) { public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
// We only want the active item to change // We only want the active item to change
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) { if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
if (viewHolder instanceof ItemTouchHelperViewHolder) { if (viewHolder instanceof ItemTouchHelperViewHolder itemViewHolder) {
// Let the view holder know that this item is being moved or dragged // Let the view holder know that this item is being moved or dragged
ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemSelected(); itemViewHolder.onItemSelected();
} }
} }
@ -118,9 +117,8 @@ public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {
viewHolder.itemView.setAlpha(ALPHA_FULL); viewHolder.itemView.setAlpha(ALPHA_FULL);
if (viewHolder instanceof ItemTouchHelperViewHolder) { if (viewHolder instanceof ItemTouchHelperViewHolder itemViewHolder) {
// Tell the view holder it's time to restore the idle state // Tell the view holder it's time to restore the idle state
ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemClear(); itemViewHolder.onItemClear();
} }
} }

View file

@ -73,8 +73,7 @@ public class TimePreferenceDialogFragment extends PreferenceDialogFragmentCompat
// Generate value to save // Generate value to save
String time = hour + ":" + minute; String time = hour + ":" + minute;
DialogPreference preference = getPreference(); DialogPreference preference = getPreference();
if (preference instanceof TimePreference) { if (preference instanceof TimePreference timePreference) {
TimePreference timePreference = ((TimePreference) preference);
if (timePreference.callChangeListener(time)) { if (timePreference.callChangeListener(time)) {
timePreference.setTime(time); timePreference.setTime(time);
} }

View file

@ -22,7 +22,6 @@ import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.exifinterface.media.ExifInterface; import androidx.exifinterface.media.ExifInterface;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.transition.ChangeBounds; import androidx.transition.ChangeBounds;
import androidx.transition.TransitionManager; import androidx.transition.TransitionManager;

View file

@ -47,10 +47,8 @@ public class BaseActivity extends AppCompatActivity {
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) { if (requestCode == READ_WRITE_STORAGE) {
case READ_WRITE_STORAGE: isPermissionGranted(grantResults[0] == PackageManager.PERMISSION_GRANTED, permissions[0]);
isPermissionGranted(grantResults[0] == PackageManager.PERMISSION_GRANTED, permissions[0]);
break;
} }
} }

View file

@ -32,7 +32,6 @@ import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.work.Data; import androidx.work.Data;
import androidx.work.ForegroundInfo; import androidx.work.ForegroundInfo;

View file

@ -66,14 +66,14 @@ public class CustomReceiver extends MessagingReceiver {
@Override @Override
public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) { public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) {
if (context != null) { if (context != null) {
synchronized(this) { synchronized (this) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, null); String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT) + slug, null);
if(storedEnpoint == null || !storedEnpoint.equals(endpoint)) { if (storedEnpoint == null || !storedEnpoint.equals(endpoint)) {
PushNotifications PushNotifications
.registerPushNotifications(context, endpoint, slug); .registerPushNotifications(context, endpoint, slug);
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, endpoint); editor.putString(context.getString(R.string.SET_STORED_ENDPOINT) + slug, endpoint);
editor.commit(); editor.commit();
} }
} }

View file

@ -17,7 +17,6 @@ package app.fedilab.android.mastodon.ui.drawer;
import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -31,7 +30,6 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityOptionsCompat;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner; import androidx.lifecycle.ViewModelStoreOwner;

View file

@ -16,7 +16,6 @@ package app.fedilab.android.mastodon.ui.drawer;
import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -26,7 +25,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.ActivityOptionsCompat;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner; import androidx.lifecycle.ViewModelStoreOwner;

View file

@ -51,7 +51,6 @@ import android.view.inputmethod.InputMethodManager;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -110,7 +109,6 @@ import app.fedilab.android.databinding.DrawerStatusComposeBinding;
import app.fedilab.android.databinding.DrawerStatusSimpleBinding; import app.fedilab.android.databinding.DrawerStatusSimpleBinding;
import app.fedilab.android.mastodon.activities.ComposeActivity; import app.fedilab.android.mastodon.activities.ComposeActivity;
import app.fedilab.android.mastodon.activities.MediaActivity; import app.fedilab.android.mastodon.activities.MediaActivity;
import app.fedilab.android.mastodon.activities.SearchResultTabActivity;
import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Account;
import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Emoji; import app.fedilab.android.mastodon.client.entities.api.Emoji;
@ -549,7 +547,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
String defaultFormat = sharedpreferences.getString(context.getString(R.string.SET_THREAD_MESSAGE), context.getString(R.string.DEFAULT_THREAD_VALUE)); String defaultFormat = sharedpreferences.getString(context.getString(R.string.SET_THREAD_MESSAGE), context.getString(R.string.DEFAULT_THREAD_VALUE));
//User asked to be prompted for threading long messages //User asked to be prompted for threading long messages
if(defaultFormat.compareToIgnoreCase("ASK") == 0 && !splitChoiceDone) { if (defaultFormat.compareToIgnoreCase("ASK") == 0 && !splitChoiceDone) {
splitChoiceDone = true; splitChoiceDone = true;
AlertDialog.Builder threadConfirm = new MaterialAlertDialogBuilder(context); AlertDialog.Builder threadConfirm = new MaterialAlertDialogBuilder(context);
threadConfirm.setTitle(context.getString(R.string.thread_long_this_message)); threadConfirm.setTitle(context.getString(R.string.thread_long_this_message));
@ -561,29 +559,29 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.content.setText(splitText.get(0)); holder.binding.content.setText(splitText.get(0));
int statusListSize = statusList.size(); int statusListSize = statusList.size();
int i = 0; int i = 0;
for(String message: splitText) { for (String message : splitText) {
if(i==0) { if (i == 0) {
i++; i++;
continue; continue;
} }
manageDrafts.onItemDraftAdded(statusListSize+(i-1), message); manageDrafts.onItemDraftAdded(statusListSize + (i - 1), message);
buttonVisibility(holder); buttonVisibility(holder);
i++; i++;
} }
dialog.dismiss(); dialog.dismiss();
}); });
threadConfirm.show(); threadConfirm.show();
} else if(defaultFormat.compareToIgnoreCase("ENABLE") == 0) { //User wants to automatically thread long messages } else if (defaultFormat.compareToIgnoreCase("ENABLE") == 0) { //User wants to automatically thread long messages
proceedToSplit = true; proceedToSplit = true;
ArrayList<String> splitText = ComposeHelper.splitToots(s.toString(), max_car); ArrayList<String> splitText = ComposeHelper.splitToots(s.toString(), max_car);
int statusListSize = statusList.size(); int statusListSize = statusList.size();
int i = 0; int i = 0;
for(String message: splitText) { for (String message : splitText) {
if(i==0) { if (i == 0) {
i++; i++;
continue; continue;
} }
manageDrafts.onItemDraftAdded(statusListSize+(i-1), message); manageDrafts.onItemDraftAdded(statusListSize + (i - 1), message);
buttonVisibility(holder); buttonVisibility(holder);
i++; i++;
} }
@ -594,7 +592,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
String contentString = s.toString(); String contentString = s.toString();
if(proceedToSplit) { if (proceedToSplit) {
int max_car = MastodonHelper.getInstanceMaxChars(context); int max_car = MastodonHelper.getInstanceMaxChars(context);
ArrayList<String> splitText = ComposeHelper.splitToots(contentString, max_car); ArrayList<String> splitText = ComposeHelper.splitToots(contentString, max_car);
contentString = splitText.get(0); contentString = splitText.get(0);
@ -1352,21 +1350,21 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
if (getItemViewType(position) == TYPE_NORMAL) { if (getItemViewType(position) == TYPE_NORMAL) {
Status status = statusList.get(position); Status status = statusList.get(position);
StatusSimpleViewHolder holder = (StatusSimpleViewHolder) viewHolder; StatusSimpleViewHolder holder = (StatusSimpleViewHolder) viewHolder;
if(status.media_attachments != null && status.media_attachments.size() > 0 ) { if (status.media_attachments != null && status.media_attachments.size() > 0) {
holder.binding.simpleMedia.removeAllViews(); holder.binding.simpleMedia.removeAllViews();
List<Attachment> attachmentList = statusList.get(position).media_attachments; List<Attachment> attachmentList = statusList.get(position).media_attachments;
for(Attachment attachment: attachmentList) { for (Attachment attachment : attachmentList) {
DrawerMediaListBinding drawerMediaListBinding = DrawerMediaListBinding.inflate(LayoutInflater.from(context), holder.binding.simpleMedia, false); DrawerMediaListBinding drawerMediaListBinding = DrawerMediaListBinding.inflate(LayoutInflater.from(context), holder.binding.simpleMedia, false);
Glide.with(drawerMediaListBinding.media.getContext()) Glide.with(drawerMediaListBinding.media.getContext())
.load(attachment.preview_url) .load(attachment.preview_url)
.into(drawerMediaListBinding.media); .into(drawerMediaListBinding.media);
if(attachment.filename != null) { if (attachment.filename != null) {
drawerMediaListBinding.mediaName.setText(attachment.filename); drawerMediaListBinding.mediaName.setText(attachment.filename);
} else if (attachment.preview_url != null){ } else if (attachment.preview_url != null) {
drawerMediaListBinding.mediaName.setText(URLUtil.guessFileName(attachment.preview_url, null, null)); drawerMediaListBinding.mediaName.setText(URLUtil.guessFileName(attachment.preview_url, null, null));
} }
drawerMediaListBinding.getRoot().setOnClickListener(v->{ drawerMediaListBinding.getRoot().setOnClickListener(v -> {
Intent mediaIntent = new Intent(context, MediaActivity.class); Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
ArrayList<Attachment> attachments = new ArrayList<>(); ArrayList<Attachment> attachments = new ArrayList<>();

View file

@ -19,7 +19,6 @@ import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.BaseMainActivity.currentNightMode; import static app.fedilab.android.BaseMainActivity.currentNightMode;
import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.statusManagement; import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.statusManagement;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -31,7 +30,6 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.ActivityOptionsCompat;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner; import androidx.lifecycle.ViewModelStoreOwner;

View file

@ -88,7 +88,6 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner; import androidx.lifecycle.ViewModelStoreOwner;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -935,7 +934,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Intent intent = new Intent(context, ProfileActivity.class); Intent intent = new Intent(context, ProfileActivity.class);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.reblog != null ? fetchedStatus.reblog.account : fetchedStatus.account); args.putSerializable(Helper.ARG_ACCOUNT, fetchedStatus.reblog != null ? fetchedStatus.reblog.account : fetchedStatus.account);
new CachedBundle(context).insertBundle(args, currentAccount,bundleId -> { new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle); intent.putExtras(bundle);
@ -1299,13 +1298,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
holder.binding.replyCount.setVisibility(View.GONE); holder.binding.replyCount.setVisibility(View.GONE);
} }
if(statusToDeal.reblogs_count > 0) { if (statusToDeal.reblogs_count > 0) {
holder.binding.boostCount.setText(String.valueOf(statusToDeal.reblogs_count)); holder.binding.boostCount.setText(String.valueOf(statusToDeal.reblogs_count));
holder.binding.boostCount.setVisibility(View.VISIBLE); holder.binding.boostCount.setVisibility(View.VISIBLE);
} else { } else {
holder.binding.boostCount.setVisibility(View.GONE); holder.binding.boostCount.setVisibility(View.GONE);
} }
if(statusToDeal.favourites_count > 0) { if (statusToDeal.favourites_count > 0) {
holder.binding.favoriteCount.setText(String.valueOf(statusToDeal.favourites_count)); holder.binding.favoriteCount.setText(String.valueOf(statusToDeal.favourites_count));
holder.binding.favoriteCount.setVisibility(View.VISIBLE); holder.binding.favoriteCount.setVisibility(View.VISIBLE);
} else { } else {
@ -1330,7 +1329,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
holder.binding.dateShort.setCompoundDrawables(null, null, null, null); holder.binding.dateShort.setCompoundDrawables(null, null, null, null);
} }
if(relativeDate) { if (relativeDate) {
if (originalDateForBoost || status.reblog == null) { if (originalDateForBoost || status.reblog == null) {
holder.binding.dateShort.setText(Helper.dateDiff(context, statusToDeal.created_at)); holder.binding.dateShort.setText(Helper.dateDiff(context, statusToDeal.created_at));
} else { } else {
@ -1795,7 +1794,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (statusToDeal.poll != null && statusToDeal.poll.options != null) { if (statusToDeal.poll != null && statusToDeal.poll.options != null) {
int normalize; int normalize;
if(statusToDeal.poll.multiple && statusToDeal.poll.voters_count > 1) { if (statusToDeal.poll.multiple && statusToDeal.poll.voters_count > 1) {
normalize = statusToDeal.poll.voters_count; normalize = statusToDeal.poll.voters_count;
} else { } else {
normalize = statusToDeal.poll.votes_count; normalize = statusToDeal.poll.votes_count;
@ -3238,8 +3237,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
@Override @Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder viewHolder) { public void onViewRecycled(@NonNull RecyclerView.ViewHolder viewHolder) {
super.onViewRecycled(viewHolder); super.onViewRecycled(viewHolder);
if (viewHolder instanceof StatusViewHolder) { if (viewHolder instanceof StatusViewHolder holder) {
StatusViewHolder holder = (StatusViewHolder) viewHolder;
if (holder.binding != null) { if (holder.binding != null) {
PlayerView doubleTapPlayerView = holder.binding.media.getRoot().findViewById(R.id.media_video); PlayerView doubleTapPlayerView = holder.binding.media.getRoot().findViewById(R.id.media_video);
if (doubleTapPlayerView != null && doubleTapPlayerView.getPlayer() != null) { if (doubleTapPlayerView != null && doubleTapPlayerView.getPlayer() != null) {

View file

@ -17,7 +17,6 @@ package app.fedilab.android.mastodon.ui.drawer;
import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -28,7 +27,6 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.ActivityOptionsCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner; import androidx.lifecycle.ViewModelStoreOwner;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;

View file

@ -111,11 +111,15 @@ public class FragmentMedia extends Fragment {
} }
}); });
binding.mediaPicture.setOnClickListener(v -> { binding.mediaPicture.setOnClickListener(v -> {
if(isAdded()){((MediaActivity) requireActivity()).toogleFullScreen();} if (isAdded()) {
((MediaActivity) requireActivity()).toogleFullScreen();
}
}); });
binding.mediaVideo.setOnClickListener(v -> { binding.mediaVideo.setOnClickListener(v -> {
if(isAdded()) {((MediaActivity) requireActivity()).toogleFullScreen();} if (isAdded()) {
((MediaActivity) requireActivity()).toogleFullScreen();
}
}); });
String type = attachment.type; String type = attachment.type;
@ -367,7 +371,8 @@ public class FragmentMedia extends Fragment {
binding.videoLayout.setVisibility(View.GONE); binding.videoLayout.setVisibility(View.GONE);
try { try {
ActivityCompat.finishAfterTransition(requireActivity()); ActivityCompat.finishAfterTransition(requireActivity());
}catch (Exception ignored){} } catch (Exception ignored) {
}
} }
} }

View file

@ -75,7 +75,7 @@ public class FragmentMediaProfile extends Fragment {
if (getArguments() != null) { if (getArguments() != null) {
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> {
if(bundle != null) { if (bundle != null) {
accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
} }

View file

@ -31,6 +31,7 @@ import app.fedilab.android.mastodon.helper.Helper;
public class FragmentTimelinesSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { public class FragmentTimelinesSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
boolean recreate; boolean recreate;
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.pref_timelines); addPreferencesFromResource(R.xml.pref_timelines);

View file

@ -39,7 +39,6 @@ import java.util.List;
import app.fedilab.android.BaseMainActivity; import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.FragmentPaginationBinding; import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.mastodon.activities.SearchResultTabActivity; import app.fedilab.android.mastodon.activities.SearchResultTabActivity;
import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Account;
@ -98,7 +97,7 @@ public class FragmentMastodonAccount extends Fragment {
} }
private void initializeAfterBundle(Bundle bundle) { private void initializeAfterBundle(Bundle bundle) {
if(bundle != null) { if (bundle != null) {
search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null); search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null);
accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
followType = (FedilabProfileTLPageAdapter.follow_type) bundle.getSerializable(Helper.ARG_FOLLOW_TYPE); followType = (FedilabProfileTLPageAdapter.follow_type) bundle.getSerializable(Helper.ARG_FOLLOW_TYPE);

View file

@ -21,7 +21,6 @@ import android.content.BroadcastReceiver;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -31,7 +30,6 @@ import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
@ -59,7 +57,6 @@ public class FragmentMastodonContext extends Fragment {
private StatusesVM statusesVM; private StatusesVM statusesVM;
private List<Status> statuses; private List<Status> statuses;
private StatusAdapter statusAdapter; private StatusAdapter statusAdapter;
private boolean refresh;
//Handle actions that can be done in other fragments //Handle actions that can be done in other fragments
private final BroadcastReceiver receive_action = new BroadcastReceiver() { private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@Override @Override
@ -128,6 +125,7 @@ public class FragmentMastodonContext extends Fragment {
} }
} }
}; };
private boolean refresh;
private Status focusedStatus; private Status focusedStatus;
private String remote_instance, focusedStatusURI; private String remote_instance, focusedStatusURI;
private Status firstStatus; private Status firstStatus;

View file

@ -50,7 +50,6 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.work.Data; import androidx.work.Data;

View file

@ -19,7 +19,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -31,7 +30,6 @@ import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;

View file

@ -36,7 +36,6 @@ import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -63,7 +62,6 @@ import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline;
import app.fedilab.android.mastodon.client.entities.app.RemoteInstance; import app.fedilab.android.mastodon.client.entities.app.RemoteInstance;
import app.fedilab.android.mastodon.client.entities.app.TagTimeline; import app.fedilab.android.mastodon.client.entities.app.TagTimeline;
import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.client.entities.app.Timeline;
import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.mastodon.helper.CrossActionHelper; import app.fedilab.android.mastodon.helper.CrossActionHelper;
import app.fedilab.android.mastodon.helper.GlideApp; import app.fedilab.android.mastodon.helper.GlideApp;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
@ -385,7 +383,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
flagLoading = false; flagLoading = false;
if (getArguments() != null) { if (getArguments() != null) {
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
if(bundleId != -1 ) { if (bundleId != -1) {
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else { } else {
initializeAfterBundle(getArguments()); initializeAfterBundle(getArguments());
@ -397,7 +395,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} }
private void initializeAfterBundle(Bundle bundle) { private void initializeAfterBundle(Bundle bundle) {
new Thread(()->{ new Thread(() -> {
if (bundle != null) { if (bundle != null) {
timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE); timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE);
lemmy_post_id = bundle.getString(Helper.ARG_LEMMY_POST_ID, null); lemmy_post_id = bundle.getString(Helper.ARG_LEMMY_POST_ID, null);

View file

@ -224,8 +224,7 @@ public class FragmentNotificationContainer extends Fragment {
Fragment fragment; Fragment fragment;
if (binding.viewpagerNotificationContainer.getAdapter() != null) { if (binding.viewpagerNotificationContainer.getAdapter() != null) {
fragment = (Fragment) binding.viewpagerNotificationContainer.getAdapter().instantiateItem(binding.viewpagerNotificationContainer, tab.getPosition()); fragment = (Fragment) binding.viewpagerNotificationContainer.getAdapter().instantiateItem(binding.viewpagerNotificationContainer, tab.getPosition());
if (fragment instanceof FragmentMastodonNotification) { if (fragment instanceof FragmentMastodonNotification fragmentMastodonNotification) {
FragmentMastodonNotification fragmentMastodonNotification = ((FragmentMastodonNotification) fragment);
fragmentMastodonNotification.scrollToTop(); fragmentMastodonNotification.scrollToTop();
} }
} }

View file

@ -52,7 +52,7 @@ public class FragmentProfileTimeline extends Fragment {
binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false); binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false);
if (getArguments() != null) { if (getArguments() != null) {
long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
if(bundleId != -1 ) { if (bundleId != -1) {
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> {
account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
@ -91,10 +91,7 @@ public class FragmentProfileTimeline extends Fragment {
public void onTabReselected(TabLayout.Tab tab) { public void onTabReselected(TabLayout.Tab tab) {
if (binding.viewpager.getAdapter() != null && binding.viewpager if (binding.viewpager.getAdapter() != null && binding.viewpager
.getAdapter() .getAdapter()
.instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()) instanceof FragmentMastodonTimeline) { .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()) instanceof FragmentMastodonTimeline fragmentMastodonTimeline) {
FragmentMastodonTimeline fragmentMastodonTimeline = (FragmentMastodonTimeline) binding.viewpager
.getAdapter()
.instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem());
fragmentMastodonTimeline.goTop(); fragmentMastodonTimeline.goTop();
} }
} }
@ -116,10 +113,7 @@ public class FragmentProfileTimeline extends Fragment {
popup.setOnDismissListener(menu1 -> { popup.setOnDismissListener(menu1 -> {
if (binding.viewpager.getAdapter() != null && binding.viewpager if (binding.viewpager.getAdapter() != null && binding.viewpager
.getAdapter() .getAdapter()
.instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()) instanceof FragmentMastodonTimeline) { .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()) instanceof FragmentMastodonTimeline fragmentMastodonTimeline) {
FragmentMastodonTimeline fragmentMastodonTimeline = (FragmentMastodonTimeline) binding.viewpager
.getAdapter()
.instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem());
FragmentTransaction fragTransaction = getChildFragmentManager().beginTransaction(); FragmentTransaction fragTransaction = getChildFragmentManager().beginTransaction();
fragTransaction.detach(fragmentMastodonTimeline).commit(); fragTransaction.detach(fragmentMastodonTimeline).commit();
Bundle args = new Bundle(); Bundle args = new Bundle();

View file

@ -1591,7 +1591,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
} }
} }
}; };
ContextCompat.registerReceiver(PeertubeActivity.this, mPowerKeyReceiver, theFilter, ContextCompat.RECEIVER_NOT_EXPORTED); ContextCompat.registerReceiver(PeertubeActivity.this, mPowerKeyReceiver, theFilter, ContextCompat.RECEIVER_NOT_EXPORTED);
} }
private void unregisterReceiver() { private void unregisterReceiver() {

View file

@ -61,7 +61,6 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager; import androidx.viewpager.widget.ViewPager;

View file

@ -47,6 +47,7 @@ import java.io.UnsupportedEncodingException;
import java.net.IDN; import java.net.IDN;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -178,11 +179,8 @@ public class RetrofitPeertubeAPI {
error.printStackTrace(); error.printStackTrace();
return; return;
} }
try { //At the state the instance can be encoded
//At the state the instance can be encoded instance = URLDecoder.decode(instance, StandardCharsets.UTF_8);
instance = URLDecoder.decode(instance, "utf-8");
} catch (UnsupportedEncodingException ignored) {
}
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
account.token = token; account.token = token;
account.client_id = client_id; account.client_id = client_id;

View file

@ -17,7 +17,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat; import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.MultiSelectListPreference; import androidx.preference.MultiSelectListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;

View file

@ -57,7 +57,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import com.avatarfirst.avatargenlib.AvatarGenerator; import com.avatarfirst.avatargenlib.AvatarGenerator;
@ -276,7 +275,7 @@ public class Helper {
* @return String rounded value to be displayed * @return String rounded value to be displayed
*/ */
public static String withSuffix(long count) { public static String withSuffix(long count) {
if (count < 1000) return "" + count; if (count < 1000) return String.valueOf(count);
int exp = (int) (Math.log(count) / Math.log(1000)); int exp = (int) (Math.log(count) / Math.log(1000));
Locale locale = null; Locale locale = null;
try { try {

View file

@ -54,7 +54,7 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
super.onCreate(); super.onCreate();
networkStateReceiver = new NetworkStateReceiver(); networkStateReceiver = new NetworkStateReceiver();
networkStateReceiver.addListener(this); networkStateReceiver.addListener(this);
ContextCompat.registerReceiver(RetrieveInfoService.this, networkStateReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED); ContextCompat.registerReceiver(RetrieveInfoService.this, networkStateReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
getString(R.string.notification_channel_name), getString(R.string.notification_channel_name),

View file

@ -109,11 +109,10 @@ public class MastalabWebChromeClient extends WebChromeClient implements MediaPla
@Override @Override
public void onShowCustomView(View view, CustomViewCallback callback) { public void onShowCustomView(View view, CustomViewCallback callback) {
if (view instanceof FrameLayout) { if (view instanceof FrameLayout frameLayout) {
if (((AppCompatActivity) activity).getSupportActionBar() != null) if (((AppCompatActivity) activity).getSupportActionBar() != null)
((AppCompatActivity) activity).getSupportActionBar().hide(); ((AppCompatActivity) activity).getSupportActionBar().hide();
// A video wants to be shown // A video wants to be shown
FrameLayout frameLayout = (FrameLayout) view;
View focusedChild = frameLayout.getFocusedChild(); View focusedChild = frameLayout.getFocusedChild();
// Save video related variables // Save video related variables
@ -125,9 +124,8 @@ public class MastalabWebChromeClient extends WebChromeClient implements MediaPla
activityNonVideoView.setVisibility(View.INVISIBLE); activityNonVideoView.setVisibility(View.INVISIBLE);
activityVideoView.addView(videoViewContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); activityVideoView.addView(videoViewContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
activityVideoView.setVisibility(View.VISIBLE); activityVideoView.setVisibility(View.VISIBLE);
if (focusedChild instanceof android.widget.VideoView) { if (focusedChild instanceof android.widget.VideoView videoView) {
// android.widget.VideoView (typically API level <11) // android.widget.VideoView (typically API level <11)
android.widget.VideoView videoView = (android.widget.VideoView) focusedChild;
// Handle all the required events // Handle all the required events
videoView.setOnCompletionListener(this); videoView.setOnCompletionListener(this);
videoView.setOnErrorListener(this); videoView.setOnErrorListener(this);