Skip to content

Commit

Permalink
Removed showing friend tox ids and blocking as they werent right. Add…
Browse files Browse the repository at this point in the history
…ed an option to resend friend requests. Maybe fixed contacts list not scrolling to the bottom properly
  • Loading branch information
markwinter committed Sep 23, 2014
1 parent 949d7b8 commit 9fcf2cb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,59 +45,26 @@ public void onCreate(Bundle savedInstanceState) {
String friendAlias = friendDetails[1];
String friendNote = friendDetails[2];

setTitle(getResources().getString(R.string.friend_profile_title, friendName));
if(friendAlias.equals(""))
setTitle(getResources().getString(R.string.friend_profile_title, friendName));
else
setTitle(getResources().getString(R.string.friend_profile_title, friendAlias));

EditText editFriendAlias = (EditText) findViewById(R.id.friendAliasText);
editFriendAlias.setText(friendAlias);

TextView editFriendNote = (TextView) findViewById(R.id.friendNoteText);
editFriendNote.setText("\""+friendNote+"\"");

TextView editFriendKey = (TextView) findViewById(R.id.friendKeyText);
editFriendKey.setText(friendKey);

/* Looks for the userkey qr.png if it doesn't exist then it creates it with the generateQR method.
* adds onClickListener to the ImageButton to add share the QR
* */
ImageButton qrCode = (ImageButton) findViewById(R.id.qr_code);

File file = new File(Environment.getExternalStorageDirectory().getPath()+"/Antox/");
if(!file.exists()){
file.mkdirs();
}
File noMedia = new File(Environment.getExternalStorageDirectory().getPath()+"/Antox/",".nomedia");
if(!noMedia.exists()){
try {
noMedia.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
file = new File(Environment.getExternalStorageDirectory().getPath()+"/Antox/"+friendName+".png");
generateQR(friendKey);
Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
qrCode.setImageBitmap(bmp);
qrCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath() + "/Antox/"+friendName+".png")));
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_with)));
}
});

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
getSupportActionBar().setIcon(R.drawable.ic_actionbar);
}
}

public void updateAlias(View view) {
AntoxDB db = new AntoxDB(this);
TextView friendKeyText = (TextView) findViewById(R.id.friendKeyText);
EditText friendAlias = (EditText) findViewById(R.id.friendAliasText);
db.updateAlias(friendAlias.getText().toString(), friendKeyText.getText().toString());
db.updateAlias(friendAlias.getText().toString(), friendKey);
db.close();

Context context = getApplicationContext();
Expand All @@ -107,48 +74,6 @@ public void updateAlias(View view) {
toast.show();
}

private void generateQR(String userKey) {
String qrData = "tox:" + userKey;
int qrCodeSize = 400;
QRCodeEncode qrCodeEncoder = new QRCodeEncode(qrData, null,
Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeSize);
FileOutputStream out;
try {
Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
out = new FileOutputStream(Environment.getExternalStorageDirectory().getPath()+"/Antox/"+friendName+".png");
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
} catch (WriterException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
public void copyID(View view)
{
Context context=getApplicationContext();
int sdk = android.os.Build.VERSION.SDK_INT;
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB)
{
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
.getSystemService(context.CLIPBOARD_SERVICE);
clipboard.setText(friendKey);
}
else
{
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
.getSystemService(context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData
.newPlainText("friendKey", friendKey);
clipboard.setPrimaryClip(clip);
}
Toast.makeText(context,context.getResources().getString(R.string.friend_profile_copied),Toast.LENGTH_SHORT).show();

}

@Override
public void onBackPressed() {
super.onBackPressed();
Expand Down
42 changes: 10 additions & 32 deletions app/src/main/java/im/tox/antox/fragments/ContactsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import im.tox.antox.utils.FriendRequest;
import im.tox.antox.utils.LeftPaneItem;
import im.tox.antox.utils.Tuple;
import im.tox.jtoxcore.FriendExistsException;
import im.tox.jtoxcore.ToxException;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
Expand Down Expand Up @@ -201,14 +202,13 @@ public boolean onItemLongClick(AdapterView<?> parent, View itemView, int index,
items = new CharSequence[]{
getResources().getString(R.string.friendrequest_accept),
getResources().getString(R.string.friendrequest_reject),
getResources().getString(R.string.friend_action_block)
};
}else {
} else {
items = new CharSequence[]{
getResources().getString(R.string.friend_action_profile),
getResources().getString(R.string.friend_action_delete),
getResources().getString(R.string.friend_action_delete_chat),
getResources().getString(R.string.friend_action_block)
getResources().getString(R.string.contacts_resend_friend_request)
};
}
builder.setTitle(getResources().getString(R.string.contacts_actions_on) + " " + item.first)
Expand Down Expand Up @@ -265,9 +265,6 @@ protected void onPostExecute(Void result) {

new RejectFriendRequest().execute();

break;
case 2:
showBlockDialog(getActivity(), item.key);
break;
}
} else {
Expand All @@ -287,8 +284,14 @@ protected void onPostExecute(Void result) {
// Delete chat logs
showDeleteChatDialog(getActivity(), key);
break;

case 3:
showBlockDialog(getActivity(), key);
// Resend Friend Request
try {
toxSingleton.jTox.addFriend(key, getResources().getString(R.string.addfriend_default_message));
} catch (ToxException e) {
} catch (FriendExistsException e) {
}
break;
}
}
Expand Down Expand Up @@ -326,31 +329,6 @@ public void afterTextChanged(Editable editable) {
return rootView;
}

public void showBlockDialog(final Context context, String fkey) {
final String key = fkey;
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage(getResources().getString(R.string.friend_action_block_friend_confirmation))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.button_yes),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
AntoxDB dbBlock = new AntoxDB(getActivity());
dbBlock.blockUser(key);
dbBlock.close();
toxSingleton.updateFriendsList(getActivity());
}
})
.setNegativeButton(getResources().getString(R.string.button_no),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
}
}
);
builder.show();
}

public void showDeleteFriendDialog(Context context, String fkey) {
final String key= fkey;
View delete_friend_dialog = View.inflate(context, R.layout.dialog_delete_friend,null);
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/im/tox/antox/fragments/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;

import java.util.Random;

import im.tox.antox.R;
import im.tox.antox.activities.LoginActivity;
import im.tox.antox.data.UserDB;
Expand Down Expand Up @@ -224,12 +226,22 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
if (key.equals("nospam")) {
ToxSingleton toxSingleton = ToxSingleton.getInstance();
try {
int nospam = Integer.parseInt(sharedPreferences.getString("nospam", ""));
String nospamString = sharedPreferences.getString("nospam", "");
int nospam;
// Check if they entered an empty nospam
if (!nospamString.equals("")) {
nospam = Integer.parseInt(sharedPreferences.getString("nospam", ""));
} else {
Random random = new Random();
nospam = random.nextInt(1000);
}

toxSingleton.jTox.setNospam(nospam);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("tox_id", toxSingleton.jTox.getAddress());
editor.commit();
bindPreferenceSummaryToValue(findPreference("tox_id"));

} catch (ToxException e) {
e.printStackTrace();
}
Expand Down
26 changes: 0 additions & 26 deletions app/src/main/res/layout/activity_friend_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,6 @@
android:onClick="updateAlias" />


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/friend_profile_key"
android:layout_marginTop="20dp"
android:id="@+id/friendKey"
android:textSize="20sp"
android:textStyle="bold" />

<TextView
android:id="@+id/friendKeyText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="end"
android:paddingBottom="5dp"
android:singleLine="true"
android:layout_marginLeft="10dp"
android:textIsSelectable="true"
android:textSize="12sp" />

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/qr_code"
android:layout_gravity="center_horizontal" />


</LinearLayout>
</ScrollView>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_contacts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<ListView
android:id="@+id/contacts_list"
android:layout_width="match_parent"
android:layout_height="479dp"
android:layout_height="fill_parent"
android:background="@color/white_absolute"
android:cacheColorHint="@android:color/transparent"
android:headerDividersEnabled="true"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<string name="friend_profile_copied">Tox ID copiat</string>

<!-- Friend request fragment -->
<string name="friend_profile_title">Perfil d\'en/na %1$</string>
<string name="friend_profile_title">Perfil d\'en/na %1$s</string>
<string name="friendrequest_accept">Acceptar</string>
<string name="friendrequest_reject">Rebutjar</string>
<string name="friend_request">Nova petició d\'amistat</string>
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,22 @@
<string name="friend_profile_copied">Tox ID Copied</string>

<!-- Friend request fragment -->
<string name="friend_profile_title">%1$s\' Profile</string>
<string name="friend_profile_title">%1$s\'s Profile</string>
<string name="friendrequest_accept">Accept</string>
<string name="friendrequest_reject">Reject</string>
<string name="friend_request">New Friend Request</string>

<!-- Contacts Fragment -->
<string name="friend_action_profile">Profile</string>
<string name="friend_action_delete">Remove Friend</string>
<string name="friend_action_delete_chat">Delete chat logs</string>
<string name="friend_action_delete_chat">Delete Chat Logs</string>
<string name="friend_action_block">Block</string>
<string name="contacts_actions_on">Actions on</string>
<string name="contacts_delimiter_requests">Requests</string>
<string name="contacts_delimiter_friends">Friends</string>
<string name="contacts_delimiter_offline">Offline</string>
<string name="contacts_delimiter_online">Online</string>
<string name="contacts_resend_friend_request">Resend Friend Request</string>

<!-- Delete Friend Dialog -->
<string name="friend_action_delete_friend_confirmation">Are you sure you want to remove this friend?</string>
Expand Down

0 comments on commit 9fcf2cb

Please sign in to comment.