Code improvements
This commit is contained in:
parent
2db6e9310a
commit
76f8f49cdf
|
@ -41,7 +41,7 @@ public class FileDiffView implements Serializable {
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
|
|
||||||
if (fileOldName.length() != 0 && !fileOldName.equals(fileNewName)) {
|
if (!fileOldName.isEmpty() && !fileOldName.equals(fileNewName)) {
|
||||||
return fileOldName + " -> " + fileNewName;
|
return fileOldName + " -> " + fileNewName;
|
||||||
}
|
}
|
||||||
return fileNewName;
|
return fileNewName;
|
||||||
|
|
|
@ -170,7 +170,6 @@ public class Markdown {
|
||||||
private Context context;
|
private Context context;
|
||||||
private String markdown;
|
private String markdown;
|
||||||
private TextView textView;
|
private TextView textView;
|
||||||
TinyDB tinyDB = TinyDB.getInstance(null);
|
|
||||||
|
|
||||||
public Renderer(Slot slot) {
|
public Renderer(Slot slot) {
|
||||||
|
|
||||||
|
@ -320,7 +319,6 @@ public class Markdown {
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
private MarkwonAdapter adapter;
|
private MarkwonAdapter adapter;
|
||||||
private RepositoryContext repository;
|
private RepositoryContext repository;
|
||||||
TinyDB tinyDB = TinyDB.getInstance(null);
|
|
||||||
|
|
||||||
private LinkPostProcessor linkPostProcessor;
|
private LinkPostProcessor linkPostProcessor;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.mian.gitnex.helpers;
|
package org.mian.gitnex.helpers;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +32,7 @@ public class MergePullRequestSpinner implements Serializable {
|
||||||
this.mergerMethod = mergerMethod;
|
this.mergerMethod = mergerMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@NonNull @Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return mergerMethod;
|
return mergerMethod;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ public class PicassoCache implements Cache {
|
||||||
private final int CACHE_SIZE;
|
private final int CACHE_SIZE;
|
||||||
private final File cachePath;
|
private final File cachePath;
|
||||||
private final HashMap<String, String> cacheMap;
|
private final HashMap<String, String> cacheMap;
|
||||||
private final Context ctx;
|
|
||||||
|
|
||||||
public PicassoCache(File cachePath, Context ctx) throws IOException, ClassNotFoundException {
|
public PicassoCache(File cachePath, Context ctx) throws IOException, ClassNotFoundException {
|
||||||
|
|
||||||
|
@ -41,7 +40,6 @@ public class PicassoCache implements Cache {
|
||||||
* 1024;
|
* 1024;
|
||||||
this.cachePath = cachePath;
|
this.cachePath = cachePath;
|
||||||
cacheMap = new HashMap<>();
|
cacheMap = new HashMap<>();
|
||||||
this.ctx = ctx;
|
|
||||||
|
|
||||||
if (cacheMapExists(cachePath)) {
|
if (cacheMapExists(cachePath)) {
|
||||||
|
|
||||||
|
@ -104,7 +102,8 @@ public class PicassoCache implements Cache {
|
||||||
|
|
||||||
for (String key : cacheMap.keySet()) {
|
for (String key : cacheMap.keySet()) {
|
||||||
|
|
||||||
currentSize += new File(cachePath, Objects.requireNonNull(cacheMap.get(key))).length();
|
currentSize +=
|
||||||
|
(int) new File(cachePath, Objects.requireNonNull(cacheMap.get(key))).length();
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentSize;
|
return currentSize;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package org.mian.gitnex.helpers;
|
package org.mian.gitnex.helpers;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author M M Arif
|
* @author M M Arif
|
||||||
|
@ -14,7 +16,7 @@ public class UrlHelper {
|
||||||
try {
|
try {
|
||||||
uri = new URI(url);
|
uri = new URI(url);
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
e.printStackTrace();
|
Log.e("UrlHelper", Objects.requireNonNull(e.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert uri != null;
|
assert uri != null;
|
||||||
|
|
|
@ -28,8 +28,8 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* valid return true if string is a valid version
|
* valid return true if string is a valid version
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value String
|
||||||
* @return
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public static boolean valid(String value) {
|
public static boolean valid(String value) {
|
||||||
|
|
||||||
|
@ -37,15 +37,13 @@ public class Version {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Pattern patternValid =
|
final Pattern patternValid =
|
||||||
Pattern.compile("^[vV]?(\\d+)+(\\.(\\d+))*([_\\-+][\\w\\-+\\.]*)?$");
|
Pattern.compile("^[vV]?(\\d+)+(\\.(\\d+))*([_\\-+][\\w\\-+.]*)?$");
|
||||||
return value.equals("main") || patternValid.matcher(value).find();
|
return value.equals("main") || patternValid.matcher(value).find();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init parse and store values for other functions of an Version instance it use the raw
|
* init parse and store values for other functions of an Version instance it use the raw
|
||||||
* variable as base
|
* variable as base
|
||||||
*
|
|
||||||
* @return if parse was successfully
|
|
||||||
*/
|
*/
|
||||||
private void init() {
|
private void init() {
|
||||||
|
|
||||||
|
@ -84,7 +82,7 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* equal return true if version is the same
|
* equal return true if version is the same
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value String
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean equal(String value) {
|
public boolean equal(String value) {
|
||||||
|
@ -95,8 +93,8 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* equal return true if version is the same
|
* equal return true if version is the same
|
||||||
*
|
*
|
||||||
* @param v
|
* @param v Version
|
||||||
* @return
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean equal(@NonNull Version v) {
|
public boolean equal(@NonNull Version v) {
|
||||||
|
|
||||||
|
@ -116,7 +114,7 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* less return true if version is less
|
* less return true if version is less
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value String
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean less(String value) {
|
public boolean less(String value) {
|
||||||
|
@ -127,8 +125,8 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* less return true if version is less
|
* less return true if version is less
|
||||||
*
|
*
|
||||||
* @param v
|
* @param v Version
|
||||||
* @return
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean less(@NonNull Version v) {
|
public boolean less(@NonNull Version v) {
|
||||||
|
|
||||||
|
@ -138,7 +136,7 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* higher return true if version is higher
|
* higher return true if version is higher
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value String
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean higher(String value) {
|
public boolean higher(String value) {
|
||||||
|
@ -149,8 +147,8 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* higher return true if version is higher
|
* higher return true if version is higher
|
||||||
*
|
*
|
||||||
* @param v
|
* @param v Version
|
||||||
* @return
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean higher(@NonNull Version v) {
|
public boolean higher(@NonNull Version v) {
|
||||||
|
|
||||||
|
@ -180,7 +178,7 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* lessOrEqual return true if version is less or equal
|
* lessOrEqual return true if version is less or equal
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value String
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean lessOrEqual(String value) {
|
public boolean lessOrEqual(String value) {
|
||||||
|
@ -191,8 +189,8 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* lessOrEqual return true if version is less or equal
|
* lessOrEqual return true if version is less or equal
|
||||||
*
|
*
|
||||||
* @param v
|
* @param v Version
|
||||||
* @return
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean lessOrEqual(@NonNull Version v) {
|
public boolean lessOrEqual(@NonNull Version v) {
|
||||||
|
|
||||||
|
@ -202,7 +200,7 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* higherOrEqual return true if version is higher or equal
|
* higherOrEqual return true if version is higher or equal
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value String
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean higherOrEqual(String value) {
|
public boolean higherOrEqual(String value) {
|
||||||
|
@ -213,8 +211,8 @@ public class Version {
|
||||||
/**
|
/**
|
||||||
* higherOrEqual return true if version is higher or equal
|
* higherOrEqual return true if version is higher or equal
|
||||||
*
|
*
|
||||||
* @param v
|
* @param v Version
|
||||||
* @return
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public boolean higherOrEqual(@NonNull Version v) {
|
public boolean higherOrEqual(@NonNull Version v) {
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,12 @@ import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
|
import android.util.Log;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author M M Arif
|
* @author M M Arif
|
||||||
|
@ -22,13 +24,13 @@ public class AttachmentUtils {
|
||||||
new File(
|
new File(
|
||||||
ctx.getFilesDir().getPath() + File.separatorChar + queryName(ctx, uri));
|
ctx.getFilesDir().getPath() + File.separatorChar + queryName(ctx, uri));
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
destinationFilename = new File(uri.getPath());
|
destinationFilename = new File(Objects.requireNonNull(uri.getPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (InputStream ins = ctx.getContentResolver().openInputStream(uri)) {
|
try (InputStream ins = ctx.getContentResolver().openInputStream(uri)) {
|
||||||
createFileFromStream(ins, destinationFilename);
|
createFileFromStream(ins, destinationFilename);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
Log.e("AttachmentUtils", Objects.requireNonNull(ex.getMessage()));
|
||||||
}
|
}
|
||||||
return destinationFilename;
|
return destinationFilename;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +56,7 @@ public class AttachmentUtils {
|
||||||
}
|
}
|
||||||
os.flush();
|
os.flush();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
Log.e("AttachmentUtils", Objects.requireNonNull(ex.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.text.Layout;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author AmrDeveloper
|
* @author AmrDeveloper
|
||||||
|
@ -18,7 +19,7 @@ public class SourcePositionListener {
|
||||||
new View.AccessibilityDelegate() {
|
new View.AccessibilityDelegate() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendAccessibilityEvent(View host, int eventType) {
|
public void sendAccessibilityEvent(@NonNull View host, int eventType) {
|
||||||
super.sendAccessibilityEvent(host, eventType);
|
super.sendAccessibilityEvent(host, eventType);
|
||||||
if (eventType == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED
|
if (eventType == AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED
|
||||||
&& onPositionChanged != null) {
|
&& onPositionChanged != null) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class LanguageStatisticsBar extends androidx.appcompat.widget.AppCompatSe
|
||||||
|
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
|
|
||||||
if (progressItemsList.size() > 0) {
|
if (!progressItemsList.isEmpty()) {
|
||||||
|
|
||||||
int progressBarWidth = getWidth();
|
int progressBarWidth = getWidth();
|
||||||
int progressBarHeight = getHeight();
|
int progressBarHeight = getHeight();
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class AdminGetUsersViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class DashboardViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class IssueCommentsViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class IssuesViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class MembersByOrgViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<User>> call, Throwable t) {
|
public void onFailure(@NonNull Call<List<User>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class MilestonesViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class OrganizationsViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class RepoWatchersViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<List<User>> call, Throwable t) {
|
public void onFailure(@NonNull Call<List<User>> call, @NonNull Throwable t) {
|
||||||
|
|
||||||
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ public class RepositoriesViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class RepositoryForksViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class WikiViewModel extends ViewModel {
|
||||||
assert list != null;
|
assert list != null;
|
||||||
assert response.body() != null;
|
assert response.body() != null;
|
||||||
|
|
||||||
if (response.body().size() != 0) {
|
if (!response.body().isEmpty()) {
|
||||||
list.addAll(response.body());
|
list.addAll(response.body());
|
||||||
adapter.updateList(list);
|
adapter.updateList(list);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.gitnex.tea4j.v2.models.Reaction;
|
import org.gitnex.tea4j.v2.models.Reaction;
|
||||||
import org.gitnex.tea4j.v2.models.User;
|
import org.gitnex.tea4j.v2.models.User;
|
||||||
|
@ -108,8 +109,9 @@ public class ReactionList extends HorizontalScrollView {
|
||||||
|
|
||||||
if (sortedReactions.containsKey(
|
if (sortedReactions.containsKey(
|
||||||
issueReaction.getContent())) {
|
issueReaction.getContent())) {
|
||||||
sortedReactions
|
Objects.requireNonNull(
|
||||||
.get(issueReaction.getContent())
|
sortedReactions.get(
|
||||||
|
issueReaction.getContent()))
|
||||||
.add(issueReaction);
|
.add(issueReaction);
|
||||||
} else {
|
} else {
|
||||||
List<Reaction> issueReactions = new ArrayList<>();
|
List<Reaction> issueReactions = new ArrayList<>();
|
||||||
|
@ -135,6 +137,7 @@ public class ReactionList extends HorizontalScrollView {
|
||||||
this,
|
this,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
assert issueReactions != null;
|
||||||
for (Reaction issueReaction : issueReactions) {
|
for (Reaction issueReaction : issueReactions) {
|
||||||
if (issueReaction
|
if (issueReaction
|
||||||
.getUser()
|
.getUser()
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class SyntaxHighlightedArea extends LinearLayout {
|
||||||
|
|
||||||
public void setContent(@NonNull String source, @NonNull String extension) {
|
public void setContent(@NonNull String source, @NonNull String extension) {
|
||||||
|
|
||||||
if (source.length() > 0) {
|
if (!source.isEmpty()) {
|
||||||
|
|
||||||
Thread highlightingThread =
|
Thread highlightingThread =
|
||||||
new Thread(
|
new Thread(
|
||||||
|
|
Loading…
Reference in New Issue