fix crash on Android 4

main
Konrad Pozniak 7 years ago
parent 634435bc57
commit 915fc49e91
  1. 5
      app/build.gradle
  2. 12
      app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java
  3. 10
      app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java
  4. 13
      app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java
  5. 2
      app/src/main/res/layout/item_follow.xml
  6. 2
      app/src/main/res/layout/item_status.xml

@ -66,10 +66,9 @@ dependencies {
compile 'com.evernote:android-job:1.2.0' compile 'com.evernote:android-job:1.2.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//room //room
implementation "android.arch.persistence.room:runtime:1.0.0" implementation 'android.arch.persistence.room:runtime:1.0.0'
kapt 'android.arch.persistence.room:compiler:1.0.0' kapt 'android.arch.persistence.room:compiler:1.0.0'
testCompile 'junit:junit:4.12'
testCompile "junit:junit:4.12"
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })

@ -17,7 +17,7 @@ package com.keylesspalace.tusky;
import android.app.Application; import android.app.Application;
import android.arch.persistence.room.Room; import android.arch.persistence.room.Room;
import android.net.Uri; import android.support.v7.app.AppCompatDelegate;
import com.evernote.android.job.JobManager; import com.evernote.android.job.JobManager;
import com.jakewharton.picasso.OkHttp3Downloader; import com.jakewharton.picasso.OkHttp3Downloader;
@ -39,12 +39,7 @@ public class TuskyApplication extends Application {
Picasso.Builder builder = new Picasso.Builder(this); Picasso.Builder builder = new Picasso.Builder(this);
builder.downloader(new OkHttp3Downloader(OkHttpUtils.getCompatibleClient())); builder.downloader(new OkHttp3Downloader(OkHttpUtils.getCompatibleClient()));
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
builder.listener(new Picasso.Listener() { builder.listener((picasso, uri, exception) -> exception.printStackTrace());
@Override
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
exception.printStackTrace();
}
});
} }
try { try {
@ -60,5 +55,8 @@ public class TuskyApplication extends Application {
.build(); .build();
JobManager.create(this).addJobCreator(new NotificationPullJobCreator(this)); JobManager.create(this).addJobCreator(new NotificationPullJobCreator(this));
//necessary for Android < APi 21
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
} }
} }

@ -246,6 +246,9 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
usernameView = itemView.findViewById(R.id.notification_username); usernameView = itemView.findViewById(R.id.notification_username);
displayNameView = itemView.findViewById(R.id.notification_display_name); displayNameView = itemView.findViewById(R.id.notification_display_name);
avatar = itemView.findViewById(R.id.notification_avatar); avatar = itemView.findViewById(R.id.notification_avatar);
//workaround because Android < API 21 does not support setting drawableLeft from xml when it is a vector image
Drawable followIcon = ContextCompat.getDrawable(message.getContext(), R.drawable.ic_person_add_24dp);
message.setCompoundDrawablesWithIntrinsicBounds(followIcon, null, null, null);
} }
void setMessage(String displayName, String username, String avatarUrl) { void setMessage(String displayName, String username, String avatarUrl) {
@ -270,12 +273,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
} }
void setupButtons(final NotificationActionListener listener, final String accountId) { void setupButtons(final NotificationActionListener listener, final String accountId) {
avatar.setOnClickListener(new View.OnClickListener() { avatar.setOnClickListener(v -> listener.onViewAccount(accountId));
@Override
public void onClick(View v) {
listener.onViewAccount(accountId);
}
});
} }
} }

@ -16,6 +16,7 @@
package com.keylesspalace.tusky.adapter; package com.keylesspalace.tusky.adapter;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.View; import android.view.View;
@ -24,6 +25,7 @@ import android.widget.TextView;
import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.interfaces.StatusActionListener;
import com.keylesspalace.tusky.util.ThemeUtils;
import com.keylesspalace.tusky.view.RoundedTransformation; import com.keylesspalace.tusky.view.RoundedTransformation;
import com.keylesspalace.tusky.viewdata.StatusViewData; import com.keylesspalace.tusky.viewdata.StatusViewData;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
@ -37,6 +39,10 @@ public class StatusViewHolder extends StatusBaseViewHolder {
super(itemView); super(itemView);
avatarReblog = itemView.findViewById(R.id.status_avatar_reblog); avatarReblog = itemView.findViewById(R.id.status_avatar_reblog);
rebloggedBar = itemView.findViewById(R.id.status_reblogged); rebloggedBar = itemView.findViewById(R.id.status_reblogged);
//workaround because Android < API 21 does not support setting drawableLeft from xml when it is a vector image
Drawable rebloggedIcon = ThemeUtils.getDrawable(rebloggedBar.getContext(),
R.attr.status_reblog_small_drawable, R.drawable.ic_reblog_dark_18dp);
rebloggedBar.setCompoundDrawablesWithIntrinsicBounds(rebloggedIcon, null, null, null);
} }
@Override @Override
@ -84,12 +90,7 @@ public class StatusViewHolder extends StatusBaseViewHolder {
// I think it's not efficient to create new object every time we bind a holder. // I think it's not efficient to create new object every time we bind a holder.
// More efficient approach would be creating View.OnClickListener during holder creation // More efficient approach would be creating View.OnClickListener during holder creation
// and storing StatusActionListener in a variable after binding. // and storing StatusActionListener in a variable after binding.
rebloggedBar.setOnClickListener(new View.OnClickListener() { rebloggedBar.setOnClickListener(v -> listener.onOpenReblog(getAdapterPosition()));
@Override
public void onClick(View v) {
listener.onOpenReblog(getAdapterPosition());
}
});
} }
private void setRebloggedByDisplayName(String name) { private void setRebloggedByDisplayName(String name) {

@ -17,9 +17,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:drawableLeft="@drawable/ic_person_add_24dp"
android:drawablePadding="10dp" android:drawablePadding="10dp"
android:drawableStart="@drawable/ic_person_add_24dp"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" android:maxLines="1"

@ -13,9 +13,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/status_reblogged_bar_top_padding" android:layout_marginTop="@dimen/status_reblogged_bar_top_padding"
android:drawableLeft="?attr/status_reblog_small_drawable"
android:drawablePadding="6dp" android:drawablePadding="6dp"
android:drawableStart="?attr/status_reblog_small_drawable"
android:gravity="center_vertical" android:gravity="center_vertical"
android:paddingLeft="38dp" android:paddingLeft="38dp"
android:paddingStart="38dp" android:paddingStart="38dp"

Loading…
Cancel
Save