1.8 fixes (#637)
* fix lint warnings * upgrade dependencies * auto cancel notifications * improve dependency injection * fix tests * remove old comment from BaseActivity * fix missing injectors
This commit is contained in:
parent
26fb180d1a
commit
27b4cf8739
25 changed files with 34 additions and 135 deletions
|
@ -44,7 +44,7 @@ android {
|
|||
}
|
||||
|
||||
ext.supportLibraryVersion = '27.1.1'
|
||||
ext.daggerVersion = '2.15'
|
||||
ext.daggerVersion = '2.16'
|
||||
|
||||
dependencies {
|
||||
implementation('com.mikepenz:materialdrawer:6.0.7@aar') {
|
||||
|
|
|
@ -47,12 +47,10 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.keylesspalace.tusky.db.AccountEntity;
|
||||
import com.keylesspalace.tusky.db.AccountManager;
|
||||
import com.keylesspalace.tusky.entity.Account;
|
||||
import com.keylesspalace.tusky.entity.Relationship;
|
||||
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
||||
import com.keylesspalace.tusky.interfaces.LinkListener;
|
||||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
import com.keylesspalace.tusky.pager.AccountPagerAdapter;
|
||||
import com.keylesspalace.tusky.receiver.TimelineReceiver;
|
||||
import com.keylesspalace.tusky.util.Assert;
|
||||
|
@ -85,8 +83,6 @@ public final class AccountActivity extends BottomSheetActivity implements Action
|
|||
REQUESTED,
|
||||
}
|
||||
|
||||
@Inject
|
||||
public MastodonApi mastodonApi;
|
||||
@Inject
|
||||
public DispatchingAndroidInjector<Fragment> dispatchingAndroidInjector;
|
||||
|
||||
|
@ -712,9 +708,4 @@ public final class AccountActivity extends BottomSheetActivity implements Action
|
|||
return dispatchingAndroidInjector;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MastodonApi getMastodonApi() {
|
||||
return mastodonApi;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.evernote.android.job.JobManager;
|
|||
import com.evernote.android.job.JobRequest;
|
||||
import com.keylesspalace.tusky.db.AccountEntity;
|
||||
import com.keylesspalace.tusky.db.AccountManager;
|
||||
import com.keylesspalace.tusky.di.Injectable;
|
||||
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -41,7 +42,7 @@ import javax.inject.Inject;
|
|||
|
||||
import retrofit2.Call;
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
public abstract class BaseActivity extends AppCompatActivity implements Injectable {
|
||||
|
||||
protected List<Call> callList;
|
||||
|
||||
|
@ -111,20 +112,14 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||
return getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
protected boolean redirectIfNotLoggedIn() {
|
||||
// This is very ugly but we cannot inject into parent class and injecting into every
|
||||
// subclass seems inconvenient as well.
|
||||
AccountEntity account = ((TuskyApplication) getApplicationContext())
|
||||
.getServiceLocator().get(AccountManager.class)
|
||||
.getActiveAccount();
|
||||
protected void redirectIfNotLoggedIn() {
|
||||
AccountEntity account = accountManager.getActiveAccount();
|
||||
if (account == null) {
|
||||
Intent intent = new Intent(this, LoginActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,6 +30,7 @@ import retrofit2.Callback
|
|||
import retrofit2.Response
|
||||
import java.net.URI
|
||||
import java.net.URISyntaxException
|
||||
import javax.inject.Inject
|
||||
|
||||
/** this is the base class for all activities that open links
|
||||
* links are checked against the api if they are mastodon links so they can be openend in Tusky
|
||||
|
@ -41,7 +42,8 @@ abstract class BottomSheetActivity : BaseActivity() {
|
|||
lateinit var bottomSheet: BottomSheetBehavior<LinearLayout>
|
||||
var searchUrl: String? = null
|
||||
|
||||
abstract fun getMastodonApi(): MastodonApi
|
||||
@Inject
|
||||
lateinit var mastodonApi: MastodonApi
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
|
@ -67,7 +69,7 @@ abstract class BottomSheetActivity : BaseActivity() {
|
|||
return
|
||||
}
|
||||
|
||||
val call = getMastodonApi().search(url, true)
|
||||
val call = mastodonApi.search(url, true)
|
||||
call.enqueue(object : Callback<SearchResults> {
|
||||
override fun onResponse(call: Call<SearchResults>, response: Response<SearchResults>) {
|
||||
if (getCancelSearchRequested(url)) {
|
||||
|
|
|
@ -24,9 +24,6 @@ import android.support.v7.widget.Toolbar;
|
|||
import android.view.MenuItem;
|
||||
|
||||
import com.keylesspalace.tusky.fragment.TimelineFragment;
|
||||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -36,8 +33,6 @@ import dagger.android.support.HasSupportFragmentInjector;
|
|||
|
||||
public class FavouritesActivity extends BottomSheetActivity implements HasSupportFragmentInjector {
|
||||
|
||||
@Inject
|
||||
public MastodonApi mastodonApi;
|
||||
@Inject
|
||||
public DispatchingAndroidInjector<Fragment> dispatchingAndroidInjector;
|
||||
|
||||
|
@ -77,9 +72,4 @@ public class FavouritesActivity extends BottomSheetActivity implements HasSuppor
|
|||
return dispatchingAndroidInjector;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MastodonApi getMastodonApi() {
|
||||
return mastodonApi;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,10 +37,8 @@ import android.widget.ImageButton;
|
|||
import android.widget.ImageView;
|
||||
|
||||
import com.keylesspalace.tusky.db.AccountEntity;
|
||||
import com.keylesspalace.tusky.db.AccountManager;
|
||||
import com.keylesspalace.tusky.entity.Account;
|
||||
import com.keylesspalace.tusky.interfaces.ActionButtonActivity;
|
||||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
import com.keylesspalace.tusky.pager.TimelinePagerAdapter;
|
||||
import com.keylesspalace.tusky.util.NotificationHelper;
|
||||
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||
|
@ -60,8 +58,6 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
|
|||
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -90,8 +86,6 @@ public class MainActivity extends BottomSheetActivity implements ActionButtonAct
|
|||
private static final long DRAWER_ITEM_SAVED_TOOT = 9;
|
||||
private static final long DRAWER_ITEM_LISTS = 10;
|
||||
|
||||
@Inject
|
||||
public MastodonApi mastodonApi;
|
||||
@Inject
|
||||
public DispatchingAndroidInjector<Fragment> fragmentInjector;
|
||||
|
||||
|
@ -268,12 +262,6 @@ public class MainActivity extends BottomSheetActivity implements ActionButtonAct
|
|||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
// Fix for GitHub issues #190, #259 (MainActivity won't restart on screen rotation.)
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
private void tintTab(TabLayout.Tab tab, boolean tinted) {
|
||||
int color = (tinted) ? R.attr.tab_icon_selected_tint : R.attr.toolbar_icon_tint;
|
||||
ThemeUtils.setDrawableTint(this, tab.getIcon(), color);
|
||||
|
@ -553,9 +541,4 @@ public class MainActivity extends BottomSheetActivity implements ActionButtonAct
|
|||
return fragmentInjector;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MastodonApi getMastodonApi() {
|
||||
return mastodonApi;
|
||||
}
|
||||
}
|
|
@ -10,7 +10,6 @@ import android.view.MenuItem
|
|||
import android.widget.FrameLayout
|
||||
import com.keylesspalace.tusky.fragment.TimelineFragment
|
||||
import com.keylesspalace.tusky.interfaces.ActionButtonActivity
|
||||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.DispatchingAndroidInjector
|
||||
import dagger.android.support.HasSupportFragmentInjector
|
||||
|
@ -18,8 +17,6 @@ import javax.inject.Inject
|
|||
|
||||
class ModalTimelineActivity : BottomSheetActivity(), ActionButtonActivity, HasSupportFragmentInjector {
|
||||
|
||||
@Inject
|
||||
lateinit var api: MastodonApi
|
||||
@Inject
|
||||
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
|
||||
|
||||
|
@ -79,8 +76,4 @@ class ModalTimelineActivity : BottomSheetActivity(), ActionButtonActivity, HasSu
|
|||
return dispatchingAndroidInjector
|
||||
}
|
||||
|
||||
override fun getMastodonApi(): MastodonApi {
|
||||
return api
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public final class NotificationPullJobCreator implements JobCreator {
|
|||
}
|
||||
|
||||
private boolean isBiggerThan(BigInteger newId, BigInteger lastShownNotificationId) {
|
||||
return lastShownNotificationId.compareTo(newId) == -1;
|
||||
return lastShownNotificationId.compareTo(newId) < 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,6 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
|
||||
import com.keylesspalace.tusky.fragment.SearchFragment;
|
||||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -42,8 +39,7 @@ import dagger.android.support.HasSupportFragmentInjector;
|
|||
|
||||
public class SearchActivity extends BottomSheetActivity implements SearchView.OnQueryTextListener,
|
||||
HasSupportFragmentInjector {
|
||||
@Inject
|
||||
public MastodonApi mastodonApi;
|
||||
|
||||
@Inject
|
||||
public DispatchingAndroidInjector<Fragment> fragmentInjector;
|
||||
|
||||
|
@ -144,9 +140,4 @@ public class SearchActivity extends BottomSheetActivity implements SearchView.On
|
|||
return fragmentInjector;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MastodonApi getMastodonApi() {
|
||||
return mastodonApi;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,6 @@ import android.support.v7.widget.Toolbar;
|
|||
import android.view.MenuItem;
|
||||
|
||||
import com.keylesspalace.tusky.fragment.TimelineFragment;
|
||||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -36,8 +33,6 @@ import dagger.android.support.HasSupportFragmentInjector;
|
|||
|
||||
public class ViewTagActivity extends BottomSheetActivity implements HasSupportFragmentInjector {
|
||||
|
||||
@Inject
|
||||
public MastodonApi mastodonApi;
|
||||
@Inject
|
||||
public DispatchingAndroidInjector<Fragment> dispatchingAndroidInjector;
|
||||
|
||||
|
@ -80,9 +75,4 @@ public class ViewTagActivity extends BottomSheetActivity implements HasSupportFr
|
|||
return dispatchingAndroidInjector;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MastodonApi getMastodonApi() {
|
||||
return mastodonApi;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,8 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
|
||||
import com.keylesspalace.tusky.fragment.ViewThreadFragment;
|
||||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
import com.keylesspalace.tusky.util.LinkHelper;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.AndroidInjector;
|
||||
|
@ -44,8 +41,6 @@ public class ViewThreadActivity extends BottomSheetActivity implements HasSuppor
|
|||
|
||||
private int revealButtonState = REVEAL_BUTTON_HIDDEN;
|
||||
|
||||
@Inject
|
||||
public MastodonApi mastodonApi;
|
||||
@Inject
|
||||
public DispatchingAndroidInjector<Fragment> dispatchingAndroidInjector;
|
||||
|
||||
|
@ -119,9 +114,4 @@ public class ViewThreadActivity extends BottomSheetActivity implements HasSuppor
|
|||
return dispatchingAndroidInjector;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public MastodonApi getMastodonApi() {
|
||||
return mastodonApi;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import android.text.Spanned;
|
|||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
|
|
@ -45,6 +45,7 @@ public class ThreadAdapter extends RecyclerView.Adapter {
|
|||
detailedStatusPosition = RecyclerView.NO_POSITION;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
switch (viewType) {
|
||||
|
|
|
@ -74,4 +74,16 @@ abstract class ActivitiesModule {
|
|||
@ContributesAndroidInjector
|
||||
abstract fun contributesReportActivity(): ReportActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesSavedTootActivity(): SavedTootActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesSPreferencesActivity(): PreferencesActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesViewMediaActivity(): ViewMediaActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesViewVideoActivity(): ViewVideoActivity
|
||||
|
||||
}
|
|
@ -22,5 +22,5 @@ import dagger.android.ContributesAndroidInjector
|
|||
@Module
|
||||
abstract class ServicesModule {
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributeMyService(): SendTootService
|
||||
abstract fun contributesSendTootService(): SendTootService
|
||||
}
|
|
@ -16,7 +16,6 @@
|
|||
package com.keylesspalace.tusky.entity
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import java.util.*
|
||||
|
||||
data class Instance (
|
||||
val uri: String,
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package com.keylesspalace.tusky.entity
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Profile(
|
||||
@SerializedName("display_name") val displayName: String?,
|
||||
val note: String?,
|
||||
val avatar: String?,
|
||||
val header: String? = null
|
||||
)
|
||||
|
|
@ -623,7 +623,7 @@ public class NotificationsFragment extends SFragment implements
|
|||
|
||||
private boolean isBiggerThan(BigInteger newId, BigInteger lastShownNotificationId) {
|
||||
|
||||
return lastShownNotificationId.compareTo(newId) == -1;
|
||||
return lastShownNotificationId.compareTo(newId) < 0;
|
||||
}
|
||||
|
||||
private void update(@Nullable List<Notification> newNotifications, @Nullable String fromId,
|
||||
|
|
|
@ -29,6 +29,7 @@ import android.support.v4.widget.SwipeRefreshLayout;
|
|||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -100,7 +101,6 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
return timelineCases;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
@ -532,11 +532,6 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
statuses.clear();
|
||||
adapter.clear();
|
||||
}
|
||||
|
||||
private void updateRevealIcon() {
|
||||
ViewThreadActivity activity = ((ViewThreadActivity) getActivity());
|
||||
if (activity == null) return;
|
||||
|
@ -544,8 +539,7 @@ public final class ViewThreadFragment extends SFragment implements
|
|||
boolean hasAnyWarnings = false;
|
||||
// Statuses are updated from the main thread so nothing should change while iterating
|
||||
for (int i = 0; i < statuses.size(); i++) {
|
||||
if (statuses.get(i).getSpoilerText() != null
|
||||
&& !statuses.get(i).getSpoilerText().isEmpty()) {
|
||||
if (!TextUtils.isEmpty(statuses.get(i).getSpoilerText())) {
|
||||
hasAnyWarnings = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public final class ProgressRequestBody extends RequestBody {
|
|||
}
|
||||
|
||||
@Override
|
||||
public long contentLength() throws IOException {
|
||||
public long contentLength() {
|
||||
return content.length;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,6 @@ import android.text.style.ClickableSpan
|
|||
abstract class ClickableSpanNoUnderline : ClickableSpan() {
|
||||
override fun updateDrawState(ds: TextPaint?) {
|
||||
super.updateDrawState(ds)
|
||||
ds?.isUnderlineText = false;
|
||||
ds?.isUnderlineText = false
|
||||
}
|
||||
}
|
|
@ -264,6 +264,7 @@ public class NotificationHelper {
|
|||
.setDeleteIntent(deletePendingIntent)
|
||||
.setColor(ContextCompat.getColor(context, (R.color.primary)))
|
||||
.setGroup(account.getAccountId())
|
||||
.setAutoCancel(true)
|
||||
.setDefaults(0); // So it doesn't ring twice, notify only in Target callback
|
||||
|
||||
setupPreferences(account, builder);
|
||||
|
@ -521,7 +522,6 @@ public class NotificationHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String bodyForType(Notification notification) {
|
||||
switch (notification.getType()) {
|
||||
case FOLLOW:
|
||||
|
|
|
@ -1,17 +1,9 @@
|
|||
package com.keylesspalace.tusky.util;
|
||||
|
||||
import android.util.Patterns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
public final static String carriageReturn = System.getProperty("line.separator");
|
||||
final static String QUOTE = "\"";
|
||||
|
||||
public static String randomAlphanumericString(int count) {
|
||||
char[] chars = new char[count];
|
||||
Random random = new Random();
|
||||
|
@ -22,13 +14,4 @@ public class StringUtils {
|
|||
return new String(chars);
|
||||
}
|
||||
|
||||
static List<String> extractUrl(String text) {
|
||||
List<String> links = new ArrayList<>();
|
||||
Matcher m = Patterns.WEB_URL.matcher(text);
|
||||
while (m.find()) {
|
||||
String url = m.group();
|
||||
links.add(url);
|
||||
}
|
||||
return links;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -282,22 +282,19 @@ class BottomSheetActivityTest {
|
|||
override fun request(): Request { throw NotImplementedError() }
|
||||
}
|
||||
|
||||
class FakeBottomSheetActivity(val api: MastodonApi) : BottomSheetActivity() {
|
||||
class FakeBottomSheetActivity(api: MastodonApi) : BottomSheetActivity() {
|
||||
|
||||
var status: Status? = null
|
||||
var accountId: String? = null
|
||||
var link: String? = null
|
||||
|
||||
init {
|
||||
mastodonApi = api
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
bottomSheet = Mockito.mock(BottomSheetBehavior::class.java) as BottomSheetBehavior<LinearLayout>
|
||||
callList = arrayListOf()
|
||||
}
|
||||
|
||||
override fun getMastodonApi(): MastodonApi {
|
||||
return api
|
||||
}
|
||||
|
||||
override fun openLink(url: String) {
|
||||
this.link = url
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.2.40'
|
||||
ext.kotlin_version = '1.2.41'
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
|
|
Loading…
Reference in a new issue