Fix the bugs reported by @mmarif on Discord.

The image bug is not completely fixed, but if the image couldn't be decoded, it will view the "not processable" warning (it shouldn't crash anymore).

**Note:** I didn't test it yet due to lack of time. I would be happy if you could do this.

Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1127
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
qwerty287 2022-05-12 17:33:03 +02:00 committed by M M Arif
parent c571e6cb95
commit 055b08ef77
8 changed files with 34 additions and 23 deletions

View File

@ -111,7 +111,7 @@ dependencies {
implementation 'com.github.chrisvest:stormpot:2.4.2'
implementation 'androidx.browser:browser:1.4.0'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation('org.codeberg.gitnex:tea4j-autodeploy:4cd6803f8f') {
implementation('org.codeberg.gitnex:tea4j-autodeploy:3111bc1b18') {
exclude module: 'org.apache.oltu.oauth2.common'
}
}

View File

@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
@ -39,7 +40,7 @@ import retrofit2.Call;
import retrofit2.Response;
/**
* Author M M Arif
* @author M M Arif
*/
public class FileViewActivity extends BaseActivity implements BottomSheetListener {
@ -116,17 +117,19 @@ public class FileViewActivity extends BaseActivity implements BottomSheetListene
// See https://developer.android.com/guide/topics/media/media-formats#core
if(Arrays.asList("bmp", "gif", "jpg", "jpeg", "png", "webp", "heic", "heif").contains(fileExtension.toLowerCase())) {
processable = true;
byte[] pictureBytes = responseBody.bytes();
runOnUiThread(() -> {
binding.contents.setVisibility(View.GONE);
binding.markdownFrame.setVisibility(View.GONE);
Bitmap image = Images.scaleImage(pictureBytes, 1920);
processable = image != null;
if(processable) {
runOnUiThread(() -> {
binding.contents.setVisibility(View.GONE);
binding.markdownFrame.setVisibility(View.GONE);
binding.photoView.setVisibility(View.VISIBLE);
binding.photoView.setImageBitmap(Images.scaleImage(pictureBytes, 1920));
});
binding.photoView.setVisibility(View.VISIBLE);
binding.photoView.setImageBitmap(image);
});
}
}
break;

View File

@ -38,7 +38,7 @@ import moe.feng.common.view.breadcrumbs.DefaultBreadcrumbsCallback;
import moe.feng.common.view.breadcrumbs.model.BreadcrumbItem;
/**
* Author M M Arif
* @author M M Arif
*/
public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapterListener {
@ -151,7 +151,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
switch(file.getType()) {
case "dir":
path.add(file.getName());
path.addWithoutEncoding(file.getName());
binding.breadcrumbsView.addItem(new BreadcrumbItem(Collections.singletonList(file.getName())));
refresh();
break;
@ -173,6 +173,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
String host = url.getHost();
UserAccountsApi userAccountsApi = BaseApi.getInstance(requireContext(), UserAccountsApi.class);
assert userAccountsApi != null;
List<UserAccount> userAccounts = userAccountsApi.loggedInUserAccounts();
UserAccount account = null;
@ -252,7 +253,6 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
binding.progressBar.setVisibility(View.VISIBLE);
FilesViewModel filesModel = new ViewModelProvider(this).get(FilesViewModel.class);
filesModel.getFilesList2(owner, repo, filesDir, ref, getContext(), binding.progressBar, binding.noDataFiles).observe(getViewLifecycleOwner(), filesListMain2 -> {
filesAdapter.getOriginalFiles().clear();

View File

@ -3,7 +3,6 @@ package org.mian.gitnex.fragments;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -36,7 +35,7 @@ import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
* @author M M Arif
*/
public class RepoInfoFragment extends Fragment {
@ -164,7 +163,7 @@ public class RepoInfoFragment extends Fragment {
binding.repoMetaForks.setText(String.valueOf(repoInfo.getForksCount()));
binding.repoMetaWatchers.setText(String.valueOf(repoInfo.getWatchersCount()));
binding.repoMetaSize.setText(FileUtils.byteCountToDisplaySize(repoInfo.getSize().intValue() * 1024));
binding.repoMetaSize.setText(FileUtils.byteCountToDisplaySize(repoInfo.getSize() * 1024));
binding.repoMetaCreatedAt.setText(TimeHelper.formatTime(repoInfo.getCreatedAt(), locale, timeFormat, ctx));
if(timeFormat.equals("pretty")) {
@ -300,12 +299,8 @@ public class RepoInfoFragment extends Fragment {
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
}
});
}
}

View File

@ -4,7 +4,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
/**
* Author M M Arif
* @author M M Arif
*/
public class Images {
@ -12,6 +12,7 @@ public class Images {
public static Bitmap scaleImage(byte[] imageData, int sizeLimit) {
Bitmap original = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
if(original == null) return null; // something went wrong
if(original.getHeight() > sizeLimit && original.getWidth() <= original.getHeight()) {

View File

@ -59,7 +59,17 @@ public class Path {
}
public int size() {
public Path addWithoutEncoding(String segment) {
if(segment != null && !segment.trim().isEmpty()) {
segments.add(segment);
}
pathChanged();
return this;
}
public int size() {
return segments.size();
}

View File

@ -3,6 +3,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:padding="16dp">
<ImageView

View File

@ -8,6 +8,7 @@
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:orientation="vertical"
android:background="?android:attr/selectableItemBackground"
tools:ignore="UseCompoundDrawables">
<ImageView