From 50b0d1fb8ddb61e875f6b946dd84f2185f6bf6db Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Mon, 25 Jun 2018 14:44:29 +0200 Subject: [PATCH] cleanup code --- .../com/keylesspalace/tusky/MainActivity.java | 1 - .../keylesspalace/tusky/di/NetworkModule.kt | 2 +- .../tusky/fragment/AccountMediaFragment.kt | 3 -- .../tusky/fragment/SFragment.java | 4 +-- .../tusky/fragment/TimelineFragment.java | 16 +++++----- .../interfaces/StatusActionListener.java | 2 -- .../tusky/network/MastodonApi.java | 2 -- .../tusky/service/TuskyTileService.java | 27 ----------------- .../com/keylesspalace/tusky/util/Assert.java | 29 ------------------- .../com/keylesspalace/tusky/util/Either.java | 2 +- .../tusky/util/EmojiCompatFont.java | 2 +- .../keylesspalace/tusky/util/LinkHelper.java | 1 - .../tusky/view/ComposeOptionsView.kt | 4 +-- .../ic_arrow_drop_down_black_24dp.xml | 4 --- .../drawable/ic_arrow_drop_up_black_24dp.xml | 4 --- 15 files changed, 13 insertions(+), 90 deletions(-) delete mode 100644 app/src/main/java/com/keylesspalace/tusky/util/Assert.java delete mode 100644 app/src/main/res/drawable/ic_arrow_drop_down_black_24dp.xml delete mode 100644 app/src/main/res/drawable/ic_arrow_drop_up_black_24dp.xml diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index 4bf392c8..a60db700 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -17,7 +17,6 @@ package com.keylesspalace.tusky; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.net.Uri; diff --git a/app/src/main/java/com/keylesspalace/tusky/di/NetworkModule.kt b/app/src/main/java/com/keylesspalace/tusky/di/NetworkModule.kt index 3f34306c..d7418ad6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/di/NetworkModule.kt +++ b/app/src/main/java/com/keylesspalace/tusky/di/NetworkModule.kt @@ -75,7 +75,7 @@ class NetworkModule { .apply { addInterceptor(InstanceSwitchAuthInterceptor(accountManager)) if (BuildConfig.DEBUG) { - addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) + addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC)) } } .build() diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt index 6f632b03..b713ee84 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt @@ -21,7 +21,6 @@ import android.os.Bundle import android.support.v4.app.ActivityOptionsCompat import android.support.v4.content.ContextCompat import android.support.v4.view.ViewCompat -import android.support.v4.widget.SwipeRefreshLayout import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.RecyclerView import android.util.Log @@ -29,8 +28,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView -import android.widget.ProgressBar -import android.widget.TextView import com.keylesspalace.tusky.R import com.keylesspalace.tusky.ViewMediaActivity import com.keylesspalace.tusky.ViewVideoActivity diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java index ad7e0a7b..3d606935 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java @@ -58,8 +58,6 @@ import javax.inject.Inject; * overlap functionality. So, I'm momentarily leaving it and hopefully working on those will clear * up what needs to be where. */ public abstract class SFragment extends BaseFragment { - protected static final int COMPOSE_RESULT = 1; - protected String loggedInAccountId; protected String loggedInUsername; @@ -137,7 +135,7 @@ public abstract class SFragment extends BaseFragment { .repyingStatusAuthor(actionableStatus.getAccount().getLocalUsername()) .replyingStatusContent(actionableStatus.getContent().toString()) .build(getContext()); - startActivityForResult(intent, COMPOSE_RESULT); + startActivity(intent); } protected void more(final Status status, View view, final int position) { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java index d94a4226..18765b4f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java @@ -266,7 +266,7 @@ public class TimelineFragment extends SFragment implements } private void setupSwipeRefreshLayout() { - Context context = Objects.requireNonNull(getContext()); + Context context = requireContext(); swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.primary); swipeRefreshLayout.setProgressBackgroundColorSchemeColor(ThemeUtils.getColor(context, @@ -274,7 +274,7 @@ public class TimelineFragment extends SFragment implements } private void setupRecyclerView() { - Context context = Objects.requireNonNull(getContext()); + Context context = requireContext(); recyclerView.setHasFixedSize(true); layoutManager = new LinearLayoutManager(context); recyclerView.setLayoutManager(layoutManager); @@ -349,7 +349,7 @@ public class TimelineFragment extends SFragment implements super.onActivityCreated(savedInstanceState); if (jumpToTopAllowed()) { - TabLayout layout = Objects.requireNonNull(getActivity()).findViewById(R.id.tab_layout); + TabLayout layout = requireActivity().findViewById(R.id.tab_layout); if (layout != null) { onTabSelectedListener = new TabLayout.OnTabSelectedListener() { @Override @@ -417,8 +417,7 @@ public class TimelineFragment extends SFragment implements @Override public void onDestroyView() { if (jumpToTopAllowed()) { - TabLayout tabLayout = Objects.requireNonNull(getActivity()) - .findViewById(R.id.tab_layout); + TabLayout tabLayout = requireActivity().findViewById(R.id.tab_layout); if (tabLayout != null) { tabLayout.removeOnTabSelectedListener(onTabSelectedListener); } @@ -427,8 +426,7 @@ public class TimelineFragment extends SFragment implements } private void setupNothingView() { - Drawable top = AppCompatResources.getDrawable(Objects.requireNonNull(getContext()), - R.drawable.elephant_friend); + Drawable top = AppCompatResources.getDrawable(requireContext(), R.drawable.elephant_friend); if (top != null) { top.setBounds(0, 0, top.getIntrinsicWidth() / 2, top.getIntrinsicHeight() / 2); } @@ -663,7 +661,7 @@ public class TimelineFragment extends SFragment implements updateAdapter(); } - public void removeAllByAccountId(String accountId) { + private void removeAllByAccountId(String accountId) { // using iterator to safely remove items while iterating Iterator> iterator = statuses.iterator(); while (iterator.hasNext()) { @@ -1067,7 +1065,7 @@ public class TimelineFragment extends SFragment implements public void onInserted(int position, int count) { adapter.notifyItemRangeInserted(position, count); if (position == 0) { - recyclerView.scrollBy(0, Utils.dpToPx(Objects.requireNonNull(getContext()), -30)); + recyclerView.scrollBy(0, Utils.dpToPx(requireContext(), -30)); } } diff --git a/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java b/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java index 94fd4f0a..fbd46783 100644 --- a/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java +++ b/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java @@ -17,8 +17,6 @@ package com.keylesspalace.tusky.interfaces; import android.view.View; -import com.keylesspalace.tusky.entity.Attachment; - public interface StatusActionListener extends LinkListener { void onReply(int position); void onReblog(final boolean reblog, final int position); diff --git a/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.java b/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.java index e55be6a7..20b373f7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.java +++ b/app/src/main/java/com/keylesspalace/tusky/network/MastodonApi.java @@ -37,7 +37,6 @@ import okhttp3.MultipartBody; import okhttp3.RequestBody; import okhttp3.ResponseBody; import retrofit2.Call; -import retrofit2.http.Body; import retrofit2.http.DELETE; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; @@ -185,7 +184,6 @@ public interface MastodonApi { * @param limit Limit returned statuses (current API limits: default - 20, max - 40) * @param excludeReplies only return statuses that are no replies * @param onlyMedia only return statuses that have media attached - * @return */ @GET("api/v1/accounts/{id}/statuses") Call> accountStatuses( diff --git a/app/src/main/java/com/keylesspalace/tusky/service/TuskyTileService.java b/app/src/main/java/com/keylesspalace/tusky/service/TuskyTileService.java index 07c68884..78413774 100644 --- a/app/src/main/java/com/keylesspalace/tusky/service/TuskyTileService.java +++ b/app/src/main/java/com/keylesspalace/tusky/service/TuskyTileService.java @@ -32,35 +32,8 @@ public class TuskyTileService extends TileService { super(); } - @Override - public void onDestroy() { - super.onDestroy(); - } - - @Override - public void onTileAdded() { - super.onTileAdded(); - } - - @Override - public void onTileRemoved() { - super.onTileRemoved(); - } - - @Override - public void onStartListening() { - super.onStartListening(); - } - - @Override - public void onStopListening() { - super.onStopListening(); - } - @Override public void onClick() { - super.onClick(); - startActivityAndCollapse(new Intent(this, ComposeActivity.class)); } } diff --git a/app/src/main/java/com/keylesspalace/tusky/util/Assert.java b/app/src/main/java/com/keylesspalace/tusky/util/Assert.java deleted file mode 100644 index c976184e..00000000 --- a/app/src/main/java/com/keylesspalace/tusky/util/Assert.java +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright 2017 Andrew Dawson - * - * This file is a part of Tusky. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Tusky; if not, - * see . */ - -package com.keylesspalace.tusky.util; - -import com.keylesspalace.tusky.BuildConfig; - -/** Android Studio complains about built-in assertions so this is an alternative. */ -public class Assert { - private static boolean ENABLED = BuildConfig.DEBUG; - - public static void expect(boolean expression) { - if (ENABLED && !expression) { - throw new AssertionError(); - } - } -} diff --git a/app/src/main/java/com/keylesspalace/tusky/util/Either.java b/app/src/main/java/com/keylesspalace/tusky/util/Either.java index 3f134f75..a080322a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/Either.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/Either.java @@ -100,7 +100,7 @@ public final class Either { } /** - * Same as {@link #getAsRightOrNull()} but returns {@code null} is the value if Left instead of + * Same as {@link #getAsRight()} but returns {@code null} is the value if Left instead of * throwing an exception. * @return contained value as Right or null */ diff --git a/app/src/main/java/com/keylesspalace/tusky/util/EmojiCompatFont.java b/app/src/main/java/com/keylesspalace/tusky/util/EmojiCompatFont.java index 25054ee2..f00f787e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/EmojiCompatFont.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/EmojiCompatFont.java @@ -216,7 +216,7 @@ public class EmojiCompatFont { BufferedSink sink = Okio.buffer(Okio.sink(downloadFile)); Source source = null; try { - long size = 0; + long size; // Download! if (response.body() != null && response.isSuccessful() diff --git a/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java b/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java index e529bc25..0e24a025 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java @@ -183,5 +183,4 @@ public class LinkHelper { } - } diff --git a/app/src/main/java/com/keylesspalace/tusky/view/ComposeOptionsView.kt b/app/src/main/java/com/keylesspalace/tusky/view/ComposeOptionsView.kt index becbb831..3202a5df 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/ComposeOptionsView.kt +++ b/app/src/main/java/com/keylesspalace/tusky/view/ComposeOptionsView.kt @@ -38,7 +38,7 @@ class ComposeOptionsView @JvmOverloads constructor(context: Context, attrs: Attr directRadioButton.setButtonDrawable(R.drawable.ic_email_24dp) } - visibilityRadioGroup.setOnCheckedChangeListener({ _, checkedId -> + visibilityRadioGroup.setOnCheckedChangeListener { _, checkedId -> val visibility = when (checkedId) { R.id.publicRadioButton -> Status.Visibility.PUBLIC @@ -52,7 +52,7 @@ class ComposeOptionsView @JvmOverloads constructor(context: Context, attrs: Attr Status.Visibility.PUBLIC } listener?.onVisibilityChanged(visibility) - }) + } } fun setStatusVisibility(visibility: Status.Visibility) { diff --git a/app/src/main/res/drawable/ic_arrow_drop_down_black_24dp.xml b/app/src/main/res/drawable/ic_arrow_drop_down_black_24dp.xml deleted file mode 100644 index 88a73064..00000000 --- a/app/src/main/res/drawable/ic_arrow_drop_down_black_24dp.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_arrow_drop_up_black_24dp.xml b/app/src/main/res/drawable/ic_arrow_drop_up_black_24dp.xml deleted file mode 100644 index 49be73b7..00000000 --- a/app/src/main/res/drawable/ic_arrow_drop_up_black_24dp.xml +++ /dev/null @@ -1,4 +0,0 @@ - - -