Some fixes

This commit is contained in:
stom79 2017-12-28 17:56:03 +01:00
parent 03358f531d
commit 89076db8ee
5 changed files with 19 additions and 42 deletions

View File

@ -54,11 +54,14 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get(), account.getInstance(), account.getToken()); API api;
if( account == null) if( account == null) {
api = new API(this.contextReference.get());
apiResponse = api.getNotifications(max_id, display); apiResponse = api.getNotifications(max_id, display);
else }else {
api = new API(this.contextReference.get(), account.getInstance(), account.getToken());
apiResponse = api.getNotificationsSince(max_id, display); apiResponse = api.getNotificationsSince(max_id, display);
}
return null; return null;
} }

View File

@ -98,7 +98,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):null); instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):null);
lastReadNotifications = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + userId, null); lastReadNotifications = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments,this.notifications); notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments,this.notifications);
lv_notifications.setAdapter(notificationsListAdapter); lv_notifications.setAdapter(notificationsListAdapter);
mLayoutManager = new LinearLayoutManager(context); mLayoutManager = new LinearLayoutManager(context);

View File

@ -67,7 +67,6 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
import android.util.Base64;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Patterns; import android.util.Patterns;
import android.view.Menu; import android.view.Menu;
@ -101,7 +100,6 @@ import com.google.gson.Gson;
import org.conscrypt.Conscrypt; import org.conscrypt.Conscrypt;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -109,19 +107,14 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.Security; import java.security.Security;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -229,7 +222,6 @@ public class Helper {
public static final String SET_SHOW_REPLIES = "set_show_replies"; public static final String SET_SHOW_REPLIES = "set_show_replies";
public static final String INSTANCE_VERSION = "instance_version"; public static final String INSTANCE_VERSION = "instance_version";
public static final String SET_LIVE_NOTIFICATIONS = "set_show_replies"; public static final String SET_LIVE_NOTIFICATIONS = "set_show_replies";
public static final String SET_PICTURE_URL = "set_picture_url";
public static final String SET_DISABLE_GIF = "set_disable_gif"; public static final String SET_DISABLE_GIF = "set_disable_gif";
public static final int ATTACHMENT_ALWAYS = 1; public static final int ATTACHMENT_ALWAYS = 1;
public static final int ATTACHMENT_WIFI = 2; public static final int ATTACHMENT_WIFI = 2;
@ -307,16 +299,9 @@ public class Helper {
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_À-ú-]+)"); public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_À-ú-]+)");
public static final Pattern mentionPattern = Pattern.compile("(@[\\w]+)"); private static final Pattern mentionPattern = Pattern.compile("(@[\\w]+)");
public static final Pattern mentionOtherInstancePattern = Pattern.compile("(@[\\w]*@[\\w.-]+)");
public static final Pattern blacklistPattern = Pattern.compile("(%[\\w_À-ú-]+)");
//Targeted field after translation
public enum targetField{
STATUS,
CW,
SIMPLE
}
//Event Type //Event Type
public enum EventStreaming{ public enum EventStreaming{
UPDATE, UPDATE,
@ -502,12 +487,12 @@ public class Helper {
/** /**
* Converts a Date date into a date-time string (SHORT format for both) * Converts a Date date into a date-time string (SHORT format for both)
* @param context * @param context Context
* @param date to be converted * @param date to be converted
* @return String * @return String
*/ */
public static String shortDateTime(Context context, Date date) { private static String shortDateTime(Context context, Date date) {
Locale userLocale; Locale userLocale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
@ -941,8 +926,6 @@ public class Helper {
if( currentSubmenu == null) if( currentSubmenu == null)
continue; continue;
final MenuItem item = currentSubmenu.add("@" + account.getAcct()); final MenuItem item = currentSubmenu.add("@" + account.getAcct());
final ImageView imageView = new ImageView(activity);
item.setIcon(R.drawable.ic_person); item.setIcon(R.drawable.ic_person);
String url = account.getAvatar(); String url = account.getAvatar();
if( url.startsWith("/") ){ if( url.startsWith("/") ){
@ -1336,7 +1319,7 @@ public class Helper {
if( val.length == 2){ if( val.length == 2){
username = val[1]; username = val[1];
Pattern urlAccountPattern = Pattern.compile( Pattern urlAccountPattern = Pattern.compile(
"https:\\/\\/[\\w._-]+\\/@"+ username); "https://[\\w._-]+/@"+ username);
Matcher matcherAccount = urlAccountPattern.matcher(finalFullContent); Matcher matcherAccount = urlAccountPattern.matcher(finalFullContent);
while (matcherAccount.find()){ while (matcherAccount.find()){
String url = matcherAccount.group(0); String url = matcherAccount.group(0);
@ -1442,6 +1425,7 @@ public class Helper {
public static Drawable changeDrawableColor(Context context, int drawable, int hexaColor){ public static Drawable changeDrawableColor(Context context, int drawable, int hexaColor){
Drawable mDrawable = ContextCompat.getDrawable(context, drawable); Drawable mDrawable = ContextCompat.getDrawable(context, drawable);
int color = Color.parseColor(context.getString(hexaColor)); int color = Color.parseColor(context.getString(hexaColor));
assert mDrawable != null;
mDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); mDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
DrawableCompat.setTint(mDrawable, ContextCompat.getColor(context, hexaColor)); DrawableCompat.setTint(mDrawable, ContextCompat.getColor(context, hexaColor));
return mDrawable; return mDrawable;
@ -1696,14 +1680,6 @@ public class Helper {
return returnedBitmap; return returnedBitmap;
} }
public static Bitmap resizeImage(Bitmap originalPicture, float maxImageSize) {
float ratio = Math.min(
maxImageSize / originalPicture.getWidth(),
maxImageSize / originalPicture.getHeight());
int width = Math.round(ratio * originalPicture.getWidth());
int height = Math.round(ratio * originalPicture.getHeight());
return Bitmap.createScaledBitmap(originalPicture, width, height, false);
}
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
public static String withSuffix(long count) { public static String withSuffix(long count) {

View File

@ -345,10 +345,10 @@ public class LiveNotificationService extends BaseService {
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
notify_user(getApplicationContext(), intent, notificationId, BitmapFactory.decodeResource(getResources(), notify_user(getApplicationContext(), intent, notificationId, BitmapFactory.decodeResource(getResources(),
R.drawable.mastodonlogo), finalTitle, "@"+account.getAcct()+"@"+account.getInstance()); R.drawable.mastodonlogo), finalTitle, "@"+account.getAcct()+"@"+account.getInstance());
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) {
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), notification.getId()); editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
editor.apply(); editor.apply();
} }
return false; return false;
@ -358,10 +358,10 @@ public class LiveNotificationService extends BaseService {
@Override @Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
notify_user(getApplicationContext(), intent, notificationId, resource, finalTitle, "@"+account.getAcct()+"@"+account.getInstance()); notify_user(getApplicationContext(), intent, notificationId, resource, finalTitle, "@"+account.getAcct()+"@"+account.getInstance());
String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null); String lastNotif = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) { if (lastNotif == null || Long.parseLong(notification.getId()) > Long.parseLong(lastNotif)) {
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), notification.getId()); editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), notification.getId());
editor.apply(); editor.apply();
} }
} }

View File

@ -77,9 +77,7 @@ public class StreamingService extends IntentService {
super.onCreate(); super.onCreate();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit(); SharedPreferences.Editor editor = sharedpreferences.edit();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING, true);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
editor.putBoolean(Helper.SHOULD_CONTINUE_STREAMING + userId + instance, true);
editor.apply(); editor.apply();
} }
@ -116,7 +114,7 @@ public class StreamingService extends IntentService {
String event; String event;
Helper.EventStreaming eventStreaming; Helper.EventStreaming eventStreaming;
while((event = reader.readLine()) != null) { while((event = reader.readLine()) != null) {
if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING + accountStream.getId() + accountStream.getInstance(), true) ) if( !sharedpreferences.getBoolean(Helper.SHOULD_CONTINUE_STREAMING, true) )
stopSelf(); stopSelf();
if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) { if ((lastEvent == Helper.EventStreaming.NONE || lastEvent == null) && !event.startsWith("data: ")) {
switch (event.trim()) { switch (event.trim()) {