1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-24 21:32:07 +01:00

Update opoc

This commit is contained in:
Gregor Santner 2018-05-21 14:57:41 +02:00
parent 65ba10712f
commit 957573ea83
12 changed files with 161 additions and 12 deletions

View file

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/gsantner/dandelion.svg?branch=master)](https://travis-ci.org/gsantner/dandelion)
[![Translate - with Stringlate](https://img.shields.io/badge/stringlate-translate-green.svg)](https://lonamiwebs.github.io/stringlate/translate?git=https%3A%2F%2Fgithub.com%2Fgsantner%2Fdandelion.git&mail=gro.xobliam@@rentnasg)
[![Chat - Matrix](https://img.shields.io/badge/chat-on%20matrix-blue.svg)](https://matrix.to/#/#dandelion:matrix.org) [![Chat - FreeNode IRC](https://img.shields.io/badge/chat-on%20irc-blue.svg)](https://kiwiirc.com/client/irc.freenode.net/?nick=dandelion-anon|?##dandelion)
[![Donate Bitcoin](https://img.shields.io/badge/support-project-orange.svg)](https://gsantner.net/supportme/?project=dandelion&source=readme)
[![Donate](https://img.shields.io/badge/donate-appreciation-orange.svg)](https://gsantner.net/supportme/?project=dandelion&source=readme)
[![Donate LiberaPay](https://img.shields.io/badge/donate-liberapay-orange.svg)](https://liberapay.com/gsantner/donate)
# dandelion\*
@ -39,7 +39,7 @@ dandelion\* requires access to the Internet and to external storage to be able t
## Contributions
The project is always open for contributions and accepts pull requests.
The project uses [AOSP Java Code Style](https://source.android.com/source/code-style#follow-field-naming-conventions), with one exception: private members are `_camelCase` instead of `mBigCamel`. You may use Android Studios _auto reformat feature_ before sending a PR. See [gsantner's android contribution guide](https://gsantner.net/android-contribution-guide/?packageid=com.github.dfa.diaspora_android&name=dandelion&web=https://github.com/gsantner/dandelion#logcat) for more information.
The project uses [AOSP Java Code Style](https://source.android.com/source/code-style#follow-field-naming-conventions), with one exception: private members are `_camelCase` instead of `mBigCamel`. You may use Android Studios _auto reformat feature_ before sending a PR. See [gsantner's android contribution guide](https://gsantner.net/android-contribution-guide/?packageid=com.github.dfa.diaspora_android&name=dandelion&web=https://github.com/gsantner/dandelion&source=readme#logcat) for more information.
Translations can be contributed on GitHub or via [E-Mail](https://gsantner.net/#contact). You can use Stringlate ([![Translate - with Stringlate](https://img.shields.io/badge/stringlate-translate-green.svg)](https://lonamiwebs.github.io/stringlate/translate?git=https%3A%2F%2Fgithub.com%2Fgsantner%2Fdandelion.git)) to translate the project directly on your Android phone. It allows you to export as E-Mail attachement and to post on GitHub.
@ -79,6 +79,6 @@ For more licensing informations, see [`3rd party licenses`](/app/src/main/res/ra
### Notice
#### Maintainers
- gsantner ([GitHub](https://github.com/gsantner), [Web](https://gsantner.net/supportme/?project=dandelion&source=readme), [diaspora*](https://pod.geraspora.de/people/d1cbdd70095301341e834860008dbc6c))
- Bitcoin: [1B9ZyYdQoY9BxMe9dRUEKaZbJWsbQqfXU5](https://gsantner.net/donate/#donate)
- Bitcoin: [1B9ZyYdQoY9BxMe9dRUEKaZbJWsbQqfXU5](https://gsantner.net/supportme/?project=dandelion&source=readme)
- vanitasvitae ([GitHub](https://github.com/vanitasvitae), [diaspora*](https://pod.geraspora.de/people/bbd7af90fbec013213e34860008dbc6c))
- Bitcoin: 1Ao3W6NaQv3xKppviB7RSFKjHo6PGd8RTy

View file

@ -13,7 +13,7 @@ import java.util.List;
/**
* Created by gsantner (http://gsantner.net/ on 30.09.16.
* Created by gsantner (https://gsantner.net/ on 30.09.16.
* DiasporaPodList - List container for DiasporaPod's, with methods to merge with other DiasporaPodLists
* DiasporaPod - Data container for a Pod, can include N DiasporaPodUrl's
* DiasporaPodUrl - A Url of an DiasporaPod

View file

@ -32,7 +32,7 @@ import org.json.JSONObject;
/**
* User profile
* Created by gsantner (http://gsantner.net/) on 24.03.16. Part of dandelion*.
* Created by gsantner (https://gsantner.net/) on 24.03.16. Part of dandelion*.
*/
public class DiasporaUserProfile {
private static final int MINIMUM_USERPROFILE_LOAD_TIMEDIFF = 5000;

View file

@ -21,7 +21,7 @@ package com.github.dfa.diaspora_android.listener;
import com.github.dfa.diaspora_android.data.DiasporaUserProfile;
/**
* Created by gsantner (http://gsantner.net/) on 26.03.16.
* Created by gsantner (https://gsantner.net/) on 26.03.16.
* Interface that needs to be implemented by classes that listen for Profile related changes
*/
public interface DiasporaUserProfileChangedListener {

View file

@ -37,7 +37,7 @@ import java.util.List;
/**
* Settings
* Created by gsantner (http://gsantner.net/) on 20.03.16. Part of dandelion*.
* Created by gsantner (https://gsantner.net/) on 20.03.16. Part of dandelion*.
*/
@SuppressWarnings("ConstantConditions")
public class AppSettings extends SharedPreferencesPropertyBackend {

View file

@ -45,5 +45,4 @@ public interface PropertyBackend<TKEY, TTHIS> {
TTHIS setIntList(TKEY key, List<Integer> value);
TTHIS setStringList(TKEY key, List<String> value);
}

View file

@ -136,6 +136,22 @@ public class SharedPreferencesPropertyBackend implements PropertyBackend<String,
return (pref != null && pref.length > 0 ? pref[0] : _prefApp);
}
public static void limitListTo(final List<?> list, int maxSize, boolean removeDuplicates) {
Object o;
int pos;
for (int i = 0; removeDuplicates && i < list.size(); i++) {
o = list.get(i);
while ((pos = list.lastIndexOf(o)) != i && pos >= 0) {
list.remove(pos);
}
}
while ((pos = list.size()) > maxSize && pos > 0) {
list.remove(list.size() - 1);
}
}
//
// Getter for resources
//

View file

@ -18,6 +18,7 @@ import android.net.Uri;
import android.os.Build;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatTextView;
import android.text.Html;
@ -163,4 +164,14 @@ public class ActivityUtils extends net.gsantner.opoc.util.ContextUtils {
Uri.parse("http://play.google.com/store/apps/" + pkgId)));
}
}
public void setStatusbarColor(int color, boolean... fromRes) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (fromRes != null && fromRes.length > 0 && fromRes[0]) {
color = ContextCompat.getColor(_context, color);
}
_activity.getWindow().setStatusBarColor(color);
}
}
}

View file

@ -20,15 +20,19 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
@SuppressWarnings({"WeakerAccess", "unused", "SameParameterValue", "SpellCheckingInspection", "deprecation"})
@ -36,6 +40,15 @@ public class FileUtils {
// Used on methods like copyFile(src, dst)
private static final int BUFFER_SIZE = 4096;
public static String readTextFileFast(final File file) {
try {
return new String(readCloseBinaryStream(new FileInputStream(file)));
} catch (FileNotFoundException e) {
System.err.println("readTextFileFast: File " + file + " not found.");
}
return "";
}
public static String readTextFile(final File file) {
try {
return readCloseTextStream(new FileInputStream(file));
@ -337,4 +350,94 @@ public class FileUtils {
return null;
}
}
/**
* Try to detect MimeType by backwards compatible methods
*/
public static String getMimeType(File file) {
String guess = null;
if (file != null && file.exists() && file.isFile()) {
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(file));
guess = URLConnection.guessContentTypeFromStream(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ignored) {
}
}
}
if (guess == null || guess.isEmpty()) {
guess = "*/*";
int dot = file.getName().lastIndexOf(".") + 1;
if (dot > 0 && dot < file.getName().length()) {
switch (file.getName().substring(dot)) {
case "md":
case "markdown":
case "mkd":
case "mdown":
case "mkdn":
case "mdwn":
case "rmd":
guess = "text/markdown";
break;
case "txt":
guess = "text/plain";
break;
}
}
}
}
return guess;
}
public static boolean isTextFile(File file) {
return getMimeType(file).startsWith("text/");
}
/**
* Analyze given textfile and retrieve multiple information from it
* Information is written back to the {@link AtomicInteger} parameters
*/
public static void retrieveTextFileSummary(File file, AtomicInteger numCharacters, AtomicInteger numLines) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
numLines.getAndIncrement();
numCharacters.getAndSet(numCharacters.get() + line.length());
}
} catch (Exception e) {
e.printStackTrace();
numCharacters.set(-1);
numLines.set(-1);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException ignored) {
}
}
}
}
/**
* Format filesize to human readable format
* Get size in bytes e.g. from {@link File} using {@code File#length()}
*/
public static String getReadableFileSize(long size, boolean abbreviation) {
if (size <= 0) {
return "0B";
}
String[] units = abbreviation ? new String[]{"B", "kB", "MB", "GB", "TB"} : new String[]{"Bytes", "Kilobytes", "Megabytes", "Gigabytes", "Terabytes"};
int unit = (int) (Math.log10(size) / Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, unit))
+ " " + units[unit];
}
}

View file

@ -182,6 +182,22 @@ public class ShareUtil {
showChooser(intent, null);
}
/**
* Open a View intent for given file
*
* @param file The file to share
*/
public void viewFileInOtherApp(File file, @Nullable String type) {
Uri fileUri = FileProvider.getUriForFile(_context, getFileProviderAuthority(), file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_STREAM, fileUri);
intent.setData(fileUri);
intent.putExtra(EXTRA_FILEPATH, file.getAbsolutePath());
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(fileUri, type);
showChooser(intent, null);
}
/**
* Share the given bitmap with given format
*
@ -397,7 +413,7 @@ public class ShareUtil {
String tmps;
String fileStr;
if ((Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action))) {
if ((Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)) || Intent.ACTION_SEND.equals(action)) {
// Markor, S.M.T FileManager
if (receivingIntent.hasExtra((tmps = EXTRA_FILEPATH))) {
return new File(receivingIntent.getStringExtra(tmps));
@ -450,6 +466,10 @@ public class ShareUtil {
}
}
}
fileUri = receivingIntent.getParcelableExtra(Intent.EXTRA_STREAM);
if (fileUri != null && !TextUtils.isEmpty(tmps = fileUri.getPath()) && tmps.startsWith("/") && (tmpf = new File(tmps)).exists()) {
return tmpf;
}
}
return null;
}

View file

@ -17,7 +17,7 @@ buildscript {
// https://github.com/guardianproject/NetCipher/releases
ext.version_library_netcipher = "2.0.0-alpha1"
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin#LookAtCentral
ext.version_plugin_kotlin = "1.2.41"
ext.version_plugin_kotlin = "1.2.21"
ext.enable_plugin_kotlin = false
repositories {

View file

@ -14,5 +14,5 @@ It adds useful features to your networking experience:
✋ <a href="https://lonamiwebs.github.io/stringlate/translate?git=https%3A%2F%2Fgithub.com%2Fgsantner%2Fdandelion.git&mail=gro.xobliam@@rentnasg">Translate using Stringlate</a>
✋ <a href="https://matrix.to/#/#dandelion:matrix.org">Join discussion on Matrix</a>
✋ <a href="https://github.com/gsantner/dandelion#contributions">More information about contributions</a>
✋ <a href="https://gsantner.net/android-contribution-guide/?packageid=com.github.dfa.diaspora_android&name=dandelion&web=https://github.com/gsantner/dandelion">Android Contribution Guide (gsantner blog)</a>
✋ <a href="http://gsantner.net/supportme?ref=dandelion&source=fdroid">Support main developer</a>
✋ <a href="https://gsantner.net/android-contribution-guide/?packageid=com.github.dfa.diaspora_android&name=dandelion&web=https://github.com/gsantner/dandelion&source=fdroid">Android Contribution Guide (gsantner blog)</a>
✋ <a href="https://gsantner.net/supportme?project=dandelion&source=fdroid">Support main developer</a>