Skip to content

Commit

Permalink
Unblock users
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Apr 3, 2014
1 parent 9e55082 commit 7258444
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
3 changes: 0 additions & 3 deletions app/src/main/java/im/tox/antox/activities/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package im.tox.antox.activities;

import android.app.AlertDialog;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
Expand All @@ -25,7 +23,6 @@
import android.support.v7.app.ActionBar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/im/tox/antox/data/AntoxDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,14 @@ public boolean isFriendBlocked(String key) {

public void blockUser(String key) {
SQLiteDatabase db = this.getWritableDatabase();
String query = "UPDATE " + Constants.TABLE_FRIENDS + " SET " + Constants.COLUMN_NAME_ISBLOCKED + "='TRUE' WHERE " + Constants.COLUMN_NAME_KEY + "='" + key + "'";
String query = "UPDATE " + Constants.TABLE_FRIENDS + " SET " + Constants.COLUMN_NAME_ISBLOCKED + "='1' WHERE " + Constants.COLUMN_NAME_KEY + "='" + key + "'";
db.execSQL(query);
db.close();
}

public void unblockUser(String key) {
SQLiteDatabase db = this.getWritableDatabase();
String query = "UPDATE " + Constants.TABLE_FRIENDS + " SET " + Constants.COLUMN_NAME_ISBLOCKED + "='FALSE' WHERE " + Constants.COLUMN_NAME_KEY + "='" + key + "'";
String query = "UPDATE " + Constants.TABLE_FRIENDS + " SET " + Constants.COLUMN_NAME_ISBLOCKED + "='0' WHERE " + Constants.COLUMN_NAME_KEY + "='" + key + "'";
db.execSQL(query);
db.close();
}
Expand Down
52 changes: 39 additions & 13 deletions app/src/main/java/im/tox/antox/fragments/ContactsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -157,18 +156,27 @@ public boolean onItemLongClick(AdapterView<?> parent, View itemView, int index,
boolean isGroupChat=false;
final boolean isFriendRequest = item.viewType==Constants.TYPE_FRIEND_REQUEST;
final CharSequence items[];

SharedPreferences settingsPref = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
final int option = settingsPref.getInt("group_option", 0);

if(isFriendRequest){
items= new CharSequence[]{
getResources().getString(R.string.friendrequest_accept),
getResources().getString(R.string.friendrequest_reject),
getResources().getString(R.string.friend_action_block)
};
}else{
} else if(option == 3) {
items = new CharSequence[] {
getResources().getString(R.string.friend_action_unblock),
getResources().getString(R.string.friend_action_deletechat)
};
} else {
items= new CharSequence[]{
getResources().getString(R.string.friend_action_profile),
getResources().getString(R.string.friend_action_delete),
getResources().getString(R.string.friend_action_deletechat),
getResources().getString(R.string.friend_action_block)
getResources().getString(R.string.friend_action_profile),
getResources().getString(R.string.friend_action_delete),
getResources().getString(R.string.friend_action_deletechat),
getResources().getString(R.string.friend_action_block)
};
}
builder.setTitle(main_act.getString(R.string.contacts_actions_on) + " " + item.first)
Expand Down Expand Up @@ -206,7 +214,31 @@ public void onClick(DialogInterface dialog, int index) {
showBlockDialog(getActivity(),item.first);
break;
}
}else{
} else if(option == 3) {
ArrayList<Friend> tmp = ((MainActivity)getActivity()).friendList;
//Get friend key
String key = "";
for(int i = 0; i < tmp.size(); i++) {
if(item.first.equals(tmp.get(i).friendName)) {
key = tmp.get(i).friendKey;
break;
}
}
switch(index) {
case 0:
AntoxDB db = new AntoxDB(getActivity().getApplicationContext());
db.unblockUser(key);
db.close();
break;
case 1:
AntoxDB db2 = new AntoxDB(getActivity().getApplicationContext());
db2.deleteChat(key);
db2.close();
main_act.updateLeftPane();
clearChat(key);
break;
}
} else {
ArrayList<Friend> tmp = ((MainActivity)getActivity()).friendList;
//Get friend key
String key = "";
Expand Down Expand Up @@ -267,16 +299,10 @@ public void showBlockDialog(Context context, String fkey) {
public void onClick(DialogInterface dialog,
int id) {
AntoxDB db = new AntoxDB(getActivity());
db.deleteChat(key);
db.deleteFriend(key);
db.blockUser(key);
db.close();
clearChat(key);
main_act.updateLeftPane();
Intent intent = new Intent(getActivity(), ToxService.class);
intent.setAction(Constants.DELETE_FRIEND_AND_CHAT);
intent.putExtra("key", key);
getActivity().startService(intent);
}
})
.setNegativeButton(getResources().getString(R.string.button_no),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<string name="friend_action_sendfile">Send File</string>
<string name="friend_action_delete">Remove Friend</string>
<string name="friend_action_block">Block</string>
<string name="friend_action_unblock">Unblock</string>
<string name="group_action_leave">Leave Group</string>
<string name="friend_action_deletechat">Delete Chat Logs</string>
<string name="friend_action_block_confirmation">
Expand Down

1 comment on commit 7258444

@markwinter
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a bug with blocking users where it completely removes them from the friends list, even in 'all' view which should select every user, but they're still in the database.

Please sign in to comment.