Skip to content
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.

Commit

Permalink
set or unset app name, remove or change timestamp/dateformat.
Browse files Browse the repository at this point in the history
  • Loading branch information
jochen@homeland committed Feb 16, 2019
1 parent 2225b17 commit 1e7a7a5
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
minSdkVersion 19
// upload alias
targetSdkVersion 22
versionCode 81
versionName "0.81"
versionCode 82
versionName "0.82"
}
buildTypes {
release {
Expand Down
Binary file modified app/release/click.dummer.notify_to_jabber.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":81,"versionName":"0.81","enabled":true,"outputFile":"click.dummer.notify_to_jabber.apk","fullName":"release","baseName":"release"},"path":"click.dummer.notify_to_jabber.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":82,"versionName":"0.82","enabled":true,"outputFile":"click.dummer.notify_to_jabber.apk","fullName":"release","baseName":"release"},"path":"click.dummer.notify_to_jabber.apk","properties":{}}]
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<!-- uses-permission android:name="android.permission.SEND_SMS" / -->

<application
android:allowBackup="true"
Expand Down
79 changes: 79 additions & 0 deletions app/src/main/java/click/dummer/notify_to_jabber/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class MainActivity extends AppCompatActivity {
private NotificationReceiver nReceiver;
private SharedPreferences mPreferences;

private Menu optionsmenu;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -144,9 +146,43 @@ protected void onPause() {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options, menu);
optionsmenu = menu;
return true;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
optionsmenu.findItem(R.id.action_sourcename).setChecked(mPreferences.getBoolean("with_source", true));

int timetype = mPreferences.getInt("with_time", 0);
switch (timetype) {
case 1:
optionsmenu.findItem(R.id.action_time).setChecked(true);
optionsmenu.findItem(R.id.action_time1).setChecked(true);
optionsmenu.setGroupEnabled(R.id.timeoptions, true);
break;
case 2:
optionsmenu.findItem(R.id.action_time).setChecked(true);
optionsmenu.findItem(R.id.action_time2).setChecked(true);
optionsmenu.setGroupEnabled(R.id.timeoptions, true);
break;
case 3:
optionsmenu.findItem(R.id.action_time).setChecked(true);
optionsmenu.findItem(R.id.action_time3).setChecked(true);
optionsmenu.setGroupEnabled(R.id.timeoptions, true);
break;
case 4:
optionsmenu.findItem(R.id.action_time).setChecked(true);
optionsmenu.findItem(R.id.action_time4).setChecked(true);
optionsmenu.setGroupEnabled(R.id.timeoptions, true);
break;
default:
optionsmenu.findItem(R.id.action_time).setChecked(false);
optionsmenu.setGroupEnabled(R.id.timeoptions, false);
}
return super.onPrepareOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
Expand All @@ -155,6 +191,49 @@ public boolean onOptionsItemSelected(MenuItem item) {
Intent intentsmspref = new Intent(MainActivity.this, PreferencesActivity.class);
startActivity(intentsmspref);
return true;
} else if (id == R.id.action_sourcename) {
if (item.isChecked()) {
item.setChecked(false);
mPreferences.edit().putBoolean("with_source", false).apply();
} else {
item.setChecked(true);
mPreferences.edit().putBoolean("with_source", true).apply();
}
} else if (id == R.id.action_time) {
if (item.isChecked()) {
item.setChecked(false);
optionsmenu.setGroupEnabled(R.id.timeoptions, false);
mPreferences.edit().putInt("with_time", 0).apply();
} else {
item.setChecked(true);
optionsmenu.setGroupEnabled(R.id.timeoptions, true);
int timetype = 0;
if (optionsmenu.findItem(R.id.action_time1).isChecked()) timetype=1;
if (optionsmenu.findItem(R.id.action_time2).isChecked()) timetype=2;
if (optionsmenu.findItem(R.id.action_time3).isChecked()) timetype=3;
if (optionsmenu.findItem(R.id.action_time4).isChecked()) timetype=4;
mPreferences.edit().putInt("with_time", timetype).apply();
}
} else if (id == R.id.action_time1) {
if (item.isChecked() == false) {
item.setChecked(true);
mPreferences.edit().putInt("with_time", 1).apply();
}
} else if (id == R.id.action_time2) {
if (item.isChecked() == false) {
item.setChecked(true);
mPreferences.edit().putInt("with_time", 2).apply();
}
} else if (id == R.id.action_time3) {
if (item.isChecked() == false) {
item.setChecked(true);
mPreferences.edit().putInt("with_time", 3).apply();
}
} else if (id == R.id.action_time4) {
if (item.isChecked() == false) {
item.setChecked(true);
mPreferences.edit().putInt("with_time", 4).apply();
}
}
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.Locale;

public class NotificationService extends NotificationListenerService {
public static final String DATETIME_FORMAT = "dd.MM. HH:mm";
//public static final String DATETIME_FORMAT = "dd.MM. HH:mm";
public static final String ACTION_INCOMING_MSG = "click.dummer.notify_to_jabber.INCOMING_MSG";
public static final String ACTION_NEW_FINGERPRINT = "click.dummer.notify_to_jabber.NEW_FINGERPRINT";
private static String TAG = "NotificationService";
Expand Down Expand Up @@ -85,7 +85,7 @@ public void onNotificationRemoved(StatusBarNotification sbn) {

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
SimpleDateFormat formatOut = new SimpleDateFormat(DATETIME_FORMAT, Locale.ENGLISH);
SimpleDateFormat formatOut;
mPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

Notification noti = sbn.getNotification();
Expand Down Expand Up @@ -152,8 +152,28 @@ public void onNotificationPosted(StatusBarNotification sbn) {
Intent i = new Intent(ACTION_INCOMING_MSG);
i.putExtra("notification_event", msg);
sendBroadcast(i);
new SendJabberTask().execute(title, msg, pack, formatOut.format(new Date()));
sendGotify(title, msg, pack, formatOut.format(new Date()));
String time = "";
switch (mPreferences.getInt("with_time", 0)) {
case 1:
formatOut = new SimpleDateFormat("dd.MM. HH:mm:ss", Locale.ENGLISH);
time = formatOut.format(new Date());
break;
case 2:
formatOut = new SimpleDateFormat("dd.MM. HH:mm", Locale.ENGLISH);
time = formatOut.format(new Date());
break;
case 3:
formatOut = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
time = formatOut.format(new Date());
break;
case 4:
time = Long.toString(new Date().getTime());
break;
default:
}
if (mPreferences.getBoolean("with_source", true) == false) pack = "";
new SendJabberTask().execute(title, msg, pack, time);
sendGotify(title, msg, pack, time);
}

private void sendGotify(String... strings) {
Expand Down Expand Up @@ -238,12 +258,20 @@ private void sendGotify(String... strings) {
.build();
}
GotifyMessageService gms = retrofit.create(GotifyMessageService.class);

GotifyMessage gotifyMessage = new GotifyMessage(
4,
pack,
title + ": " + message
);
GotifyMessage gotifyMessage;
if (pack.equals("")) {
gotifyMessage = new GotifyMessage(
4,
title,
message
);
} else {
gotifyMessage = new GotifyMessage(
4,
pack,
title + ": " + message
);
}

Call<GotifyMessage> call = gms.createMessage(appToken, gotifyMessage);
call.execute();
Expand Down Expand Up @@ -292,7 +320,12 @@ protected Void doInBackground(String... strings) {
if (connection.isConnected()) {
ChatManager chatManager = ChatManager.getInstanceFor(connection);
Chat chat = chatManager.createChat(toJID);
chat.sendMessage("["+pack+"] " + time + "\n" + title + ": " + message);
if (!time.equals("")) time = time + "\n";
if (pack.equals("")) {
chat.sendMessage(time + title + ": " + message);
} else {
chat.sendMessage("["+pack+"] " + time + title + ": " + message);
}
//connection.disconnect();
}
} catch (Exception e) {
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/menu/options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
app:showAsAction="never" />
</group>

<group android:checkableBehavior="single" android:enabled="false">
<group
android:id="@+id/timeoptions"
android:checkableBehavior="single"
android:enabled="false">
<item
android:id="@+id/action_time1"
android:checked="false"
Expand All @@ -40,10 +43,12 @@
<item
android:id="@+id/action_blacklist"
android:title="@string/opt_blacklist"
android:visible="false"
app:showAsAction="never" />

<item
android:id="@+id/action_sms"
android:title="@string/settings"
android:visible="false"
app:showAsAction="never" />
</menu>

0 comments on commit 1e7a7a5

Please sign in to comment.