mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
clean
This commit is contained in:
parent
809ef0b6bc
commit
94913a334c
@ -194,7 +194,7 @@ import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.PushCharacterCalculator;
|
||||
import org.session.libsession.utilities.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.Util; // Cannot be modified
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import org.session.libsession.messaging.sending_receiving.contacts.Contact;
|
||||
import org.session.libsession.messaging.sending_receiving.linkpreview.LinkPreview;
|
||||
@ -466,7 +466,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Util.isEmpty(composeText) || attachmentManager.isAttachmentPresent()) {
|
||||
if (!org.thoughtcrime.securesms.util.Util.isEmpty(composeText) || attachmentManager.isAttachmentPresent()) {
|
||||
saveDraft();
|
||||
attachmentManager.clear(glideRequests, false);
|
||||
silentlySetComposeText("");
|
||||
@ -1371,7 +1371,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
new AsyncTask<Void, Void, Boolean>() {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
return Util.isMmsCapable(ConversationActivity.this);
|
||||
return org.thoughtcrime.securesms.util.Util.isMmsCapable(ConversationActivity.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1723,7 +1723,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private Drafts getDraftsForCurrentState() {
|
||||
Drafts drafts = new Drafts();
|
||||
|
||||
if (!Util.isEmpty(composeText)) {
|
||||
if (!org.thoughtcrime.securesms.util.Util.isEmpty(composeText)) {
|
||||
drafts.add(new Draft(Draft.TEXT, composeText.getTextTrimmed()));
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ import network.loki.messenger.R;
|
||||
import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.logsubmit.util.Scrubber;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.utilities.Util;
|
||||
import org.session.libsession.utilities.task.ProgressDialogAsyncTask;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -507,7 +507,7 @@ public class SubmitLogFragment extends Fragment {
|
||||
.append(" ")
|
||||
.append(pm.getPackageInfo(context.getPackageName(), 0).versionName)
|
||||
.append(" (")
|
||||
.append(Util.getManifestApkVersion(context))
|
||||
.append(org.thoughtcrime.securesms.util.Util.getManifestApkVersion(context))
|
||||
.append(")\n");
|
||||
} catch (PackageManager.NameNotFoundException nnfe) {
|
||||
builder.append("Unknown\n");
|
||||
|
@ -44,81 +44,10 @@ import network.loki.messenger.BuildConfig;
|
||||
|
||||
public class Util {
|
||||
|
||||
private static volatile Handler handler;
|
||||
|
||||
public static String join(String[] list, String delimiter) {
|
||||
return join(Arrays.asList(list), delimiter);
|
||||
}
|
||||
|
||||
public static String join(Collection<String> list, String delimiter) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
int i = 0;
|
||||
|
||||
for (String item : list) {
|
||||
result.append(item);
|
||||
|
||||
if (++i < list.size())
|
||||
result.append(delimiter);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static boolean isEmpty(ComposeText value) {
|
||||
return value == null || value.getText() == null || TextUtils.isEmpty(value.getTextTrimmed());
|
||||
}
|
||||
|
||||
public static boolean isEmpty(Collection collection) {
|
||||
return collection == null || collection.isEmpty();
|
||||
}
|
||||
|
||||
public static <E> List<List<E>> chunk(@NonNull List<E> list, int chunkSize) {
|
||||
List<List<E>> chunks = new ArrayList<>(list.size() / chunkSize);
|
||||
|
||||
for (int i = 0; i < list.size(); i += chunkSize) {
|
||||
List<E> chunk = list.subList(i, Math.min(list.size(), i + chunkSize));
|
||||
chunks.add(chunk);
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public static boolean isOwnNumber(Context context, Address address) {
|
||||
if (address.isGroup()) return false;
|
||||
|
||||
return TextSecurePreferences.getLocalNumber(context).equals(address.serialize());
|
||||
}
|
||||
|
||||
public static byte[] readFully(InputStream in) throws IOException {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[4096];
|
||||
int read;
|
||||
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
bout.write(buffer, 0, read);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
return bout.toByteArray();
|
||||
}
|
||||
|
||||
public static String readFullyAsString(InputStream in) throws IOException {
|
||||
return new String(readFully(in));
|
||||
}
|
||||
|
||||
public static <T> List<List<T>> partition(List<T> list, int partitionSize) {
|
||||
List<List<T>> results = new LinkedList<>();
|
||||
|
||||
for (int index=0;index<list.size();index+=partitionSize) {
|
||||
int subListSize = Math.min(partitionSize, list.size() - index);
|
||||
|
||||
results.add(list.subList(index, index + subListSize));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* The app version.
|
||||
* <p>
|
||||
@ -148,24 +77,4 @@ public class Util {
|
||||
public static boolean isMmsCapable(Context context) {
|
||||
return (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) || OutgoingLegacyMmsConnection.isConnectionPossible(context);
|
||||
}
|
||||
|
||||
public static boolean isMainThread() {
|
||||
return Looper.myLooper() == Looper.getMainLooper();
|
||||
}
|
||||
|
||||
public static void runOnMain(final @NonNull Runnable runnable) {
|
||||
if (isMainThread()) runnable.run();
|
||||
else getHandler().post(runnable);
|
||||
}
|
||||
|
||||
private static Handler getHandler() {
|
||||
if (handler == null) {
|
||||
synchronized (Util.class) {
|
||||
if (handler == null) {
|
||||
handler = new Handler(Looper.getMainLooper());
|
||||
}
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package org.thoughtcrime.securesms.jobmanager.impl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.session.libsession.messaging.jobs.Data;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.BaseUnitTest;
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -5,6 +5,8 @@ import org.junit.Test;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.session.libsession.utilities.Util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class UtilTest {
|
||||
|
@ -155,6 +155,18 @@ object Util {
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun <E> chunk(list: List<E>, chunkSize: Int): List<List<E>> {
|
||||
val chunks: MutableList<List<E>> = ArrayList(list.size / chunkSize)
|
||||
var i = 0
|
||||
while (i < list.size) {
|
||||
val chunk = list.subList(i, Math.min(list.size, i + chunkSize))
|
||||
chunks.add(chunk)
|
||||
i += chunkSize
|
||||
}
|
||||
return chunks
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun equals(a: Any?, b: Any?): Boolean {
|
||||
return a === b || a != null && a == b
|
||||
|
Loading…
Reference in New Issue
Block a user