Permalink
Browse files

user can now ignore calls from unsaved contacts

  • Loading branch information...
dakhnod committed Jul 26, 2018
1 parent f4029ac commit 4cc813e6a80705e188357ac100eff421c3992faf
@@ -6,6 +6,7 @@
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
@@ -81,6 +82,14 @@ public void insertContact(Contact c) throws ContactAlreadyAddedException {
c.setId(database.insert(tableName, null, values));
}
public boolean contactSaved(String identifier){
Log.d("SQL", "searching " + identifier);
Cursor c = database.query(this.tableName, new String[]{columnID}, columnIdentifier + "=?", new String[]{identifier}, null, null, null);
boolean has = c.getCount() > 0;
c.close();
return has;
}
public void updateContact(Contact c) {
ContentValues values = new ContentValues(5);
values.put(columnIP, c.getAddress());
@@ -1,12 +1,11 @@
package d.d.meshenger;
import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.content.SharedPreferences;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -52,6 +51,8 @@
private RTCCall currentCall = null;
private boolean ignoreUnsaved;
@Override
public void onCreate() {
log("onCreate()");
@@ -108,7 +109,9 @@ private void initNetwork() throws IOException {
private void refreshContacts() {
contacts = (ArrayList<Contact>) sqlHelper.getContacts();
userName = getSharedPreferences(getPackageName(), MODE_PRIVATE).getString("username", "Unknown");
SharedPreferences pregs = getSharedPreferences(getPackageName(), MODE_PRIVATE);
userName = pregs.getString("username", "Unknown");
ignoreUnsaved = pregs.getBoolean("ignoreUnsaved", false);
}
private void mainLoop() throws IOException {
@@ -148,6 +151,10 @@ private void handleClient(Socket client) {
//TODO
this.currentCall = new RTCCall(client, this, request.getString("offer"));
if(ignoreUnsaved && !sqlHelper.contactSaved(identifier)){
currentCall.decline();
continue;
};
Intent intent = new Intent(this, CallActivity.class);
intent.setAction("ACTION_ACCEPT_CALL");
intent.putExtra("EXTRA_USERNAME", request.getString("username"));
@@ -492,6 +499,12 @@ public void onReceive(Context context, Intent intent) {
switch (subject) {
case "username": {
userName = intent.getStringExtra("username");
Log.d("Service", "username: " + userName);
break;
}
case "ignoreUnsaved":{
ignoreUnsaved = intent.getBooleanExtra("ignoreUnsaved", false);
Log.d("Service", "ignore: " + ignoreUnsaved);
break;
}
}
@@ -82,6 +82,7 @@ public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringSt
if (iceGatheringState == PeerConnection.IceGatheringState.COMPLETE) {
log("transferring offer...");
try {
//TODO
commSocket = new Socket(target.getAddress().replace("%zone", "%wlan0"), MainService.serverPort);
OutputStream os = commSocket.getOutputStream();
reportStateChange(CallState.CONNECTING);
@@ -442,7 +443,10 @@ public void cleanup(){
public void hangUp() {
new Thread(() -> {
try {
if(commSocket != null) commSocket.close();
if(commSocket != null){
commSocket.getOutputStream().write("{\"action\":\"dismissed\"}\n".getBytes());
commSocket.close();
}
if(connection != null) connection.close();
reportStateChange(CallState.ENDED);
@@ -4,10 +4,14 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.util.ObjectsCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
@@ -32,6 +36,15 @@ protected void onCreate(Bundle savedInstanceState) {
nick = prefs.getString("username", "undefined");
findViewById(R.id.changeNickLayout).setOnClickListener((v) -> changeNick());
CheckBox ignoreCB = findViewById(R.id.checkBoxIgnoreUnsaved);
ignoreCB.setChecked(prefs.getBoolean("ignoreUnsaved", false));
ignoreCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
prefs.edit().putBoolean("ignoreUnsaved", b).apply();
syncSettings("ignoreUnsaved", b);
}
});
}
private void getLocale(){
@@ -80,12 +93,25 @@ private void changeNick(){
.setPositiveButton("ok", (dialogInterface, i) -> {
nick = et.getText().toString();
prefs.edit().putString("username", nick).apply();
syncSettings("username", nick);
initViews();
})
.setNegativeButton(getResources().getText(R.string.cancel), null)
.show();
}
private void syncSettings(String what, boolean content){
Intent intent = new Intent("settings_changed");
intent.putExtra("subject", what);
intent.putExtra(what, content);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
private void syncSettings(String what, String content){
Intent intent = new Intent("settings_changed");
intent.putExtra(what, content);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
@Override
protected void onResume() {
super.onResume();
@@ -57,6 +57,28 @@
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings_ignore_unsaved"
android:textColor="@android:color/black"
android:textSize="25dp"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:id="@+id/checkBoxIgnoreUnsaved"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
@@ -23,4 +23,5 @@
<string name="contact_edit">Kontakt bearbeiten</string>
<string name="permission_mic">Dafür muss die App auf das Mikro zugreifen können.</string>
<string name="hello">Hallo!</string>
<string name="settings_ignore_unsaved">Ungespeicherte ignorieren</string>
</resources>
@@ -23,4 +23,5 @@
<string name="contact_edit">Edit contact</string>
<string name="permission_mic">Microphone permission needed to make calls</string>
<string name="hello">Hello!</string>
<string name="settings_ignore_unsaved">Ignore unsaved</string>
</resources>
@@ -26,4 +26,5 @@
<string name="contact_edit">Edit contact</string>
<string name="permission_mic">Microphone permission needed to make calls</string>
<string name="hello">Hello!</string>
<string name="settings_ignore_unsaved">Ignore unsaved</string>
</resources>

1 comment on commit 4cc813e

@mwarning

This comment has been minimized.

Show comment
Hide comment
@mwarning

mwarning Jul 26, 2018

Contributor

thanks!!

Contributor

mwarning commented on 4cc813e Jul 26, 2018

thanks!!

Please sign in to comment.