diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 8c321234..ec60e99a 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -36,7 +36,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.database.MatrixCursor; import android.graphics.PorterDuff; import android.graphics.drawable.BitmapDrawable; @@ -73,7 +72,6 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.SearchView; import androidx.core.app.ActivityCompat; -import androidx.core.app.ActivityOptionsCompat; import androidx.core.content.ContextCompat; import androidx.core.view.GravityCompat; import androidx.cursoradapter.widget.CursorAdapter; @@ -81,7 +79,6 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProvider; - import androidx.navigation.NavController; import androidx.navigation.Navigation; import androidx.navigation.ui.AppBarConfiguration; @@ -1625,8 +1622,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (binding.viewPager.getAdapter() != null) { int tabPosition = binding.tabLayout.getSelectedTabPosition(); Fragment fragment = (Fragment) binding.viewPager.getAdapter().instantiateItem(binding.viewPager, Math.max(tabPosition, 0)); - if (fragment instanceof FragmentMastodonTimeline && fragment.isVisible()) { - FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment); + if (fragment instanceof FragmentMastodonTimeline fragmentMastodonTimeline && fragment.isVisible()) { fragmentMastodonTimeline.refreshAllAdapters(); } } @@ -1921,14 +1917,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt int position = binding.tabLayout.getSelectedTabPosition(); if (binding.viewPager.getAdapter() != null) { Fragment fragment = (Fragment) binding.viewPager.getAdapter().instantiateItem(binding.viewPager, Math.max(position, 0)); - if (fragment instanceof FragmentMastodonTimeline) { - FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment); + if (fragment instanceof FragmentMastodonTimeline fragmentMastodonTimeline) { fragmentMastodonTimeline.scrollToTop(); - } else if (fragment instanceof FragmentMastodonConversation) { - FragmentMastodonConversation fragmentMastodonConversation = ((FragmentMastodonConversation) fragment); + } else if (fragment instanceof FragmentMastodonConversation fragmentMastodonConversation) { fragmentMastodonConversation.scrollToTop(); - } else if (fragment instanceof FragmentNotificationContainer) { - FragmentNotificationContainer fragmentNotificationContainer = ((FragmentNotificationContainer) fragment); + } else if (fragment instanceof FragmentNotificationContainer fragmentNotificationContainer) { fragmentNotificationContainer.scrollToTop(); } } diff --git a/app/src/main/java/app/fedilab/android/activities/AboutActivity.java b/app/src/main/java/app/fedilab/android/activities/AboutActivity.java index fe57ba51..7e7841f5 100644 --- a/app/src/main/java/app/fedilab/android/activities/AboutActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AboutActivity.java @@ -28,7 +28,6 @@ import android.view.MenuItem; import android.view.View; import android.widget.Toast; -import androidx.core.app.ActivityOptionsCompat; import androidx.lifecycle.ViewModelProvider; import java.util.ArrayList; @@ -87,10 +86,10 @@ public class AboutActivity extends BaseBarActivity { String finalVersion = version; - binding.aboutVersionCopy.setOnClickListener(v->{ + binding.aboutVersionCopy.setOnClickListener(v -> { 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); if (clipboard != null) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java index 72bd611b..84c454ba 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/AccountReportActivity.java @@ -52,6 +52,7 @@ public class AccountReportActivity extends BaseBarActivity { private ActivityAdminReportBinding binding; private AdminVM adminVM; private AdminAccount targeted_account; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -73,9 +74,10 @@ public class AccountReportActivity extends BaseBarActivity { initializeAfterBundle(null); } } + private void initializeAfterBundle(Bundle bundle) { - if(bundle != null) { + if (bundle != null) { account_id = bundle.getString(Helper.ARG_ACCOUNT_ID, null); targeted_account = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); report = (AdminReport) bundle.getSerializable(Helper.ARG_REPORT); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java index 6ab76c08..b0c2041d 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java @@ -39,7 +39,6 @@ import org.conscrypt.Conscrypt; import java.security.Security; -import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.ThemeHelper; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java index 5c52063d..3b089342 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java @@ -50,7 +50,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; 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); statusList = new ArrayList<>(); Bundle b = getIntent().getExtras(); - if(b != null) { + if (b != null) { long bundleId = b.getLong(Helper.ARG_INTENT_ID, -1); - if(bundleId != -1 ) { + if (bundleId != -1) { new CachedBundle(ComposeActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(b); @@ -497,7 +496,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana private void initializeAfterBundle(Bundle b) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); - new Thread(()->{ + new Thread(() -> { if (b != null) { statusReply = (Status) b.getSerializable(Helper.ARG_STATUS_REPLY); 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.mentions = statusList.get(position - 1).mentions; status.visibility = statusList.get(position - 1).visibility; - if(initialContent != null) { + if (initialContent != null) { status.text = initialContent; } final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ComposeActivity.this); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java index 77fa5ce5..8d5a49f5 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/EditProfileActivity.java @@ -33,7 +33,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.lifecycle.ViewModelProvider; - import com.bumptech.glide.Glide; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.textfield.TextInputEditText; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/FollowedTagActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/FollowedTagActivity.java index 9b75fe47..badd5898 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/FollowedTagActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/FollowedTagActivity.java @@ -40,7 +40,6 @@ import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityFollowedTagsBinding; 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.app.Timeline; 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)}); dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> { 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(); return; } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java index 83ac74a5..94d8b0e9 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java @@ -29,7 +29,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.lifecycle.ViewModelProvider; - import com.google.android.material.dialog.MaterialAlertDialogBuilder; import java.util.ArrayList; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/InstanceHealthActivity.kt b/app/src/main/java/app/fedilab/android/mastodon/activities/InstanceHealthActivity.kt index a0290ba9..1a0bd5c5 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/InstanceHealthActivity.kt +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/InstanceHealthActivity.kt @@ -60,63 +60,63 @@ class InstanceHealthActivity : DialogFragment() { private fun checkInstance() { val instanceSocialVM = - ViewModelProvider(this@InstanceHealthActivity)[InstanceSocialVM::class.java] + ViewModelProvider(this@InstanceHealthActivity)[InstanceSocialVM::class.java] instanceSocialVM.getInstances(BaseMainActivity.currentInstance.trim { it <= ' ' }) - .observe(this@InstanceHealthActivity) { instanceSocialList: InstanceSocial? -> - val instance = instanceSocialList?.instances?.firstOrNull { instance -> - instance.name.equals( - BaseMainActivity.currentInstance.trim { it <= ' ' }, - 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) + .observe(this@InstanceHealthActivity) { instanceSocialList: InstanceSocial? -> + val instance = instanceSocialList?.instances?.firstOrNull { instance -> + instance.name.equals( + BaseMainActivity.currentInstance.trim { it <= ' ' }, + ignoreCase = true + ) } - binding.name.text = instance.name - if (instance.up) { - binding.up.setText(R.string.is_up) - binding.up.setTextColor( - ThemeHelper.getAttColor( - requireContext(), - R.attr.colorPrimary + 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.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 + } 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 { + binding.instanceData.isVisible = false + binding.noInstance.isVisible = true } - 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 { - binding.instanceData.isVisible = false - binding.noInstance.isVisible = true + binding.loader.isVisible = false } - binding.loader.isVisible = false - } } override fun onDestroyView() { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/MastodonListActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/MastodonListActivity.java index 0be0a8ca..2e487374 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/MastodonListActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/MastodonListActivity.java @@ -32,7 +32,6 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProvider; - import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java index 39da1713..04f4641a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java @@ -240,7 +240,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload } private Spannable linkify(Context context, String content) { - if(content == null) { + if (content == null) { return new SpannableString(""); } Matcher matcher = WEB_URL.matcher(content); @@ -263,7 +263,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload @Override public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); - if(!underlineLinks) { + if (!underlineLinks) { ds.setUnderlineText(status != null && status.underlined); } } @@ -300,7 +300,8 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload finish(); try { ActivityCompat.finishAfterTransition(MediaActivity.this); - }catch (Exception ignored){} + } catch (Exception ignored) { + } return true; } else if (item.getItemId() == R.id.action_save) { int position = binding.mediaViewpager.getCurrentItem(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/PartnerShipActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/PartnerShipActivity.java index 7c1e9037..f171923c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/PartnerShipActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/PartnerShipActivity.java @@ -25,7 +25,6 @@ import android.view.MenuItem; import android.view.View; import android.widget.TextView; -import androidx.core.app.ActivityOptionsCompat; import androidx.lifecycle.ViewModelProvider; import java.util.ArrayList; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java index 1106067d..44240c6f 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ProfileActivity.java @@ -54,7 +54,6 @@ import androidx.appcompat.app.AlertDialog; import androidx.core.app.ActivityOptionsCompat; import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -136,7 +135,7 @@ public class ProfileActivity extends BaseActivity { Bundle args = intent.getExtras(); if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - if(bundleId != -1 ) { + if (bundleId != -1) { new CachedBundle(ProfileActivity.this).getBundle(bundleId, currentAccount, bundle -> { Account accountReceived = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); if (bundle.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java index a0cdd267..53a8263b 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ReorderTimelinesActivity.java @@ -31,7 +31,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.lifecycle.ViewModelProvider; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java index 4107a572..146f9bd0 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ReportActivity.java @@ -74,9 +74,9 @@ public class ReportActivity extends BaseBarActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } Bundle args = getIntent().getExtras(); - if(args != null) { + if (args != null) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); - if(bundleId != -1 ) { + if (bundleId != -1) { new CachedBundle(ReportActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(args); diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java index c57b6d38..b48a156a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/SearchResultTabActivity.java @@ -114,14 +114,11 @@ public class SearchResultTabActivity extends BaseBarActivity { Fragment fragment; if (binding.searchViewpager.getAdapter() != null) { fragment = (Fragment) binding.searchViewpager.getAdapter().instantiateItem(binding.searchViewpager, tab.getPosition()); - if (fragment instanceof FragmentMastodonAccount) { - FragmentMastodonAccount fragmentMastodonAccount = ((FragmentMastodonAccount) fragment); + if (fragment instanceof FragmentMastodonAccount fragmentMastodonAccount) { fragmentMastodonAccount.scrollToTop(); - } else if (fragment instanceof FragmentMastodonTimeline) { - FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment); + } else if (fragment instanceof FragmentMastodonTimeline fragmentMastodonTimeline) { fragmentMastodonTimeline.scrollToTop(); - } else if (fragment instanceof FragmentMastodonTag) { - FragmentMastodonTag fragmentMastodonTag = ((FragmentMastodonTag) fragment); + } else if (fragment instanceof FragmentMastodonTag fragmentMastodonTag) { fragmentMastodonTag.scrollToTop(); } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminAccountActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminAccountActivity.java index a78191e5..fc9ba241 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminAccountActivity.java @@ -112,7 +112,7 @@ public class AdminAccountActivity extends BaseActivity { private void initializeAfterBundle(Bundle bundle) { - if(bundle !=null) { + if (bundle != null) { adminAccount = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); account_id = bundle.getString(Helper.ARG_ACCOUNT_ID, null); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminDomainBlockActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminDomainBlockActivity.java index a032d163..0bd4cc07 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminDomainBlockActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminDomainBlockActivity.java @@ -27,7 +27,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.lifecycle.ViewModelProvider; - import com.google.android.material.dialog.MaterialAlertDialogBuilder; import java.util.Objects; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminReportActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminReportActivity.java index fb170a48..73da31f8 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminReportActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/admin/AdminReportActivity.java @@ -48,7 +48,6 @@ import com.bumptech.glide.request.transition.Transition; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.List; import java.util.Locale; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -115,7 +114,7 @@ public class AdminReportActivity extends BaseBarActivity { private void initializeAfterBundle(Bundle bundle) { - if(bundle != null) { + if (bundle != null) { adminAccount = (AdminAccount) bundle.getSerializable(Helper.ARG_ACCOUNT); if (adminAccount != null) { account = adminAccount.account; diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/EmojiInstance.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/EmojiInstance.java index ce672178..a64b092f 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/EmojiInstance.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/EmojiInstance.java @@ -19,16 +19,13 @@ import static app.fedilab.android.BaseMainActivity.emojis; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; -import android.database.sqlite.SQLiteBlobTooBigException; import android.database.sqlite.SQLiteDatabase; import android.os.Handler; import android.os.Looper; import androidx.annotation.NonNull; -import androidx.lifecycle.ViewModelProvider; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.annotations.SerializedName; 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.exception.DBException; import app.fedilab.android.mastodon.helper.Helper; -import app.fedilab.android.mastodon.viewmodel.mastodon.InstancesVM; import app.fedilab.android.sqlite.Sqlite; import okhttp3.OkHttpClient; import retrofit2.Call; @@ -230,17 +226,12 @@ public class EmojiInstance implements Serializable { } } - public interface EmojiFilteredCallBack{ - void get(List emojiList); - } - /** * Returns the emojis for an instance * * @param instance String - * @param filter String + * @param filter String * @param callBack EmojiFilteredCallBack - Get filtered emojis - * * @return List - List of {@link Emoji} */ 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."); } new Thread(() -> { - List emojiArrayList= new ArrayList<>(); - List emojiFiltered= new ArrayList<>(); + List emojiArrayList = new ArrayList<>(); + List emojiFiltered = new ArrayList<>(); if (emojis == null || !emojis.containsKey(BaseMainActivity.currentInstance) || emojis.get(BaseMainActivity.currentInstance) == null) { try { 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) { MastodonInstanceService mastodonInstanceService = init(instance); Call> emojiCall = mastodonInstanceService.customEmoji(); @@ -271,9 +262,9 @@ public class EmojiInstance implements Serializable { } else { emojiArrayList = emojis.get(instance); } - if(emojiArrayList != null && emojiArrayList.size() > 0 ) { - for(Emoji emoji: emojiArrayList) { - if(emoji.shortcode.contains(filter)) { + if (emojiArrayList != null && emojiArrayList.size() > 0) { + for (Emoji emoji : emojiArrayList) { + if (emoji.shortcode.contains(filter)) { emojiFiltered.add(emoji); } } @@ -311,4 +302,8 @@ public class EmojiInstance implements Serializable { } return filteredEmojis; } + + public interface EmojiFilteredCallBack { + void get(List emojiList); + } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Tag.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Tag.java index 5b2a5bbe..ac59de9e 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Tag.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Tag.java @@ -32,7 +32,8 @@ public class Tag implements Serializable { @SerializedName("following") public boolean following = false; - public Tag() {} + public Tag() { + } public Tag(String name) { this.name = name; diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java index 718023b9..7dbce5ab 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java @@ -56,7 +56,9 @@ public class CachedBundle { private transient Context context; - public CachedBundle() {} + public CachedBundle() { + } + public CachedBundle(Context context) { //Creation of the DB with tables this.context = context; @@ -79,11 +81,11 @@ public class CachedBundle { values.put(Sqlite.COL_BUNDLE, serializeBundle(bundle)); values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); 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(); Bundle bundleAccount = new Bundle(); Account account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); - if(account != null) { + if (account != null) { bundleAccount.putSerializable(Helper.ARG_ACCOUNT, account); valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleAccount)); valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date())); @@ -95,11 +97,11 @@ public class CachedBundle { 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(); Bundle bundleStatus = new Bundle(); Status status = (Status) bundle.getSerializable(Helper.ARG_STATUS); - if(status != null) { + if (status != null) { bundleStatus.putSerializable(Helper.ARG_STATUS, status); valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleStatus)); 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) { - new Thread(()->{ + new Thread(() -> { Bundle bundle = null; try { CachedBundle cachedBundle = getCachedBundle(String.valueOf(id)); if (cachedBundle != null) { 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)); - if(cachedAccount != null) { + if (cachedAccount != null) { 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)); - if(cachedStatus != null) { + if (cachedStatus != null) { bundle.putSerializable(Helper.ARG_STATUS, cachedStatus); } } } removeIntent(String.valueOf(id)); - } catch (DBException ignored) {} + } catch (DBException ignored) { + } Handler mainHandler = new Handler(Looper.getMainLooper()); Bundle finalBundle = bundle; Runnable myRunnable = () -> callback.get(finalBundle); @@ -157,11 +152,12 @@ public class CachedBundle { } public void insertBundle(Bundle bundle, BaseAccount Account, BundleInsertCallback callback) { - new Thread(()->{ + new Thread(() -> { long dbBundleId = -1; try { dbBundleId = insertIntent(bundle, Account); - } catch (DBException ignored) {} + } catch (DBException ignored) { + } Handler mainHandler = new Handler(Looper.getMainLooper()); long finalDbBundleId = dbBundleId; Runnable myRunnable = () -> callback.inserted(finalDbBundleId); @@ -169,8 +165,6 @@ public class CachedBundle { }).start(); } - - /** * Returns a bundle by targeted account id * @@ -181,17 +175,17 @@ public class CachedBundle { if (db == null) { throw new DBException("db is null. Wrong initialization."); } - if(account == null || target_id == null) { + if (account == null || target_id == null) { return null; } try { 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_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1"); CachedBundle cachedBundle = cursorToCachedBundle(c); - if(cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_ACCOUNT) ) { - return (Account) cachedBundle.bundle.getSerializable(Helper.ARG_ACCOUNT); + if (cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_ACCOUNT)) { + return (Account) cachedBundle.bundle.getSerializable(Helper.ARG_ACCOUNT); } } catch (Exception e) { return null; @@ -199,7 +193,6 @@ public class CachedBundle { return null; } - /** * Returns a bundle by targeted status id * @@ -210,17 +203,17 @@ public class CachedBundle { if (db == null) { throw new DBException("db is null. Wrong initialization."); } - if(account == null || target_id == null) { + if (account == null || target_id == null) { return null; } try { 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_TARGET_ID + " = '" + target_id + "'", null, null, null, null, "1"); CachedBundle cachedBundle = cursorToCachedBundle(c); - if(cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_STATUS) ) { - return (Status) cachedBundle.bundle.getSerializable(Helper.ARG_STATUS); + if (cachedBundle != null && cachedBundle.bundle.containsKey(Helper.ARG_STATUS)) { + return (Status) cachedBundle.bundle.getSerializable(Helper.ARG_STATUS); } } catch (Exception e) { return null; @@ -228,7 +221,6 @@ public class CachedBundle { return null; } - /** * Returns a bundle by its ID * @@ -259,24 +251,21 @@ public class CachedBundle { db.delete(Sqlite.TABLE_INTENT, Sqlite.COL_ID + " = '" + id + "'", null); } - /** * Remove a bundle from db - * */ private void removeIntent(BaseAccount account, String target_id) throws DBException { if (db == null) { throw new DBException("db is null. Wrong initialization."); } - if(account == null || target_id == null) { + if (account == null || target_id == null) { return; } 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); } - /*** * Method to hydrate an CachedBundle from database * @param c Cursor @@ -325,7 +314,7 @@ public class CachedBundle { zos.write(parcel.marshall()); zos.close(); base64 = Base64.encodeToString(bos.toByteArray(), 0); - } catch(IOException e) { + } catch (IOException e) { e.printStackTrace(); } finally { parcel.recycle(); @@ -350,13 +339,12 @@ public class CachedBundle { bundle = parcel.readBundle(getClass().getClassLoader()); } catch (IOException e) { e.printStackTrace(); - } finally { + } finally { parcel.recycle(); } return bundle; } - public enum CacheType { @SerializedName("ARGS") ARGS("ARGS"), @@ -370,9 +358,19 @@ public class CachedBundle { CacheType(String value) { this.value = value; } + public String getValue() { return value; } } + public interface BundleCallback { + void get(Bundle bundle); + } + + + public interface BundleInsertCallback { + void inserted(long bundleId); + } + } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/BlurHashDecoder.kt b/app/src/main/java/app/fedilab/android/mastodon/helper/BlurHashDecoder.kt index e192239f..9cc73818 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/BlurHashDecoder.kt +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/BlurHashDecoder.kt @@ -69,20 +69,20 @@ class BlurHashDecoder { val g = (value / 19) % 19 val b = value % 19 return floatArrayOf( - signedPow2((r - 9) / 9.0f) * maxAc, - signedPow2((g - 9) / 9.0f) * maxAc, - signedPow2((b - 9) / 9.0f) * maxAc + signedPow2((r - 9) / 9.0f) * maxAc, + signedPow2((g - 9) / 9.0f) * maxAc, + signedPow2((b - 9) / 9.0f) * maxAc ) } private fun signedPow2(value: Float) = value.pow(2f).withSign(value) private fun composeBitmap( - width: Int, - height: Int, - numCompX: Int, - numCompY: Int, - colors: Array + width: Int, + height: Int, + numCompX: Int, + numCompY: Int, + colors: Array ): Bitmap { val imageArray = IntArray(width * height) for (y in 0 until height) { @@ -100,7 +100,7 @@ class BlurHashDecoder { } } 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) @@ -116,12 +116,12 @@ class BlurHashDecoder { } private val charMap = listOf( - '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', - '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', '#', '$', '%', '*', '+', ',', - '-', '.', ':', ';', '=', '?', '@', '[', ']', '^', '_', '{', '|', '}', '~' + '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', + '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', '#', '$', '%', '*', '+', ',', + '-', '.', ':', ';', '=', '?', '@', '[', ']', '^', '_', '{', '|', '}', '~' ) - .mapIndexed { i, c -> c to i } - .toMap() + .mapIndexed { i, c -> c to i } + .toMap() } \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/ComposeHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/ComposeHelper.java index 57de14a3..dc275254 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/ComposeHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/ComposeHelper.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.regex.Matcher; - public class ComposeHelper { @@ -44,13 +43,13 @@ public class ComposeHelper { Matcher matcher = mentionPatternALL.matcher(content); while (matcher.find()) { String mentionLong = matcher.group(1); - if(mentionLong != null) { + if (mentionLong != null) { if (!mentions.contains(mentionLong)) { mentions.add(mentionLong); } } String mentionShort = matcher.group(2); - if(mentionShort != null) { + if (mentionShort != null) { if (!mentions.contains(mentionShort)) { mentions.add(mentionShort); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index c686d2cf..c40ff792 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -78,7 +78,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.browser.customtabs.CustomTabColorSchemeParams; import androidx.browser.customtabs.CustomTabsIntent; -import androidx.core.app.ActivityOptionsCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; import androidx.core.content.ContextCompat; @@ -89,7 +88,6 @@ import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelStoreOwner; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; @@ -848,7 +846,7 @@ public class Helper { @SuppressLint("DefaultLocale") 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)); Locale locale = null; try { @@ -1000,8 +998,7 @@ public class Helper { if (context == null) { return false; } - if (context instanceof Activity) { - final Activity activity = (Activity) context; + if (context instanceof Activity activity) { return !activity.isDestroyed() && !activity.isFinishing(); } return true; @@ -1611,7 +1608,7 @@ public class Helper { 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) .setContentText(message); int ledColour = Color.BLUE; @@ -1673,7 +1670,7 @@ public class Helper { .setLargeIcon(icon) .setSmallIcon(getNotificationIcon(context)) .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) .build(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/PinnedTimelineHelper.java index 1722a8b4..d1b924b6 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/PinnedTimelineHelper.java @@ -679,8 +679,7 @@ public class PinnedTimelineHelper { popup.setOnDismissListener(menu1 -> { if (activityMainBinding.viewPager.getAdapter() != null && activityMainBinding.tabLayout.getSelectedTabPosition() != -1) { Fragment fragment = (Fragment) activityMainBinding.viewPager.getAdapter().instantiateItem(activityMainBinding.viewPager, activityMainBinding.tabLayout.getSelectedTabPosition()); - if (fragment instanceof FragmentMastodonTimeline && fragment.isVisible()) { - FragmentMastodonTimeline fragmentMastodonTimeline = ((FragmentMastodonTimeline) fragment); + if (fragment instanceof FragmentMastodonTimeline fragmentMastodonTimeline && fragment.isVisible()) { fragmentMastodonTimeline.refreshAllAdapters(); } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java index 41326050..4e69af01 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java @@ -312,7 +312,7 @@ public class SpannableHelper { @Override public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); - if(!underlineLinks) { + if (!underlineLinks) { ds.setUnderlineText(status != null && status.underlined); } if (linkColor != -1) { @@ -604,7 +604,7 @@ public class SpannableHelper { @Override public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); - if(!underlineLinks) { + if (!underlineLinks) { ds.setUnderlineText(status != null && status.underlined); } if (linkColor != -1) { @@ -763,7 +763,7 @@ public class SpannableHelper { @Override public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); - if(!underlineLinks) { + if (!underlineLinks) { ds.setUnderlineText(status != null && status.underlined); } if (linkColor != -1) { @@ -916,7 +916,7 @@ public class SpannableHelper { @Override public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); - if(!underlineLinks) { + if (!underlineLinks) { ds.setUnderlineText(false); } if (linkColor != -1) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/ThemeHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/ThemeHelper.java index 51d1b8d0..460a9ff8 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/ThemeHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/ThemeHelper.java @@ -176,12 +176,10 @@ public class ThemeHelper { String[] list; try { list = context.getAssets().list("themes/contributors"); - if (list.length > 0) { - for (String file : list) { - InputStream is = context.getAssets().open("themes/contributors/" + file); - LinkedHashMap data = readCSVFile(is); - linkedHashMaps.add(data); - } + for (String file : list) { + InputStream is = context.getAssets().open("themes/contributors/" + file); + LinkedHashMap data = readCSVFile(is); + linkedHashMaps.add(data); } } catch (IOException e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/TranslateHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/TranslateHelper.java index 0f159528..7f91a364 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/TranslateHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/TranslateHelper.java @@ -81,7 +81,7 @@ public class TranslateHelper { String translate; if (translates == null || translates.size() <= 1) { translate = MyTransL.getLocale(); - if(translates != null && translates.size() == 1 ) { + if (translates != null && translates.size() == 1) { for (String val : translates) { translate = val; } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/itemtouchhelper/SimpleItemTouchHelperCallback.java b/app/src/main/java/app/fedilab/android/mastodon/helper/itemtouchhelper/SimpleItemTouchHelperCallback.java index a43c817a..9548f6cb 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/itemtouchhelper/SimpleItemTouchHelperCallback.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/itemtouchhelper/SimpleItemTouchHelperCallback.java @@ -102,9 +102,8 @@ public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback { public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) { // We only want the active item to change 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 - ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder; itemViewHolder.onItemSelected(); } } @@ -118,9 +117,8 @@ public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback { 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 - ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder; itemViewHolder.onItemClear(); } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/settings/TimePreferenceDialogFragment.java b/app/src/main/java/app/fedilab/android/mastodon/helper/settings/TimePreferenceDialogFragment.java index b7538565..4afa907a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/settings/TimePreferenceDialogFragment.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/settings/TimePreferenceDialogFragment.java @@ -73,8 +73,7 @@ public class TimePreferenceDialogFragment extends PreferenceDialogFragmentCompat // Generate value to save String time = hour + ":" + minute; DialogPreference preference = getPreference(); - if (preference instanceof TimePreference) { - TimePreference timePreference = ((TimePreference) preference); + if (preference instanceof TimePreference timePreference) { if (timePreference.callChangeListener(time)) { timePreference.setTime(time); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/imageeditor/EditImageActivity.java b/app/src/main/java/app/fedilab/android/mastodon/imageeditor/EditImageActivity.java index e97d8bf5..192128bc 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/imageeditor/EditImageActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/imageeditor/EditImageActivity.java @@ -22,7 +22,6 @@ import androidx.constraintlayout.widget.ConstraintSet; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.exifinterface.media.ExifInterface; - import androidx.recyclerview.widget.LinearLayoutManager; import androidx.transition.ChangeBounds; import androidx.transition.TransitionManager; diff --git a/app/src/main/java/app/fedilab/android/mastodon/imageeditor/base/BaseActivity.java b/app/src/main/java/app/fedilab/android/mastodon/imageeditor/base/BaseActivity.java index 5d8f03f9..47acdfa3 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/imageeditor/base/BaseActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/imageeditor/base/BaseActivity.java @@ -47,10 +47,8 @@ public class BaseActivity extends AppCompatActivity { @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); - switch (requestCode) { - case READ_WRITE_STORAGE: - isPermissionGranted(grantResults[0] == PackageManager.PERMISSION_GRANTED, permissions[0]); - break; + if (requestCode == READ_WRITE_STORAGE) { + isPermissionGranted(grantResults[0] == PackageManager.PERMISSION_GRANTED, permissions[0]); } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/jobs/ComposeWorker.java b/app/src/main/java/app/fedilab/android/mastodon/jobs/ComposeWorker.java index 2a80e3af..fd5658bc 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/jobs/ComposeWorker.java +++ b/app/src/main/java/app/fedilab/android/mastodon/jobs/ComposeWorker.java @@ -32,7 +32,6 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.core.app.NotificationCompat; - import androidx.preference.PreferenceManager; import androidx.work.Data; import androidx.work.ForegroundInfo; diff --git a/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java b/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java index ab5fbc4c..e7c2b7cd 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java +++ b/app/src/main/java/app/fedilab/android/mastodon/services/CustomReceiver.java @@ -66,14 +66,14 @@ public class CustomReceiver extends MessagingReceiver { @Override public void onNewEndpoint(@Nullable Context context, @NotNull String endpoint, @NotNull String slug) { if (context != null) { - synchronized(this) { + synchronized (this) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); - String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT)+slug, null); - if(storedEnpoint == null || !storedEnpoint.equals(endpoint)) { + String storedEnpoint = sharedpreferences.getString(context.getString(R.string.SET_STORED_ENDPOINT) + slug, null); + if (storedEnpoint == null || !storedEnpoint.equals(endpoint)) { PushNotifications .registerPushNotifications(context, endpoint, slug); 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(); } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountAdapter.java index 7d086aac..10e470cc 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountAdapter.java @@ -17,7 +17,6 @@ package app.fedilab.android.mastodon.ui.drawer; import static app.fedilab.android.BaseMainActivity.currentAccount; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -31,7 +30,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; -import androidx.core.app.ActivityOptionsCompat; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelStoreOwner; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountFollowRequestAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountFollowRequestAdapter.java index 239c263c..537f1be3 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountFollowRequestAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/AccountFollowRequestAdapter.java @@ -16,7 +16,6 @@ package app.fedilab.android.mastodon.ui.drawer; import static app.fedilab.android.BaseMainActivity.currentAccount; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -26,7 +25,6 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; -import androidx.core.app.ActivityOptionsCompat; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelStoreOwner; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java index 97bd72f2..274c536b 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java @@ -51,7 +51,6 @@ import android.view.inputmethod.InputMethodManager; import android.webkit.URLUtil; import android.widget.ArrayAdapter; import android.widget.Button; -import android.widget.GridView; import android.widget.LinearLayout; import android.widget.TextView; @@ -110,7 +109,6 @@ import app.fedilab.android.databinding.DrawerStatusComposeBinding; import app.fedilab.android.databinding.DrawerStatusSimpleBinding; import app.fedilab.android.mastodon.activities.ComposeActivity; 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.Attachment; import app.fedilab.android.mastodon.client.entities.api.Emoji; @@ -549,7 +547,7 @@ public class ComposeAdapter extends RecyclerView.Adapter splitText = ComposeHelper.splitToots(s.toString(), max_car); int statusListSize = statusList.size(); int i = 0; - for(String message: splitText) { - if(i==0) { + for (String message : splitText) { + if (i == 0) { i++; continue; } - manageDrafts.onItemDraftAdded(statusListSize+(i-1), message); + manageDrafts.onItemDraftAdded(statusListSize + (i - 1), message); buttonVisibility(holder); i++; } @@ -594,7 +592,7 @@ public class ComposeAdapter extends RecyclerView.Adapter splitText = ComposeHelper.splitToots(contentString, max_car); contentString = splitText.get(0); @@ -1352,21 +1350,21 @@ public class ComposeAdapter extends RecyclerView.Adapter 0 ) { + if (status.media_attachments != null && status.media_attachments.size() > 0) { holder.binding.simpleMedia.removeAllViews(); List 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); Glide.with(drawerMediaListBinding.media.getContext()) .load(attachment.preview_url) .into(drawerMediaListBinding.media); - if(attachment.filename != null) { + if (attachment.filename != null) { 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.getRoot().setOnClickListener(v->{ + drawerMediaListBinding.getRoot().setOnClickListener(v -> { Intent mediaIntent = new Intent(context, MediaActivity.class); Bundle b = new Bundle(); ArrayList attachments = new ArrayList<>(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/NotificationAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/NotificationAdapter.java index 9e8805f2..e18cd9b1 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/NotificationAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/NotificationAdapter.java @@ -19,7 +19,6 @@ import static app.fedilab.android.BaseMainActivity.currentAccount; import static app.fedilab.android.BaseMainActivity.currentNightMode; import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.statusManagement; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -31,7 +30,6 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.core.app.ActivityOptionsCompat; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelStoreOwner; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index 474e7afa..8f89be84 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -88,7 +88,6 @@ import androidx.fragment.app.Fragment; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelStoreOwner; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -935,7 +934,7 @@ public class StatusAdapter extends RecyclerView.Adapter Intent intent = new Intent(context, ProfileActivity.class); Bundle args = new Bundle(); 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.putLong(Helper.ARG_INTENT_ID, bundleId); intent.putExtras(bundle); @@ -1299,13 +1298,13 @@ public class StatusAdapter extends RecyclerView.Adapter } else { 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.setVisibility(View.VISIBLE); } else { 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.setVisibility(View.VISIBLE); } else { @@ -1330,7 +1329,7 @@ public class StatusAdapter extends RecyclerView.Adapter } else { holder.binding.dateShort.setCompoundDrawables(null, null, null, null); } - if(relativeDate) { + if (relativeDate) { if (originalDateForBoost || status.reblog == null) { holder.binding.dateShort.setText(Helper.dateDiff(context, statusToDeal.created_at)); } else { @@ -1795,7 +1794,7 @@ public class StatusAdapter extends RecyclerView.Adapter if (statusToDeal.poll != null && statusToDeal.poll.options != null) { 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; } else { normalize = statusToDeal.poll.votes_count; @@ -3238,8 +3237,7 @@ public class StatusAdapter extends RecyclerView.Adapter @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder viewHolder) { super.onViewRecycled(viewHolder); - if (viewHolder instanceof StatusViewHolder) { - StatusViewHolder holder = (StatusViewHolder) viewHolder; + if (viewHolder instanceof StatusViewHolder holder) { if (holder.binding != null) { PlayerView doubleTapPlayerView = holder.binding.media.getRoot().findViewById(R.id.media_video); if (doubleTapPlayerView != null && doubleTapPlayerView.getPlayer() != null) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/SuggestionAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/SuggestionAdapter.java index 0d86ae39..cb5fb225 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/SuggestionAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/SuggestionAdapter.java @@ -17,7 +17,6 @@ package app.fedilab.android.mastodon.ui.drawer; import static app.fedilab.android.BaseMainActivity.currentAccount; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -28,7 +27,6 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.core.app.ActivityOptionsCompat; import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelStoreOwner; import androidx.preference.PreferenceManager; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java index 41f81f07..4fad1bf3 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMedia.java @@ -111,11 +111,15 @@ public class FragmentMedia extends Fragment { } }); binding.mediaPicture.setOnClickListener(v -> { - if(isAdded()){((MediaActivity) requireActivity()).toogleFullScreen();} + if (isAdded()) { + ((MediaActivity) requireActivity()).toogleFullScreen(); + } }); binding.mediaVideo.setOnClickListener(v -> { - if(isAdded()) {((MediaActivity) requireActivity()).toogleFullScreen();} + if (isAdded()) { + ((MediaActivity) requireActivity()).toogleFullScreen(); + } }); String type = attachment.type; @@ -367,7 +371,8 @@ public class FragmentMedia extends Fragment { binding.videoLayout.setVisibility(View.GONE); try { ActivityCompat.finishAfterTransition(requireActivity()); - }catch (Exception ignored){} + } catch (Exception ignored) { + } } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java index 875e2f12..d6009fc1 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/media/FragmentMediaProfile.java @@ -75,7 +75,7 @@ public class FragmentMediaProfile extends Fragment { if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { - if(bundle != null) { + if (bundle != null) { accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentTimelinesSettings.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentTimelinesSettings.java index 77946049..696dc321 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentTimelinesSettings.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentTimelinesSettings.java @@ -31,6 +31,7 @@ import app.fedilab.android.mastodon.helper.Helper; public class FragmentTimelinesSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { boolean recreate; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.pref_timelines); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java index d4d96276..f3916ca2 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonAccount.java @@ -39,7 +39,6 @@ import java.util.List; import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; -import app.fedilab.android.activities.MainActivity; import app.fedilab.android.databinding.FragmentPaginationBinding; import app.fedilab.android.mastodon.activities.SearchResultTabActivity; import app.fedilab.android.mastodon.client.entities.api.Account; @@ -98,7 +97,7 @@ public class FragmentMastodonAccount extends Fragment { } private void initializeAfterBundle(Bundle bundle) { - if(bundle != null) { + if (bundle != null) { search = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null); accountTimeline = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); followType = (FedilabProfileTLPageAdapter.follow_type) bundle.getSerializable(Helper.ARG_FOLLOW_TYPE); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java index 3adf0c1f..b5d2d74f 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonContext.java @@ -21,7 +21,6 @@ import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -31,7 +30,6 @@ import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; @@ -59,7 +57,6 @@ public class FragmentMastodonContext extends Fragment { private StatusesVM statusesVM; private List statuses; private StatusAdapter statusAdapter; - private boolean refresh; //Handle actions that can be done in other fragments private final BroadcastReceiver receive_action = new BroadcastReceiver() { @Override @@ -128,6 +125,7 @@ public class FragmentMastodonContext extends Fragment { } } }; + private boolean refresh; private Status focusedStatus; private String remote_instance, focusedStatusURI; private Status firstStatus; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonDirectMessage.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonDirectMessage.java index 3c0a6164..caa441cd 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonDirectMessage.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonDirectMessage.java @@ -50,7 +50,6 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.work.Data; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonNotification.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonNotification.java index e5f09fa7..971ae01c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonNotification.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonNotification.java @@ -19,7 +19,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; @@ -31,7 +30,6 @@ import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java index 83351c85..2bad1574 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -36,7 +36,6 @@ import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; - import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; 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.TagTimeline; 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.GlideApp; import app.fedilab.android.mastodon.helper.Helper; @@ -385,7 +383,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. flagLoading = false; if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); - if(bundleId != -1 ) { + if (bundleId != -1) { new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle); } else { initializeAfterBundle(getArguments()); @@ -397,7 +395,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } private void initializeAfterBundle(Bundle bundle) { - new Thread(()->{ + new Thread(() -> { if (bundle != null) { timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE); lemmy_post_id = bundle.getString(Helper.ARG_LEMMY_POST_ID, null); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentNotificationContainer.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentNotificationContainer.java index fa5736bd..6350b0fb 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentNotificationContainer.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentNotificationContainer.java @@ -224,8 +224,7 @@ public class FragmentNotificationContainer extends Fragment { Fragment fragment; if (binding.viewpagerNotificationContainer.getAdapter() != null) { fragment = (Fragment) binding.viewpagerNotificationContainer.getAdapter().instantiateItem(binding.viewpagerNotificationContainer, tab.getPosition()); - if (fragment instanceof FragmentMastodonNotification) { - FragmentMastodonNotification fragmentMastodonNotification = ((FragmentMastodonNotification) fragment); + if (fragment instanceof FragmentMastodonNotification fragmentMastodonNotification) { fragmentMastodonNotification.scrollToTop(); } } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java index 0bbde980..9c83daaf 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentProfileTimeline.java @@ -52,7 +52,7 @@ public class FragmentProfileTimeline extends Fragment { binding = FragmentProfileTimelinesBinding.inflate(inflater, container, false); if (getArguments() != null) { long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1); - if(bundleId != -1 ) { + if (bundleId != -1) { new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> { account = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false); @@ -91,10 +91,7 @@ public class FragmentProfileTimeline extends Fragment { public void onTabReselected(TabLayout.Tab tab) { if (binding.viewpager.getAdapter() != null && binding.viewpager .getAdapter() - .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()) instanceof FragmentMastodonTimeline) { - FragmentMastodonTimeline fragmentMastodonTimeline = (FragmentMastodonTimeline) binding.viewpager - .getAdapter() - .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()); + .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()) instanceof FragmentMastodonTimeline fragmentMastodonTimeline) { fragmentMastodonTimeline.goTop(); } } @@ -116,10 +113,7 @@ public class FragmentProfileTimeline extends Fragment { popup.setOnDismissListener(menu1 -> { if (binding.viewpager.getAdapter() != null && binding.viewpager .getAdapter() - .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()) instanceof FragmentMastodonTimeline) { - FragmentMastodonTimeline fragmentMastodonTimeline = (FragmentMastodonTimeline) binding.viewpager - .getAdapter() - .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()); + .instantiateItem(binding.viewpager, binding.viewpager.getCurrentItem()) instanceof FragmentMastodonTimeline fragmentMastodonTimeline) { FragmentTransaction fragTransaction = getChildFragmentManager().beginTransaction(); fragTransaction.detach(fragmentMastodonTimeline).commit(); Bundle args = new Bundle(); diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java index cab6b84f..0fd8dd48 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeActivity.java @@ -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() { diff --git a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java index 3e56a2b6..9c9fccc0 100644 --- a/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java +++ b/app/src/main/java/app/fedilab/android/peertube/activities/PeertubeMainActivity.java @@ -61,7 +61,6 @@ import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; - import androidx.preference.PreferenceManager; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; diff --git a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java index 2de3aaee..769ac6d1 100644 --- a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java @@ -47,6 +47,7 @@ import java.io.UnsupportedEncodingException; import java.net.IDN; import java.net.URL; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; @@ -178,11 +179,8 @@ public class RetrofitPeertubeAPI { error.printStackTrace(); return; } - try { - //At the state the instance can be encoded - instance = URLDecoder.decode(instance, "utf-8"); - } catch (UnsupportedEncodingException ignored) { - } + //At the state the instance can be encoded + instance = URLDecoder.decode(instance, StandardCharsets.UTF_8); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); account.token = token; account.client_id = client_id; diff --git a/app/src/main/java/app/fedilab/android/peertube/fragment/SettingsFragment.java b/app/src/main/java/app/fedilab/android/peertube/fragment/SettingsFragment.java index c535c1a5..404fea4d 100644 --- a/app/src/main/java/app/fedilab/android/peertube/fragment/SettingsFragment.java +++ b/app/src/main/java/app/fedilab/android/peertube/fragment/SettingsFragment.java @@ -17,7 +17,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.res.ResourcesCompat; import androidx.fragment.app.FragmentActivity; - import androidx.preference.ListPreference; import androidx.preference.MultiSelectListPreference; import androidx.preference.Preference; diff --git a/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java b/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java index 3197ab45..db5c74bc 100644 --- a/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/peertube/helper/Helper.java @@ -57,7 +57,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; - import androidx.preference.PreferenceManager; import com.avatarfirst.avatargenlib.AvatarGenerator; @@ -276,7 +275,7 @@ public class Helper { * @return String rounded value to be displayed */ 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)); Locale locale = null; try { diff --git a/app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java b/app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java index a4b4842c..d4274e0c 100644 --- a/app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java +++ b/app/src/main/java/app/fedilab/android/peertube/services/RetrieveInfoService.java @@ -54,7 +54,7 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver super.onCreate(); networkStateReceiver = new NetworkStateReceiver(); 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) { NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, getString(R.string.notification_channel_name), diff --git a/app/src/main/java/app/fedilab/android/peertube/webview/MastalabWebChromeClient.java b/app/src/main/java/app/fedilab/android/peertube/webview/MastalabWebChromeClient.java index eb98146c..aa7d05b3 100644 --- a/app/src/main/java/app/fedilab/android/peertube/webview/MastalabWebChromeClient.java +++ b/app/src/main/java/app/fedilab/android/peertube/webview/MastalabWebChromeClient.java @@ -109,11 +109,10 @@ public class MastalabWebChromeClient extends WebChromeClient implements MediaPla @Override public void onShowCustomView(View view, CustomViewCallback callback) { - if (view instanceof FrameLayout) { + if (view instanceof FrameLayout frameLayout) { if (((AppCompatActivity) activity).getSupportActionBar() != null) ((AppCompatActivity) activity).getSupportActionBar().hide(); // A video wants to be shown - FrameLayout frameLayout = (FrameLayout) view; View focusedChild = frameLayout.getFocusedChild(); // Save video related variables @@ -125,9 +124,8 @@ public class MastalabWebChromeClient extends WebChromeClient implements MediaPla activityNonVideoView.setVisibility(View.INVISIBLE); activityVideoView.addView(videoViewContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 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 videoView = (android.widget.VideoView) focusedChild; // Handle all the required events videoView.setOnCompletionListener(this); videoView.setOnErrorListener(this);