Commit 4b3ffdf5 authored by axet's avatar axet 🍄

Merge branch 'smsgate-1.9.3'

parents 1356b90d fc42fbb8
Pipeline #35923243 (#169) passed with stage
in 19 seconds
......@@ -8,8 +8,8 @@ android {
applicationId "com.github.axet.smsgate"
minSdkVersion 9
targetSdkVersion 26
versionCode 211
versionName "1.9.2"
versionCode 212
versionName "1.9.3"
}
packagingOptions {
exclude 'META-INF/LICENSE'
......@@ -39,7 +39,7 @@ android {
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.github.axet:android-library:1.27.22' // implementation project(':android-library')
implementation 'com.github.axet:android-library:1.27.24' // implementation project(':android-library')
implementation 'com.android.support:design:25.3.1'
implementation 'com.intellij:annotations:12.0'
implementation 'com.beetstra.jutf7:jutf7:1.0.0'
......
......@@ -67,6 +67,7 @@ public class SMSApplication extends App {
public static final String PREF_FIREBASESETTINGS = "firebase_settings";
public static final String PREF_REBOOT = "reboot";
public static final String PREF_STORAGE = "storage";
public static final String PREF_NAMEFORMAT = "name";
public static final String PREF_APPS = "applications"; // enabled
public static final String APPS_INDEX = "APPS_";
......
......@@ -10,6 +10,7 @@ import android.os.Build;
import android.os.Handler;
import android.support.v7.preference.PreferenceManager;
import android.telephony.PhoneNumberUtils;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
......@@ -35,6 +36,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Locale;
......@@ -156,6 +158,22 @@ public class Storage extends com.github.axet.androidlibrary.app.Storage {
}
}
public static String getFormatted(String f, SMSMessage sms) {
f = f.replaceAll("%D", SIMPLE.format(sms.sent));
f = f.replaceAll("%d", ISO8601.format(sms.sent));
f = f.replaceAll("%t", sms.type.equals("IN") ? "↓" : "↑");
f = f.replaceAll("%P", PhoneNumberUtils.formatNumber(sms.threadPhone));
f = f.replaceAll("%p", sms.threadPhone);
if (!sms.threadName.isEmpty() && !sms.threadPhone.equals(sms.threadName))
f = f.replaceAll("%n", sms.threadName);
else
f = f.replaceAll("%n", "");
f = f.replaceAll("%m", Build.MODEL);
f = f.replaceAll("\\(\\)", "");
f = f.replaceAll(" ", " ");
return f;
}
public static class SMSMessage {
public String id;
public long sent;
......@@ -165,6 +183,17 @@ public class Storage extends com.github.axet.androidlibrary.app.Storage {
public String threadName; // person Full Name
public String message;
public SMSMessage() {
}
public SMSMessage(long s, String type, String phone, String name, String msg) {
this.sent = s;
this.type = type;
this.threadPhone = phone;
this.threadName = name;
this.message = msg;
}
public String toJSON() {
try {
JSONObject j = new JSONObject();
......@@ -316,6 +345,8 @@ public class Storage extends com.github.axet.androidlibrary.app.Storage {
String from = Build.DEVICE;
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
int count = 0;
while (cursors.hasNext()) {
BackupCursors.CursorAndType cursor = cursors.next();
......@@ -324,7 +355,8 @@ public class Storage extends com.github.axet.androidlibrary.app.Storage {
continue;
Map<String, String> map = getMessageMap(cursor.cursor);
SMSMessage sms = messageFromMapSms(mPersonLookup, map);
String name = formatName(sms);
String ff = shared.getString(SMSApplication.PREF_NAMEFORMAT, "%d %t (%m) %p");
String name = getFormatted(ff, sms);
String text = formatBody(from, sms);
Uri uri = getStoragePath();
String s = uri.getScheme();
......@@ -353,6 +385,8 @@ public class Storage extends com.github.axet.androidlibrary.app.Storage {
Toast.Error(context, "unable to write file", e);
return 0;
}
} else {
throw new UnknownUri();
}
if (cursor.type == DataType.SMS)
b.setLastSMS(sms.sent);
......
......@@ -62,6 +62,7 @@ import com.github.axet.smsgate.services.SmsReplyService;
import com.github.axet.androidlibrary.widgets.AdminPreferenceCompat;
import com.github.axet.smsgate.widgets.ApplicationsPreference;
import com.github.axet.smsgate.widgets.DefaultSMSPreferenceCompat;
import com.github.axet.smsgate.widgets.NameFormatPreferenceCompat;
import com.github.axet.smsgate.widgets.RebootPreferenceCompat;
import com.zegoggles.smssync.App;
import com.zegoggles.smssync.Consts;
......@@ -868,4 +869,13 @@ public class SettingsFragment extends PreferenceFragmentCompat implements MainAc
((AdminPreferenceCompat) findPreference(SMSApplication.PREF_ADMIN)).onActivityResult(resultCode, data);
}
}
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (preference instanceof NameFormatPreferenceCompat) {
NameFormatPreferenceCompat.show(this, preference.getKey());
return;
}
super.onDisplayPreferenceDialog(preference);
}
}
package com.github.axet.smsgate.widgets;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.provider.DocumentsContract;
import android.util.AttributeSet;
import com.github.axet.smsgate.app.Storage;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class NameFormatPreferenceCompat extends com.github.axet.androidlibrary.widgets.NameFormatPreferenceCompat {
public NameFormatPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public NameFormatPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public NameFormatPreferenceCompat(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NameFormatPreferenceCompat(Context context) {
super(context);
}
@Override
public void create() {
super.create();
if (!StoragePathPreferenceCompat.isVisible(getContext()))
setVisible(false);
}
@Override
public String getFormatted(String str) {
String n = getPredefined(str);
if (n != null)
return n;
return Storage.getFormatted(str, new Storage.SMSMessage(1493561080000l, "IN", "+1333445566", "Name Contact", "Message text"));
}
}
......@@ -17,6 +17,11 @@ import java.io.File;
public class StoragePathPreferenceCompat extends com.github.axet.androidlibrary.widgets.StoragePathPreferenceCompat {
CharSequence defSummary;
public static boolean isVisible(Context context) {
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
}
public StoragePathPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
......@@ -69,8 +74,7 @@ public class StoragePathPreferenceCompat extends com.github.axet.androidlibrary.
choicer.setTitle(getTitle().toString());
choicer.setContext(getContext());
PackageManager pm = getContext().getPackageManager();
if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY))
if (!isVisible(getContext()))
setVisible(false);
}
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="colorAccent" format="color" />
</resources>
\ No newline at end of file
<string-array name="name_values" translatable="false">
<item formatted="false">%D %t %P (%n)</item>
<item formatted="false">%d %t (%m) %p</item>
</string-array>
</resources>
......@@ -388,4 +388,9 @@
<string name="admin_web_description">Allow user to control following device admin functions using application web interface:</string>
<string name="admin_web_erase">Allow erase ALL data using application web interface.</string>
<string name="admin_web_lock">Allow lock device screen using application web interface.</string>
<string-array name="name_text">
<item>2017-03-14 14.22.11 ↓↑ +1 (222) 333 33 44 (Name Caller).txt</item>
<item>20170314T142211 ↓↑ (Nexus 5) +12223333344.txt</item>
</string-array>
</resources>
......@@ -221,6 +221,14 @@
</PreferenceScreen>
</PreferenceScreen>
</PreferenceScreen>
<com.github.axet.smsgate.widgets.NameFormatPreferenceCompat
android:defaultValue="%d %t (%m) %p"
android:entries="@array/name_text"
android:entryValues="@array/name_values"
android:key="name"
android:summary=""
android:title="SMS Storage format" />
</PreferenceCategory>
<PreferenceCategory android:title="Application">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment