1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-12 17:57:29 +00:00

null checks and try with resources

This commit is contained in:
Ammar Githam 2021-05-25 00:43:20 +09:00
parent c18e1ddb93
commit bc6fdd03d9
3 changed files with 11 additions and 10 deletions

View File

@ -198,7 +198,7 @@ public final class InboxManager {
hasOlder = false;
return;
}
if (!response.getStatus().equals("ok")) {
if (!Objects.equals(response.getStatus(), "ok")) {
Log.e(TAG, "DM inbox fetch response: status not ok");
inbox.postValue(Resource.error(R.string.generic_not_ok_response, getCurrentDirectInbox()));
hasOlder = false;
@ -209,12 +209,13 @@ public final class InboxManager {
viewer = response.getViewer();
}
final DirectInbox inbox = response.getInbox();
if (inbox == null) return;
if (!TextUtils.isEmpty(cursor)) {
final DirectInbox currentDirectInbox = getCurrentDirectInbox();
if (currentDirectInbox != null) {
List<DirectThread> threads = currentDirectInbox.getThreads();
threads = threads == null ? new LinkedList<>() : new LinkedList<>(threads);
threads.addAll(inbox.getThreads());
threads.addAll(inbox.getThreads() == null ? Collections.emptyList() : inbox.getThreads());
inbox.setThreads(threads);
}
}

View File

@ -16,7 +16,6 @@ import com.google.common.collect.Iterables;
import org.json.JSONObject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.ArrayList;
@ -1008,7 +1007,7 @@ public final class ThreadManager {
return;
}
sendPhoto(data, uri, dimensions.first, dimensions.second);
} catch (FileNotFoundException e) {
} catch (IOException e) {
data.postValue(Resource.error(e.getMessage(), null));
Log.e(TAG, "sendPhoto: ", e);
}

View File

@ -17,7 +17,6 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -243,13 +242,15 @@ public final class BitmapUtils {
* @return dimensions of the image
*/
public static Pair<Integer, Integer> decodeDimensions(@NonNull final ContentResolver contentResolver,
@NonNull final Uri uri) throws FileNotFoundException {
@NonNull final Uri uri) throws IOException {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(contentResolver.openInputStream(uri), null, options);
return (options.outWidth == -1 || options.outHeight == -1)
? null
: new Pair<>(options.outWidth, options.outHeight);
try (final InputStream stream = contentResolver.openInputStream(uri)) {
BitmapFactory.decodeStream(stream, null, options);
return (options.outWidth == -1 || options.outHeight == -1)
? null
: new Pair<>(options.outWidth, options.outHeight);
}
}
public static File convertToJpegAndSaveToFile(@NonNull final Bitmap bitmap, @Nullable final File file) throws IOException {